这次就来说说基于上一节介绍的系统框图去建立我们所需要的任务,顺便学习Raw-OS提供的API,根据上节的分析,对于Slave Board有如下设计:

Slave Board有三个任务,分别负责测试阻抗,电压,电流功能,至于底层实现先不管,先把任务框架设计出来~

对于任务相关的操作,Raw-OS提供一组API操作,用到什么解释什么,说多了都是泪~

首先建立任务用到的API是raw_task_create,详细的解释见下文~

  1. /*
  2. ************************************************************************************************************************
  3. * Create a task
  4. *
  5. * Description: This function is called to create a task.
  6. *
  7. * Arguments : task_obj is a pointer to the RAW_TASK_OBJ.
  8. * ------
  9. * task_name is a string name assigned to a task
  10. * ------
  11. * task_arg is an argument passing to task
  12. * ------
  13. * task_prio is a priority to task, smalled priority is higher priority
  14. * -------
  15. * time_slice is run time slice tick to task, assign to 0 means it will accept default slice time
  16. * -------
  17. * task_stack_base is a low address of memory
  18. * ------
  19. * stack_size is the number of stack elements of this task
  20. * ------
  21. * task_entry is the entry of this task
  22. * ------
  23. * auto_start is the flag to activate task:
  24. * RAW_AUTO_START 1
  25. * RAW_DONT_START 0
  26. *
  27. * Returns : RAW_IDLE_EXIT the idle priority should only be created once.
  28. * -----
  29. * RAW_OS_STOPPED raw os has not been started yet
  30. * -----
  31. * RAW_SUCCESS raw os return success.
  32. *
  33. * Note(s) :
  34. *
  35. *
  36. ************************************************************************************************************************
  37. */
  38. #if (CONFIG_RAW_TASK_CREATE > 0)
  39.  
  40. RAW_U16 raw_task_create(RAW_TASK_OBJ *task_obj, RAW_U8 *task_name, RAW_VOID *task_arg,
  41. RAW_U8 task_prio, RAW_U32 time_slice, PORT_STACK *task_stack_base,
  42. RAW_U32 stack_size, RAW_TASK_ENTRY task_entry, RAW_U8 auto_start)

首先,建立任务所需要的参数,包括:任务优先级,任务堆栈,任务对象,任务时间片~

  1. /* tasks parameters */
  2. #define IMPEDANCE_PRIO 10
  3. #define IMPEDANCE_SLICE 100
  4.  
  5. #define VOLTAGE_PRIO 10
  6. #define VOLTAGE_SLICE 100
  7.  
  8. #define CURRENT_PRIO 10
  9. #define CURRENT_SLICE 100
  10.  
  11. /* task stack */
  12. PORT_STACK impedance_stack[TASK_STK_SIZE];
  13. PORT_STACK voltage_stack[TASK_STK_SIZE];
  14. PORT_STACK current_stack[TASK_STK_SIZE];
  15.  
  16. /* task instance */
  17. RAW_TASK_OBJ taskMeasureImpedance_obj;
  18. RAW_TASK_OBJ taskMeasureVoltage_obj;
  19. RAW_TASK_OBJ taskMeasureCurrent_obj;

那么,首先建立slave_board.c把slave_board的任务建立好~3个任务~

  1. /* taskMeasureImpedance function */
  2. void taskMeasureImpedance(void *pParam){
  3. /* taskMeasureImpedance loop */
  4. while(1){
  5.  
  6. }
  7. }
  8.  
  9. /* taskMeasureVoltage function */
  10. void taskMeasureVoltage(void *pParam){
  11. /* taskMeasureVoltage loop */
  12. while(1){
  13.  
  14. }
  15. }
  16.  
  17. /* taskMeasureCurrent function */
  18. void taskMeasureCurrent(void *pParam){
  19. /* taskMeasureCurrent loop */
  20. while(1){
  21.  
  22. }
  23. }

顺利建立好3个任务之后,封装到到一个专门负责slave任务建立的函数中~

  1. int slaveTaskInit(void){
  2. RAW_U32 resultImpedance = -1;
  3. RAW_U32 resultVoltage = -1;
  4. RAW_U32 resultCurrent = -1;
  5.  
  6. raw_printk("\n");
  7. raw_printk("====== Slave Board Tasks Setup ======\n");
  8.  
  9. /* Creat taskMeasureImpedance */
  10. resultImpedance = raw_task_create(&taskMeasureImpedance_obj, "taskMeasureImpedance", NULL,
  11. IMPEDANCE_PRIO, IMPEDANCE_SLICE, impedance_stack, TASK_STK_SIZE, taskMeasureImpedance, 0);
  12. if(resultImpedance == RAW_OS_STOPPED){
  13. raw_printk("creat taskMeasureImpedance successful ...\n");
  14. }
  15. else{
  16. raw_printk("creat taskMeasureImpedance faild with error code : %x ... \n", resultImpedance);
  17. RAW_ASSERT(0)
  18. }
  19.  
  20. /* Creat taskMeasureVoltage */
  21. resultVoltage = raw_task_create(&taskMeasureVoltage_obj, "taskMeasureVoltage", NULL,
  22. VOLTAGE_PRIO, VOLTAGE_SLICE, voltage_stack, TASK_STK_SIZE, taskMeasureVoltage, 0);
  23. if(resultVoltage == RAW_OS_STOPPED){
  24. raw_printk("creat taskMeasureVoltage successful ...\n");
  25. }
  26. else{
  27. raw_printk("creat taskMeasureVoltage faild with error code : %x ... \n", resultVoltage);
  28. RAW_ASSERT(0)
  29. }
  30.  
  31. /* Creat taskMeasureCurrent */
  32. resultCurrent = raw_task_create(&taskMeasureCurrent_obj, "taskMeasureCurrent", NULL,
  33. CURRENT_PRIO, CURRENT_SLICE, current_stack, TASK_STK_SIZE, taskMeasureCurrent, 0);
  34. if(resultCurrent == RAW_OS_STOPPED){
  35. raw_printk("creat taskMeasureCurrent successful ...\n");
  36. }
  37. else{
  38. raw_printk("creat taskMeasureCurrent faild with error code : %x ... \n", resultCurrent);
  39. RAW_ASSERT(0)
  40. }
  41.  
  42. raw_printk("\n");
  43.  
  44. return 0;
  45. }

对于master board也有相似的过程~建立master board任务如下:

对应slave board任务建立的过程,编写master board任务,并且最后封装到负责master任务建立的函数~

  1. #include "application.h"
  2.  
  3. #define TASK_STK_SIZE 512
  4.  
  5. /* tasks parameters */
  6. #define KEY_MSG_PROCESS_PRIO 10
  7. #define KEY_MSG_PROCESS_SLICE 100
  8.  
  9. #define MASTER_SEND_CMD_PRIO 10
  10. #define MASTER_SEND_CMD_SLICE 100
  11.  
  12. #define GET_MEASURE_MSG_PRIO 10
  13. #define GET_MEASURE_MSG_SLICE 100
  14.  
  15. #define LCD_DISP_PRIO 10
  16. #define LCD_DISP_SLICE 100
  17.  
  18. #define SD_STORE_PRIO 10
  19. #define SD_STORE_SLICE 100
  20.  
  21. /* task stack */
  22. PORT_STACK key_msg_process_stack[TASK_STK_SIZE];
  23. PORT_STACK master_send_cmd_stack[TASK_STK_SIZE];
  24. PORT_STACK get_measure_msg_stack[TASK_STK_SIZE];
  25. PORT_STACK lcd_disp_stack[TASK_STK_SIZE];
  26. PORT_STACK sd_store_stack[TASK_STK_SIZE];
  27.  
  28. /* task instance */
  29. RAW_TASK_OBJ taskKeyMsgProcess_obj;
  30. RAW_TASK_OBJ taskMasterSendCmd_obj;
  31. RAW_TASK_OBJ taskGetMeasureMsg_obj;
  32. RAW_TASK_OBJ taskLcdDisp_obj;
  33. RAW_TASK_OBJ taskSdStore_obj;
  34.  
  35. /* taskKeyMsgProcess function */
  36. void taskKeyMsgProcess(void *pParam){
  37. /* taskKeyMsgProcess loop */
  38. while(1){
  39.  
  40. }
  41. }
  42.  
  43. /* taskMasterSendCmd function */
  44. void taskMasterSendCmd(void *pParam){
  45. /* taskMasterSendCmd loop */
  46. while(1){
  47.  
  48. }
  49. }
  50.  
  51. /* taskGetMeasureMsg function */
  52. void taskGetMeasureMsg(void *pParam){
  53. /* taskGetMeasureMsg loop */
  54. while(1){
  55.  
  56. }
  57. }
  58.  
  59. /* taskLcdDisp function */
  60. void taskLcdDisp(void *pParam){
  61. /* taskLcdDisp loop */
  62. while(1){
  63.  
  64. }
  65. }
  66.  
  67. /* taskSdStore function */
  68. void taskSdStore(void *pParam){
  69. /* taskSdStore loop */
  70. while(1){
  71.  
  72. }
  73. }
  74.  
  75. int masterTaskInit(void){
  76. RAW_U32 resultKeyMsgProcess = -1;
  77. RAW_U32 resultMasterSendCmd = -1;
  78. RAW_U32 resultGetMeasureMsg = -1;
  79. RAW_U32 LcdDisp = -1;
  80. RAW_U32 SdStore = -1;
  81.  
  82. raw_printk("\n");
  83. raw_printk("====== Master Board Tasks Setup ======\n");
  84.  
  85. /* Creat KeyMsgProcess */
  86. resultKeyMsgProcess = raw_task_create(&taskKeyMsgProcess_obj, "taskKeyMsgProcess", NULL,
  87. KEY_MSG_PROCESS_PRIO, KEY_MSG_PROCESS_SLICE, key_msg_process_stack, TASK_STK_SIZE, taskKeyMsgProcess, 0);
  88. if(resultKeyMsgProcess == RAW_OS_STOPPED){
  89. raw_printk("creat KeyMsgProcess successful ...\n");
  90. }
  91. else{
  92. raw_printk("creat KeyMsgProcess faild with error code : %x ... \n", resultKeyMsgProcess);
  93. RAW_ASSERT(0)
  94. }
  95.  
  96. /* Creat MasterSendCmd */
  97. resultMasterSendCmd = raw_task_create(&taskMasterSendCmd_obj, "taskMasterSendCmd", NULL,
  98. MASTER_SEND_CMD_PRIO, MASTER_SEND_CMD_SLICE, master_send_cmd_stack, TASK_STK_SIZE, taskMasterSendCmd, 0);
  99. if(resultMasterSendCmd == RAW_OS_STOPPED){
  100. raw_printk("creat taskMasterSendCmd successful ...\n");
  101. }
  102. else{
  103. raw_printk("creat taskMasterSendCmd faild with error code : %x ... \n", resultMasterSendCmd);
  104. RAW_ASSERT(0)
  105. }
  106.  
  107. /* Creat taskGetMeasureMsg */
  108. resultGetMeasureMsg = raw_task_create(&taskGetMeasureMsg_obj, "taskGetMeasureMsg", NULL,
  109. GET_MEASURE_MSG_PRIO, GET_MEASURE_MSG_SLICE, get_measure_msg_stack, TASK_STK_SIZE, taskGetMeasureMsg, 0);
  110. if(resultGetMeasureMsg == RAW_OS_STOPPED){
  111. raw_printk("creat taskGetMeasureMsg successful ...\n");
  112. }
  113. else{
  114. raw_printk("creat taskGetMeasureMsg faild with error code : %x ... \n", resultGetMeasureMsg);
  115. RAW_ASSERT(0)
  116. }
  117.  
  118. /* Creat taskLcdDisp */
  119. LcdDisp = raw_task_create(&taskLcdDisp_obj, "taskLcdDisp", NULL,
  120. LCD_DISP_PRIO, LCD_DISP_SLICE, lcd_disp_stack, TASK_STK_SIZE, taskLcdDisp, 0);
  121. if(LcdDisp == RAW_OS_STOPPED){
  122. raw_printk("creat taskLcdDisp successful ...\n");
  123. }
  124. else{
  125. raw_printk("creat taskLcdDisp faild with error code : %x ... \n", LcdDisp);
  126. RAW_ASSERT(0)
  127. }
  128.  
  129. /* Creat taskSdStore */
  130. SdStore = raw_task_create(&taskSdStore_obj, "taskSdStore", NULL,
  131. SD_STORE_PRIO, SD_STORE_SLICE, sd_store_stack, TASK_STK_SIZE, taskSdStore, 0);
  132. if(SdStore == RAW_OS_STOPPED){
  133. raw_printk("creat taskSdStore successful ...\n");
  134. }
  135. else{
  136. raw_printk("creat taskSdStore faild with error code : %x ... \n", SdStore);
  137. RAW_ASSERT(0)
  138. }
  139.  
  140. raw_printk("\n");
  141.  
  142. return 0;
  143. }

好了,到此结束了,这次先把任务建立起来,可以下载Raw-OS的kernel看看任务头文件还有那些函数可用,先熟悉熟悉,至于编程练习,可以自行试试,至少一半的函数都用用。

  1. /* 2012-4 Created by jorya_txj
  2. * xxxxxx please added here
  3. */
  4.  
  5. #ifndef RAW_TASK_H
  6. #define RAW_TASK_H
  7.  
  8. typedef RAW_VOID (*RAW_TASK_ENTRY)(RAW_VOID *p_arg);
  9.  
  10. RAW_U16 raw_task_create(RAW_TASK_OBJ *task_obj, RAW_U8 *task_name, RAW_VOID *task_arg,
  11. RAW_U8 task_prio, RAW_U32 time_slice, PORT_STACK *task_stack_base,
  12. RAW_U32 stack_size, RAW_TASK_ENTRY task_entry, RAW_U8 auto_start);
  13.  
  14. RAW_U16 raw_disable_sche(void);
  15.  
  16. RAW_U16 raw_enable_sche(void);
  17.  
  18. RAW_U16 raw_sleep(RAW_TICK_TYPE dly);
  19. RAW_U16 raw_time_sleep(RAW_U16 hours, RAW_U16 minutes, RAW_U16 seconds, RAW_U32 milli);
  20.  
  21. #if (CONFIG_RAW_TASK_SUSPEND > 0)
  22. RAW_U16 raw_task_suspend(RAW_TASK_OBJ *task_ptr);
  23. RAW_U16 raw_task_resume(RAW_TASK_OBJ *task_ptr);
  24. RAW_U16 task_suspend(RAW_TASK_OBJ *task_ptr);
  25. RAW_U16 task_resume(RAW_TASK_OBJ *task_ptr);
  26.  
  27. #endif
  28.  
  29. #if (CONFIG_RAW_TASK_PRIORITY_CHANGE > 0)
  30. RAW_U16 raw_task_priority_change (RAW_TASK_OBJ *task_ptr, RAW_U8 new_priority, RAW_U8 *old_priority);
  31. #endif
  32.  
  33. #if (CONFIG_RAW_TASK_DELETE > 0)
  34. RAW_U16 raw_task_delete(RAW_TASK_OBJ *task_ptr);
  35. #endif
  36.  
  37. #if (CONFIG_RAW_TASK_WAIT_ABORT > 0)
  38. RAW_U16 raw_task_wait_abort(RAW_TASK_OBJ *task_ptr);
  39. #endif
  40.  
  41. #if (CONFIG_SCHED_FIFO_RR > 0)
  42. RAW_U16 raw_task_time_slice_change(RAW_TASK_OBJ *task_ptr, RAW_U32 new_time_slice);
  43. RAW_U16 raw_set_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 policy);
  44. RAW_U16 raw_get_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 *policy_ptr);
  45. #endif
  46.  
  47. RAW_TASK_OBJ *raw_task_identify(void);
  48.  
  49. #if (CONFIG_RAW_TASK_STACK_CHECK > 0)
  50. RAW_U16 raw_task_stack_check(RAW_TASK_OBJ *task_obj, RAW_U32 *free_stack);
  51. #endif
  52.  
  53. #if (CONFIG_USER_DATA_POINTER > 0)
  54. RAW_VOID raw_set_task_user_point(RAW_TASK_OBJ *task_ptr, RAW_VOID *user_point, RAW_U32 point_position);
  55.  
  56. RAW_VOID *raw_get_task_user_point(RAW_TASK_OBJ *task_ptr, RAW_U32 point_position);
  57. #endif
  58.  
  59. #if (CONFIG_RAW_DEBUG > 0)
  60. RAW_U16 raw_iter_block_task(LIST *object_head, RAW_VOID (*debug_function)(RAW_TASK_OBJ *), RAW_U8 opt);
  61. RAW_U32 raw_get_system_global_space(void);
  62. #endif
  63.  
  64. #define RAW_TASK_AUTO_START 1
  65. #define RAW_TASK_DONT_START 0
  66.  
  67. #endif

最后,在linux下openrisc架构验证的信息是这样的:

在Raw-OS的官网下载相关API说明,看看任务相关还有哪些函数可用,小弟也会本着用到再去解释的原则去说明一下,希望大家继续支持Raw-OS发展哈~

http://www.raw-os.org/

好了,下次见,荆轲刺秦王~~~

or1200下raw-os学习(任务篇)的更多相关文章

  1. 基于raw os 的事件触发系统

    Raw os的事件触发系统有以下特点: 1 基于UML的状态机理念设计,实现了有限状态机(fsm)以及层次状态机(HSM). 2 实现了活动对象(ACTIVE OBJECT)的特性,一个活动对象包含了 ...

  2. Java并发包下锁学习第一篇:介绍及学习安排

    Java并发包下锁学习第一篇:介绍及学习安排 在Java并发编程中,实现锁的方式有两种,分别是:可以使用同步锁(synchronized关键字的锁),还有lock接口下的锁.从今天起,凯哥将带领大家一 ...

  3. Java并发包下锁学习第二篇Java并发基础框架-队列同步器介绍

    Java并发包下锁学习第二篇队列同步器 还记得在第一篇文章中,讲到的locks包下的类结果图吗?如下图: ​ 从图中,我们可以看到AbstractQueuedSynchronizer这个类很重要(在本 ...

  4. 如何系统学习C 语言(下)之 预处理命令篇

    大话c语言(下)之 预处理命令篇 预处理就是在编译之前,通过一些预处理命令对源代码进行管理和控制的过程. 由源代码得到可执行的程序,会经过预处理.编译.汇编和链接几个过程 预处理命令大致可以分为文件包 ...

  5. 一、React Native 搭建开发环境(1)(Mac OS - IOS项目篇)

    React Native是Facebook推出的一个开发IOS和安卓APP的技术.至于更多的详情,这里不再描述,大家可以自行百度它的定义. 原因:由于我想在一台电脑上同时开发IOS和Android两个 ...

  6. [置顶] Firefox OS 学习——manifest.webapp结构分析

    在Firefox OS 学习——Gaia 编译分析  这篇文章多次提到manifest.webapp文件,对于做过android app 开发的人来说,都很熟悉Android.mk 和Manifest ...

  7. Docker虚拟化实战学习——基础篇(转)

    Docker虚拟化实战学习——基础篇 2018年05月26日 02:17:24 北纬34度停留 阅读数:773更多 个人分类: Docker   Docker虚拟化实战和企业案例演练 深入剖析虚拟化技 ...

  8. [Django]模型学习记录篇--基础

    模型学习记录篇,仅仅自己学习时做的记录!!! 实现模型变更的三个步骤: 修改你的模型(在models.py文件中). 运行python manage.py makemigrations ,为这些修改创 ...

  9. Unix和Linux下C语言学习指南

    转自:http://www.linuxdiyf.com/viewarticle.php?id=174074 Unix和Linux下C语言学习指南 引言 尽管 C 语言问世已近 30 年,但它的魅力仍未 ...

随机推荐

  1. Python 异常相关参考

    Python所有的异常都是从BaseException类派生的,常见的错误类型和继承关系如下: BaseException +-- SystemExit +-- KeyboardInterrupt + ...

  2. web开发中禁止因为网速慢导致重复提交数据

    var checkSubmitFlg = false;  function check() {                if (!checkSubmitFlg) {                ...

  3. Downloading the Source

    The Android source tree is located in a Git repository hosted by Google. This document  describes ho ...

  4. just test Gson

    just test Gson code package com.qilin.test; import com.google.gson.Gson; import org.apache.commons.l ...

  5. 【加解密】关于DES加密算法的JAVA加密代码及C#解密代码

    JAVA加密: package webdomain; import java.security.Key; import java.security.spec.AlgorithmParameterSpe ...

  6. 《C陷阱与缺陷》读书笔记

    1. 词法“陷阱” = 不同于 == , 可以通过if( 1 == a )来避免 & | 不同于 && || 词法分析中的“贪心法” 编译器将程序分解成符号的方法是,从左到右一 ...

  7. Ruby on Rails vs. PHP vs. Python

    开发者在开发web应用时,往往会对平台的选择感到困惑,而web专家通常会建议:要考虑几个因素,这些因素包括周转时间.质量.跨浏览器兼容性.与其他框架的整合.数据安全性.易于访问性等. 在考虑了这些因素 ...

  8. 无线网WEP的安全测试及防范

    650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...

  9. mysql基础知识(5)--视图

    视图 单词:view 什么是视图: 视图可以看作是一个“临时存储的数据所构成的表”(非真实表),其实本质上只是一个select语句.只是将该select语句(通常比较复杂)进行一个“包装”,并设定了一 ...

  10. 第三百四十二天 how can I 坚持

    再问世间都去哪儿了,天气预报没搞完,计划没制定,又周三了. 今天回到家八点,吃完饭接近九点,和老妈开了会视频,这就九点半多了,发了呆洗了个碗就到这时候了,整天浑浑噩噩的,该如何是好. 又有点上火,舌头 ...