久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费
標題:
基于消息隊列的UCOSII STM32源碼
[打印本頁]
作者:
tangqi334
時間:
2018-10-19 10:40
標題:
基于消息隊列的UCOSII STM32源碼
此文件適合于STM32上移植UCOSII系統,通過消息隊列的方法創建程序,完成3個LED燈的閃爍。
單片機源程序如下:
/****************************************************************************
* 本例程在 奮斗版STM32開發板V2,2.1,V3,MINI上調試通過
*
* 文件名: app.c
* 內容簡述:
* 本例程操作系統采用ucos2.86a版本, 建立了2個任務
任務名 優先級
APP_TASK_START_PRIO 2 主任務
Task_Led1_PRIO 7 LED閃爍任務
當然還包含了系統任務:
OS_TaskIdle 空閑任務-----------------優先級最低
OS_TaskStat 統計運行時間的任務-------優先級次低
* 通過建立消息隊列,傳送3個指針型變量給Led1_Task,經過判斷,觸發3個led燈的閃爍控制
* 文件歷史:
* 版本號 日期 作者 說明
* v0.1 2012-10-08 sun68 創建該文件
*
*/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#define GLOBALS
#include "stdarg.h"
#include "includes.h"
//#include "globals.h"
OS_EVENT *MsgQueue;
void *MsgQueueTbl[20];
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE];
static OS_STK Task_Led1Stk[Task_Led1_STK_SIZE];
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void App_TaskCreate(void);
static void App_TaskStart(void* p_arg);
static void Task_Led1(void* p_arg);
#define LED_LED1_ON() GPIO_SetBits(GPIOB, GPIO_Pin_5 ); //LED1 亮
#define LED_LED1_OFF() GPIO_ResetBits(GPIOB, GPIO_Pin_5 ); //LED1 滅
#define LED_LED2_ON() GPIO_SetBits(GPIOD, GPIO_Pin_6 ); //LED2 亮
#define LED_LED2_OFF() GPIO_ResetBits(GPIOD, GPIO_Pin_6 ); //LED2 滅
#define LED_LED3_ON() GPIO_SetBits(GPIOD, GPIO_Pin_3 ); //LED3 亮
#define LED_LED3_OFF() GPIO_ResetBits(GPIOD, GPIO_Pin_3 ); //LED3 滅
/*
*********************************************************************************************************
* 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.
*
* Argument : none.
*
* Return : none.
*********************************************************************************************************
*/
int main(void)
{
CPU_INT08U os_err;
//禁止CPU中斷
CPU_IntDis();
//UCOS 初始化
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
//硬件平臺初始化
BSP_Init(); /* Initialize BSP functions. */
//建立主任務, 優先級最高 建立這個任務另外一個用途是為了以后使用統計任務
os_err = OSTaskCreate((void (*) (void *)) App_TaskStart, //指向任務代碼的指針
(void *) 0, //任務開始執行時,傳遞給任務的參數的指針
(OS_STK *) &App_TaskStartStk[APP_TASK_START_STK_SIZE - 1], //分配給任務的堆棧的棧頂指針 從頂向下遞減
(INT8U) APP_TASK_START_PRIO); //分配給任務的優先級
//ucos的節拍計數器清0 節拍計數器是0-4294967295 對于節拍頻率100hz時, 每隔497天就重新計數
OSTimeSet(0);
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */
/* Start multitasking (i.e. give control to uC/OS-II). */
return (0);
}
/*
*********************************************************************************************************
* App_TaskStart()
*
* Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
*
* Argument : p_arg Argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
*
* Return : none.
*
* Caller : This is a task.
*
* Note : none.
*********************************************************************************************************
*/
static void App_TaskStart(void* p_arg)
{
char one='1';
char two='2';
char three='3';
(void) p_arg;
//初始化ucos時鐘節拍
OS_CPU_SysTickInit(); /* Initialize the SysTick. */
//使能ucos 的統計任務
#if (OS_TASK_STAT_EN > 0)
//----統計任務初始化函數
OSStatInit(); /* Determine CPU capacity. */
#endif
//建立其他的任務
App_TaskCreate();
while (1)
{
OSQPost(MsgQueue,(void *)&one);
OSTimeDlyHMSM(0, 0,1, 0);
OSQPost(MsgQueue,(void *)&two);
OSTimeDlyHMSM(0, 0,0, 500);
OSQPost(MsgQueue,(void *)&three);
OSTimeDlyHMSM(0, 0,1, 0);
}
}
//LED閃爍任務----------------------------------------
static void Task_Led1(void* p_arg)
{
INT8U err;
INT8U *msg;
(void) p_arg;
while (1)
{
msg=(INT8U*)OSQPend(MsgQueue,0,&err); //等待Led1信號量
if(*msg=='1'){
LED_LED1_ON();
LED_LED2_OFF();
LED_LED3_OFF();
}
else if(*msg=='2'){
LED_LED2_ON();
LED_LED1_OFF();
LED_LED3_OFF();
}
else if(*msg=='3'){
LED_LED3_ON();
LED_LED1_OFF();
LED_LED2_OFF();
}
OSTimeDlyHMSM(0, 0,0, 500);
}
}
/*
*********************************************************************************************************
* App_TaskCreate()
*
* Description : Create the application tasks.
*
* Argument : none.
*
* Return : none.
*
* Caller : App_TaskStart().
*
* Note : none.
*********************************************************************************************************
*/
static void App_TaskCreate(void)
{
//CPU_INT08U os_err;
MsgQueue=OSQCreate(&MsgQueueTbl[0],20); //建立消息隊列
//LED1 閃爍任務------------------------------------------------------
OSTaskCreateExt(Task_Led1,(void *)0,(OS_STK *)&Task_Led1Stk[Task_Led1_STK_SIZE-1],Task_Led1_PRIO,Task_Led1_PRIO,(OS_STK *)&Task_Led1Stk[0],
Task_Led1_STK_SIZE,
(void *)0,
OS_TASK_OPT_STK_CHK|OS_TASK_OPT_STK_CLR);
}
/*
*********************************************************************************************************
*********************************************************************************************************
* uC/OS-II APP HOOKS
*********************************************************************************************************
*********************************************************************************************************
*/
#if (OS_APP_HOOKS_EN > 0)
/*
*********************************************************************************************************
* TASK CREATION HOOK (APPLICATION)
*
* Description : This function is called when a task is created.
*
* Argument : ptcb is a pointer to the task control block of the task being created.
*
* Note : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskCreateHook(OS_TCB* ptcb)
{
}
/*
*********************************************************************************************************
* TASK DELETION HOOK (APPLICATION)
*
* Description : This function is called when a task is deleted.
*
* Argument : ptcb is a pointer to the task control block of the task being deleted.
*
* Note : (1) Interrupts are disabled during this call.
*********************************************************************************************************
*/
void App_TaskDelHook(OS_TCB* ptcb)
{
(void) ptcb;
}
/*
*********************************************************************************************************
* IDLE TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskIdleHook(), which is called by the idle task. This hook
* has been added to allow you to do such things as STOP the CPU to conserve power.
*
* Argument : none.
*
* Note : (1) Interrupts are enabled during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 251
void App_TaskIdleHook(void)
{
}
#endif
/*
*********************************************************************************************************
* STATISTIC TASK HOOK (APPLICATION)
*
* Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
* statistics task. This allows your application to add functionality to the statistics task.
*
* Argument : none.
*********************************************************************************************************
*/
void App_TaskStatHook(void)
{
}
/*
*********************************************************************************************************
* TASK SWITCH HOOK (APPLICATION)
*
* Description : This function is called when a task switch is performed. This allows you to perform other
* operations during a context switch.
*
* Argument : none.
*
* Note : 1 Interrupts are disabled during this call.
*
* 2 It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
* will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
* task being switched out (i.e. the preempted task).
*********************************************************************************************************
*/
#if OS_TASK_SW_HOOK_EN > 0
void App_TaskSwHook(void)
{
}
#endif
/*
*********************************************************************************************************
* OS_TCBInit() HOOK (APPLICATION)
*
* Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
* up most of the TCB.
*
* Argument : ptcb is a pointer to the TCB of the task being created.
*
* Note : (1) Interrupts may or may not be ENABLED during this call.
*********************************************************************************************************
*/
#if OS_VERSION >= 204
void App_TCBInitHook(OS_TCB* ptcb)
{
(void) ptcb;
}
#endif
#endif
復制代碼
全部資料51hei下載地址:
STM32-LED閃爍-消息隊列.rar
(382.32 KB, 下載次數: 19)
2018-10-19 10:40 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.zg4o1577.cn/bbs/)
Powered by Discuz! X3.1
主站蜘蛛池模板:
在线观看av网站永久
|
精品一二三区
|
日韩精品视频中文字幕
|
四虎最新地址
|
亚洲欧美激情精品一区二区
|
国产精品久久
|
国产精品综合色区在线观看
|
亚洲啪啪
|
免费视频一区
|
成人深夜福利在线观看
|
欧美2区
|
91激情视频
|
深夜福利影院
|
亚洲一区二区视频在线播放
|
欧美激情一区二区三区
|
56pao在线
|
欧美一区二区三区
|
亚洲精品视频三区
|
中文字幕 亚洲一区
|
99久久国产
|
久久久久亚洲
|
国产一二区在线
|
狠狠操av
|
蜜桃视频在线观看免费视频网站www
|
精品一区二区三区av
|
欧美二区三区
|
成人av播放
|
亚洲精品一区二区三区
|
久久久久久一区
|
在线观看成人小视频
|
乱一性一乱一交一视频a∨ 色爱av
|
亚洲一区二区三区四区五区午夜
|
精品成人一区二区
|
一区二区三区视频在线免费观看
|
久久久蜜桃一区二区人
|
91高清视频在线观看
|
久久伊人亚洲
|
久久精品一
|
欧美日韩亚
|
91美女在线观看
|
国产成人综合一区二区三区
|