找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2565|回复: 0
打印 上一主题 下一主题
收起左侧

STM32F0各种OS工程源码例程

[复制链接]
跳转到指定楼层
楼主
STM32F0例程,关于os系统搭建


单片机源程序如下:
  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. /* 任务函数 ------------------------------------------------------------------*/
  16. static  void  App_Task_LED1(void* p_arg);
  17. static  void  App_Task_LED2(void* p_arg);
  18. /* 私有函数 ------------------------------------------------------------------*/
  19. void LED_Configuration(void);
  20. void Delay(__IO uint32_t nCount);

  21. /***************************************************************************//**
  22.   * @brief  主函数,硬件初始化,实现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.     //创建LED1闪烁的任务
  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.     //创建LED2闪烁的任务
  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;//仅仅是清除这个变量未使用的编译警告
  46.    
  47.     //启动uSOS 操作系统
  48.     OSStart ();
  49. }

  50. /***************************************************************************//**
  51.   * @brief  配置使用LED
  52.   * @note   LED相关的定义需要根据需求用宏定义来修改
  53.   * @param  无
  54.   * @retval 无
  55. *******************************************************************************/
  56. void LED_Configuration(void)
  57. {
  58.     GPIO_InitTypeDef GPIO_InitStructure;
  59.    
  60.     //使能LED所在GPIO的时钟
  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.   * @函数名称        LED_On
  74.   * @函数说明   点亮LED
  75.   * @输入参数   LEDx:LED的编号
  76.   * @输出参数   无
  77.   * @返回参数   无
  78. *******************************************************************************/
  79. void LED_On(uint16_t LEDx)
  80. {
  81.         GPIO_SetBits (LED_PORT, LEDx);
  82. }

  83. /*******************************************************************************
  84.   * @函数名称        LED_Off
  85.   * @函数说明   关闭LEDx
  86.   * @输入参数   LEDx:LED的编号
  87.   * @输出参数   无
  88.   * @返回参数   无
  89. *******************************************************************************/
  90. void LED_Off(uint16_t LEDx)
  91. {
  92.         GPIO_ResetBits (LED_PORT, LEDx);
  93. }

  94. /*******************************************************************************
  95.   * @函数名称        App_Task_LED1
  96.   * @函数说明   LED任务1
  97.   * @输入参数   无
  98.   * @输出参数   无
  99.   * @返回参数   无
  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.   * @函数名称        App_Task_LED2
  114.   * @函数说明   LED任务2
  115.   * @输入参数   无
  116.   * @输出参数   无
  117.   * @返回参数   无
  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  插入一段延时时间
  132.   * @note   无
  133.   * @param  nCount:指定延时的时间长度
  134.   * @retval 无
  135. *******************************************************************************/
  136. void Delay(__IO uint32_t nCount)
  137. {
  138.     int i,j;
  139.     //利用循环来延时一定的时间
  140.     for (i=0; i<nCount; i++)
  141.         for (j=0; j<5000; j++)
  142.             ;
  143. }

  144. #ifdef  USE_FULL_ASSERT
  145. /***************************************************************************//**
  146.   * @brief  报告在检查参数发生错误时的源文件名和错误行数
  147.   * @param  file: 指向错误文件的源文件名
  148.   * @param  line: 错误的源代码所在行数
  149.   * @retval 无
  150. *******************************************************************************/
  151. void assert_failed(uint8_t* file, uint32_t line)
  152. {
  153.     /* 用户可以增加自己的代码用于报告错误的文件名和所在行数,
  154.        例如:printf("错误参数值: 文件名 %s 在 %d行\r\n", file, line) */

  155.     /* 死循环 */
  156.     while (1)
  157.     {
  158.     }
  159. }
  160. #endif

  161. /******************* (C) COPYRIGHT wuguoyana ***************文件结束***********/
复制代码

所有资料51hei提供下载:
STM32F0 各种OS工程源码实验(已更新RTT的bug).rar (1.47 MB, 下载次数: 59)


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏2 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表