下载 FreeRTOS
 

出色的 RTOS & 嵌入式软件

最新资讯
简化任何设备的身份验证云连接。
利用 CoAP 设计节能型云连接 IoT 解决方案。
11.0.0 版 FreeRTOS 内核简介:
FreeRTOS 路线图和代码贡献流程。
使用 FreeRTOS 实现 OPC-UA over TSN。

MCUBoot 移植 API 引用

通过实现以下移植函数,可将 Bootloader 移植到其他硬件上。 移植 API 位于 lib/mcuboot/boot/freertos/include/port 中。请注意, flash_map_backend.h 的实现特定于 MCUBoot, 可点击此处查看相关文档。

Bootloader 移植 API

断言

/* Passed file name, line number, and function name of triggered assertion */
boot_port_assert_handler( const char *pcFile, int lLine, const char * pcFunc  );

此函数定义了 MCUBOOT_HAVE_ASSERT_H 设置为 1 时可执行的断言处理程序 (在 mcuboot_config.h 中进行设置)。

/* Called prior to any heap usage, should the heap require setup */
void  boot_port_heap_init( void );

/* Perform standard malloc/free/realloc responsibilities */
void *boot_port_malloc( size_t size );
void  boot_port_free( void *mem );
void *boot_port_realloc( void *ptr, size_t size );

在演示的默认配置中,并不需要堆。但是,如果将引导加载程序 配置为使用 MBEDTLS,而不是 TinyCrypt ,则上述定义必须实现函数的 标准职责。

日志记录

/* Configure HW so log messages output on choice channel */
void boot_port_log_init( void );

/* Primitive logging function that is built upon in mcuboot_logging.h */
int vLog( const char *pcFormat, ...);

mcuboot_config.h 中将 MCUBOOT_HAVE_LOGGING 设置为 0,可忽略日志记录。 默认情况下,日志记录处于启用状态,也可以将 MCUBOOT_LOG_LEVEL 设置 为 mcuboot_logging.h 中定义的任何级别来修改日志级别。

加载器和其他硬件

/* Called at start of bootloader configuring any extra desired hardware such as watchdog */
void boot_port_init( void );

/* Responsible for loading the application specified in rsp */
void boot_port_startup( struct boot_rsp *rsp );

看门狗 (Watchdog)

/* Feed the watchdog, resetting the watchdog timer */
void boot_port_wdt_feed( void );

/* Disable watchdog */
void boot_port_wdt_disable( void );

看门狗保护为可选,但建议使用。应用程序应禁用引导加载程序看门狗, 以防止其被重置并可能还原。

串行模式移植 API

仅在 MCUBOOT_SERIAL 设置为 1 时 (在 mcuboot_config.h 中),才需要以下移植函数。这些函数可以省略,从而移除与 mcumgr 的接口函数。

UART 接口

/* Initializes UART interface for mcumgr and gpio for serial boot pin */
void boot_port_serial_init( void );

/* Return true if serial boot pin was activated within some timeout */
bool boot_port_serial_detect_boot_pin( void );

/* Returns pointer to static structure with boot_uart_funcs defined */
const struct boot_uart_funcs * boot_port_serial_get_functions( void );

boot_uart_funcs 结构体有两个成员:.read.write。 可在 MCUBoot 的 boot_serial.h 中找到这两个函数的签名。需要注意的是, read 函数应以 readline 方式操作, 在读取整行时将其 *newline 输入参数设置为 1。

编码

int base64_port_encode( char * dst, size_t dlen, size_t * olen, char * src, size_t slen );
int base64_port_decode( char * dst, size_t dlen, int * olen, char * src, size_t slen );
uint16_t crc16_port_ccitt( uint16_t crc, char * data, uint32_t len);

这些函数独立于硬件,应很快会在 FreeRTOS 生态系统中实现标准化。 目前,可从此演示的 port 目录复制这些函数的现有实现。

系统接口

/* Converts x from big endian to system's endianness */
uint16_t system_port_ntohs( uint16_t x );

/* Converts x from system endianness to big endian */
uint16_t system_port_htons( uint16_t x );

/* Sleep the device for usec microseconds */
void system_port_usleep( uint32_t usec );

/* Trigger a soft reset of the device */
void system_port_reset( void );
Copyright (C) Amazon Web Services, Inc. or its affiliates. All rights reserved.