標(biāo)題:
STM32F0各種OS工程源碼例程
[打印本頁]
作者:
劉明州
時間:
2019-6-24 20:12
標(biāo)題:
STM32F0各種OS工程源碼例程
STM32F0例程,關(guān)于os系統(tǒng)搭建
0.png
(4.65 KB, 下載次數(shù): 51)
下載附件
2019-6-25 04:03 上傳
單片機源程序如下:
/* 包含的頭文件---------------------------------------------------------------*/
#include "stm32f0xx.h"
#include "ucos_ii.h"
/* 私有類型定義---------------------------------------------------------------*/
/* 私有定義 ------------------------------------------------------------------*/
/* 私有宏定義 ----------------------------------------------------------------*/
#define LED3 GPIO_Pin_9
#define LED4 GPIO_Pin_8
#define LED_PORT GPIOC
#define LED_GPIO_CLK RCC_AHBPeriph_GPIOC
/* 私有變量 ------------------------------------------------------------------*/
/* 變量 ----------------------------------------------------------------------*/
static OS_STK App_Task_LED1_Stk[APP_TASK_LED1_STK_SIZE];
static OS_STK App_Task_LED2_Stk[APP_TASK_LED2_STK_SIZE];
/* 任務(wù)函數(shù) ------------------------------------------------------------------*/
static void App_Task_LED1(void* p_arg);
static void App_Task_LED2(void* p_arg);
/* 私有函數(shù) ------------------------------------------------------------------*/
void LED_Configuration(void);
void Delay(__IO uint32_t nCount);
/***************************************************************************//**
* @brief 主函數(shù),硬件初始化,實現(xiàn)LED1-LED4閃爍
* @note 無
* @param 無
* @retval 無
*******************************************************************************/
int main(void)
{
INT8U os_err;
LED_Configuration ();
OSInit();
OS_CPU_SysTickInit();
//創(chuàng)建LED1閃爍的任務(wù)
os_err = OSTaskCreate( App_Task_LED1,
(void *) 0,
(OS_STK *) &App_Task_LED1_Stk[APP_TASK_LED1_STK_SIZE - 1],
(INT8U) APP_TASK_LED1_PRIO);
//創(chuàng)建LED2閃爍的任務(wù)
os_err = OSTaskCreate( App_Task_LED2,
(void*) 0,
(OS_STK*) &App_Task_LED2_Stk[APP_TASK_LED2_STK_SIZE - 1],
(INT8U ) APP_TASK_LED2_PRIO);
os_err = os_err;//僅僅是清除這個變量未使用的編譯警告
//啟動uSOS 操作系統(tǒng)
OSStart ();
}
/***************************************************************************//**
* @brief 配置使用LED
* @note LED相關(guān)的定義需要根據(jù)需求用宏定義來修改
* @param 無
* @retval 無
*******************************************************************************/
void LED_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能LED所在GPIO的時鐘
RCC_AHBPeriphClockCmd(LED_GPIO_CLK, ENABLE);
//初始化LED的GPIO
GPIO_InitStructure.GPIO_Pin = LED3 | LED4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(LED_PORT, &GPIO_InitStructure);
GPIO_ResetBits(LED_PORT,LED3 | LED4); //熄滅LED3-4
}
/*******************************************************************************
* @函數(shù)名稱 LED_On
* @函數(shù)說明 點亮LED
* @輸入?yún)?shù) LEDx:LED的編號
* @輸出參數(shù) 無
* @返回參數(shù) 無
*******************************************************************************/
void LED_On(uint16_t LEDx)
{
GPIO_SetBits (LED_PORT, LEDx);
}
/*******************************************************************************
* @函數(shù)名稱 LED_Off
* @函數(shù)說明 關(guān)閉LEDx
* @輸入?yún)?shù) LEDx:LED的編號
* @輸出參數(shù) 無
* @返回參數(shù) 無
*******************************************************************************/
void LED_Off(uint16_t LEDx)
{
GPIO_ResetBits (LED_PORT, LEDx);
}
/*******************************************************************************
* @函數(shù)名稱 App_Task_LED1
* @函數(shù)說明 LED任務(wù)1
* @輸入?yún)?shù) 無
* @輸出參數(shù) 無
* @返回參數(shù) 無
*******************************************************************************/
void App_Task_LED1(void* pdata)
{
pdata = pdata;
for (;;)
{
LED_On(LED3);
OSTimeDlyHMSM(0, 0, 0, 500);
LED_Off(LED3);
OSTimeDlyHMSM(0, 0, 0, 500);
}
}
/*******************************************************************************
* @函數(shù)名稱 App_Task_LED2
* @函數(shù)說明 LED任務(wù)2
* @輸入?yún)?shù) 無
* @輸出參數(shù) 無
* @返回參數(shù) 無
*******************************************************************************/
void App_Task_LED2(void* pdata)
{
pdata = pdata;
for (;;)
{
LED_On(LED4);
OSTimeDly(100);
LED_Off(LED4);
OSTimeDly(100);
}
}
/***************************************************************************//**
* @brief 插入一段延時時間
* @note 無
* @param nCount:指定延時的時間長度
* @retval 無
*******************************************************************************/
void Delay(__IO uint32_t nCount)
{
int i,j;
//利用循環(huán)來延時一定的時間
for (i=0; i<nCount; i++)
for (j=0; j<5000; j++)
;
}
#ifdef USE_FULL_ASSERT
/***************************************************************************//**
* @brief 報告在檢查參數(shù)發(fā)生錯誤時的源文件名和錯誤行數(shù)
* @param file: 指向錯誤文件的源文件名
* @param line: 錯誤的源代碼所在行數(shù)
* @retval 無
*******************************************************************************/
void assert_failed(uint8_t* file, uint32_t line)
{
/* 用戶可以增加自己的代碼用于報告錯誤的文件名和所在行數(shù),
例如:printf("錯誤參數(shù)值: 文件名 %s 在 %d行\(zhòng)r\n", file, line) */
/* 死循環(huán) */
while (1)
{
}
}
#endif
/******************* (C) COPYRIGHT wuguoyana ***************文件結(jié)束***********/
復(fù)制代碼
所有資料51hei提供下載:
STM32F0 各種OS工程源碼實驗(已更新RTT的bug).rar
(1.47 MB, 下載次數(shù): 59)
2019-6-24 20:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1