部分代码
void main(void)
{
#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
INT8U err;
#endif
OSInit();
LcdInit();
TestLCDS();
//设置空闲任务名称
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(OS_TASK_IDLE_PRIO, "uC/OS-II Idle", &err);
#endif
//设置统计任务名称
#if (OS_TASK_NAME_SIZE > 14) && (OS_TASK_STAT_EN > 0)
OSTaskNameSet(OS_TASK_STAT_PRIO, "uC/OS-II Stat", &err);
#endif
//用任务建立任务
OSTaskCreateExt(APP_TaskStart, //void (*task)(void *pd) 任务首地址
(void *)0, //void *pdata 数据指针
&APP_TaskStartStk[APP_TASK_START_STK_SIZE - 1], //OS_STK *ptos 指向任务堆栈栈顶的指针
(INT8U)APP_TASK_START_PRIO, //INT8U prio 任务优先级
(INT16U)APP_TASK_START_ID, //INT16U id 任务的ID号
&APP_TaskStartStk[0], //OS_STK *pbos 指向任务堆栈栈底的指针
(INT32U)APP_TASK_START_STK_SIZE, //INT32U stk_size 堆栈容量
(void *)0, //void *pnext 数据指针
OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR); //INT16U opt 设定OSTaskCreateExt的选项
#if OS_TASK_NAME_SIZE > 14
OSTaskNameSet(APP_TASK_START_PRIO, "Task-Start", &err);
#endif
OSStart();
}
static void Task1_LED1(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_5);
byte_disp(7,3,'1'); //补丁
OSTimeDly(OS_TICKS_PER_SEC * 2);
GPIO_SetBits(GPIOE, GPIO_Pin_5);
byte_disp(7,3,'0'); //补丁
OSTimeDly(OS_TICKS_PER_SEC * 2);
}
}
static void Task2_LED2(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_4);
byte_disp(7,7,'1'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 1);
GPIO_SetBits(GPIOE, GPIO_Pin_4);
byte_disp(7,7,'0'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 1);
}
}
static void Task3_LED3(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_3);
byte_disp(7,11,'1'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 2);
GPIO_SetBits(GPIOE, GPIO_Pin_3);
byte_disp(7,11,'0'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 2);
}
}
static void Task4_LED4(void *pdata)
{
pdata = pdata;
while(1)
{
GPIO_ResetBits(GPIOE, GPIO_Pin_2);
byte_disp(7,15,'1'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 4);
GPIO_SetBits(GPIOE, GPIO_Pin_2);
byte_disp(7,15,'0'); //补丁
OSTimeDly(OS_TICKS_PER_SEC / 4);
}
}
//bsp.c(补丁部分)
static void BSP_LED_Init (void)
{
GPIO_InitTypeDef gpio_init;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE, ENABLE);
gpio_init.GPIO_Pin = BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4;
gpio_init.GPIO_Speed = GPIO_Speed_50MHz;
gpio_init.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOE, &gpio_init);
}
/*
*********************************************************************************************************
* BSP_LED_On()
*
* Description : Turn ON any or all the LEDs on the board.
*
* Argument(s) : led The ID of the LED to control:
*
* 0 turn ON all LEDs on the board
* 1 turn ON LED 1
* 2 turn ON LED 2
* 3 turn ON LED 3
* 4 turn ON LED 4
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_On (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_SetBits(GPIOE, BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4);
break;
case 1:
GPIO_SetBits(GPIOE, BSP_GPIOE_LED1);
break;
case 2:
GPIO_SetBits(GPIOE, BSP_GPIOE_LED2);
break;
case 3:
GPIO_SetBits(GPIOE, BSP_GPIOE_LED3);
break;
case 4:
GPIO_SetBits(GPIOE, BSP_GPIOE_LED4);
break;
default:
break;
}
}
/*
*********************************************************************************************************
* BSP_LED_Off()
*
* Description : Turn OFF any or all the LEDs on the board.
*
* Argument(s) : led The ID of the LED to control:
*
* 0 turn OFF all LEDs on the board
* 1 turn OFF LED 1
* 2 turn OFF LED 2
* 3 turn OFF LED 3
* 4 turn OFF LED 4
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_Off (CPU_INT08U led)
{
switch (led) {
case 0:
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1 | BSP_GPIOE_LED2 | BSP_GPIOE_LED3 | BSP_GPIOE_LED4);
break;
case 1:
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1);
break;
case 2:
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED2);
break;
case 3:
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED3);
break;
case 4:
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED4);
break;
default:
break;
}
}
/*
*********************************************************************************************************
* BSP_LED_Toggle()
*
* Description : TOGGLE any or all the LEDs on the board.
*
* Argument(s) : led The ID of the LED to control:
*
* 0 TOGGLE all LEDs on the board
* 1 TOGGLE LED 1
* 2 TOGGLE LED 2
* 3 TOGGLE LED 3
* 4 TOGGLE LED 4
*
* Return(s) : none.
*
* Caller(s) : Application.
*
* Note(s) : none.
*********************************************************************************************************
*/
void BSP_LED_Toggle (CPU_INT08U led)
{
CPU_INT32U pins;
pins = GPIO_ReadOutputData(GPIOE);
switch (led) {
case 0:
BSP_LED_Toggle(1);
BSP_LED_Toggle(2);
BSP_LED_Toggle(3);
BSP_LED_Toggle(4);
break;
case 1:
if ((pins & BSP_GPIOE_LED1) == 0) {
GPIO_SetBits( GPIOE, BSP_GPIOE_LED1);
} else {
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED1);
}
break;
case 2:
if ((pins & BSP_GPIOE_LED2) == 0) {
GPIO_SetBits( GPIOE, BSP_GPIOE_LED2);
} else {
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED2);
}
break;
case 3:
if ((pins & BSP_GPIOE_LED3) == 0) {
GPIO_SetBits( GPIOE, BSP_GPIOE_LED3);
} else {
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED3);
}
break;
case 4:
if ((pins & BSP_GPIOE_LED4) == 0) {
GPIO_SetBits( GPIOE, BSP_GPIOE_LED4);
} else {
GPIO_ResetBits(GPIOE, BSP_GPIOE_LED4);
}
break;
default:
break;
}
}
}
文件结构