

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 行動介面程式庫
<a name="cellular-interface"></a>

**注意**  <a name="out-of-date-message"></a>
此頁面上的內容可能不是up-to-date。如需最新更新，請參閱 [FreeRTOS.org 程式庫頁面。](https://www.freertos.org/Documentation/03-Libraries/01-Library-overview/01-All-libraries)

## 簡介
<a name="freertos-cellular-interface-introduction"></a>

行動介面程式庫實作簡單的統一 [API](https://freertos.github.io/FreeRTOS-Cellular-Interface/v1.3.0/)，可隱藏行動數據機特定 AT 命令的複雜性，並向 C 程式設計人員公開類似通訊端的介面。

大多數行動數據機會實作更多或更少 [3GPP TS v27.007 標準所定義的 AT 命令。](https://portal.3gpp.org/desktopmodules/Specifications/SpecificationDetails.aspx?specificationId=1515)此專案在[可重複使用的常見元件](https://freertos.org/Documentation/api-ref/cellular/cellular_porting_module_guide.html)中提供此類標準 AT 命令的[實作](https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/tree/main/source)。此專案中的三個行動介面程式庫都利用了該常見程式碼。每個數據機的程式庫只會實作廠商特定的 AT 命令，然後公開完整的行動介面程式庫 API。

實作 3GPP TS v27.007 標準的常見元件已依照下列程式碼品質標準撰寫：
+ GNU 複雜性分數不超過 8
+ MISRA C：2012 編碼標準。任何與標準的偏差都會記錄在標有「覆蓋性」的原始程式碼註解中。

## 相依性和要求
<a name="freertos-cellular-interface-dependencies"></a>

行動介面程式庫沒有直接相依性。不過，Ethernet、Wi-Fi 和行動網路無法同時存在於 FreeRTOS 網路堆疊中。開發人員必須選擇其中一個網路介面，才能與 [Secure Sockets 程式庫](https://docs.aws.amazon.com/freertos/latest/userguide/secure-sockets.html)整合。

## 移植
<a name="freertos-cellular-interface-porting"></a>

如需有關將行動介面程式庫移植到平台的資訊，請參閱 *FreeRTOS 移植指南*中的[移植行動介面程式庫](https://docs.aws.amazon.com/freertos/latest/portingguide/freertos-porting-cellular.html)。

## 記憶體使用
<a name="freertos-cellular-interface-memory-use"></a>


****  

| 行動介面程式庫的程式碼大小 （使用 GCC for ARM Cortex-M 產生的範例） | 檔案 | 使用 -O1 最佳化 | 使用 -Os 最佳化 | 
| --- | --- | --- | --- | 
| cellular\$13gpp\$1api.c | 6.3K | 5.7K | 
| cellular\$13gpp\$1urc\$1handler.c | 0.9K | 0.8K | 
| cellular\$1at\$1core.c | 1.4K | 1.2K | 
| cellular\$1common\$1api.c | 0.5K | 0.5K | 
| cellular\$1common.c | 1.6K | 1.4K | 
| cellular\$1pkthandler.c | 1.4K | 1.2K | 
| cellular\$1pktio.c | 1.8K | 1.6K | 
| 預估總計 | 13.9K | 12.4K | 

## 開始使用
<a name="freertos-cellular-interface-getting-started"></a>

### 下載原始程式碼
<a name="freertos-cellular-interface-download-source"></a>

原始程式碼可以下載為 FreeRTOS 程式庫的一部分，也可以單獨下載。

若要使用 HTTPS 從 Github 複製程式庫：

```
git clone https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface.git 
```

使用 SSH：

```
git clone git@github.com:FreeRTOS/FreeRTOS-Cellular-Interface.git 
```

### 資料夾結構
<a name="freertos-cellular-interface-folder-structure"></a>

在此儲存庫的根目錄中，您會看到這些資料夾：
+ `source` ：可重複使用的一般程式碼，可實作 3GPP TS v27.007 定義的標準 AT 命令
+ `doc` ：文件
+ `test` ：單元測試和 cbmc
+ `tools` ：適用於 Coverity 靜態分析和 CMock 的工具

### 設定和建置程式庫
<a name="freertos-cellular-interface-configure"></a>

行動介面程式庫應建置為應用程式的一部分。若要這樣做，您必須提供特定組態。[ FreeRTOS\$1Cellular\$1Interface\$1Windows\$1Simulator](https://github.com/FreeRTOS/FreeRTOS/tree/main/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator) 專案提供如何設定建置[的範例](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/MQTT_Mutual_Auth_Demo_with_BG96/cellular_config.h)。如需詳細資訊，請參閱[行動網路 API 參考](https://freertos.github.io/FreeRTOS-Cellular-Interface/v1.3.0/cellular_config.html)。

如需詳細資訊，請參閱[行動網路介面](https://www.freertos.org/cellular/index.html)頁面。

## 將行動介面程式庫與 MCU 平台整合
<a name="freertos-cellular-interface-integrate"></a>

行動介面程式庫使用抽象介面 [Comm Interface](https://github.com/FreeRTOS/FreeRTOS-Cellular-Interface/blob/main/source/interface/cellular_comm_interface.h) 在 MCUs 上執行，以與行動數據機通訊。通訊介面也必須在 MCU 平台上實作。通訊介面最常見的實作會透過 UART 硬體進行通訊，但也可以透過其他實體介面進行實作，例如 SPI。您可以在[行動網路程式庫 API 參考](https://freertos.github.io/FreeRTOS-Cellular-Interface/v1.3.0/cellular_porting.html#cellular_porting_comm_if)中找到通訊介面的文件。通訊介面提供下列範例實作：
+ [ FreeRTOS Windows 模擬器通訊介面](https://github.com/FreeRTOS/FreeRTOS/blob/main/FreeRTOS-Plus/Demo/FreeRTOS_Cellular_Interface_Windows_Simulator/Common/comm_if_windows.c)
+ [ FreeRTOS 通用 IO UART 通訊介面](https://github.com/aws/amazon-freertos/blob/main/libraries/abstractions/common_io/include/iot_uart.h)
+ [ STM32 L475 探索板通訊介面](https://github.com/aws/amazon-freertos/blob/feature/cellular/vendors/st/boards/stm32l475_discovery/ports/comm_if/comm_if_uart.c)
+ [ Sierra Sensor Hub 主機板通訊介面](https://github.com/aws/amazon-freertos/blob/feature/cellular/vendors/sierra/boards/sensorhub/ports/comm_if/comm_if_sierra.c)