当前位置: 首页 > news >正文

网站建议公司晋安网站建设

网站建议公司,晋安网站建设,做网站怎么在图片上加文字,wordpress怎么设置主页STM32F4X UCOSIII任务消息队列 任务消息队列和内核消息队列对比内核消息队列内核消息队列 UCOSIII任务消息队列API任务消息队列发送函数任务消息队列接收函数 UCOSIII任务消息队列例程 之前的章节中讲解过消息队列这个机制,UCOSIII除了有内核消息队列之外&#xff0…

STM32F4X UCOSIII任务消息队列

  • 任务消息队列和内核消息队列对比
    • 内核消息队列
    • 内核消息队列
  • UCOSIII任务消息队列API
    • 任务消息队列发送函数
    • 任务消息队列接收函数
  • UCOSIII任务消息队列例程

之前的章节中讲解过消息队列这个机制,UCOSIII除了有内核消息队列之外,还有任务消息队列。在UCOSIII中,每个任务内部都会有一个内嵌消息队列。在大多数情况下,任务消息队列可以代替内核消息队列。

任务消息队列和内核消息队列对比

内容内核消息队列任务消息队列
是否需要创建
是否需要指定任务
是否可以广播

内核消息队列

内核消息队列在使用前需要用户创建消息队列,内核消息队列不需要指定接收消息队列的任务,并且可以以广播的方式给所有等待消息队列的任务获取消息。

内核消息队列

任务消息队列不需要用户创建,任务消息队列在创建任务的时候就已经内嵌到任务控制块里面。任务消息队列使用的时候需要指定接收任务消息队列的任务,而且一次只能指定一个任务,不能广播。

UCOSIII任务消息队列API

任务消息队列发送函数

/** p_tcb:指向需要发送信号量的任务,NULL则代表自己* p_void:需要发送的消息指针* msg_size:需要发送的消息长度* opt:用户选项* p_err:错误代码
*/
void  OSTaskQPost (OS_TCB       *p_tcb,void         *p_void,OS_MSG_SIZE   msg_size,OS_OPT        opt,OS_ERR       *p_err)

opt可以选择OS_OPT_POST_FIFO和OS_OPT_POST_LIFO

  • OS_OPT_POST_FIFO:消息以先进先出的模式存放
  • OS_OPT_POST_LIFO:消息以后进先出的模式存放

任务消息队列接收函数

/** timeout:超时时间* opt:用户选项* p_msg_size:接收到的消息长度* p_ts:时间戳* p_err:错误代码
返回值:返回接收到消息指针,如果为NULL则接收错误
*/
void  *OSTaskQPend (OS_TICK       timeout,OS_OPT        opt,OS_MSG_SIZE  *p_msg_size,CPU_TS       *p_ts,OS_ERR       *p_err)

opt可以选择OS_OPT_PEND_BLOCKING和OS_OPT_PEND_NON_BLOCKING

  • OS_OPT_PEND_BLOCKING:阻塞等待任务消息队列,除非有任务消息队列,否则任务不会恢复
  • OS_OPT_PEND_NON_BLOCKING:不阻塞等待任务消息队列,如果任务等待时间超过设定的超时时间,任务会恢复并返回一个错误代码

UCOSIII任务消息队列例程

例程中任务1会每隔1秒向任务2发送任务消息,任务2则阻塞等待消息

/*
*********************************************************************************************************
*                                              EXAMPLE CODE
*
*                             (c) Copyright 2013; Micrium, Inc.; Weston, FL
*
*                   All rights reserved.  Protected by international copyright laws.
*                   Knowledge of the source code may not be used to write a similar
*                   product.  This file may only be used in accordance with a license
*                   and should not be redistributed in any way.
*********************************************************************************************************
*//*
*********************************************************************************************************
*
*                                            EXAMPLE CODE
*
*                                       IAR Development Kits
*                                              on the
*
*                                    STM32F429II-SK KICKSTART KIT
*
* Filename      : app.c
* Version       : V1.00
* Programmer(s) : YS
*********************************************************************************************************
*//*
*********************************************************************************************************
*                                             INCLUDE FILES
*********************************************************************************************************
*/#include  <includes.h>/*
*********************************************************************************************************
*                                            LOCAL DEFINES
*********************************************************************************************************
*//*
*********************************************************************************************************
*                                       LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*//* ----------------- APPLICATION GLOBALS -------------- */
static  OS_TCB   AppTaskStartTCB;
static  CPU_STK  AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];#define APPTASK1NAME    "App Task1"
#define APP_TASK1_PRIO          3   
#define APP_TASK1_STK_SIZE 1024
static OS_TCB AppTask1TCB;
static void  AppTask1  (void *p_arg);
static CPU_STK AppTask1Stk[APP_TASK1_STK_SIZE];#define APPTASK2NAME    "App Task2"
#define APP_TASK2_PRIO          4   
#define APP_TASK2_STK_SIZE 1024
static OS_TCB AppTask2TCB;
static void  AppTask2  (void *p_arg);
static CPU_STK AppTask2Stk[APP_TASK2_STK_SIZE];
/*
*********************************************************************************************************
*                                         FUNCTION PROTOTYPES
*********************************************************************************************************
*/static  void  AppTaskStart          (void     *p_arg);
struct msg
{char msg_string[50];int value;
};/*
*********************************************************************************************************
*                                                main()
*
* Description : This is the standard entry point for C code.  It is assumed that your code will call
*               main() once you have performed all necessary initialization.
*
* Arguments   : none
*
* Returns     : none
*********************************************************************************************************
*/int main(void)
{OS_ERR  err;OSInit(&err);                                               /* Init uC/OS-III.                                      */OSTaskCreate((OS_TCB       *)&AppTaskStartTCB,              /* Create the start task                                */(CPU_CHAR     *)"App Task Start",(OS_TASK_PTR   )AppTaskStart,(void         *)0u,(OS_PRIO       )APP_CFG_TASK_START_PRIO,(CPU_STK      *)&AppTaskStartStk[0u],(CPU_STK_SIZE  )AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE / 10u],(CPU_STK_SIZE  )APP_CFG_TASK_START_STK_SIZE,(OS_MSG_QTY    )0u,(OS_TICK       )0u,(void         *)0u,(OS_OPT        )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),(OS_ERR       *)&err);OSStart(&err);                                              /* Start multitasking (i.e. give control to uC/OS-III). */}/*
*********************************************************************************************************
*                                          STARTUP TASK
*
* Description : This is an example of a startup task.  As mentioned in the book's text, you MUST
*               initialize the ticker only once multitasking has started.
*
* Arguments   : p_arg   is the argument passed to 'AppTaskStart()' by 'OSTaskCreate()'.
*
* Returns     : none
*
* Notes       : 1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
*                  used.  The compiler should not generate any code for this statement.
*********************************************************************************************************
*/static  void  AppTaskStart (void *p_arg)
{CPU_INT32U  cpu_clk_freq;CPU_INT32U  cnts;OS_ERR      err;(void)p_arg;BSP_Init();                      CPU_Init();                                                 /* Initialize the uC/CPU services                       */cpu_clk_freq = BSP_CPU_ClkFreq();                           /* Determine SysTick reference freq.                    */cnts         = cpu_clk_freq                                 /* Determine nbr SysTick increments                     *// (CPU_INT32U)OSCfg_TickRate_Hz;OS_CPU_SysTickInit(cnts);                                   /* Init uC/OS periodic time src (SysTick).              */Mem_Init();                                                 /* Initialize memory managment module                   */Math_Init();                                                /* Initialize mathematical module                       */#if OS_CFG_STAT_TASK_EN > 0uOSStatTaskCPUUsageInit(&err);                               /* Compute CPU capacity with no task running            */
#endif#ifdef CPU_CFG_INT_DIS_MEAS_ENCPU_IntDisMeasMaxCurReset();
#endif#if (APP_CFG_SERIAL_EN == DEF_ENABLED)App_SerialInit();                                           /* Initialize Serial communication for application ...  */
#endifOSTaskCreate((OS_TCB     *)&AppTask1TCB,  // 线程TCB              (CPU_CHAR   *)APPTASK1NAME, // 线程名字(OS_TASK_PTR ) AppTask1, // 线程入口函数(void       *) "TASK1", // 线程参数(OS_PRIO     ) APP_TASK1_PRIO, // 线程优先级(CPU_STK    *)&AppTask1Stk[0], // 线程栈起始地址(CPU_STK_SIZE) APP_TASK1_STK_SIZE / 10, // 栈深度的限制位置(CPU_STK_SIZE) APP_TASK1_STK_SIZE, // 栈大小(OS_MSG_QTY  ) 5u, // 最大的消息个数(OS_TICK     ) 0u, // 时间片(void       *) 0, // 向用户提供的内存位置的指针(OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), // 线程特定选项(OS_ERR     *)&err); // 错误标志if(OS_ERR_NONE == err)printf("%s Create Success\r\n",APPTASK1NAME);elseprintf("%s Create Error\r\n",APPTASK1NAME);OSTaskCreate((OS_TCB     *)&AppTask2TCB,  // 线程TCB              (CPU_CHAR   *)APPTASK2NAME, // 线程名字(OS_TASK_PTR ) AppTask2, // 线程入口函数(void       *) "TASK2", // 线程参数(OS_PRIO     ) APP_TASK2_PRIO, // 线程优先级(CPU_STK    *)&AppTask2Stk[0], // 线程栈起始地址(CPU_STK_SIZE) APP_TASK2_STK_SIZE / 10, // 栈深度的限制位置(CPU_STK_SIZE) APP_TASK2_STK_SIZE, // 栈大小(OS_MSG_QTY  ) 5u, // 最大的消息个数(OS_TICK     ) 0u, // 时间片(void       *) 0, // 向用户提供的内存位置的指针(OS_OPT      )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR), // 线程特定选项(OS_ERR     *)&err); // 错误标志if(OS_ERR_NONE == err)printf("%s Create Success\r\n",APPTASK2NAME);elseprintf("%s Create Error\r\n",APPTASK2NAME);OSTaskDel ( & AppTaskStartTCB, & err );		 }static void  AppTask1  (void *p_arg)
{OS_ERR      err;static struct msg msg_send = {0};while(DEF_TRUE){OSTimeDly ( 1000, OS_OPT_TIME_DLY, & err ); // 1s运行一次Str_Copy_N(msg_send.msg_string,"hello this is a msg1",sizeof(msg_send.msg_string)); // 填充消息OSTaskQPost(&AppTask2TCB,&msg_send,sizeof(struct msg),OS_OPT_POST_FIFO,&err); // 向TASK2发送任务消息msg_send.value++;if(err == OS_ERR_NONE)printf("Task1 Msg Post Success\r\n");elseprintf("Task1 Msg Post Error\r\n");}}
static void  AppTask2  (void *p_arg)
{OS_ERR      err;struct msg *pmsg;OS_MSG_SIZE msg_size;while(DEF_TRUE){pmsg = OSTaskQPend(0,OS_OPT_PEND_BLOCKING,&msg_size,0,&err); // 阻塞等待任务消息if(err == OS_ERR_NONE)printf("Task2 Get Msg Success \r\n");elseprintf("Task1 Get Msg Error\r\n");printf("msg srting %s\r\n",pmsg->msg_string);printf("msg value %d\r\n",pmsg->value);}}

在这里插入图片描述

http://www.yayakq.cn/news/322568/

相关文章:

  • 电子商务网站开发代码开一个公司需要具备什么条件
  • 国外购物网站平台有哪些百度电脑版官网
  • 工程承包网站有哪些中国建设移动门户网站
  • 北京市建设工程审核网站宁波网站建设哪个公司好
  • 网站结构seo安徽省住房城乡建设厅网站
  • 昆山普立斯特做的有网站荣耀手机正品官网查询
  • 电子商务网站的优势可以赚钱做任务的网站
  • 西安代做毕业设计网站ae
  • 模块网站需要多少钱广州地铁18号线最新线路图
  • 网站广告位图片更换没反应电子产品营销策划书
  • 提交网站入口陈村网站开发
  • 仿 手机 网站模板html如何制作网站视频的软件
  • 做网站设计累吗手机网站建设效果
  • 哈尔滨手机网站建设价格低vi企业形象设计案例
  • 易进网站建设推广网站建设公司有前途吗
  • 南京 高端网站制作做的网站怎么联网
  • 建那种外卖网站该怎么做安国手机网站设计
  • 滨州市网站建设穆棱市住房和城乡建设局网站
  • 网站建设新趋势个人网页制作价格
  • seo网站关键词优化排名黄页88网站
  • 重庆便宜网站建设电子商务网站建设模式
  • 挂马网站教程网站单页生成器
  • 做物流的网站有哪些功能php学建网站
  • 深圳外贸建站及推广iis7 发布静态网站
  • 网站 域名 授权服务器 分布式做网站哪里买空间好
  • 互联网做网站的话术手机app推荐
  • 当当网网站建设需求分析wordpress展示页面模板
  • 做网站的财务会涉及到的科目潮州营销型网站建设推广
  • 做网站所需要哪方面的知识wordpress公众号文章
  • 如何将网站变成免费wordpress定时发布