请各位大神帮帮忙,我建立的四个任务,通过Task_Led1调用OSMboxPost(Com1_MBOX, &led1
timer),但是Task_Com1任务就是没唤醒
/*********app.c********************/
#include <includes.h>
#include "BSP_usart.h"
static OS_STK startup_task_stk[STARTUP_TASK_STK_SIZE];
static OS_STK com1_task_stk[COM1_TASK_STK_SIZE];
static OS_STK led0_task_stk[LED_TASK_STK_SIZE];
static OS_STK led1_task_stk[LED_TASK_STK_SIZE];
static OS_STK led2_task_stk[LED_TASK_STK_SIZE];
INT8U OS_Time_en = 0;
OS_EVENT * Com1_SEM; //uart signal
OS_EVENT * Com1_MBOX; //uart mail box
INT8U led1Timer;
static void Task_Com1(void * p_arg)
{
INT8U err;
unsigned char * msg;
(void)p_arg;
while(1)
{
msg = (unsigned char *)OSMboxPend(Com1_MBOX, 0, &err);
Bsp_printf("Com1 task run
");
}
}
static void Task_Led0(void * p_arg)
{
(void)p_arg;
while(1)
{
BSP_LED_On(LED0);
OSTimeDlyHMSM(0, 0, 0, 500);
BSP_LED_Off(LED0);
OSTimeDlyHMSM(0, 0, 0, 500);
}
}
static void Task_Led1(void * p_arg)
{
(void)p_arg;
while(1)
{
led1Timer++;
BSP_LED_On(LED1);
OSTimeDlyHMSM(0, 0, 1, 0);
BSP_LED_Off(LED1);
OSTimeDly(500);
OSMboxPost(Com1_MBOX, &led1Timer);
}
}
static void Task_Led2(void * p_arg)
{
(void)p_arg;
while(1)
{
BSP_LED_On(LED2);
OSTimeDlyHMSM(0, 0, 2, 0);
BSP_LED_Off(LED2);
OSTimeDlyHMSM(0, 0, 2, 0);
}
}
static void App_TaskCreate(void)
{
OS_CPU_SR cpu_sr = 0;
Com1_MBOX = OSMboxCreate((void *)0);
OS_ENTER_CRITICAL();
OSTaskCreate(Task_Com1, (void *)0, (OS_STK *)&com1_task_stk[COM1_TASK_STK_SIZE-1], COM1_TASK_PRIO);
OSTaskCreate(Task_Led0, (void *)0, (OS_STK *)&led0_task_stk[LED_TASK_STK_SIZE-1], LED0_TASK_PRIO);
OSTaskCreate(Task_Led1, (void *)0, (OS_STK *)&led1_task_stk[LED_TASK_STK_SIZE-1], LED1_TASK_PRIO);
OSTaskCreate(Task_Led2, (void *)0, (OS_STK *)&led2_task_stk[LED_TASK_STK_SIZE-1], LED2_TASK_PRIO);
OS_EXIT_CRITICAL();
}
static void startup_task(void * p_arg)
{
OS_Time_en = 1;
#if(OS_TASK_STAT_EN>0)
OSStatInit(); /* Determine CPU capacity */
#endif
App_TaskCreate();
/* TODO: create other application tasks here */
while(1) //假设任务是一个周期的循环结构
{
/* TODO: run appliction tasks here */
OSTimeDlyHMSM(0, 0, 1, 0);
}
}
void app(void)
{
Bsp_printf("System is initialising!
");
OSInit();
OSTaskCreate(startup_task,(void *)0,&startup_task_stk[STARTUP_TASK_STK_SIZE-1],STARTUP_TASK_PRIO);
Bsp_printf("System is initialised!
");
OSStart();
}
/*************app.c****end***************/
/***************main.c******************/
#include "main.h"
void SystemClock_Config(void);
static void Error_Handler(void);
int main(void)
{
HAL_Init();
SystemClock_Config();
Uart_Init();
BSP_LED_Init();
app();
}
/**
* @brief System Clock Configuration
* The system Clock is configured as follow :
* System Clock source = PLL (HSI)
* SYSCLK(Hz) = 64000000
* HCLK(Hz) = 64000000
* AHB Prescaler = 1
* APB1 Prescaler = 2
* APB2 Prescaler = 1
* HSI Frequency(Hz) = 8000000
* PREDIV = RCC_PREDIV_DIV2 (2)
* PLLMUL = RCC_PLL_MUL16 (16)
* Flash Latency(WS) = 2
* @param None
* @retval None
*/
void SystemClock_Config(void)
{
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_OscInitTypeDef RCC_OscInitStruct;
/* HSI Oscillator already ON after system reset, activate PLL with HSI as source */
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_NONE;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
RCC_OscInitStruct.PLL.PREDIV = RCC_PREDIV_DIV2;
RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL16;
RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
if (HAL_RCC_OscConfig(&RCC_OscInitStruct)!= HAL_OK)
{
Error_Handler();
}
/* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2
clocks dividers */
RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2);
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2)!= HAL_OK)
{
Error_Handler();
}
}
/**
* @brief This function is executed in case of error occurrence.
* @param None
* @retval None
*/
static void Error_Handler(void)
{
/* User may add here some code to deal with this error */
while(1)
{
BSP_LED_Toggle(LED2);
HAL_Delay(1000);
}
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t *file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d
", file, line) */
/* Infinite loop */
while (1)
{
}
}
#endif
/*************main.c****end*****************/
/***************BSP_usart.c*****************/
#include "BSP_usart.h"
#include "string.h"
UART_HandleTypeDef UartHandle;
static void Error_Handler(void);
uint8_t Rx_buffer[USARTx_BUFFER_SIZE];
uint8_t * pRxBuff;
void UART2_RxBuff_Clr(void)
{
int i = 0;
while(Rx_buffer
!=' ')
{
Rx_buffer=' ';
if(i>=USARTx_BUFFER_SIZE)
break;
i++;
}
}
void Uart_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__GPIOA_CLK_ENABLE();
GPIO_InitStructure.Mode =GPIO_MODE_AF_PP;;
GPIO_InitStructure.Alternate = GPIO_AF7_USART2;
GPIO_InitStructure.Pin = GPIO_PIN_2|GPIO_PIN_3;
GPIO_InitStructure.Pull = GPIO_PULLUP;
GPIO_InitStructure.Speed = GPIO_SPEED_HIGH;
HAL_GPIO_Init(GPIOA, &GPIO_InitStructure);
}
void Uart_Init(void)
{
Uart_GPIO_Init();
__USART2_CLK_ENABLE();
HAL_NVIC_SetPriority(USART2_IRQn, 0x0C, 0x00);
HAL_NVIC_EnableIRQ(USART2_IRQn);
UartHandle.Instance = USARTx;
UartHandle.Init.BaudRate = 115200;
UartHandle.Init.WordLength = UART_WORDLENGTH_8B;
UartHandle.Init.StopBits = UART_STOPBITS_1;
UartHandle.Init.Parity = UART_PARITY_NONE;
UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE;
UartHandle.Init.Mode = UART_MODE_TX_RX;
UartHandle.Init.OverSampling = UART_OVERSAMPLING_16;
UartHandle.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
UartHandle.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
if(HAL_UART_Init(&UartHandle)!=HAL_OK)
{
Error_Handler();
}
}
void Bsp_printf(char * dataBuf)
{
uint16_t dataLen = strlen(dataBuf);
HAL_UART_Transmit(&UartHandle,(uint8_t *)dataBuf, dataLen, 0xFF);
}
static void Error_Handler(void)
{
while(1)
{
}
}
一周热门 更多>