TA的每日心情 | 慵懒 2016-10-17 12:07 |
---|
签到天数: 306 天 连续签到: 1 天 [LV.8]以坛为家I
|
首先跑个RTOS吧,以前只用过RTX51-tiny 。。。第一次玩Cortex-M的。。。
以下内容是在上一篇的例子中做修改,:
选择RTX,如下:
图3-1:RTX
图3-2:RTX选择
main函数修改如下:
#include "gd32f1x0.h"#include "gd32f1x0_gpio.h"#include "gd32f1x0_rcc.h"#include "cmsis_os.h"#define LED_ON (1)#define LED_OFF (0)#define LED1 (1)#define LED2 (2)#define LED3 (3)#define LEDALL (5)void EVB_LEDConfig(void){ GPIO_InitPara GPIO_InitStructure; RCC_AHBPeriphClock_Enable(RCC_AHBPERIPH_GPIOC,ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_PIN_10|GPIO_PIN_11; GPIO_InitStructure.GPIO_Mode = GPIO_MODE_OUT; GPIO_InitStructure.GPIO_Speed = GPIO_SPEED_50MHZ; GPIO_InitStructure.GPIO_OType = GPIO_OTYPE_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PUPD_NOPULL; GPIO_Init(GPIOC,&GPIO_InitStructure); GPIO_ResetBits(GPIOC,GPIO_PIN_10|GPIO_PIN_11);}void EVB_LEDControl(int index, int cmd){ switch (index) { case LED1: { if (cmd == LED_ON) { GPIO_SetBits(GPIOC,GPIO_PIN_10); } else { GPIO_ResetBits(GPIOC,GPIO_PIN_10); } break; } case LED2: { if (cmd == LED_ON) { GPIO_SetBits(GPIOC,GPIO_PIN_11); } else { GPIO_ResetBits(GPIOC,GPIO_PIN_11); } break; } default: { if (cmd == LED_ON) { GPIO_ResetBits(GPIOC,GPIO_PIN_10|GPIO_PIN_11); } else { GPIO_ResetBits(GPIOC,GPIO_PIN_10|GPIO_PIN_11); } break; } }}osThreadId tid_ledOn; /* Thread id of thread: ledOn */osThreadId tid_ledOff; /* Thread id of thread: ledOff *//*---------------------------------------------------------------------------- Thread 1 'ledOn': switches the LED on*---------------------------------------------------------------------------*/void ledOn (void const *argument) { for (;;) { EVB_LEDControl(LED2, LED_OFF); osDelay(100); EVB_LEDControl(LED2, LED_ON); osDelay(100); osSignalSet(tid_ledOff, 0x0001); }}/*---------------------------------------------------------------------------- Thread 2 'ledOff': switches the LED off*---------------------------------------------------------------------------*/void ledOff (void const *argument) { for (;;) { EVB_LEDControl(LED1, LED_OFF); osDelay(200); EVB_LEDControl(LED1, LED_ON); osDelay(200); osSignalSet(tid_ledOff, 0x0001); }}osThreadDef(ledOn, osPriorityNormal, 1, 0);osThreadDef(ledOff, osPriorityNormal, 1, 0);int main(void){ int i; EVB_LEDConfig(); tid_ledOn = osThreadCreate(osThread(ledOn) , NULL); tid_ledOff = osThreadCreate(osThread(ledOff), NULL); osSignalSet(tid_ledOn, 0x0001); /* set signal to ledOn thread */ osDelay(osWaitForever); while(1); /* EVB_LEDControl(LED2, LED_OFF); EVB_LEDControl(LED1, LED_OFF); while(1) { for (i = 0; i< 0x0fffff; i++); EVB_LEDControl(LED2, LED_ON); for (i = 0; i< 0x0fffff; i++); EVB_LEDControl(LED2, LED_OFF); } */}关于RTX具体可以查看文档,是离线的。如下:
图3-3:RTX文档
程序如下:
demo下载 |
|