




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、#include usi.h#include frw.hstatic void *frw_core_config_pthread_routine(void *arg)frw_core_config_pthread_t *pthread = (frw_core_config_pthread_t *)arg;frw_lib_pthread_init_t init = pthread-init;frw_lib_pthread_block_t block = pthread-block;frw_lib_pthread_deal_t deal = pthread-deal;usi_uint8_t arg
2、sFRW_LIB_PTHREAD_OWNED_SIZE;usi_status_t ret;if (init) if (init(args) != USI_SUCCESS) return NULL;if (!block | !deal) return NULL;while(1) ret = block(args);if (deal(ret, args) != USI_SUCCESS) continue;return NULL;frw_core_config_pthread_t frw_core_config_pthreads = timer, FRW_LIB_PTHREAD_PRIORITY_H
3、IGHEST, 0, frw_core_timer_thread_init, frw_core_timer_thread_block, frw_core_timer_thread_deal, USI_TRUE , , 0, 0, NULL, NULL, NULL, USI_FALSE ;usi_status_t _init frw_core_config_pthread(void)usi_uint32_t desc, i = 0;while (frw_core_config_pthreadsi.init) if (FRW_PTHREAD_NR_MAX = i) return USI_ERROR
4、;if (USI_FALSE = frw_core_config_pthreadsi.used) i+;continue;desc = frw_lib_pthread_create(frw_core_config_pthreadsi.priority,frw_core_config_pthreadsi.stack,frw_core_config_pthread_routine,&frw_core_config_pthreadsi);if (FRW_LIB_PTHREAD_DESC_INVALID = desc) return USI_ERROR;i+;return USI_SUCCESS;fr
5、w_core_config_sch_t frw_core_config_schs = main, FRW_SCH_MAIN, FRW_CORE_SCH_PRIORITY_M, 0, frw_core_sch_main, USI_TRUE , , 0, 0, 0, NULL, USI_FALSE ;usi_status_t _init frw_core_config_sch(void)usi_uint32_t i = 0;while (frw_core_config_schsi.start) if (FRW_SCH_NR_MAX = i) return USI_ERROR;if (USI_FAL
6、SE = frw_core_config_schsi.used) i+;continue;if (frw_core_sch_create(frw_core_config_,frw_core_config_schsi.sch,frw_core_config_schsi.priority,frw_core_config_schsi.stack,frw_core_config_schsi.start) != USI_SUCCESS) return USI_ERROR;i+;return USI_SUCCESS;frw_core_config_proc_t frw_core_con
7、fig_procs = frw_ctrl_proc, FRW_PROC_CTRL, FRW_SCH_MAIN, FRW_SCH_PROC_T0, FRW_TIME_FOREVER, FRW_TIME_03_SEC, frw_ctrl_proc , frw_test0_proc, FRW_PROC_GEN(1, 0), FRW_SCH_MAIN, FRW_SCH_PROC_T3, FRW_TIME_FOREVER, FRW_TIME_03_SEC, frw_test0_proc , frw_test1_proc, FRW_PROC_GEN(2, 0), FRW_SCH_MAIN, FRW_SCH
8、_PROC_T2, FRW_TIME_FOREVER, FRW_TIME_03_SEC, frw_test1_proc , frw_test2_proc, FRW_PROC_GEN(3, 0), FRW_SCH_MAIN, FRW_SCH_PROC_T1, FRW_TIME_FOREVER, FRW_TIME_03_SEC, frw_test2_proc , , 0, 0, 0, 0, 0, NULL ;usi_status_t _init frw_core_config_proc(void)usi_uint32_t i = 0;while (frw_core_config_procsi.st
9、art) if (FRW_PROC_CLS_NR_MAX * FRW_PROC_INST_NR_MAX) 16) & 0xffff);usi_uint16_t inst = (usi_uint16_t)(proc & 0xffff);usi_assert(!inst);return cls * FRW_PROC_INST_NR_MAX + inst;frw_core_proc_list_t *frw_core_proc_get_list(usi_uint32_t *nr)frw_core_sch_pcb_t *pcb;usi_uint32_t type, desc, i = 0;for (ty
10、pe = 0; type = FRW_SCH_PROC_T3; type+) for (desc = 0; desc ithresh) continue;if (type = pcb-type) frw_core_proc_c = pcb-proc;frw_core_proc_listsi.ithresh = pcb-ithresh;frw_core_proc_listsi.rthresh = pcb-rthresh;i+;*nr = i;return frw_core_proc_lists;frw_core_sch_pcb_t *frw_core_proc_alloc_p
11、cb(usi_uint32_t proc)usi_uint32_t desc; desc = frw_core_proc_calc_desc(proc);if (FRW_PROC_CLS_NR_MAX * FRW_PROC_INST_NR_MAX) = desc) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_WARN, frw_core_proc_alloc_pcb(): invalid proc(%d).n, proc);return NULL;if (USI_TRUE = frw_core_proc_descsdes
12、c.used) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_WARN, frw_core_proc_alloc_pcb(): proc(%d) in use.n, proc);return NULL;frw_core_proc_descsdesc.used = USI_TRUE;return &frw_core_proc_descsdesc.pcb;usi_status_t frw_core_proc_free_pcb(usi_uint32_t proc)usi_uint32_t desc; desc = frw_cor
13、e_proc_calc_desc(proc);if (FRW_PROC_CLS_NR_MAX * FRW_PROC_INST_NR_MAX) = desc) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_WARN, frw_core_proc_free_pcb(): invalid proc(%d).n, proc);return USI_ERROR;if (USI_TRUE != frw_core_proc_descsdesc.used) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_
14、LO, FRW_DBG_LEVEL_WARN, frw_core_proc_free_pcb(): proc(%d) not in use.n, proc);return USI_ERROR;frw_core_proc_descsdesc.used = USI_FALSE;return USI_SUCCESS;frw_core_sch_pcb_t *frw_core_proc_get_pcb(usi_uint32_t proc)usi_uint32_t desc;desc = frw_core_proc_calc_desc(proc);if (FRW_PROC_CLS_NR_MAX * FRW
15、_PROC_INST_NR_MAX) = desc) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_proc_get_pcb(): invalid proc(%d).n, proc);return NULL;if (USI_TRUE != frw_core_proc_descsdesc.used) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_proc_get_pcb(): proc(%d
16、) not in use.n, proc);return NULL;return &frw_core_proc_descsdesc.pcb;usi_status_t _init frw_core_proc_init(void)usi_uint32_t desc;memset(void *)frw_core_proc_descs, 0, (FRW_PROC_CLS_NR_MAX * FRW_PROC_INST_NR_MAX * sizeof(frw_core_proc_desc_t);for (desc = 0; desc obj_name;usi_uint32_t frw_core_proc_
17、get_sch(usi_uint32_t proc)frw_core_sch_pcb_t *pcb;pcb = frw_core_proc_get_pcb(proc);if (!pcb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_proc_get_sch(): invalid proc(%d).n, proc);return FRW_CORE_SCH_INVALID; return pcb-sch;#include usi.h#include frw.hfrw_core_sch_desc
18、_t frw_core_sch_descsFRW_SCH_NR_MAX;usi_status_t _init frw_core_sch_init(void)usi_uint32_t desc;memset(void *)frw_core_sch_descs, 0, (FRW_SCH_NR_MAX * sizeof (frw_core_sch_desc_t);for (desc = 0; desc FRW_SCH_NR_MAX; desc+) frw_core_sch_descsdesc.used = USI_FALSE;return USI_SUCCESS;static usi_uint32_
19、t frw_core_sch_calc_desc(usi_uint32_t sch)usi_uint32_t desc;desc = sch;return desc;static frw_core_sch_scb_t *frw_core_sch_alloc_scb(usi_uint32_t sch)usi_uint32_t desc;desc = frw_core_sch_calc_desc(sch);if (FRW_SCH_NR_MAX = desc) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_
20、core_sch_alloc_scb(): invalid sch(%d).n, sch);return NULL;if (USI_TRUE = frw_core_sch_descsdesc.used) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_alloc_scb(): sch(%d) in use.n, sch);return NULL;frw_core_sch_descsdesc.used = USI_TRUE;return &frw_core_sch_descsdesc.s
21、cb;static usi_status_t frw_core_sch_free_scb(usi_uint32_t sch)usi_uint32_t desc;desc = frw_core_sch_calc_desc(sch);if (FRW_SCH_NR_MAX = desc) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_free_scb(): invalid sch(%d).n, sch);return USI_ERROR;if (USI_TRUE != frw_core_s
22、ch_descsdesc.used) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_free_scb(): sch(%d) not in use.n, sch);return USI_ERROR;frw_core_sch_descsdesc.used = USI_FALSE;return USI_SUCCESS;frw_core_sch_scb_t *frw_core_sch_get_scb(usi_uint32_t sch)usi_uint32_t desc;desc = frw_
23、core_sch_calc_desc(sch);if (FRW_SCH_NR_MAX pend, &pcb-node, FRW_LIB_FIFO_TAIL);pcb-status = FRW_CORE_SCH_PROC_STATUS_PEND;return USI_SUCCESS;usi_status_t frw_core_sch_create_proc(usi_char_t *name, usi_uint32_t proc, usi_uint32_t sch, usi_uint32_t type, usi_uint32_t ithresh, usi_uint32_t rthresh, frw
24、_core_sch_routine_t start)frw_core_sch_pcb_t *pcb;usi_uint32_t i;pcb = frw_core_proc_alloc_pcb(proc);if (!pcb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_create_proc(): invalid proc(%d).n, proc);return USI_ERROR;memset(void *)pcb, 0, sizeof(frw_core_sch_pcb_t);snp
25、rintf(pcb-obj_name, FRW_OBJ_NAME_SIZE, %s, name);pcb-proc = proc;pcb-sch = sch;pcb-type = type;pcb-ithresh = ithresh;pcb-rthresh = rthresh;pcb-state = 0;pcb-osize = FRW_PROC_OWNED_SIZE_MAX;pcb-owned = malloc(pcb-osize);if (!pcb-owned) frw_core_proc_free_pcb(proc);return USI_ERROR;memset(void *)pcb-o
26、wned, 0, pcb-osize);frw_lib_fifo_init(&pcb-mailbox);pcb-mails = 0;pcb-gtimers = FRW_CORE_TIMER_DESC_INVALID;pcb-avlroot = FRW_CORE_TIMER_DESC_INVALID;for (i = 0; i itimersi = FRW_CORE_TIMER_DESC_INVALID;pcb-start = start;pcb-status = FRW_CORE_SCH_PROC_STATUS_IDLE;if (frw_core_sch_attach_proc(pcb-sch
27、, pcb) = USI_ERROR) free(void *)pcb-owned);frw_core_proc_free_pcb(proc);return USI_ERROR;return USI_SUCCESS;usi_uint32_t frw_core_sch_get_current(void)frw_core_sch_scb_t *scb;usi_uint32_t pthread, sch;pthread = frw_lib_pthread_get_current();if (FRW_LIB_PTHREAD_DESC_INVALID = pthread) return FRW_CORE
28、_SCH_INVALID;for (sch = 0; sch pthread = pthread) return sch;return FRW_CORE_SCH_INVALID;usi_uint32_t frw_core_sch_get_proc(void)frw_core_sch_scb_t *scb;scb = frw_core_sch_get_scb(frw_core_sch_get_current();if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_get_
29、proc(): invalid sch.n);return FRW_CORE_PROC_INVALID;return scb-proc;usi_status_t frw_core_sch_get_proc_state(usi_uint16_t *state)frw_core_sch_pcb_t *pcb;usi_assert(state);pcb = frw_core_proc_get_pcb(frw_core_sch_get_proc();if (!pcb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, f
30、rw_core_sch_get_proc_state(): invalid proc.n);return USI_ERROR;*state = pcb-state;return USI_SUCCESS;usi_status_t frw_core_sch_set_proc_state(usi_uint16_t state)frw_core_sch_pcb_t *pcb;pcb = frw_core_proc_get_pcb(frw_core_sch_get_proc();if (!pcb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_
31、LEVEL_ERROR, frw_core_sch_set_proc_state(): invalid proc.n);return USI_ERROR;pcb-state = state;return USI_SUCCESS;usi_uint8_t *frw_core_sch_get_proc_owned(void)frw_core_sch_pcb_t *pcb;pcb = frw_core_proc_get_pcb(frw_core_sch_get_proc();if (!pcb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_L
32、EVEL_ERROR, frw_core_sch_get_proc_owned(): invalid proc.n);return NULL; return pcb-owned;usi_status_t frw_core_sch_get_msg_type(usi_uint32_t *type)frw_core_sch_scb_t *scb;frw_ilink_msg_header_t *msg;usi_assert(type);scb = frw_core_sch_get_scb(frw_core_sch_get_current();if (!scb) frw_dbg_output(FRW_S
33、YSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_get_msg_type(): invalid sch.n);return USI_ERROR;if (scb-msg) msg = (frw_ilink_msg_header_t *)(usi_uint8_t *)scb-msg + sizeof(frw_ilink_ipc_header_t);*type = msg-type;return USI_SUCCESS;return USI_ERROR;usi_status_t frw_core_sch_get_msg_size(
34、usi_uint32_t *size)frw_core_sch_scb_t *scb;frw_ilink_msg_header_t *msg;usi_assert(size);scb = frw_core_sch_get_scb(frw_core_sch_get_current();if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_get_msg_size(): invalid sch.n);return USI_ERROR;if (scb-msg) msg = (f
35、rw_ilink_msg_header_t *)(usi_uint8_t *)scb-msg + sizeof(frw_ilink_ipc_header_t);*size = msg-size;return USI_SUCCESS;return USI_ERROR;usi_status_t frw_core_sch_get_msg_src(frw_ilink_proc_desc_t *src)frw_core_sch_scb_t *scb;frw_ilink_msg_header_t *msg;usi_assert(src);scb = frw_core_sch_get_scb(frw_cor
36、e_sch_get_current();if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_get_msg_src(): invalid sch.n);return USI_ERROR;if (scb-msg) msg = (frw_ilink_msg_header_t *)(usi_uint8_t *)scb-msg + sizeof(frw_ilink_ipc_header_t);memcpy(void *)src, (const void *)(&msg-src)
37、, sizeof(frw_ilink_proc_desc_t);return USI_SUCCESS;return USI_ERROR;static usi_status_t frw_core_sch_load(usi_uint32_t sch, frw_core_sch_pcb_t *pcb)frw_core_sch_scb_t *scb;scb = frw_core_sch_get_scb(sch);if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_load():
38、 invalid sch(%d).n, sch);return USI_ERROR;if (FRW_CORE_SCH_PROC_STATUS_PEND = pcb-status) frw_lib_fifo_remove(&scb-pend, &pcb-node);frw_lib_fifo_put(&scb-ready, &pcb-node, FRW_LIB_FIFO_TAIL);pcb-status = FRW_CORE_SCH_PROC_STATUS_READY;return USI_SUCCESS;static void frw_core_sch_run(frw_core_sch_pcb_
39、t *pcb, frw_ilink_ipc_header_t *ipc)frw_core_sch_routine_t start;frw_core_msg_node_t *node;usi_assert(pcb & ipc);node = (frw_core_msg_node_t *)(usi_uint8_t *)ipc - sizeof(frw_core_msg_node_t);if (FRW_CORE_MSG_NODE_FLAG_EXPIRE = node-flag) frw_core_msg_free(void *)ipc);return;start = pcb-start;start(
40、pcb-state, (void *)pcb-owned, (frw_ilink_msg_header_t *)(ipc + 1);return;usi_status_t frw_core_sch_create(usi_char_t *name, usi_uint32_t sch, usi_uint32_t priority, usi_uint32_t stack, frw_lib_pthread_routine_t start)frw_core_sch_scb_t *scb;scb = frw_core_sch_alloc_scb(sch);if (!scb) frw_dbg_output(
41、FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_create(): invalid sch(%d).n, sch);return USI_ERROR;frw_lib_fifo_init(&scb-pend);frw_lib_fifo_init(&scb-ready);scb-proc = FRW_CORE_PROC_INVALID;scb-msg = NULL;scb-mqueue = frw_lib_mqueue_create(FRW_SCH_MSG_NR_MAX, FRW_SCH_MSG_SIZE_MAX, 0
42、);if (FRW_LIB_MQUEUE_DESC_INVALID = scb-mqueue) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_create(): sch(%d) create mqueue error.n, sch);frw_core_sch_free_scb(sch);return USI_ERROR;scb-pthread = frw_lib_pthread_create(priority, stack, start, (void *)scb);if (FRW_L
43、IB_PTHREAD_DESC_INVALID = scb-pthread) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_create(): sch(%d) create pthread error.n, sch);frw_lib_mqueue_destroy(scb-mqueue);frw_core_sch_free_scb(sch);return USI_ERROR;return USI_SUCCESS;usi_status_t frw_core_sch_destroy(usi
44、_uint32_t sch)frw_core_sch_scb_t *scb;scb = frw_core_sch_get_scb(sch);if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_destory(): invalid sch(%d).n, sch);return USI_ERROR;frw_lib_pthread_suspend(scb-pthread);frw_lib_pthread_destroy(scb-pthread);frw_lib_mqueue_
45、destroy(scb-mqueue);frw_core_sch_free_scb(sch);return USI_SUCCESS;usi_status_t frw_core_sch_tx(usi_uint32_t sch, usi_uint8_t *ipc, usi_int32_t timeout, usi_int32_t priority)frw_core_sch_scb_t *scb;scb = frw_core_sch_get_scb(sch);if (!scb) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR, frw_core_sch_tx(): invalid sch(%d).n, sch);frw_core_msg_free(void *)ipc);return USI_ERROR;if (frw_lib_mqueue_tx(scb-mqueue, (usi_char_t *)(&ipc), sizeof(usi_uint8_t *), priority) = USI_ERROR) frw_dbg_output(FRW_SYSTEM_LO, FRW_MODULE_LO, FRW_DBG_LEVEL_ERROR
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 餐饮门店损益管理办法
- 餐饮打包服务管理办法
- 高考美术画室管理办法
- 2025年在线教育平台用户学习体验满意度提升策略研究报告
- 城市绿化与生态环境:2025年低碳城市建设规划与武汉实践案例剖析
- 酒类储存家庭管理办法
- 高档酒店管理办法标准
- 长治地区墓葬管理办法
- DB4451T 4-2023 潮州工夫茶艺技术规程
- 针灸治疗消毒管理办法
- 统计技术应用管理办法
- 水电站安全生产管理制度
- 抖音代运营公司策划方案
- 2025至2030洗碗机里的啤酒行业产业运行态势及投资规划深度研究报告
- 美容培训资料
- 2025年广西中考英语真题含答案
- 2025年医疗健康行业医疗信息化建设与网络安全研究报告
- 辽宁省文体旅集团所属企业招聘笔试题库2025
- 团建活动桌球店活动方案
- 2025年时事政治考试题及参考答案(100题)
- T-CESA 1281-2023 制造业企业质量管理能力评估规范
评论
0/150
提交评论