找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

帖子
查看: 3396|回復(fù): 0
打印 上一主題 下一主題
收起左側(cè)

STM32F0各種OS工程源碼例程

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
STM32F0例程,關(guān)于os系統(tǒng)搭建


單片機(jī)源程序如下:
  1. /* 包含的頭文件---------------------------------------------------------------*/
  2. #include "stm32f0xx.h"
  3. #include "ucos_ii.h"

  4. /* 私有類型定義---------------------------------------------------------------*/
  5. /* 私有定義 ------------------------------------------------------------------*/
  6. /* 私有宏定義 ----------------------------------------------------------------*/
  7. #define LED3            GPIO_Pin_9
  8. #define LED4            GPIO_Pin_8

  9. #define LED_PORT        GPIOC
  10. #define LED_GPIO_CLK    RCC_AHBPeriph_GPIOC

  11. /* 私有變量 ------------------------------------------------------------------*/
  12. /* 變量 ----------------------------------------------------------------------*/
  13. static   OS_STK   App_Task_LED1_Stk[APP_TASK_LED1_STK_SIZE];
  14. static   OS_STK   App_Task_LED2_Stk[APP_TASK_LED2_STK_SIZE];

  15. /* 任務(wù)函數(shù) ------------------------------------------------------------------*/
  16. static  void  App_Task_LED1(void* p_arg);
  17. static  void  App_Task_LED2(void* p_arg);
  18. /* 私有函數(shù) ------------------------------------------------------------------*/
  19. void LED_Configuration(void);
  20. void Delay(__IO uint32_t nCount);

  21. /***************************************************************************//**
  22.   * @brief  主函數(shù),硬件初始化,實(shí)現(xiàn)LED1-LED4閃爍
  23.   * @note   無
  24.   * @param  無
  25.   * @retval 無
  26. *******************************************************************************/
  27. int main(void)
  28. {
  29.     INT8U os_err;

  30.     LED_Configuration ();
  31.     OSInit();
  32.     OS_CPU_SysTickInit();
  33.    
  34.     //創(chuàng)建LED1閃爍的任務(wù)
  35.     os_err = OSTaskCreate( App_Task_LED1,
  36.                           (void *) 0,
  37.                           (OS_STK *) &App_Task_LED1_Stk[APP_TASK_LED1_STK_SIZE - 1],
  38.                           (INT8U) APP_TASK_LED1_PRIO);

  39.     //創(chuàng)建LED2閃爍的任務(wù)
  40.     os_err = OSTaskCreate( App_Task_LED2,
  41.                           (void*) 0,
  42.                           (OS_STK*) &App_Task_LED2_Stk[APP_TASK_LED2_STK_SIZE - 1],
  43.                           (INT8U ) APP_TASK_LED2_PRIO);
  44.    
  45.     os_err = os_err;//僅僅是清除這個(gè)變量未使用的編譯警告
  46.    
  47.     //啟動(dòng)uSOS 操作系統(tǒng)
  48.     OSStart ();
  49. }

  50. /***************************************************************************//**
  51.   * @brief  配置使用LED
  52.   * @note   LED相關(guān)的定義需要根據(jù)需求用宏定義來修改
  53.   * @param  無
  54.   * @retval 無
  55. *******************************************************************************/
  56. void LED_Configuration(void)
  57. {
  58.     GPIO_InitTypeDef GPIO_InitStructure;
  59.    
  60.     //使能LED所在GPIO的時(shí)鐘
  61.     RCC_AHBPeriphClockCmd(LED_GPIO_CLK, ENABLE);

  62.     //初始化LED的GPIO
  63.     GPIO_InitStructure.GPIO_Pin = LED3 | LED4;
  64.     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  65.     GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  66.     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  67.     GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
  68.     GPIO_Init(LED_PORT, &GPIO_InitStructure);
  69.    
  70.     GPIO_ResetBits(LED_PORT,LED3 | LED4);  //熄滅LED3-4
  71. }

  72. /*******************************************************************************
  73.   * @函數(shù)名稱        LED_On
  74.   * @函數(shù)說明   點(diǎn)亮LED
  75.   * @輸入?yún)?shù)   LEDx:LED的編號
  76.   * @輸出參數(shù)   無
  77.   * @返回參數(shù)   無
  78. *******************************************************************************/
  79. void LED_On(uint16_t LEDx)
  80. {
  81.         GPIO_SetBits (LED_PORT, LEDx);
  82. }

  83. /*******************************************************************************
  84.   * @函數(shù)名稱        LED_Off
  85.   * @函數(shù)說明   關(guān)閉LEDx
  86.   * @輸入?yún)?shù)   LEDx:LED的編號
  87.   * @輸出參數(shù)   無
  88.   * @返回參數(shù)   無
  89. *******************************************************************************/
  90. void LED_Off(uint16_t LEDx)
  91. {
  92.         GPIO_ResetBits (LED_PORT, LEDx);
  93. }

  94. /*******************************************************************************
  95.   * @函數(shù)名稱        App_Task_LED1
  96.   * @函數(shù)說明   LED任務(wù)1
  97.   * @輸入?yún)?shù)   無
  98.   * @輸出參數(shù)   無
  99.   * @返回參數(shù)   無
  100. *******************************************************************************/
  101. void App_Task_LED1(void* pdata)
  102. {
  103.     pdata = pdata;

  104.     for (;;)
  105.     {
  106.         LED_On(LED3);
  107.         OSTimeDlyHMSM(0, 0, 0, 500);
  108.         LED_Off(LED3);
  109.         OSTimeDlyHMSM(0, 0, 0, 500);
  110.     }

  111. }

  112. /*******************************************************************************
  113.   * @函數(shù)名稱        App_Task_LED2
  114.   * @函數(shù)說明   LED任務(wù)2
  115.   * @輸入?yún)?shù)   無
  116.   * @輸出參數(shù)   無
  117.   * @返回參數(shù)   無
  118. *******************************************************************************/
  119. void App_Task_LED2(void* pdata)
  120. {
  121.     pdata = pdata;

  122.     for (;;)
  123.     {
  124.         LED_On(LED4);
  125.         OSTimeDly(100);
  126.         LED_Off(LED4);
  127.         OSTimeDly(100);
  128.     }
  129. }

  130. /***************************************************************************//**
  131.   * @brief  插入一段延時(shí)時(shí)間
  132.   * @note   無
  133.   * @param  nCount:指定延時(shí)的時(shí)間長度
  134.   * @retval 無
  135. *******************************************************************************/
  136. void Delay(__IO uint32_t nCount)
  137. {
  138.     int i,j;
  139.     //利用循環(huán)來延時(shí)一定的時(shí)間
  140.     for (i=0; i<nCount; i++)
  141.         for (j=0; j<5000; j++)
  142.             ;
  143. }

  144. #ifdef  USE_FULL_ASSERT
  145. /***************************************************************************//**
  146.   * @brief  報(bào)告在檢查參數(shù)發(fā)生錯(cuò)誤時(shí)的源文件名和錯(cuò)誤行數(shù)
  147.   * @param  file: 指向錯(cuò)誤文件的源文件名
  148.   * @param  line: 錯(cuò)誤的源代碼所在行數(shù)
  149.   * @retval 無
  150. *******************************************************************************/
  151. void assert_failed(uint8_t* file, uint32_t line)
  152. {
  153.     /* 用戶可以增加自己的代碼用于報(bào)告錯(cuò)誤的文件名和所在行數(shù),
  154.        例如:printf("錯(cuò)誤參數(shù)值: 文件名 %s 在 %d行\(zhòng)r\n", file, line) */

  155.     /* 死循環(huán) */
  156.     while (1)
  157.     {
  158.     }
  159. }
  160. #endif

  161. /******************* (C) COPYRIGHT wuguoyana ***************文件結(jié)束***********/
復(fù)制代碼

所有資料51hei提供下載:
STM32F0 各種OS工程源碼實(shí)驗(yàn)(已更新RTT的bug).rar (1.47 MB, 下載次數(shù): 59)


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏2 分享淘帖 頂 踩
回復(fù)

使用道具 舉報(bào)

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表