20240909-DXSPX-emb/Src/Usr/App/app.c

288 lines
10 KiB
C
Raw Normal View History

/*****************************************************************************/
/* ZTYP Technology , Inc. Copyright (c) 2001-2018 */
/*****************************************************************************/
/*
*********************************************************************************************************
* INCLUDE FILES
*********************************************************************************************************
*/
#include <string.h>
#include "app_cfg.h"
#include "cpu_core.h"
#include "os.h"
#include "bsp.h"
#include "bsp_sys.h"
#include "BSPSys.h"
#include "DrvSys.h"
#include "BSPLwip.h"
#include "DrvRtcI2c.h"
#include "DrvSdSpi.h"
#include "RTCTask.h"
#include "UartTask.h"
#include "TcpTask.h"
#include "FatfsTask.h"
//#include "usr_task_sys.h"
//#include "usr_task_network.h"
//#include "usr_task_watchdog.h"
//#include "usr_task_heart.h"
//#include "usr_task_inside_para_sensor.h"
//#include "usr_task_many_para_sensor.h"
//#include "usr_task_camera.h"
//#include "usr_task_rtc.h"
//#include "usr_task_timer.h"
//#include "usr_task_imu.h"
/*
*********************************************************************************************************
* LOCAL DEFINES
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL CONSTANTS
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL DATA TYPES
*********************************************************************************************************
*/
/*$PAGE*/
/*
*********************************************************************************************************
* LOCAL GLOBAL VARIABLES
*********************************************************************************************************
*/
static OS_STK AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE];
static OS_STK RtcTaskStk[RTC_TASK_STK_SIZE];
static OS_STK UartTaskStk[UART_TASK_STK_SIZE];
static OS_STK ClientTaskStk[CLIENT_TASK_STK_SIZE];
static OS_STK ServerCallbackTaskStk[SERVER_TASK_STK_SIZE];
static OS_STK FATFSTaskStk[FATFS_TASK_STK_SIZE];
static NETWORK_IPADDR gs_localIpAddr = {192,168,1,100};
static NETWORK_IPADDR gs_lcaolMaskAddr = {255,255,255,0};
static NETWORK_IPADDR gs_localGwAddr = {192,168,1,112};
static uint64_t gs_mac = 2001 + 1001;
/*
*********************************************************************************************************
* LOCAL MACRO'S
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* LOCAL FUNCTION PROTOTYPES
*********************************************************************************************************
*/
static void AppTaskCreate (void);
static void AppTaskStart (void *p_arg);
/*$PAGE*/
/*
*********************************************************************************************************
* main()
*
* Description : Entry point for C code.
*
* Arguments : none.
*
* Returns : none.
*
* Note(s) : (1) It is assumed that your code will call main() once you have performed all necessary
* initialization.
*********************************************************************************************************
*/
int main (void)
{
#if (OS_TASK_NAME_EN > 0)
CPU_INT08U err;
#endif
#if (CPU_CFG_NAME_EN == DEF_ENABLED)
CPU_ERR cpu_err;
#endif
#if (CPU_CFG_NAME_EN == DEF_ENABLED)
CPU_NameSet((CPU_CHAR *)"TM4C1294NCPDT",
(CPU_ERR *)&cpu_err);
#endif
CPU_IntDis(); /* Disable all interrupts. */
OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel" */
OSTaskCreateExt((void (*)(void *)) AppTaskStart, /* Create the start task */
(void *) 0,
(OS_STK *)&AppTaskStartStk[APP_CFG_TASK_START_STK_SIZE - 1],
(INT8U ) APP_CFG_TASK_START_PRIO,
(INT16U ) APP_CFG_TASK_START_PRIO,
(OS_STK *)&AppTaskStartStk[0],
(INT32U ) APP_CFG_TASK_START_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
#if (OS_TASK_NAME_EN > 0)
OSTaskNameSet(APP_CFG_TASK_START_PRIO, (INT8U *)"Start", &err);
#endif
OSStart(); /* Start multitasking (i.e. give control to uC/OS-II) */
while (1) {
;
}
}
/*$PAGE*/
/*
*********************************************************************************************************
* App_TaskStart()
*
* Description : Startup task example code.
*
* Arguments : p_arg Argument passed by 'OSTaskCreate()'.
*
* Returns : none.
*
* Created by : main().
*
* Notes : (1) The first line of code is used to prevent a compiler warning because 'p_arg' is not
* used. The compiler should not generate any code for this statement.
*********************************************************************************************************
*/
static void AppTaskStart (void *p_arg)
{
CPU_INT32U cpu_clk_freq;
CPU_INT32U cnts;
// CPU_INT08U sd_err;
(void)p_arg; /* See Note #1 */
(void)&p_arg;
BSP_Init(); /* Initialize BSP functions */
cpu_clk_freq = BSP_SysClkFreqGet(); /* Determine SysTick reference freq. */
cnts = cpu_clk_freq /* Determine nbr SysTick increments */
/ (CPU_INT32U)OS_TICKS_PER_SEC;
OS_CPU_SysTickInit(cnts);
CPU_Init(); /* Initialize the uC/CPU services */
#if (OS_TASK_STAT_EN > 0)
OSStatInit(); /* Determine CPU capacity */
#endif
Mem_Init();
#ifdef CPU_CFG_INT_DIS_MEAS_EN
CPU_IntDisMeasMaxCurReset();
#endif
BspSetSysClock(cpu_clk_freq);
DrvSysInit();
// 初始化FATFS
InitFileSystem();
// 初始化LWIP
BSP_LwipInit(gs_localIpAddr, gs_lcaolMaskAddr, gs_localGwAddr, gs_mac);
AppTaskCreate(); /* Creates all the necessary application tasks. */
while (DEF_ON) {
OSTimeDly(1000);
}
}
/*
*********************************************************************************************************
* AppTaskCreate()
*
* Description : Create the application tasks.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : AppTaskStart()
*
* Note(s) : none.
*********************************************************************************************************
*/
static void AppTaskCreate (void)
{
OSTaskCreateExt((void (*)(void *)) RtcTask,
(void *) 0,
(OS_STK *)&RtcTaskStk[RTC_TASK_STK_SIZE - 1],
(INT8U ) RTC_TASK_PRIO,
(INT16U ) RTC_TASK_PRIO,
(OS_STK *)&RtcTaskStk[0],
(INT32U ) RTC_TASK_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
OSTaskCreateExt((void (*)(void *)) FATFSTask,
(void *) 0,
(OS_STK *)&FATFSTaskStk[FATFS_TASK_STK_SIZE - 1],
(INT8U ) FATFS_TASK_PRIO,
(INT16U ) FATFS_TASK_PRIO,
(OS_STK *)&FATFSTaskStk[0],
(INT32U ) FATFS_TASK_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
OSTaskCreateExt((void (*)(void *)) ServerCallbackTask,
(void *) 0,
(OS_STK *)&ServerCallbackTaskStk[SERVER_TASK_STK_SIZE - 1],
(INT8U ) SERVER_TASK_PRIO,
(INT16U ) SERVER_TASK_PRIO,
(OS_STK *)&ServerCallbackTaskStk[0],
(INT32U ) SERVER_TASK_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
OSTaskCreateExt((void (*)(void *)) ClientTask,
(void *) 0,
(OS_STK *)&ClientTaskStk[CLIENT_TASK_STK_SIZE - 1],
(INT8U ) CLIENT_TASK_PRIO,
(INT16U ) CLIENT_TASK_PRIO,
(OS_STK *)&ClientTaskStk[0],
(INT32U ) CLIENT_TASK_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
OSTaskCreateExt((void (*)(void *)) UartTask,
(void *) 0,
(OS_STK *)&UartTaskStk[UART_TASK_STK_SIZE - 1],
(INT8U ) UART_TASK_PRIO,
(INT16U ) UART_TASK_PRIO,
(OS_STK *)&UartTaskStk[0],
(INT32U ) UART_TASK_STK_SIZE,
(void *) 0,
(INT16U )(OS_TASK_OPT_STK_CHK | OS_TASK_OPT_STK_CLR));
}