358 lines
10 KiB
C
358 lines
10 KiB
C
/**
|
|
*******************************************************************************
|
|
* @file gpio/gpio_output/source/main.c
|
|
* @brief Main program of GPIO for the Device Driver Library.
|
|
@verbatim
|
|
Change Logs:
|
|
Date Author Notes
|
|
2020-06-12 Zhangxl First version
|
|
@endverbatim
|
|
*******************************************************************************
|
|
* Copyright (C) 2020, Huada Semiconductor Co., Ltd. All rights reserved.
|
|
*
|
|
* This software component is licensed by HDSC under BSD 3-Clause license
|
|
* (the "License"); You may not use this file except in compliance with the
|
|
* License. You may obtain a copy of the License at:
|
|
* opensource.org/licenses/BSD-3-Clause
|
|
*
|
|
*******************************************************************************
|
|
*/
|
|
/******************************************************************************
|
|
* Include files
|
|
******************************************************************************/
|
|
#include "hc32_ddl.h"
|
|
#include "bsp_init.h"
|
|
#include <includes.h>
|
|
#include "usart.h"
|
|
#include "task_manager.h"
|
|
#include "console.h"
|
|
#include "brtc.h"
|
|
#include "ff_shell.h"
|
|
#include "vi.h"
|
|
#include "temp.h"
|
|
#include "afe_comm.h"
|
|
#include "io.h"
|
|
#include "can_comm.h"
|
|
|
|
/******************************************************************************
|
|
* Local pre-processor symbols/macros ('#define')
|
|
******************************************************************************/
|
|
|
|
/******************************************************************************
|
|
* Global variable definitions (declared in header file with 'extern')
|
|
******************************************************************************/
|
|
void console_task(void *p_arg);
|
|
|
|
//Task priority
|
|
#define START_TASK_PRIO 9
|
|
//Task stack size
|
|
#define START_STK_SIZE 1024
|
|
//Task stack
|
|
CPU_STK START_TASK_STK[START_STK_SIZE];
|
|
//Task functions
|
|
void start_task(void *p_arg);
|
|
|
|
//rtc_task
|
|
//Task priority
|
|
#define RTC_TASK_PRIO 8
|
|
//Task stack size
|
|
#define RTC_TASK_STK_SIZE 128
|
|
//Task stack
|
|
CPU_STK RTC_TASK_STK[RTC_TASK_STK_SIZE];
|
|
//Task functions
|
|
void rtc_task(void *p_arg);
|
|
|
|
//can_comm task
|
|
//Task priority
|
|
#define CAN_COMM_TASK_PRIO 6
|
|
//Task stack size
|
|
#define CAN_COMM_STK_SIZE 512
|
|
//Task stack
|
|
CPU_STK CAN_COMM_TASK_STK[CAN_COMM_STK_SIZE];
|
|
//Task functions
|
|
void can_comm_task(void *p_arg);
|
|
|
|
//PL455 comm task
|
|
//Task priority
|
|
#define AFE_COMM_TASK_PRIO 5
|
|
//Task stack size
|
|
#define AFE_COMM_STK_SIZE 512
|
|
//Task stack
|
|
CPU_STK AFE_COMM_TASK_STK[AFE_COMM_STK_SIZE];
|
|
//Task functions
|
|
void afe_comm_task(void *p_arg);
|
|
|
|
//VI ADC task
|
|
//Task priority
|
|
#define VI_ADC_TASK_PRIO 3
|
|
//Task stack size
|
|
#define VI_ADC_STK_SIZE 512
|
|
//Task stack
|
|
CPU_STK VI_ADC_TASK_STK[VI_ADC_STK_SIZE];
|
|
//Task functions
|
|
void vi_adc_task(void *p_arg);
|
|
|
|
//TEMP task
|
|
//Task priority
|
|
#define TEMP_TASK_PRIO 7
|
|
//Task stack size
|
|
#define TEMP_STK_SIZE 512
|
|
//Task stack
|
|
CPU_STK TEMP_TASK_STK[TEMP_STK_SIZE];
|
|
//Task functions
|
|
void temp_task(void *p_arg);
|
|
|
|
//io task
|
|
//Task priority
|
|
#define IO_TASK_PRIO 4
|
|
//Task stack size
|
|
#define IO_STK_SIZE 128
|
|
//Task stack
|
|
CPU_STK IO_TASK_STK[IO_STK_SIZE];
|
|
//Task functions
|
|
void io_task(void *p_arg);
|
|
|
|
////log task
|
|
////Task priority
|
|
//#define LOG_TASK_PRIO 10
|
|
////Task stack size
|
|
//#define LOG_STK_SIZE 2048
|
|
////Task control block
|
|
//OS_TCB LOGTaskTCB;
|
|
////Task stack
|
|
//CPU_STK LOG_TASK_STK[LOG_STK_SIZE];
|
|
////Task functions
|
|
//void log_task(void *p_arg);
|
|
|
|
/******************************************************************************
|
|
* Local type definitions ('typedef')
|
|
******************************************************************************/
|
|
|
|
/**
|
|
******************************************************************************
|
|
** \brief Main function of project
|
|
**
|
|
** \return uint32_t return value, if needed
|
|
**
|
|
** This sample
|
|
**
|
|
******************************************************************************/
|
|
int32_t main(void)
|
|
{
|
|
OS_ERR err;
|
|
CPU_SR_ALLOC();
|
|
|
|
OSInit(&err);
|
|
|
|
OS_CRITICAL_ENTER(); // Enter critical section
|
|
OSTaskCreate((OS_TCB *)GetAppTaskTCB(START_TASK_PRIO), /*Task TCB*/
|
|
(CPU_CHAR *)"Start Task", /*task Name*/
|
|
(OS_TASK_PTR )start_task, /*Task Entry*/
|
|
(void *)NULL, /*Task Parameter*/
|
|
(OS_PRIO )START_TASK_PRIO, /*Task Poirity*/
|
|
(CPU_STK *)&START_TASK_STK[0], /*Stack Start*/
|
|
(CPU_STK )START_STK_SIZE / 10, /*Stack Limit*/
|
|
(CPU_STK )START_STK_SIZE, /*Stack Size*/
|
|
(OS_MSG_QTY )0u,
|
|
(OS_TICK )0u,
|
|
(void *)0u,
|
|
(OS_OPT )(OS_OPT_TASK_STK_CHK | OS_OPT_TASK_STK_CLR),
|
|
(OS_ERR *) &err
|
|
);
|
|
OS_CRITICAL_EXIT(); //Exit the critical section
|
|
OSStart(&err);
|
|
|
|
while(1)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
//Start task functions
|
|
void start_task(void *p_arg)
|
|
{
|
|
OS_ERR err;
|
|
CPU_SR_ALLOC();
|
|
p_arg = p_arg;
|
|
|
|
BSP_Init();
|
|
|
|
CPU_Init();
|
|
|
|
OS_CPU_SysTickInit(SystemCoreClock / OSCfg_TickRate_Hz);
|
|
|
|
Mem_Init(); // Initialize memory management components
|
|
|
|
#if OS_CFG_STAT_TASK_EN > 0u
|
|
OSStatTaskCPUUsageInit(&err); //Statistical tasks
|
|
#endif
|
|
|
|
#ifdef CPU_CFG_INT_DIS_MEAS_EN //If measurement is enabled interrupt off time
|
|
CPU_IntDisMeasMaxCurReset();
|
|
#endif
|
|
|
|
#if OS_CFG_SCHED_ROUND_ROBIN_EN //When you use the Web when
|
|
//The time slice round robin feature, the length of the time slice to 1 system clock ticks, 1*5=5ms
|
|
OSSchedRoundRobinCfg(DEF_ENABLED,1,&err);
|
|
#endif
|
|
|
|
OS_CRITICAL_ENTER(); //Enters the critical section
|
|
// CAN Comm Task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(RTC_TASK_PRIO),
|
|
(CPU_CHAR* )"RTC Task",
|
|
(OS_TASK_PTR )rtc_task,
|
|
(void* )0,
|
|
(OS_PRIO )RTC_TASK_PRIO,
|
|
(CPU_STK* )&RTC_TASK_STK[0],
|
|
(CPU_STK_SIZE)RTC_TASK_STK_SIZE/10,
|
|
(CPU_STK_SIZE)RTC_TASK_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
// CAN Comm Task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(CAN_COMM_TASK_PRIO),
|
|
(CPU_CHAR* )"CAN Comm Task",
|
|
(OS_TASK_PTR )can_comm_task,
|
|
(void* )0,
|
|
(OS_PRIO )CAN_COMM_TASK_PRIO,
|
|
(CPU_STK* )&CAN_COMM_TASK_STK[0],
|
|
(CPU_STK_SIZE)CAN_COMM_STK_SIZE/10,
|
|
(CPU_STK_SIZE)CAN_COMM_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
// AFE Comm task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(AFE_COMM_TASK_PRIO),
|
|
(CPU_CHAR* )"AFE Comm Task",
|
|
(OS_TASK_PTR )afe_comm_task,
|
|
(void* )0,
|
|
(OS_PRIO )AFE_COMM_TASK_PRIO,
|
|
(CPU_STK* )&AFE_COMM_TASK_STK[0],
|
|
(CPU_STK_SIZE)AFE_COMM_STK_SIZE/10,
|
|
(CPU_STK_SIZE)AFE_COMM_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
//VI ADC task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(VI_ADC_TASK_PRIO),
|
|
(CPU_CHAR* )"VI ADC Task",
|
|
(OS_TASK_PTR )vi_adc_task,
|
|
(void* )0,
|
|
(OS_PRIO )VI_ADC_TASK_PRIO,
|
|
(CPU_STK* )&VI_ADC_TASK_STK[0],
|
|
(CPU_STK_SIZE)VI_ADC_STK_SIZE/10,
|
|
(CPU_STK_SIZE)VI_ADC_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
//Temp ADC task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(TEMP_TASK_PRIO),
|
|
(CPU_CHAR* )"Temp ADC Task",
|
|
(OS_TASK_PTR )temp_task,
|
|
(void* )0,
|
|
(OS_PRIO )TEMP_TASK_PRIO,
|
|
(CPU_STK* )&TEMP_TASK_STK[0],
|
|
(CPU_STK_SIZE)TEMP_STK_SIZE/10,
|
|
(CPU_STK_SIZE)TEMP_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
//IO Task
|
|
OSTaskCreate((OS_TCB* )GetAppTaskTCB(IO_TASK_PRIO),
|
|
(CPU_CHAR* )"IO task",
|
|
(OS_TASK_PTR )io_task,
|
|
(void* )0,
|
|
(OS_PRIO )IO_TASK_PRIO,
|
|
(CPU_STK* )&IO_TASK_STK[0],
|
|
(CPU_STK_SIZE)IO_STK_SIZE/10,
|
|
(CPU_STK_SIZE)IO_STK_SIZE,
|
|
(OS_MSG_QTY )0,
|
|
(OS_TICK )0,
|
|
(void* )0,
|
|
(OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
(OS_ERR* )&err);
|
|
//Log Task
|
|
// OSTaskCreate((OS_TCB* )&LOGTaskTCB,
|
|
// (CPU_CHAR* )"LOG task",
|
|
// (OS_TASK_PTR )log_task,
|
|
// (void* )0,
|
|
// (OS_PRIO )LOG_TASK_PRIO,
|
|
// (CPU_STK* )&LOG_TASK_STK[0],
|
|
// (CPU_STK_SIZE)LOG_STK_SIZE/10,
|
|
// (CPU_STK_SIZE)LOG_STK_SIZE,
|
|
// (OS_MSG_QTY )0,
|
|
// (OS_TICK )0,
|
|
// (void* )0,
|
|
// (OS_OPT )OS_OPT_TASK_STK_CHK|OS_OPT_TASK_STK_CLR,
|
|
// (OS_ERR* )&err);
|
|
|
|
// OS_TaskSuspend((OS_TCB*)GetAppTaskTCB(START_TASK_PRIO),&err); //Pending start task
|
|
OS_CRITICAL_EXIT(); //Exit the critical section
|
|
|
|
console_task(p_arg);
|
|
}
|
|
|
|
// Console Task
|
|
void console_task(void *p_arg)
|
|
{
|
|
p_arg = p_arg;
|
|
|
|
AppTaskDebug();
|
|
}
|
|
|
|
// RTC Task
|
|
void rtc_task(void *p_arg)
|
|
{
|
|
p_arg = p_arg;
|
|
|
|
AppTaskRTC();
|
|
}
|
|
|
|
//CAN COMM Task
|
|
void can_comm_task(void *p_arg)
|
|
{
|
|
App_TaskCanComm();
|
|
}
|
|
|
|
// AFE COMM Task
|
|
void afe_comm_task(void *p_arg)
|
|
{
|
|
App_TaskAfeComm();
|
|
}
|
|
|
|
//VI Adc Task
|
|
void vi_adc_task(void *p_arg)
|
|
{
|
|
AppTaskVIAdc();
|
|
}
|
|
|
|
//Temp Task
|
|
void temp_task(void *p_arg)
|
|
{
|
|
AppTaskTempAdc();
|
|
}
|
|
|
|
//IO Task
|
|
void io_task(void *p_arg)
|
|
{
|
|
App_TaskIO();
|
|
}
|
|
|
|
////LOG Task
|
|
//void log_task(void *p_arg)
|
|
//{
|
|
//// while(1)
|
|
//// {
|
|
//// }
|
|
//}
|