高级会员
- 积分
- 658
- 金钱
- 658
- 注册时间
- 2013-11-22
- 在线时间
- 131 小时
|
楼主 |
发表于 2019-3-16 10:11:10
|
显示全部楼层
本帖最后由 zhp 于 2019-3-16 10:18 编辑
好的,为了方便不用下载工程就可以看到代码,我把主要代码贴上来,由于KEIL把代码粘过来中文显示会乱码,所以干脆截图给大家看,下面是mian.c的代码
main.c
mian.c的代码也贴出来吧,程序中只是将printf输出换成了uart1输出,printf函数其实也是从uart1输出的
[mw_shl_code=cpp,true]#include "sys.h"
#include "delay.h"
#include "usart.h"
#include "led.h"
#include "timer.h"
#include "lcd.h"
#include "key.h"
#include "beep.h"
#include "malloc.h"
#include "string.h"
#include "FreeRTOS.h"
#include "task.h"
#include "semphr.h"
/************************************************
ALIENTEK Õ½½¢STM32F103¿a·¢°å FreeRTOSêμÑé14-4
FreeRTOS»¥3aDÅoÅá¿2ù×÷êμÑé-¿aoˉêy°æ±¾
¼¼êõÖ§3Ö£owww.openedv.com
ìÔ±|μêÆì£ohttp://eboard.taobao.com
1Øע΢DÅ1«Öúƽì¨Î¢DÅoÅ£o"ÕyμãÔ-×ó"£¬Ãa·Ñ»ñè¡STM32×êáÏ¡£
1ãÖYêDDÇòíμç×ó¿Æ¼¼óDÏT1«Ë¾
×÷ÕߣoÕyμãÔ-×ó @ALIENTEK
************************************************/
//èÎÎñóÅÏ輶
#define START_TASK_PRIO 1
//èÎÎñ¶ÑÕ»′óD¡
#define START_STK_SIZE 256
//èÎÎñ¾ä±ú
TaskHandle_t StartTask_Handler;
//èÎÎñoˉêy
void start_task(void *pvParameters);
//èÎÎñóÅÏ輶
#define LOW_TASK_PRIO 2
//èÎÎñ¶ÑÕ»′óD¡
#define LOW_STK_SIZE 256
//èÎÎñ¾ä±ú
TaskHandle_t LowTask_Handler;
//èÎÎñoˉêy
void low_task(void *pvParameters);
//èÎÎñóÅÏ輶
#define MIDDLE_TASK_PRIO 3
//èÎÎñ¶ÑÕ»′óD¡
#define MIDDLE_STK_SIZE 256
//èÎÎñ¾ä±ú
TaskHandle_t MiddleTask_Handler;
//èÎÎñoˉêy
void middle_task(void *pvParameters);
//èÎÎñóÅÏ輶
#define HIGH_TASK_PRIO 4
//èÎÎñ¶ÑÕ»′óD¡
#define HIGH_STK_SIZE 256
//èÎÎñ¾ä±ú
TaskHandle_t HighTask_Handler;
//èÎÎñoˉêy
void high_task(void *pvParameters);
//»¥3aDÅoÅ῾ä±ú
SemaphoreHandle_t MutexSemaphore; //»¥3aDÅoÅá¿
//LCDË¢Æáê±ê1óÃμÄÑÕé«
int lcd_discolor[14]={ WHITE, BLACK, BLUE, BRED,
GRED, GBLUE, RED, MAGENTA,
GREEN, CYAN, YELLOW,BROWN,
BRRED, GRAY };
int main(void)
{
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_4);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é4
delay_init(); //Ñóê±oˉêy3õê¼»ˉ
uart_init(115200); //3õê¼»ˉ′®¿ú
LED_Init(); //3õê¼»ˉLED
KEY_Init(); //3õê¼»ˉ°′¼ü
BEEP_Init(); //3õê¼»ˉ·äÃùÆ÷
LCD_Init(); //3õê¼»ˉLCD
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
POINT_COLOR = RED;
LCD_ShowString(30,10,200,16,16,"ATK STM32F103/407");
LCD_ShowString(30,30,200,16,16,"FreeRTOS Examp 14-3");
LCD_ShowString(30,50,200,16,16,"Priority Overturn");
LCD_ShowString(30,70,200,16,16,"ATOM@ALIENTEK");
LCD_ShowString(30,90,200,16,16,"2016/11/25");
//′′½¨¿aê¼èÎÎñ
xTaskCreate((TaskFunction_t )start_task, //èÎÎñoˉêy
(const char* )"start_task", //èÎÎñÃû3Æ
(uint16_t )START_STK_SIZE, //èÎÎñ¶ÑÕ»′óD¡
(void* )NULL, //′«μY¸øèÎÎñoˉêyμÄ2Îêy
(UBaseType_t )START_TASK_PRIO, //èÎÎñóÅÏ輶
(TaskHandle_t* )&StartTask_Handler); //èÎÎñ¾ä±ú
vTaskStartScheduler(); //¿aÆôèÎÎñμ÷¶è
}
//¿aê¼èÎÎñèÎÎñoˉêy
void start_task(void *pvParameters)
{
taskENTER_CRITICAL(); //½øèëáù½çÇø
//′′½¨»¥3aDÅoÅá¿
MutexSemaphore=xSemaphoreCreateMutex();
//′′½¨¸ßóÅÏ輶èÎÎñ
xTaskCreate((TaskFunction_t )high_task,
(const char* )"high_task",
(uint16_t )HIGH_STK_SIZE,
(void* )NULL,
(UBaseType_t )HIGH_TASK_PRIO,
(TaskHandle_t* )&HighTask_Handler);
//′′½¨ÖDμèóÅÏ輶èÎÎñ
xTaskCreate((TaskFunction_t )middle_task,
(const char* )"middle_task",
(uint16_t )MIDDLE_STK_SIZE,
(void* )NULL,
(UBaseType_t )MIDDLE_TASK_PRIO,
(TaskHandle_t* )&MiddleTask_Handler);
//′′½¨μíóÅÏ輶èÎÎñ
xTaskCreate((TaskFunction_t )low_task,
(const char* )"low_task",
(uint16_t )LOW_STK_SIZE,
(void* )NULL,
(UBaseType_t )LOW_TASK_PRIO,
(TaskHandle_t* )&LowTask_Handler);
vTaskDelete(StartTask_Handler); //é¾3y¿aê¼èÎÎñ
taskEXIT_CRITICAL(); //íË3öáù½çÇø
}
//¸ßóÅÏ輶èÎÎñμÄèÎÎñoˉêy
void high_task(void *pvParameters)
{
u8 num;
u8 bufpend[]="high task Pend Sem\r\n";
u8 bufrunn[]="high task Running!\r\n";
POINT_COLOR = BLACK;
LCD_DrawRectangle(5,110,115,314); //»-ò»¸ö¾ØDÎ
LCD_DrawLine(5,130,115,130); //»-Ïß
POINT_COLOR = BLUE;
LCD_ShowString(6,111,110,16,16,"High Task");
while(1)
{
vTaskDelay(500); //Ñóê±500ms£¬ò2¾íêÇ500¸öê±Öó½úÅÄ
num++;
//printf("high task Pend Sem\r\n");
uart1_send_buf(bufpend, sizeof(bufpend));
xSemaphoreTake(MutexSemaphore,portMAX_DELAY); //»ñè¡»¥3aDÅoÅá¿
//printf("high task Running!\r\n");
uart1_send_buf(bufrunn, sizeof(bufrunn));
LCD_Fill(6,131,114,313,lcd_discolor[num%14]); //ìî3äÇøóò
LED1=!LED1;
xSemaphoreGive(MutexSemaphore); //êí·ÅDÅoÅá¿
vTaskDelay(500); //Ñóê±500ms£¬ò2¾íêÇ500¸öê±Öó½úÅÄ
}
}
//ÖDμèóÅÏ輶èÎÎñμÄèÎÎñoˉêy
void middle_task(void *pvParameters)
{
u8 num;
u8 buf[]="middle task Running!\r\n";
POINT_COLOR = BLACK;
LCD_DrawRectangle(125,110,234,314); //»-ò»¸ö¾ØDÎ
LCD_DrawLine(125,130,234,130); //»-Ïß
POINT_COLOR = BLUE;
LCD_ShowString(126,111,110,16,16,"Middle Task");
while(1)
{
num++;
//printf("middle task Running!\r\n");
uart1_send_buf(buf, sizeof(buf));
LCD_Fill(126,131,233,313,lcd_discolor[13-num%14]); //ìî3äÇøóò
LED0=!LED0;
vTaskDelay(1000); //Ñóê±1s£¬ò2¾íêÇ1000¸öê±Öó½úÅÄ
}
}
//μíóÅÏ輶èÎÎñμÄèÎÎñoˉêy
void low_task(void *pvParameters)
{
static u32 times;
u8 buf[]="low task Running!\r\n";
while(1)
{
xSemaphoreTake(MutexSemaphore,portMAX_DELAY); //»ñè¡»¥3aDÅoÅá¿
//printf("low task Running!\r\n");
uart1_send_buf(buf, sizeof(buf));
for(times=0;times<5000000;times++) //Ä£ÄaμíóÅÏ輶èÎÎñÕ¼óû¥3aDÅoÅá¿
{
taskYIELD(); //·¢ÆeèÎÎñμ÷¶è
}
xSemaphoreGive(MutexSemaphore); //êí·Å»¥3aDÅoÅá¿
vTaskDelay(1000); //Ñóê±1s£¬ò2¾íêÇ1000¸öê±Öó½úÅÄ
}
}
[/mw_shl_code]
|
|