cmiot_sys.c 源码
2026/7/20大约 2 分钟附录源码附录OTA
cmiot_sys.c — OTA 系统接口实现
路径: components/ota/cmiot/port/oneos/cmiot_sys.c
功能: OTA 远程升级组件的系统服务接口实现,将 OTA 核心需要的系统调用(延时、时间、日志、重启)映射到 OneOS API。这是 OTA 组件与 OneOS 内核之间的系统适配层。
引用章节: 7.8 OTA 远程升级组件
完整源码
/**
***********************************************************************************************************************
* Copyright (c) 2021, China Mobile Communications Group Co.,Ltd.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* @file cmiot_sys.c
*
* @brief Interface related to OS.
*
* @revision
* Date Author Notes
* 2020-10-13 OneOS Team First Version
***********************************************************************************************************************
*/
#include "cmiot_sys.h"
#include "cmiot_client.h"
#ifdef CMIOT_USING_CTW
#include <os_clock.h>
#endif
#include <os_util.h>
#include <os_task.h>
/**
* @brief This function for sleep
* @param[in] time The sleep time, ms
*/
void cmiot_msleep(cmiot_uint32 time)
{
os_task_msleep(time);
}
#ifdef CMIOT_USING_CTW
/**
* @brief This function will return relative now time
* @return relative now time, ms
*/
cmiot_uint32 cmiot_get_now_time(void)
{
return os_tick_get_value() * 1000 / OS_TICK_PER_SECOND;
}
#endif
/**
* @brief This function for output data
* @param[in] data The data
* @param[in] len The data len
*/
void cmiot_printf(cmiot_char *data, cmiot_uint32 len)
{
os_kprintf("%s", data);
}
#ifdef CMIOT_USING_MULTI_SLAVE
/**
* @brief This function for reboot
*/
void cmiot_reboot_device(void)
{
extern void os_hw_cpu_reset(void);
os_hw_cpu_reset();
}
#endif
OS_INIT_CALL(cmiot_init, OS_INIT_LEVEL_APPLICATION, OS_INIT_SUBLEVEL_LOW);关键说明
| 模块 | 说明 |
|---|---|
| 延时映射 | cmiot_msleep → os_task_msleep,OTA 下载等待网络响应时使用 |
| 时间获取 | cmiot_get_now_time 将系统 tick 转换为毫秒(仅在 CMIOT_USING_CTW 平台启用) |
| 日志输出 | cmiot_printf → os_kprintf,统一 OTA 日志输出通道 |
| 设备重启 | cmiot_reboot_device → os_hw_cpu_reset,升级完成后重启到新固件 |
| 自动初始化 | `OS_INIT_CALL(cmiot_init, OS_INIT_LEVEL_APPLICATION, OS_INIT |