ucos-ii系统移植到STM32F4上,运行多个任务,其中一个任务设置优先级为3后其他所有任务不会执行,优先级设定是否有问题?还有我用到两个串口1和3,对于数据的传输是否会有影响,串口3的数据总是会通过串口1显示。(使用串口1进行ISP下载,在串口调试助手里会显示那一串数组,无法通过串口3传输)#include "sys.h"#include "delay.h"
#include "usart.h"
#include "led.h"
#include "magnetic.h"
#include "motor.h"
#include "includes.h"
#define START_TASK_PRIO 10
#define START_STK_SIZE 128
OS_STK START_TASK_STK[START_STK_SIZE];
void start_task(void *pdata);
#define LED0_TASK_PRIO 7
#define LED0_STK_SIZE 128
OS_STK LED0_TASK_STK[LED0_STK_SIZE];
void led0_task(void *pdata);
#define LED1_TASK_PRIO 6
#define LED1_STK_SIZE 128
OS_STK LED1_TASK_STK[LED1_STK_SIZE];
void led1_task(void *pdata);
#define FLOAT_TASK_PRIO 5
#define FLOAT_STK_SIZE 128
__align(8) OS_STK FLOAT_TASK_STK[FLOAT_STK_SIZE];
void float_task(void *pdata);
#define MAGNETIC_TASK_PRIO 3
#define MAGNETIC_STK_SIZE 128
__align(8) OS_STK MAGNETIC_TASK_STK[LED0_STK_SIZE];
void magnetic_task(void *pdata);
#define MOTOR_TASK_PRIO 4
#define MOTOR_STK_SIZE 128
OS_STK MOTOR_TASK_STK[LED0_STK_SIZE];
void motor_task(void *pdata);
int main(void)
{
delay_init(168);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
uart_init(115200);
uart3_init(115200);
LED_Init();
MOTOR_Init();
MAGNETIC_Init();
OSInit();
OSTaskCreate(start_task,(void*)0,(OS_STK*)&START_TASK_STK[START_STK_SIZE-1],START_TASK_PRIO);
OSStart();
}
void start_task(void *pdata)
{
OS_CPU_SR cpu_sr=0;
pdata=pdata;
OSStatInit();
OS_ENTER_CRITICAL();
OSTaskCreate(led0_task,(void*)0,(OS_STK*)&LED0_TASK_STK[LED0_STK_SIZE-1],LED0_TASK_PRIO);
OSTaskCreate(led1_task,(void*)0,(OS_STK*)&LED1_TASK_STK[LED1_STK_SIZE-1],LED1_TASK_PRIO);
OSTaskCreate(float_task,(void*)0,(OS_STK*)&FLOAT_TASK_STK[FLOAT_STK_SIZE-1],FLOAT_TASK_PRIO);
OSTaskCreate(magnetic_task,(void*)0,(OS_STK*)&MAGNETIC_TASK_STK[MAGNETIC_STK_SIZE-1],MAGNETIC_TASK_PRIO);
OSTaskCreate(motor_task,(void*)0,(OS_STK*)&MOTOR_TASK_STK[MOTOR_STK_SIZE-1],MOTOR_TASK_PRIO);
OSTaskSuspend(START_TASK_PRIO);
OS_EXIT_CRITICAL();
}
void led0_task(void *pdata)
{
while(1)
{
LED0=0;
delay_ms(80);
LED0=1;
delay_ms(100);
}
}
void led1_task(void *pdata)
{
while(1)
{
LED1=0;
delay_ms(300);
LED1=1;
delay_ms(300);
}
}
void float_task(void *pdata)
{
OS_CPU_SR cpu_sr=0;
static float float_num=0.01;
while(1)
{
float_num+=0.01f;
OS_ENTER_CRITICAL();
printf("float_numμÄÖμÎa: %f\r\n",float_num);
OS_EXIT_CRITICAL();
delay_ms(500);
}
}
void magnetic_task(void *pdata)
{
u32 ulGPIO_Values;
while(1){
ulGPIO_Values=GPIO_ReadInputData(GPIOE);
USART_SendData(USART1,ulGPIO_Values);
while(USART_GetFlagStatus(USART1,USART_FLAG_TC)!=SET);
delay_ms(500);
}
}
void motor_task(void *pdata)
{
u8 t;
u8 i;
u8 data1[78]={0x08,0x00,0x10,0x24,0xA2,0x00,0x14,0x00,0x00,0xF2,
0x08,0x00,0x10,0x24,0xA0,0x08,0x86,0x00,0x00,0x6A,
0x08,0x00,0x10,0x24,0x9E,0xF8,0x30,0xFF,0xFF,0x00,
0x08,0x00,0x10,0x59,0x09,0xDF,0xFF,0x00,0x00,0x58,
0x08,0x00,0x10,0x59,0x09,0xBF,0xC1,0x87,0x01,0x82,
0x08,0x00,0x10,0x59,0x09,0xFF,0xFF,0x40,0x00,0xB8,
0x04,0x00,0x10,0x01,0x08,0x1D,
0x04,0x00,0x10,0x70,0x0F,0x93,0x04,0x00,0x10,0x04,0x08,0x20};
u8 data2[78]={0x08,0x0F,0xF0,0x24,0xA2,0x00,0x14,0x00,0x00,0xE1,
0x08,0x0F,0xF0,0x24,0xA0,0x55,0x5A,0x01,0x4D,0xC8,
0x08,0x0F,0xF0,0x24,0x9E,0xF8,0x30,0xFF,0xFF,0xEF,
0x08,0x0F,0xF0,0x59,0x09,0xDF,0xFF,0x00,0x00,0x47,
0x08,0x0F,0xF0,0x59,0x09,0xBF,0xC1,0x87,0x01,0x71,
0x08,0x0F,0xF0,0x59,0x09,0xFF,0xFF,0x40,0x00,0xA7,
0x04,0x0F,0xF0,0x01,0x08,0x0C,
0x04,0x0F,0xF0,0x70,0x0F,0x82,0x04,0x0F,0xF0,0x04,0x08,0x0F};
while(1)
{
for(t=0;t<78;t++)
{
USART_SendData(USART3,data1[t]);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET); }
for(i=0;i<78;i++)
{
USART_SendData(USART3,data2);
while(USART_GetFlagStatus(USART3,USART_FLAG_TC)!=SET);
}
}
}
|