RTX

注意:

如果在KEIL中添加了集成的RTX5系统文件,第一个错误是:

C:\Keil_v5\ARM\PACK\ARM\CMSIS\5.0.1\CMSIS\RTOS2\RTX\Include1\cmsis_os.h(150): error:  #5: cannot open source input file "cmsis_os2.h": No such file or directory

那么就是你没有勾选另外的下发的一个地方


初始化:

osKernelInitialize();

osKernelStart();

int32_t osKernelRunning(void);       检验运行否


任务:

osThreadId  ID_ThreadRF =  0;

osThreadDef (Task_CC1101, osPriorityHigh, 1, 0) ; // osThreadDef(name, thread, priority, instances, stacksz) 定义线程类

ID_ThreadRF= osThreadCreate (osThread(Task_CC1101), NULL);

ID_ThreadRF= osThreadGetId (void);                                     //返回当前线程

osStatus osThreadTerminate (ID_ThreadRF);                         //终结线程

osStatus osThreadSetPriority (ID_ThreadRF, osPriorityHigh);       //设置线程优先级

osPriority osThreadGetPriority (ID_ThreadRF);                       //获取线程优先级

优先级 :

typedef enum  {
  osPriorityIdle                   = -3,          ///< priority: idle (lowest)
  osPriorityLow                  = -2,          ///< priority: low
  osPriorityBelowNormal   = -1,          ///< priority: below normal
  osPriorityNormal             =  0,          ///< priority: normal (default)
  osPriorityAboveNormal   = +1,          ///< priority: above normal
  osPriorityHigh                 = +2,          ///< priority: high
  osPriorityRealtime          = +3,          ///< priority: realtime (highest)
  osPriorityError                =  0x84,       ///< system cannot determine priority or thread has illegal priority
  os_priority_reserved       =  0x7FFFFFFF  ///< prevent from enum down-size compiler optimization.
} osPriority;

互斥量:

osMutexDef(name)                                      定义os_mutex_def结构体

osMutex(name)                                            获取os_mutex_def结构体的指针

osMutexId osMutexCreate (const osMutexDef_t *mutex_def);                     

osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec);           

osStatus osMutexRelease (osMutexId mutex_id);                         

osStatus osMutexDelete (osMutexId mutex_id);      

  信号量:

osSemaphoreDef(name)                                        定义os_semaphore_def结构体

osSemaphore(name)                                              获取os_semaphore_def结构体的指针

osSemaphoreId    osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t count);     

int32_t    osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec);            

osStatus osSemaphoreRelease (osSemaphoreId semaphore_id);                    

osStatus osSemaphoreDelete (osSemaphoreId semaphore_id);                

信号:

int32_t     osSignalSet (osThreadId thread_id, int32_t signals);                  

                osSignalSet(MotorControl,0x02);    // 发送通知到任务MotorControl, 信号为0x02 

        RTX 的 osSignalSet是对FreeRTOS中的xTaskNotifyFromISR和xTaskNotify的条件封装,处于中断回调函数中时调用xTaskNotifyFromISR,否则使用xTaskNotify,在使用中无需再进行选择;

osEvent   osSignalWait (int32_t signals, uint32_t millisec);                   

osEvent eve;                                          //在任务中实现

eve=osSignalWait(0,osWaitForever);    //   #define osWaitForever     0xFFFFFFFFU    ///< wait forever timeout value

if(eve.value.signals & 0x01).....

if(eve.value.signals & 0x02).....

        在实际使用中,osSignalWait(0x20,600);就是等待确定信号0x20的到来,不是任意位触发(关系或),除了0x20外,诸如0x30之类的包含确定位也不能释放该信号等待。这与UCOS的位设定模式有一些差异,使用起来有点不痛快。osSignalWait(0,600); 为等待任意位信号到来,综合起来就是无法组合信号值。

int32_t     osSignalClear (osThreadId thread_id, int32_t signals);     清除信号。

消息队列:

osMessageQId  MsgBox;               //消息队列的ID 
osMessageQDef(MsgBox, 1, int); //创建一个长度为1,单位int 的消息队列

 MsgBox = osMessageCreate(osMessageQ(MsgBox), NULL);   一定要给声明的变量osMessageQId  MsgBox赋值

消息传送:osMessagePut(MsgBox, 1, osWaitForever);

 osEvent  evt;

消息取出:evt = osMessageGet(MsgBox, osWaitForever);

if (evt.status == osEventMessage)
{
      ptr = evt.value.p;  //  value = evt.value.v;

      ........
}

网上有例程代码取数据:

    osEvent  evt = osMessageGet(RF_MsgQ, osWaitForever);
    if (evt.status == osOK){.....}     使用osOK是无法取到的!

osEvent类型定义:

typedef struct  {
  osStatus                   status;         ///< status code: event or error information
  union  {
    uint32_t                    v;              ///< message as 32-bit value
    void                         *p;              ///< message or mail as void pointer
    int32_t                     signals;      ///< signal flags
  } value;                                        ///< event value
  union  {
    osMailQId               mail_id;              ///< mail id obtained by \ref osMailCreate
    osMessageQId       message_id;      ///< message id obtained by \ref osMessageCreate
  } def;                           
} osEvent;

在使用中,osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec);传递的变量 info 为 uint32_t类型,如果需要传递更复杂的参数,需要用此来传递指针变量,涉及到申请内存空间:

osPoolDef(mpool, 2, RadioMail);                

osPoolId    mpool;

RadioMail *RF_Mail;

RF_Mail = osPoolAlloc(mpool);  .......  所以在传递大量或者自定义数据类型时,还是用mailQ实在。

邮箱队列:

osMailQDef(name, queue_sz, type)

osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id);

void *osMailAlloc (osMailQId queue_id, uint32_t millisec);      //分配一个消息的空间
void *osMailCAlloc (osMailQId queue_id, uint32_t millisec);   //分配一个消息的空间并且清零
osStatus osMailPut (osMailQId queue_id, void *mail);            //将成员丢到邮箱中
osEvent osMailGet (osMailQId queue_id, uint32_t millisec);  //从邮箱中获取消息
osStatus osMailFree (osMailQId queue_id, void *mail);         //释放消息空间










  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值