or1200下raw-os学习(任务篇)
这次就来说说基于上一节介绍的系统框图去建立我们所需要的任务,顺便学习Raw-OS提供的API,根据上节的分析,对于Slave Board有如下设计:
Slave Board有三个任务,分别负责测试阻抗,电压,电流功能,至于底层实现先不管,先把任务框架设计出来~
对于任务相关的操作,Raw-OS提供一组API操作,用到什么解释什么,说多了都是泪~
首先建立任务用到的API是raw_task_create,详细的解释见下文~
/*
************************************************************************************************************************
* Create a task
*
* Description: This function is called to create a task.
*
* Arguments : task_obj is a pointer to the RAW_TASK_OBJ.
* ------
* task_name is a string name assigned to a task
* ------
* task_arg is an argument passing to task
* ------
* task_prio is a priority to task, smalled priority is higher priority
* -------
* time_slice is run time slice tick to task, assign to 0 means it will accept default slice time
* -------
* task_stack_base is a low address of memory
* ------
* stack_size is the number of stack elements of this task
* ------
* task_entry is the entry of this task
* ------
* auto_start is the flag to activate task:
* RAW_AUTO_START 1
* RAW_DONT_START 0
*
* Returns : RAW_IDLE_EXIT the idle priority should only be created once.
* -----
* RAW_OS_STOPPED raw os has not been started yet
* -----
* RAW_SUCCESS raw os return success.
*
* Note(s) :
*
*
************************************************************************************************************************
*/
#if (CONFIG_RAW_TASK_CREATE > 0) RAW_U16 raw_task_create(RAW_TASK_OBJ *task_obj, RAW_U8 *task_name, RAW_VOID *task_arg,
RAW_U8 task_prio, RAW_U32 time_slice, PORT_STACK *task_stack_base,
RAW_U32 stack_size, RAW_TASK_ENTRY task_entry, RAW_U8 auto_start)
首先,建立任务所需要的参数,包括:任务优先级,任务堆栈,任务对象,任务时间片~
/* tasks parameters */
#define IMPEDANCE_PRIO 10
#define IMPEDANCE_SLICE 100 #define VOLTAGE_PRIO 10
#define VOLTAGE_SLICE 100 #define CURRENT_PRIO 10
#define CURRENT_SLICE 100 /* task stack */
PORT_STACK impedance_stack[TASK_STK_SIZE];
PORT_STACK voltage_stack[TASK_STK_SIZE];
PORT_STACK current_stack[TASK_STK_SIZE]; /* task instance */
RAW_TASK_OBJ taskMeasureImpedance_obj;
RAW_TASK_OBJ taskMeasureVoltage_obj;
RAW_TASK_OBJ taskMeasureCurrent_obj;
那么,首先建立slave_board.c把slave_board的任务建立好~3个任务~
/* taskMeasureImpedance function */
void taskMeasureImpedance(void *pParam){
/* taskMeasureImpedance loop */
while(1){ }
} /* taskMeasureVoltage function */
void taskMeasureVoltage(void *pParam){
/* taskMeasureVoltage loop */
while(1){ }
} /* taskMeasureCurrent function */
void taskMeasureCurrent(void *pParam){
/* taskMeasureCurrent loop */
while(1){ }
}
顺利建立好3个任务之后,封装到到一个专门负责slave任务建立的函数中~
int slaveTaskInit(void){
RAW_U32 resultImpedance = -1;
RAW_U32 resultVoltage = -1;
RAW_U32 resultCurrent = -1;
raw_printk("\n");
raw_printk("====== Slave Board Tasks Setup ======\n");
/* Creat taskMeasureImpedance */
resultImpedance = raw_task_create(&taskMeasureImpedance_obj, "taskMeasureImpedance", NULL,
IMPEDANCE_PRIO, IMPEDANCE_SLICE, impedance_stack, TASK_STK_SIZE, taskMeasureImpedance, 0);
if(resultImpedance == RAW_OS_STOPPED){
raw_printk("creat taskMeasureImpedance successful ...\n");
}
else{
raw_printk("creat taskMeasureImpedance faild with error code : %x ... \n", resultImpedance);
RAW_ASSERT(0)
}
/* Creat taskMeasureVoltage */
resultVoltage = raw_task_create(&taskMeasureVoltage_obj, "taskMeasureVoltage", NULL,
VOLTAGE_PRIO, VOLTAGE_SLICE, voltage_stack, TASK_STK_SIZE, taskMeasureVoltage, 0);
if(resultVoltage == RAW_OS_STOPPED){
raw_printk("creat taskMeasureVoltage successful ...\n");
}
else{
raw_printk("creat taskMeasureVoltage faild with error code : %x ... \n", resultVoltage);
RAW_ASSERT(0)
}
/* Creat taskMeasureCurrent */
resultCurrent = raw_task_create(&taskMeasureCurrent_obj, "taskMeasureCurrent", NULL,
CURRENT_PRIO, CURRENT_SLICE, current_stack, TASK_STK_SIZE, taskMeasureCurrent, 0);
if(resultCurrent == RAW_OS_STOPPED){
raw_printk("creat taskMeasureCurrent successful ...\n");
}
else{
raw_printk("creat taskMeasureCurrent faild with error code : %x ... \n", resultCurrent);
RAW_ASSERT(0)
}
raw_printk("\n");
return 0;
}
对于master board也有相似的过程~建立master board任务如下:
对应slave board任务建立的过程,编写master board任务,并且最后封装到负责master任务建立的函数~
#include "application.h" #define TASK_STK_SIZE 512 /* tasks parameters */
#define KEY_MSG_PROCESS_PRIO 10
#define KEY_MSG_PROCESS_SLICE 100 #define MASTER_SEND_CMD_PRIO 10
#define MASTER_SEND_CMD_SLICE 100 #define GET_MEASURE_MSG_PRIO 10
#define GET_MEASURE_MSG_SLICE 100 #define LCD_DISP_PRIO 10
#define LCD_DISP_SLICE 100 #define SD_STORE_PRIO 10
#define SD_STORE_SLICE 100 /* task stack */
PORT_STACK key_msg_process_stack[TASK_STK_SIZE];
PORT_STACK master_send_cmd_stack[TASK_STK_SIZE];
PORT_STACK get_measure_msg_stack[TASK_STK_SIZE];
PORT_STACK lcd_disp_stack[TASK_STK_SIZE];
PORT_STACK sd_store_stack[TASK_STK_SIZE]; /* task instance */
RAW_TASK_OBJ taskKeyMsgProcess_obj;
RAW_TASK_OBJ taskMasterSendCmd_obj;
RAW_TASK_OBJ taskGetMeasureMsg_obj;
RAW_TASK_OBJ taskLcdDisp_obj;
RAW_TASK_OBJ taskSdStore_obj; /* taskKeyMsgProcess function */
void taskKeyMsgProcess(void *pParam){
/* taskKeyMsgProcess loop */
while(1){ }
} /* taskMasterSendCmd function */
void taskMasterSendCmd(void *pParam){
/* taskMasterSendCmd loop */
while(1){ }
} /* taskGetMeasureMsg function */
void taskGetMeasureMsg(void *pParam){
/* taskGetMeasureMsg loop */
while(1){ }
} /* taskLcdDisp function */
void taskLcdDisp(void *pParam){
/* taskLcdDisp loop */
while(1){ }
} /* taskSdStore function */
void taskSdStore(void *pParam){
/* taskSdStore loop */
while(1){ }
} int masterTaskInit(void){
RAW_U32 resultKeyMsgProcess = -1;
RAW_U32 resultMasterSendCmd = -1;
RAW_U32 resultGetMeasureMsg = -1;
RAW_U32 LcdDisp = -1;
RAW_U32 SdStore = -1; raw_printk("\n");
raw_printk("====== Master Board Tasks Setup ======\n"); /* Creat KeyMsgProcess */
resultKeyMsgProcess = raw_task_create(&taskKeyMsgProcess_obj, "taskKeyMsgProcess", NULL,
KEY_MSG_PROCESS_PRIO, KEY_MSG_PROCESS_SLICE, key_msg_process_stack, TASK_STK_SIZE, taskKeyMsgProcess, 0);
if(resultKeyMsgProcess == RAW_OS_STOPPED){
raw_printk("creat KeyMsgProcess successful ...\n");
}
else{
raw_printk("creat KeyMsgProcess faild with error code : %x ... \n", resultKeyMsgProcess);
RAW_ASSERT(0)
} /* Creat MasterSendCmd */
resultMasterSendCmd = raw_task_create(&taskMasterSendCmd_obj, "taskMasterSendCmd", NULL,
MASTER_SEND_CMD_PRIO, MASTER_SEND_CMD_SLICE, master_send_cmd_stack, TASK_STK_SIZE, taskMasterSendCmd, 0);
if(resultMasterSendCmd == RAW_OS_STOPPED){
raw_printk("creat taskMasterSendCmd successful ...\n");
}
else{
raw_printk("creat taskMasterSendCmd faild with error code : %x ... \n", resultMasterSendCmd);
RAW_ASSERT(0)
} /* Creat taskGetMeasureMsg */
resultGetMeasureMsg = raw_task_create(&taskGetMeasureMsg_obj, "taskGetMeasureMsg", NULL,
GET_MEASURE_MSG_PRIO, GET_MEASURE_MSG_SLICE, get_measure_msg_stack, TASK_STK_SIZE, taskGetMeasureMsg, 0);
if(resultGetMeasureMsg == RAW_OS_STOPPED){
raw_printk("creat taskGetMeasureMsg successful ...\n");
}
else{
raw_printk("creat taskGetMeasureMsg faild with error code : %x ... \n", resultGetMeasureMsg);
RAW_ASSERT(0)
} /* Creat taskLcdDisp */
LcdDisp = raw_task_create(&taskLcdDisp_obj, "taskLcdDisp", NULL,
LCD_DISP_PRIO, LCD_DISP_SLICE, lcd_disp_stack, TASK_STK_SIZE, taskLcdDisp, 0);
if(LcdDisp == RAW_OS_STOPPED){
raw_printk("creat taskLcdDisp successful ...\n");
}
else{
raw_printk("creat taskLcdDisp faild with error code : %x ... \n", LcdDisp);
RAW_ASSERT(0)
} /* Creat taskSdStore */
SdStore = raw_task_create(&taskSdStore_obj, "taskSdStore", NULL,
SD_STORE_PRIO, SD_STORE_SLICE, sd_store_stack, TASK_STK_SIZE, taskSdStore, 0);
if(SdStore == RAW_OS_STOPPED){
raw_printk("creat taskSdStore successful ...\n");
}
else{
raw_printk("creat taskSdStore faild with error code : %x ... \n", SdStore);
RAW_ASSERT(0)
} raw_printk("\n"); return 0;
}
好了,到此结束了,这次先把任务建立起来,可以下载Raw-OS的kernel看看任务头文件还有那些函数可用,先熟悉熟悉,至于编程练习,可以自行试试,至少一半的函数都用用。
/* 2012-4 Created by jorya_txj
* xxxxxx please added here
*/ #ifndef RAW_TASK_H
#define RAW_TASK_H typedef RAW_VOID (*RAW_TASK_ENTRY)(RAW_VOID *p_arg); RAW_U16 raw_task_create(RAW_TASK_OBJ *task_obj, RAW_U8 *task_name, RAW_VOID *task_arg,
RAW_U8 task_prio, RAW_U32 time_slice, PORT_STACK *task_stack_base,
RAW_U32 stack_size, RAW_TASK_ENTRY task_entry, RAW_U8 auto_start); RAW_U16 raw_disable_sche(void); RAW_U16 raw_enable_sche(void); RAW_U16 raw_sleep(RAW_TICK_TYPE dly);
RAW_U16 raw_time_sleep(RAW_U16 hours, RAW_U16 minutes, RAW_U16 seconds, RAW_U32 milli); #if (CONFIG_RAW_TASK_SUSPEND > 0)
RAW_U16 raw_task_suspend(RAW_TASK_OBJ *task_ptr);
RAW_U16 raw_task_resume(RAW_TASK_OBJ *task_ptr);
RAW_U16 task_suspend(RAW_TASK_OBJ *task_ptr);
RAW_U16 task_resume(RAW_TASK_OBJ *task_ptr); #endif #if (CONFIG_RAW_TASK_PRIORITY_CHANGE > 0)
RAW_U16 raw_task_priority_change (RAW_TASK_OBJ *task_ptr, RAW_U8 new_priority, RAW_U8 *old_priority);
#endif #if (CONFIG_RAW_TASK_DELETE > 0)
RAW_U16 raw_task_delete(RAW_TASK_OBJ *task_ptr);
#endif #if (CONFIG_RAW_TASK_WAIT_ABORT > 0)
RAW_U16 raw_task_wait_abort(RAW_TASK_OBJ *task_ptr);
#endif #if (CONFIG_SCHED_FIFO_RR > 0)
RAW_U16 raw_task_time_slice_change(RAW_TASK_OBJ *task_ptr, RAW_U32 new_time_slice);
RAW_U16 raw_set_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 policy);
RAW_U16 raw_get_sched_way(RAW_TASK_OBJ *task_ptr, RAW_U8 *policy_ptr);
#endif RAW_TASK_OBJ *raw_task_identify(void); #if (CONFIG_RAW_TASK_STACK_CHECK > 0)
RAW_U16 raw_task_stack_check(RAW_TASK_OBJ *task_obj, RAW_U32 *free_stack);
#endif #if (CONFIG_USER_DATA_POINTER > 0)
RAW_VOID raw_set_task_user_point(RAW_TASK_OBJ *task_ptr, RAW_VOID *user_point, RAW_U32 point_position); RAW_VOID *raw_get_task_user_point(RAW_TASK_OBJ *task_ptr, RAW_U32 point_position);
#endif #if (CONFIG_RAW_DEBUG > 0)
RAW_U16 raw_iter_block_task(LIST *object_head, RAW_VOID (*debug_function)(RAW_TASK_OBJ *), RAW_U8 opt);
RAW_U32 raw_get_system_global_space(void);
#endif #define RAW_TASK_AUTO_START 1
#define RAW_TASK_DONT_START 0 #endif
最后,在linux下openrisc架构验证的信息是这样的:
在Raw-OS的官网下载相关API说明,看看任务相关还有哪些函数可用,小弟也会本着用到再去解释的原则去说明一下,希望大家继续支持Raw-OS发展哈~
好了,下次见,荆轲刺秦王~~~
or1200下raw-os学习(任务篇)的更多相关文章
- 基于raw os 的事件触发系统
Raw os的事件触发系统有以下特点: 1 基于UML的状态机理念设计,实现了有限状态机(fsm)以及层次状态机(HSM). 2 实现了活动对象(ACTIVE OBJECT)的特性,一个活动对象包含了 ...
- Java并发包下锁学习第一篇:介绍及学习安排
Java并发包下锁学习第一篇:介绍及学习安排 在Java并发编程中,实现锁的方式有两种,分别是:可以使用同步锁(synchronized关键字的锁),还有lock接口下的锁.从今天起,凯哥将带领大家一 ...
- Java并发包下锁学习第二篇Java并发基础框架-队列同步器介绍
Java并发包下锁学习第二篇队列同步器 还记得在第一篇文章中,讲到的locks包下的类结果图吗?如下图: 从图中,我们可以看到AbstractQueuedSynchronizer这个类很重要(在本 ...
- 如何系统学习C 语言(下)之 预处理命令篇
大话c语言(下)之 预处理命令篇 预处理就是在编译之前,通过一些预处理命令对源代码进行管理和控制的过程. 由源代码得到可执行的程序,会经过预处理.编译.汇编和链接几个过程 预处理命令大致可以分为文件包 ...
- 一、React Native 搭建开发环境(1)(Mac OS - IOS项目篇)
React Native是Facebook推出的一个开发IOS和安卓APP的技术.至于更多的详情,这里不再描述,大家可以自行百度它的定义. 原因:由于我想在一台电脑上同时开发IOS和Android两个 ...
- [置顶] Firefox OS 学习——manifest.webapp结构分析
在Firefox OS 学习——Gaia 编译分析 这篇文章多次提到manifest.webapp文件,对于做过android app 开发的人来说,都很熟悉Android.mk 和Manifest ...
- Docker虚拟化实战学习——基础篇(转)
Docker虚拟化实战学习——基础篇 2018年05月26日 02:17:24 北纬34度停留 阅读数:773更多 个人分类: Docker Docker虚拟化实战和企业案例演练 深入剖析虚拟化技 ...
- [Django]模型学习记录篇--基础
模型学习记录篇,仅仅自己学习时做的记录!!! 实现模型变更的三个步骤: 修改你的模型(在models.py文件中). 运行python manage.py makemigrations ,为这些修改创 ...
- Unix和Linux下C语言学习指南
转自:http://www.linuxdiyf.com/viewarticle.php?id=174074 Unix和Linux下C语言学习指南 引言 尽管 C 语言问世已近 30 年,但它的魅力仍未 ...
随机推荐
- Linux服务部署
1. 构建NTP时间服务器 NTP服务器是用于局域网服务器时间同步使用的,可以保证局域网所有的服务器与时间服务器的时间保持一致,某些应用对时间实时性要求高的必须统一时间.互联网的时间服务器也有很多,例 ...
- [转]linux系统磁盘分区之parted
转自:http://blog.csdn.net/h249059945/article/details/12668793 对于linux的分区通常可以使用fdisk命令工具和parted工具对于分区表通 ...
- [转]linux的du和df命令
转自:http://blog.csdn.net/kmesg/article/details/6570800 今天也有同学问我Linux下查看目录大小的命令,现在也将前阵子学习到du/df两个命令总结一 ...
- 记一个社交APP的开发过程——基础架构选型(转自一位大哥)
记一个社交APP的开发过程——基础架构选型 目录[-] 基本产品形态 技术选型 最近两周在忙于开发一个社交App,因为之前做过一点儿社交方面的东西,就被拉去做API后端了,一个人头一次完整的去搭这么一 ...
- 利用BlazeDS的AMF3数据封装与Flash 进行Socket通讯
前几天看到了Adobe有个开源项目BlazeDS,里面提供了Java封装AMF3格式的方法.这个项目貌似主要是利用Flex来Remoting的,不过我们可以利用他来与Flash中的Socket通讯. ...
- Linux下静态库生成和使用
Linux下静态库生成和使用 一.静态库概念 1.库是预编译的目标文件(object files)的集合,它们可以被链接进程序.静态库以后缀为”.a”的特殊的存档(archive file)存储. ...
- openjdk sunjdk区别
使用过LINUX的人都应该知道,在大多数LINUX发行版本里,内置或者通过软件源安装JDK的话,都是安装的openjdk,那么到底什么是openjdk,它与sun jdk有什么关系和区别呢? 历史上的 ...
- 第三百三十五天 how can I 坚持
晚上回来看了个奥斯卡影片,<疯狂的麦克斯-狂暴之路>,挺震撼的场面.导演确实挺厉害,不知道是怎么想象出来的. 睡觉,明天继续.
- ESB 客户端调用 处理类
esb package com.isoftstone.synchronize.entrance; import java.io.File; import java.text.SimpleDateFor ...
- JavaScript学习——内置属性
在js中,几乎所有的对象都是同源对象,都继承Object对象.对象的内置属性指的是它们作为Object实例所具有的属性,这些属性通常反映对象本身的基本信息和数据无关.因此我们称它们为元属性.这些属性通 ...