vsf的mcu移植包括2部分,1是基本构架,2是外设驱动移植。这里先讲一下基本构架的移植。
vsf的基本构架的移植,包括arch移植、编译器的移植。
1. 编译器移植
位于vsf/compiler目录下,可以参考iar的compiler.h,需要实现如下宏/函数:
1) packed相关的宏
#define packed_head __packed
#define packed_mid
#define packed_tail
复制代码用例:
packed_head struct packed_mid vsfip_protoport_t
{
uint16_t src;
uint16_t dst;
}; packed_tail
复制代码2) rootfunc
#define rootfunc __root
复制代码用例:
rootfunc void uart0_irqhandler(void)
{
uart_handler(0);
}
复制代码3) weak相关宏
#define weakfunc_head __weak
#define weakfunc_tail
复制代码用例:
weakfunc_head void hardfault_handler(void) weakfunc_tail
{
while (1);
}
复制代码4) 中断控制相关
#define vsf_gint_t __istate_t
#define vsf_set_gint(gint) __set_interrupt_state(gint)
#define vsf_get_gint() __get_interrupt_state()
#define vsf_enter_critical() __disable_interrupt()
#define vsf_leave_critical() __enable_interrupt()
复制代码5) heap相关unsigned char * compiler_get_heap(void);
long compiler_get_heap_size(void);
复制代码实现:
#pragma segment=“heap”
unsigned char * compiler_get_heap(void)
{
return __sfb(“heap”);
}
long compiler_get_heap_size(void)
{
return (long)__sfe(“heap”) - (long)__sfb(“heap”);
}
复制代码6) pc/lr相关,实际没有用到,做一些实验的时候加上的
#define compiler_set_pc(reg) asm(“mov pc, %0” : :“r”(reg))
#define compiler_get_lr(reg) asm(“mov %0, lr” : “=r”(reg))
复制代码
2. arch移植位于vsf/hal/arch/xxxx
多任务核心根据需要实现的优先级数量,对mcu的中断系统会有不同的要求。
1) 只需要非实时,系统运行类似前后台
对mcu没要求,大部分mcu都可以使用,这种模式下,vsfmain.c可以非常简单,如下:
// important: donot change anything in this file
#include “vsf.h”
#include “usrapp.h”
#if defined(appcfg_nrt_queue_len) && (appcfg_nrt_queue_len 》 0)
#define appcfg_mainq_en // 设置了nrt队列,使能main_queue
#endif
#if defined(appcfg_vsftimer_num) && (appcfg_vsftimer_num 》 0)
#define appcfg_vsftimer_en // 设置了定制器支持
#endif
struct vsfapp_t
{
// 用户的app结构指针
struct usrapp_t *usrapp;
// 如果使能了定时器,根据是否支持内存管理,来选择定时器的内存池类型(动态池和静态池)
#ifdef appcfg_vsftimer_en
#ifdef appcfg_bufmgr_size
struct vsf_dynpool_t vsftimer_pool;
#else
vsfpool_define(vsftimer_pool, struct vsftimer_t, appcfg_vsftimer_num);
#endif
#endif
// 设置main_queue数据结构
#if vsfsm_cfg_prempt_en
#ifdef appcfg_mainq_en
struct vsfsm_evtq_t mainq;
struct vsfsm_evtq_element_t mainq_ele[appcfg_nrt_queue_len];
#endif
#endif
} static app =
{
.usrapp = (struct usrapp_t *)&usrapp,
#if vsfsm_cfg_prempt_en
#ifdef appcfg_mainq_en
.mainq.size = dimof(app.mainq_ele),
.mainq.queue = app.mainq_ele,
.mainq.activate = null,
#endif
#endif
#if defined(appcfg_vsftimer_en) && defined(appcfg_bufmgr_size)
.vsftimer_pool.item_size = sizeof(struct vsftimer_t),
.vsftimer_pool.pool_size = appcfg_vsftimer_num,
#endif
};
// 定时器分配接口
#ifdef appcfg_vsftimer_en
#ifdef appcfg_bufmgr_size
static struct vsftimer_t* vsftimer_memop_alloc(void)
{
return vsf_dynpool_alloc(&app.vsftimer_pool);
}
static void vsftimer_memop_free(struct vsftimer_t *timer)
{
vsf_dynpool_free(&app.vsftimer_pool, timer);
}
#else
static struct vsftimer_t* vsftimer_memop_alloc(void)
{
return vsfpool_alloc(&app.vsftimer_pool, struct vsftimer_t);
}
static void vsftimer_memop_free(struct vsftimer_t *timer)
{
vsfpool_free(&app.vsftimer_pool, timer);
}
#endif
const struct vsftimer_mem_op_t vsftimer_memop =
{
.alloc = vsftimer_memop_alloc,
.free = vsftimer_memop_free,
};
// 定时器回调
// tickclk interrupt, simply call vsftimer_callback_int
static void app_tickclk_callback_int(void *param)
{
vsftimer_callback_int();
}
#endif
static void vsfapp_init(struct vsfapp_t *app)
{
#if vsfsm_cfg_prempt_en
vsfsm_evtq_set(&app-》mainq);
#endif
// 初始化mcu内核、tickclk(系统滴答)
vsfhal_core_init(null);
vsfhal_tickclk_init(appcfg_tickclk_priority);
vsfhal_tickclk_start();
// 初始化定时器内存池
#ifdef appcfg_vsftimer_en
#ifdef appcfg_bufmgr_size
vsf_dynpool_init(&app-》vsftimer_pool);
#else
vsfpool_init(&app-》vsftimer_pool, struct vsftimer_t, appcfg_vsftimer_num);
#endif
vsftimer_init((struct vsftimer_mem_op_t *)&vsftimer_memop);
vsfhal_tickclk_config_cb(app_tickclk_callback_int, null);
#endif
// 初始化内存管理
#ifdef appcfg_bufmgr_size
vsf_bufmgr_init(compiler_get_heap(), appcfg_bufmgr_size);
#endif
// 用户非实时部分初始化
#ifdef appcfg_nrt_queue_len
usrapp_nrt_init(app-》usrapp);
#endif
}
int main(void)
{
// 关中断
vsf_enter_critical();
#ifdef appcfg_initial_init
usrapp_initial_init(app.usrapp);
#endif
// main_queue初始化
#ifdef appcfg_mainq_en
vsfsm_evtq_init(&app.mainq);
#endif
// 应用初始化
vsfapp_init(&app);
// 开中断
vsf_leave_critical();
while (1)
{
#if defined(appcfg_usr_poll) && !defined(appcfg_mainq_en)
// 轮询模式
vsfhal_tickclk_poll();
usrapp_nrt_poll(app.usrapp);
#elif defined(appcfg_usr_poll_sleep)
// 带休眠轮询
usrapp_nrt_poll(app.usrapp);
vsfhal_core_sleep(vsfhal_sleep_wfi);
#elif defined(appcfg_mainq_en)
// 事件队列模式
vsfsm_poll();
#ifdef appcfg_usr_poll
usrapp_nrt_poll(app.usrapp);
#endif
vsf_enter_critical();
if (!vsfsm_get_event_pending()
#ifdef appcfg_usr_cansleep
&& usrapp_cansleep(app.usrapp)
#endif
)
{
vsfhal_core_sleep(vsfhal_sleep_wfi); // will enable interrupt
}
else
vsf_leave_critical();
#else
// 无非实时任务
vsfhal_core_sleep(vsfhal_sleep_wfi);
#endif
}
}
复制代码vsfhal中内核层需要实现的基本接口:vsfhal_core_init: mcu内核初始化,初始化时钟、复位、调试口、等等核心功能
tickclk相关: 用于实现系统滴答,可选
vsfhal_core_sleep: 内核休眠,可选
2) 非实时+软实时+硬实时
在1) 的基础上,需要mcu支持可控的、可屏蔽的、可设置优先级的软件中断。比如cortexm的pendsv,cortexa的sgi。
ISSI推出了三种不同等级的汽车异步SRAM产品
控制器电源芯片U6119具备功能多样性
动力电池行业竞争格局变数增加 中小企业仍有求生机会
ADXL327:小尺寸 低功耗 三轴±2g加速度计简介
关于锂离子动力电池在新能源汽车领域安全性的分析与探究
VSF MCU的基本架构移植技巧浅析
海林投资徐凯旋受聘青岛工信局首席招商投资顾问
全方面解读广本缤智底盘
LT3088 宽安全工作区电源线性稳压器,1.5Vout @ 800mA
车载硬盘播放机
一文详解Linux内核源码组织结构
巴塞罗那绽放中国智能 百度国际化组团亮相MWC
探讨自动驾驶在传感器选型和布置上考虑的问题
微机电系统(MEMS)的基本工艺和应用
RCC式开关电源及应用技术方案
谈谈三大运营商福利待遇以及晋升制度
半年报后,海尔智家、美的、格力的市值有何变化?
比亚迪电动汽车运输船正式运营
电机名牌的参数你知道有多少?
MS8416助力2.4G无线音频模块发展