STM32F0例程,關于os系統搭建
0.png (4.65 KB, 下載次數: 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];
- /* 任務函數 ------------------------------------------------------------------*/
- static void App_Task_LED1(void* p_arg);
- static void App_Task_LED2(void* p_arg);
- /* 私有函數 ------------------------------------------------------------------*/
- void LED_Configuration(void);
- void Delay(__IO uint32_t nCount);
- /***************************************************************************//**
- * @brief 主函數,硬件初始化,實現LED1-LED4閃爍
- * @note 無
- * @param 無
- * @retval 無
- *******************************************************************************/
- int main(void)
- {
- INT8U os_err;
- LED_Configuration ();
- OSInit();
- OS_CPU_SysTickInit();
-
- //創建LED1閃爍的任務
- 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);
- //創建LED2閃爍的任務
- 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 操作系統
- OSStart ();
- }
- /***************************************************************************//**
- * @brief 配置使用LED
- * @note LED相關的定義需要根據需求用宏定義來修改
- * @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
- }
- /*******************************************************************************
- * @函數名稱 LED_On
- * @函數說明 點亮LED
- * @輸入參數 LEDx:LED的編號
- * @輸出參數 無
- * @返回參數 無
- *******************************************************************************/
- void LED_On(uint16_t LEDx)
- {
- GPIO_SetBits (LED_PORT, LEDx);
- }
- /*******************************************************************************
- * @函數名稱 LED_Off
- * @函數說明 關閉LEDx
- * @輸入參數 LEDx:LED的編號
- * @輸出參數 無
- * @返回參數 無
- *******************************************************************************/
- void LED_Off(uint16_t LEDx)
- {
- GPIO_ResetBits (LED_PORT, LEDx);
- }
- /*******************************************************************************
- * @函數名稱 App_Task_LED1
- * @函數說明 LED任務1
- * @輸入參數 無
- * @輸出參數 無
- * @返回參數 無
- *******************************************************************************/
- 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);
- }
- }
- /*******************************************************************************
- * @函數名稱 App_Task_LED2
- * @函數說明 LED任務2
- * @輸入參數 無
- * @輸出參數 無
- * @返回參數 無
- *******************************************************************************/
- 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;
- //利用循環來延時一定的時間
- for (i=0; i<nCount; i++)
- for (j=0; j<5000; j++)
- ;
- }
- #ifdef USE_FULL_ASSERT
- /***************************************************************************//**
- * @brief 報告在檢查參數發生錯誤時的源文件名和錯誤行數
- * @param file: 指向錯誤文件的源文件名
- * @param line: 錯誤的源代碼所在行數
- * @retval 無
- *******************************************************************************/
- void assert_failed(uint8_t* file, uint32_t line)
- {
- /* 用戶可以增加自己的代碼用于報告錯誤的文件名和所在行數,
- 例如:printf("錯誤參數值: 文件名 %s 在 %d行\r\n", file, line) */
- /* 死循環 */
- while (1)
- {
- }
- }
- #endif
- /******************* (C) COPYRIGHT wuguoyana ***************文件結束***********/
復制代碼
所有資料51hei提供下載:
STM32F0 各種OS工程源碼實驗(已更新RTT的bug).rar
(1.47 MB, 下載次數: 59)
2019-6-24 20:10 上傳
點擊文件名下載附件
下載積分: 黑幣 -5
|