** 1、freertos**
freertos是一个迷你的实时操作系统内核。作为一个轻量级的操作系统,功能包括:任务管理、时间管理、信号量、消息队列、内存管理、记录功能、软件定时器、协程等,可基本满足较小系统的需要。由于rtos需占用一定的系统资源(尤其是ram资源),只有μc/os-ii、embos、salvo、freertos等少数实时操作系统能在小ram单片机上运行。相对μc/os-ii、embos等商业操作系统,freertos操作系统是完全免费的操作系统,具有源码公开、可移植、可裁减、调度策略灵活的特点,可以方便地移植到各种单片机上运行。
2、移植
(1)第一步:创建工程
修改时钟
(2)第二步:led配置
(3)第三步:freertos配置
freertos公共部分配置
led线程配置
(4)第四部:任务入口函数编写
#include led_task.h#include led.h /* led entry function */ /* pvparameters contains taskhandle_t */ void led_task_entry(void * pvparameters){ fsp_parameter_not_used(pvparameters); /* todo: add your own code here */ while(1) { led_on(); vtaskdelay(750); led_off(); vtaskdelay(750); } }(5)第五步:主函数处理
/* generated main source file - do not edit */#include bsp_api.h #include freertos.h #include task.h #include semphr.h extern void prt_task_create(void); extern taskhandle_t prt_task; extern void led_task_create(void); extern taskhandle_t led_task; uint32_t g_fsp_common_thread_count; bool g_fsp_common_initialized; semaphorehandle_t g_fsp_common_initialized_semaphore; #if configsupport_stat ic _allocation staticsemaphore_t g_fsp_common_initialized_semaphore_memory; #endif void g_hal_init(void); /** weak reference for tx_err_callback */ #if defined(__iccarm__) #define rtos_startup_err_callback_weak_attribute #pragma weak rtos_startup_err_callback = rtos_startup_err_callback_internal #elif defined(__gnuc__) #define rtos_startup_err_callback_weak_attribute __attribute__ ((weak, alias(rtos_startup_err_callback_internal))) #endif void rtos_startup_err_callback_internal(void * p_instance, void * p_data); void rtos_startup_err_callback(void * p_instance, void * p_data) rtos_startup_err_callback_weak_attribute; /********************************************************************************************************************* * @brief this is a weak example initialization error function. it should be overridden by defining a user function * with the prototype below. * - void rtos_startup_err_callback(void * p_instance, void * p_data) * * @param[in] p_instance arguments used to identify which instance caused the error and p_data callback arguments used to identify what error caused the callback. **********************************************************************************************************************/ void rtos_startup_err_callback_internal(void * p_instance, void * p_data); void rtos_startup_err_callback_internal(void * p_instance, void * p_data){ /** suppress compiler warning for not using parameters. */ fsp_parameter_not_used(p_instance); fsp_parameter_not_used(p_data); /** an error has occurred. please check function arguments for more information. */ bsp_cfg_handle_unrecoverable_error(0); } void rtos_startup_common_init(void); void rtos_startup_common_init(void){ /* first thread will take care of common initialization. */ basetype_t err; err = xsemaphoretake(g_fsp_common_initialized_semaphore, portmax_delay); if (pdpass != err) { /* check err, problem occurred. */ rtos_startup_err_callback(g_fsp_common_initialized_semaphore, 0); } /* only perform common initialization if this is the first thread to execute. */ if (false == g_fsp_common_initialized) { /* later threads will not run this code. */ g_fsp_common_initialized = true; /* perform common module initialization. */ g_hal_init(); /* now that common initialization is done, let other threads through. */ /* first decrement by 1 since 1 thread has already come through. */ g_fsp_common_thread_count--; while (g_fsp_common_thread_count > 0) { err = xsemaphoregive(g_fsp_common_initialized_semaphore); if (pdpass != err) { /* check err, problem occurred. */ rtos_startup_err_callback(g_fsp_common_initialized_semaphore, 0); } g_fsp_common_thread_count--; } } } int main(void){ g_fsp_common_thread_count = 0; g_fsp_common_initialized = false; /* create semaphore to make sure common init is done before threads start running. */ g_fsp_common_initialized_semaphore = #if configsupport_static_allocation xsemaphorecreatecountingstatic( #else xsemaphorecreatecounting( #endif 256, 1 #if configsupport_static_allocation , &g_fsp_common_initialized_semaphore_memory #endif ); if (null == g_fsp_common_initialized_semaphore) { rtos_startup_err_callback(g_fsp_common_initialized_semaphore, 0); } /* init rtos tasks. */// prt_task_create();led_task_create(); /* start the scheduler. */ vtaskstartscheduler(); return 0; } #if configsupport_static_allocation void vapplicationgetidletaskmemory(statictask_t **ppxidletasktcbbuffer, stacktype_t **ppxidletaskstackbuffer, uint32_t *pulidletaskstacksize) bsp_weak_reference; void vapplicationgettimertaskmemory(statictask_t **ppxtimertasktcbbuffer, stacktype_t **ppxtimertaskstackbuffer, uint32_t *pultimertaskstacksize) bsp_weak_reference; /* if configsupport_static_allocation is set to 1, the application must provide an * implementation of vapplicationgetidletaskmemory() to provide the memory that is * used by the idle task. */ void vapplicationgetidletaskmemory( statictask_t ** ppxidletasktcbbuffer, stacktype_t ** ppxidletaskstackbuffer, uint32_t * pulidletaskstacksize ) { /* if the buffers to be provided to the idle task are declared inside this * function then they must be declared static - otherwise they will be allocated on * the stack and so not exists after this function exits. */ static statictask_t xidletasktcb; static stacktype_t uxidletaskstack[ configminimal_stack_size ]; /* pass out a pointer to the statictask_t structure in which the idle * task's state will be stored. */ *ppxidletasktcbbuffer = &xidletasktcb; /* pass out the array that will be used as the idle task's stack. */ *ppxidletaskstackbuffer = uxidletaskstack; /* pass out the size of the array pointed to by *ppxidletaskstackbuffer. * note that, as the array is necessarily of type stacktype_t, * configminimal_stack_size is specified in words, not bytes. */ *pulidletaskstacksize = configminimal_stack_size; } /* if configsupport_static_allocation is set to 1, the application must provide an * implementation of vapplicationgettimertaskmemory() to provide the memory that is * used by the rtos daemon/time task. */ void vapplicationgettimertaskmemory( statictask_t ** ppxtimertasktcbbuffer, stacktype_t ** ppxtimertaskstackbuffer, uint32_t * pultimertaskstacksize ) { /* if the buffers to be provided to the timer task are declared inside this * function then they must be declared static - otherwise they will be allocated on * the stack and so not exists after this function exits. */ static statictask_t xtimertasktcb; static stacktype_t uxtimertaskstack[ configminimal_stack_size ]; /* pass out a pointer to the statictask_t structure in which the idle * task's state will be stored. */ *ppxtimertasktcbbuffer = &xtimertasktcb; /* pass out the array that will be used as the timer task's stack. */ *ppxtimertaskstackbuffer = uxtimertaskstack; /* pass out the size of the array pointed to by *ppxtimertaskstackbuffer. * note that, as the array is necessarily of type stacktype_t, * configminimal_stack_size is specified in words, not bytes. */ *pultimertaskstacksize = configminimal_stack_size; } #endif(6)第六步:观察结果
OPPO带你重新认识平板电脑 在万家灯火阑珊处
SOLIDWORKS PDM让团队协作更紧密 正版达索 众联
格力和奥克斯所争论的“能效”,到底是指什么?
三星宣布将在6月终止S Voice服务
三星发布GalaxyS9邀请函 2月25日不见不散
FreeRTOS:一个迷你的实时操作系统内核
康佳彩电微处理器ST6367故障检修
自制6P14小功率胆机
新型低成本PSoC4S系列8/16位平台将取代传统的8位和16位平台
燕山石化“一条龙”生产110千伏电缆绝缘料!
什么是区块链的自然和超自然状态
为什么无铅锡膏焊后不光滑,有颗粒?
亚马逊正开发自己的真无线耳机 与苹果AirPod在功能和设计上会较为相似
DS-MDK简介及异构系统的开发解决方案
国内的互联网AI造芯竞争激烈不断
提升智慧矿山运输效率的皮带跑偏视频分析AI算法
热敏晶振的温度特性及选型
人工智能如何让科幻和现实交融
机器学习如何满足DNN推理的要求
储能逆变器和光伏逆变器的区别