187 lines
4.8 KiB
C
187 lines
4.8 KiB
C
/**
|
|
* @file main.c
|
|
* @author
|
|
* @brief
|
|
* @version 0.1
|
|
* @date 2025-12-05
|
|
*
|
|
* @copyright Copyright (c) 2025
|
|
*
|
|
*/
|
|
|
|
#include <FreeRTOS.h>
|
|
#include <queue.h>
|
|
#include "gd32h7xx.h"
|
|
#include "systick.h"
|
|
|
|
void cache_enable(void);
|
|
void mpu_config(void);
|
|
|
|
void cache_enable(void);
|
|
void mpu_config(void);
|
|
|
|
///< 主任务配置
|
|
#define MAIN_TASK_STACK_SIZE 1024
|
|
static StaticTask_t mainTaskTCB;
|
|
static StackType_t mainTaskStack[MAIN_TASK_STACK_SIZE];
|
|
static void MainTask(void * parameters);
|
|
|
|
#define EVENT1_TASK_STACK_SIZE 512
|
|
static StaticTask_t event1TaskTCB;
|
|
static StackType_t event1TaskStack[EVENT1_TASK_STACK_SIZE];
|
|
static void Event1Task(void* parameters);
|
|
|
|
#define EVENT2_TASK_STACK_SIZE 512
|
|
static StaticTask_t event2TaskTCB;
|
|
static StackType_t event2TaskStack[EVENT2_TASK_STACK_SIZE];
|
|
static void Event2Task(void* parameters);
|
|
|
|
|
|
QueueHandle_t xQueue1, xQueue2;
|
|
|
|
int main()
|
|
{
|
|
cache_enable();
|
|
mpu_config();
|
|
|
|
// systick_config();
|
|
///< 创建主线程
|
|
(void)xTaskCreateStatic(MainTask,
|
|
"Main",
|
|
MAIN_TASK_STACK_SIZE,
|
|
NULL,
|
|
configMAX_PRIORITIES - 1U,
|
|
&( mainTaskStack[ 0 ] ),
|
|
&( mainTaskTCB ));
|
|
|
|
///< 创建事件1线程
|
|
(void)xTaskCreateStatic(Event1Task,
|
|
"Event1",
|
|
EVENT1_TASK_STACK_SIZE,
|
|
NULL,
|
|
configMAX_PRIORITIES - 5U,
|
|
&( event1TaskStack[ 0 ] ),
|
|
&( event1TaskTCB ));
|
|
|
|
///< 创建事件1线程
|
|
(void)xTaskCreateStatic(Event2Task,
|
|
"Event2",
|
|
EVENT2_TASK_STACK_SIZE,
|
|
NULL,
|
|
configMAX_PRIORITIES - 5U,
|
|
&( event2TaskStack[ 0 ] ),
|
|
&( event2TaskTCB ));
|
|
|
|
/* Start the scheduler. */
|
|
vTaskStartScheduler();
|
|
|
|
while (1)
|
|
{
|
|
delay_1ms(100);
|
|
}
|
|
}
|
|
|
|
|
|
/*!
|
|
\brief enable the CPU cache
|
|
\param[in] none
|
|
\param[out] none
|
|
\retval none
|
|
*/
|
|
void cache_enable(void)
|
|
{
|
|
/* enable i-cache */
|
|
SCB_EnableICache();
|
|
/* enable d-cache */
|
|
SCB_EnableDCache();
|
|
}
|
|
|
|
/*!
|
|
\brief configure the MPU attributes
|
|
\param[in] none
|
|
\param[out] none
|
|
\retval none
|
|
*/
|
|
void mpu_config(void)
|
|
{
|
|
mpu_region_init_struct mpu_init_struct;
|
|
mpu_region_struct_para_init(&mpu_init_struct);
|
|
|
|
/* disable the MPU */
|
|
ARM_MPU_Disable();
|
|
ARM_MPU_SetRegion(0, 0);
|
|
|
|
/* configure the MPU attributes for the entire 4GB area, Reserved, no access */
|
|
/* This configuration is highly recommended to prevent Speculative Prefetching of external memory,
|
|
which may cause CPU read locks and even system errors */
|
|
mpu_init_struct.region_base_address = 0x0;
|
|
mpu_init_struct.region_size = MPU_REGION_SIZE_4GB;
|
|
mpu_init_struct.access_permission = MPU_AP_NO_ACCESS;
|
|
mpu_init_struct.access_bufferable = MPU_ACCESS_NON_BUFFERABLE;
|
|
mpu_init_struct.access_cacheable = MPU_ACCESS_NON_CACHEABLE;
|
|
mpu_init_struct.access_shareable = MPU_ACCESS_SHAREABLE;
|
|
mpu_init_struct.region_number = MPU_REGION_NUMBER0;
|
|
mpu_init_struct.subregion_disable = 0x87;
|
|
mpu_init_struct.instruction_exec = MPU_INSTRUCTION_EXEC_NOT_PERMIT;
|
|
mpu_init_struct.tex_type = MPU_TEX_TYPE0;
|
|
mpu_region_config(&mpu_init_struct);
|
|
mpu_region_enable();
|
|
|
|
/* enable the MPU */
|
|
ARM_MPU_Enable(MPU_MODE_PRIV_DEFAULT);
|
|
}
|
|
|
|
|
|
uint32_t ulVar = 10U;
|
|
|
|
static void MainTask( void * parameters )
|
|
{
|
|
/* Unused parameters. */
|
|
( void ) parameters;
|
|
xQueue1 = xQueueCreate( 10, sizeof( uint32_t ) );
|
|
if( xQueue1 == 0 ) {
|
|
|
|
}
|
|
xQueue2 = xQueueCreate( 10, sizeof( struct AMessage * ) );
|
|
if( xQueue2 == 0 ) {
|
|
|
|
}
|
|
|
|
|
|
for( ; ; )
|
|
{
|
|
/* Example Task Code */
|
|
if( xQueueSend( xQueue1, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS ) {
|
|
ulVar++;
|
|
}
|
|
vTaskDelay( 100 ); /* delay 100 ticks */
|
|
/* Example Task Code */
|
|
if( xQueueSend( xQueue2, ( void * ) &ulVar, ( TickType_t ) 10 ) != pdPASS ) {
|
|
ulVar++;
|
|
}
|
|
vTaskDelay( 100 ); /* delay 100 ticks */
|
|
}
|
|
}
|
|
|
|
|
|
static void Event1Task(void* parameters) {
|
|
while(1) {
|
|
struct AMessage *pxRxedMessage = NULL;
|
|
xQueueReceive(xQueue1, (void*)&pxRxedMessage, (TickType_t) 0);
|
|
if(pxRxedMessage != NULL) {
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
static void Event2Task(void* parameters) {
|
|
while(1) {
|
|
struct AMessage *pxRxedMessage = NULL;
|
|
xQueueReceive(xQueue2, (void*)&pxRxedMessage, (TickType_t) 0);
|
|
if(pxRxedMessage != NULL) {
|
|
|
|
}
|
|
}
|
|
} |