app.c
上传用户:yj_qqy
上传日期:2017-01-28
资源大小:2911k
文件大小:28k
- /*
- *********************************************************************************************************
- * EXAMPLE CODE
- *
- * (c) Copyright 2003-2006; Micrium, Inc.; Weston, FL
- *
- * All rights reserved. Protected by international copyright laws.
- * Knowledge of the source code may NOT be used to develop a similar product.
- * Please help us continue to provide the Embedded community with the finest
- * software available. Your honesty is greatly appreciated.
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- *
- * EXAMPLE CODE
- *
- * ST Microelectronics STM32
- * with the
- * STM3210B-EVAL Evaluation Board
- *
- * Filename : app.c
- * Version : V1.10
- * Programmer(s) : BAN
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * INCLUDE FILES
- *********************************************************************************************************
- */
- #include <includes.h>
- #define MID_SAMPLE 100
- /*
- *********************************************************************************************************
- * LOCAL DEFINES
- *********************************************************************************************************
- */
- /*
- *********************************************************************************************************
- * LOCAL GLOBAL VARIABLES
- *********************************************************************************************************
- */
- static OS_STK App_TaskStartStk[APP_TASK_START_STK_SIZE];
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- OS_STK TerminalTaskStk[APP_TASK_TERMINAL_STK_SIZE];
- void TerminalTask(void *pdata);
- void AppTerminalRx(CPU_INT08U rx_data);
- CPU_INT08U AppTerminalRxMboxData = 0;
- OS_EVENT *AppTerminalRxMbox;
- #endif
- /*
- *********************************************************************************************************
- * LOCAL FUNCTION PROTOTYPES
- *********************************************************************************************************
- */
- static void App_TaskCreate (void);
- static void App_EventCreate (void);
- static void App_TaskStart (void *p_arg);
- //static void APP_TaskPilot (void *p_arg);
- #if (APP_LCD_EN == DEF_ENABLED)
- static void App_TaskUserIF (void *p_arg);
- static void App_DispScr_SignOn (void);
- static void App_DispScr_VersionTickRate(void);
- static void App_DispScr_CPU (void);
- static void App_DispScr_CtxSw (void);
- static void App_DispScr_GPS (void);
- #endif
- //static void PlayWAV(const char* pPath);
- #define r2d 57.29577951308 // = 180 / PI
- #define d2r 00.01745329252 // = PI / 180
- #define PI 3.1415926535
- void ADC_init(void);
- void ADC_offset(void);
- void kalmanReset(void);
- void readSensors (void);
- void kalmanFilter(void);
- void state_update(void);
- void accel2angle(void);
- //state variables
- volatile FP32 gyroRate[3]; //roll, nick, yaw in rad/sec 横滚,俯仰,偏航 度/秒
- volatile FP32 gyroBias[3]={0.0,0.0,0.0}; // bias is the second 陀螺偏差
- volatile FP32 accelVal[3]; //Ax (=roll),Ay (=nick), Az
- //kalman estimates
- volatile FP32 angleMeasured[3] = {0.0,0.0,0.0}; //accelerometer based angle estimate 角度测量值
- volatile FP32 angleEstimate[3]; // angle is the first part of the state vector 角度估计值
- volatile FP32 dt = (1.0 / 100); // update funcs are called every 10ms
- /*
- * Our Process covariance matrix. This is updated at every time step to
- * determine how well the sensors are tracking the actual state.
- * 处理我们的协方差矩阵。这是在每一个更新的时间点,以确定如何以及传感器跟踪的实际状况。
- */
- volatile FP32 P[3][2][2] = {
- {
- { 1, 0 },
- { 0, 1 },
- },
- {
- { 1, 0 },
- { 0, 1 },
- },
- {
- { 1, 0 },
- { 0, 1 },
- }
- };
- /*
- * R represents the measurement covariance noise. In this case,
- * it is a 1x1 matrix that says that we expect R rad jitter
- * from the accelerometer.
- * R代表了测量方差噪音。在这种情况下,它是一个1x1矩阵说,我们期望抖动R弧度从加速度。
- */
- const FP32 R_angle = 0.5;
- /*
- * Q is a 2x2 matrix that represents the process covariance noise.
- * Q是2x2矩阵,代表进程协噪音
- */
- const FP32 Q_angle = 0.10; // = angle noise E(alpha^2) 角噪音E
- const FP32 Q_gyro = 0.0010; // = bias noise E(bias^2) 倾斜噪音E
- volatile INT32S angleN; // nick (front/back) angle in degrees 俯仰角
- volatile INT32S angleR; // roll (left/right) angle in degrees 横滚角
- volatile INT32S totalG; // total acceleration = sqrt(x^2 + y^2 + z^2)
- volatile INT32S gX, gY, gZ; // static acceleration without angle offsets
- volatile FP32 gyroCal[3]; // only for gyro calibration
- volatile INT32S calN;
- volatile INT32S calR;
- volatile INT32S calY;
- //-------------------------------------------------------------------------------
- // kalman reset is called when sensors are calibrated
- void kalmanReset()
- {
- INT8U i;
- for (i=0; i<3; i++)
- {
- angleMeasured[i] = 0.0;
- angleEstimate[i] = 0.0;
- gyroBias[i] = 0.0;
- P[i][0][0] = 1;
- P[i][0][1] = 0;
- P[i][1][0] = 0;
- P[i][1][1] = 1;
- gyroCal[i]=0.0;
- }
- }
- //-------------------------------------------------------------------------------
- //readSensors is called every 10ms. It transforms the raw gyro rates into radians/dt
- //rescales the accels values and computes the nick and roll angles in degrees*4. These are
- //then used in the mixer.
- void readSensors (void)
- {
- gyroRate[0] = (FP32)-(ADC_Mittelwert[ADC_ROLL]);
- gyroRate[0] *= PI / 16465.92;
- gyroRate[1] = (FP32)ADC_Mittelwert[ADC_NICK];
- gyroRate[1] *= PI / 16465.92;
- gyroRate[2] = (FP32)ADC_Mittelwert[ADC_GIER];
- gyroRate[2] *= PI / 16465.92;
- accelVal[0] = (FP32)ADC_Mittelwert[ADC_ACCX];
- accelVal[0] /= 4096 / 5.5f; // normalize
- accelVal[1] = (FP32)ADC_Mittelwert[ADC_ACCY];
- accelVal[1] /= 4096 / 5.5f;
- accelVal[2] = (FP32)ADC_Mittelwert[ADC_ACCZ];
- accelVal[2] /= 4096 / 5.5f;
-
- angleR = angleEstimate[0] * r2d; // covert to degrees and scale for mixer
- angleN = angleEstimate[1] * r2d;
- calN = (INT32S)(gyroCal[1] * 256);
- calR = (INT32S)(gyroCal[0] * 256);
- calY = (INT32S)(gyroCal[2] * 256);
- }
- //-------------------------------------------------------------------------------
- //accel2angle computes the angles with the accel values
- void accel2angle(void)
- {
- FP32 f;
-
- // Calculate g ( ||g_vec|| )
- FP32 g = sqrt(accelVal[0]*accelVal[0] + accelVal[1]*accelVal[1] + accelVal[2]*accelVal[2]);
-
- totalG = (g - 1.0) * 64; // = |a| - gravity
- //values in radians
- angleMeasured[0] = -asin(accelVal[0] / g);
- angleMeasured[1] = asin(accelVal[1] / g);
- angleMeasured[2] = 0; // later: magnetometer ...
- /* try to compute the linear part of the acceleration.
- We assume, that the angleEstimate currently are the correct angles.
- */
- f = 64 * (accelVal[0] + sin(angleEstimate[0]));
- gX = (INT32S)f;
- f = 64 * (sin(angleEstimate[1]) - accelVal[1]);
- gY = (INT32S)f;
- }
- //-------------------------------------------------------------------------------
- //
- void state_update() //called on new gyro output available
- {
- INT8U i;
- FP32 Pdot[4];
- for(i=0;i<3;i++)
- {
- // integrate angle by adding gyro rate
- angleEstimate[i] += (dt * (gyroRate[i] - gyroBias[i]));
- gyroCal[i] += (dt * gyroRate[i]);
- Pdot[0] = Q_angle - P[i][0][1] - P[i][1][0]; /* 0,0 */
- Pdot[1] = - P[i][1][1]; /* 0,1 */
- Pdot[2] = - P[i][1][1]; /* 1,0 */
- Pdot[3] = Q_gyro; /* 1,1 */
- /* Update the covariance matrix */
- P[i][0][0] += Pdot[0] * dt;
- P[i][0][1] += Pdot[1] * dt;
- P[i][1][0] += Pdot[2] * dt;
- P[i][1][1] += Pdot[3] * dt;
- }
- }
- //-------------------------------------------------------------------------------
- //
- void kalmanFilter(void)
- {
- FP32 angle_err;
- INT8U i;
- FP32 PCt_0, PCt_1, E, K_0, K_1, t_0, t_1;
-
- //our extractor matrix. We only want the angle part, not the bias
- const FP32 C_0 = 1.0;
-
- for(i=0;i<3;i++)
- {
- angle_err = angleMeasured[i] - angleEstimate[i];
- PCt_0 = C_0 * P[i][0][0];
- PCt_1 = C_0 * P[i][1][0];
-
- //error estimate
- E = R_angle + C_0 * PCt_0;
- K_0 = PCt_0 / E;
- K_1 = PCt_1 / E;
-
- t_0 = PCt_0;
- t_1 = C_0 * P[i][0][1];
- P[i][0][0] -= K_0 * t_0;
- P[i][0][1] -= K_0 * t_1;
- P[i][1][0] -= K_1 * t_0;
- P[i][1][1] -= K_1 * t_1;
-
- angleEstimate[i] += K_0 * angle_err;
- gyroBias[i] += K_1 * angle_err;
- }
- }
- void ADC_init(void){
- CPU_INT08U os_err;
- INT16U mid_i, pos;
- INT32S mux[8] = {0,0,0,0,0,0,0,0};
- BSP_LED_Off(1);
- for(mid_i = 0; mid_i < MID_SAMPLE; mid_i++) {
- BSP_LED_Toggle(1);
- OSTimeDlyHMSM(0, 0, 0, 20);
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- OSSemPend(App_ADCSem, 0, &os_err);
- for(pos = 0; pos < 8; pos++) {
- mux[pos] += ADC_Mittelwert[pos];
- }
- }
- BSP_LED_Off(1);
- ADC_Neutral[ADC_GIER] = abs(mux[ADC_GIER] / MID_SAMPLE);
- ADC_Neutral[ADC_ACCX] = abs(mux[ADC_ACCX] / MID_SAMPLE);
- ADC_Neutral[ADC_ACCZ] = 0;
- ADC_Neutral[ADC_ACCY] = abs(mux[ADC_ACCY] / MID_SAMPLE);
- ADC_Neutral[ADC_NICK] = abs(mux[ADC_NICK] / MID_SAMPLE);
- ADC_Neutral[ADC_ROLL] = abs(mux[ADC_ROLL] / MID_SAMPLE);
- }
- void ADC_offset(void) {
- OSTimeDlyHMSM(0, 0, 0, 200);
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- ADC_Neutral[ADC_GIER] -= ADC_Mittelwert[ADC_GIER];
- ADC_Neutral[ADC_NICK] += ADC_Mittelwert[ADC_NICK];
- ADC_Neutral[ADC_ROLL] += ADC_Mittelwert[ADC_ROLL];
- ADC_Neutral[ADC_ACCX] -= ADC_Mittelwert[ADC_ACCX];
- ADC_Neutral[ADC_ACCY] += ADC_Mittelwert[ADC_ACCY];
- OSTimeDlyHMSM(0, 0, 0, 200);
- ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- ADC_Neutral[ADC_GIER] -= ADC_Mittelwert[ADC_GIER];
- ADC_Neutral[ADC_NICK] += ADC_Mittelwert[ADC_NICK];
- ADC_Neutral[ADC_ROLL] += ADC_Mittelwert[ADC_ROLL];
- ADC_Neutral[ADC_ACCX] -= ADC_Mittelwert[ADC_ACCX];
- ADC_Neutral[ADC_ACCY] += ADC_Mittelwert[ADC_ACCY];
- }
- #if 0
- void AddStr(char *s1,char *s2,char *d)
- {
- while(*s1!=' ') {*d=*s1; d++; s1++;}
- while(*s2!=' ') {*d=*s2; d++; s2++;}
- *d=' ';
- }
- void PlayWAV(const char* pPath)
- {
- FS_DIR *pDir;
- FS_FILE *pFile;
- struct FS_DIRENT *pDirEnt;
-
- char d[50];
- INT8U Buffer[512];
- int x;
- FS_Init();
- printf("正在搜索目录.rn");
- pDir = FS_OpenDir(pPath);
- if(pDir)
- {
- printf("找到目录并已打开.rn");
- for(;;)
- {
- pDirEnt = FS_ReadDir(pDir);
- if((void*)pDirEnt == NULL) {break;}
- //pDirEnt = FS_ReadDir(pDir);
-
- AddStr("mmc:\",pDirEnt->d_name,d);
- pFile=FS_FOpen(d,"rb");
- if(pFile)
- {
- printf(pDirEnt->d_name);
- printf("rn");
- do
- {
- x = FS_FRead(Buffer,1,512,pFile);
- if(x)
- {
- OSTimeDly(1);
- }
-
- }while(x);
- }
- FS_FClose(pFile);
- }
- FS_CloseDir(pDir);
- }
- FS_Exit();
- printf("读取文件结束.rn");
- }
- void GetDiskInfo(void) {
- FS_DISKFREE_T disk_data;
- FS_u32 free;
- FS_u32 space;
- int x;
- FS_Init();
- printf("Test FS_IoCtl command FS_CMD_GET_DISKFREE :rn");
- x = FS_IoCtl("",FS_CMD_GET_DISKFREE,0,(void*) &disk_data);
- if (x==0) {
- space = disk_data.total_clusters * disk_data.sectors_per_cluster * disk_data.bytes_per_sector;
- free = disk_data.avail_clusters * disk_data.sectors_per_cluster * disk_data.bytes_per_sector;
- printf("Total clusters : %lurn"
- "Available clusters : %lurn"
- "Sectors/cluster : %urn"
- "Bytes per sector : %urn"
- "Total space : %lurn"
- "Free space : %lurn",
- disk_data.total_clusters, disk_data.avail_clusters, disk_data.sectors_per_cluster, disk_data.bytes_per_sector, space, free);
- printf("OKrn");
- } else {
- printf("Test failedrn");
- }
- printf("rn");
- FS_Exit();
- }
- #endif
- /*
- *********************************************************************************************************
- * main()
- *
- * Description : This is the standard entry point for C code. It is assumed that your code will call
- * main() once you have performed all necessary initialization.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *********************************************************************************************************
- */
- INT32S main (void)
- {
- CPU_INT08U os_err;
- #if 0
- INT32U sdret, i;
- INT8U buffer[512];
- BSP_Init();
- sdret = SD_Initialize();
- printf("sdret=0x%02Xrn", sdret);
- if(!sdret) {
- while(1) {
- sdret = SD_ReadBlock(0, 512, buffer);
- //printf("---------------------------------rn");
- //for(i = 0; i < 512; i+=8)
- //{
- // printf("%03X %02X %02X %02X %02X %02X %02X %02X %02Xrn",i, buffer[i], buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7]);
- //}
- if(sdret) {
- printf("sdret=0x%02Xrn", sdret);
- break;
- }
- OSTimeDly(1);
- }
- }
- #endif
- BSP_IntDisAll(); /* Disable all ints until we are ready to accept them. */
- OSInit(); /* Initialize "uC/OS-II, The Real-Time Kernel". */
- os_err = OSTaskCreateExt((void (*)(void *)) App_TaskStart, /* Create the start task. */
- (void * ) 0,
- (OS_STK * )&App_TaskStartStk[APP_TASK_START_STK_SIZE - 1],
- (INT8U ) APP_TASK_START_PRIO,
- (INT16U ) APP_TASK_START_PRIO,
- (OS_STK * )&App_TaskStartStk[0],
- (INT32U ) APP_TASK_START_STK_SIZE,
- (void * )0,
- (INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
- #if OS_TASK_NAME_EN > 0
- OSTaskNameSet(APP_TASK_START_PRIO, (CPU_INT08U *)"Start Task", &os_err);
- #endif
- OSStart(); /* Start multitasking (i.e. give control to uC/OS-II). */
- return (0);
- }
- /*
- *********************************************************************************************************
- * App_TaskStart()
- *
- * Description : The startup task. The uC/OS-II ticker should only be initialize once multitasking starts.
- *
- * Argument(s) : p_arg Argument passed to 'App_TaskStart()' by 'OSTaskCreate()'.
- *
- * Return(s) : none.
- *
- * Caller(s) : This is a task.
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- static void App_TaskStart (void *p_arg)
- {
- //CPU_INT08U os_err;
- INT32U count = 0, sdret;// i;
- INT8U buffer[512];
- (void)p_arg;
- BSP_Init(); /* Initialize BSP functions. */
- OS_CPU_SysTickInit(); /* Initialize the SysTick. */
- #if (OS_TASK_STAT_EN > 0)
- OSStatInit(); /* Determine CPU capacity. */
- #endif
- #if (GPS_MODULE == DEF_ENABLED)
- GPS_Init(); /* GPS Init */
- GPS_RxIntEn(); /* Enable Rx Interrupts */
- #endif
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- OSView_Init(115200); /* OSView Init, baud rate = 115200 */
- OSView_TerminalRxSetCallback(AppTerminalRx);
- OSView_RxIntEn(); /* Enable Rx Interrupts */
- AppTerminalRxMbox = OSMboxCreate((void *)0);
- #endif
- App_EventCreate(); /* Create application events. */
- App_TaskCreate(); /* Create application tasks. */
- //ADC_init();
- //ADC_offset();
- //GetDiskInfo();
- //PlayWAV("mmc:\");
- sdret = SD_Initialize();
- printf("sdret=0x%02Xrn", sdret);
- if(!sdret) {
- while(1) {
- sdret = SD_ReadBlock(0, 512, buffer);
- //printf("---------------------------------rn");
- //for(i = 0; i < 512; i+=8)
- //{
- // printf("%03X %02X %02X %02X %02X %02X %02X %02X %02Xrn",i, buffer[i], buffer[i+1], buffer[i+2], buffer[i+3], buffer[i+4], buffer[i+5], buffer[i+6], buffer[i+7]);
- //}
- if(sdret) {
- printf("sdret=0x%02Xrn", sdret);
- break;
- }
- OSTimeDly(1);
- }
- }
-
- //while(DEF_TRUE) {
- // GPIO_SetBits(GPIOA, GPIO_Pin_6);
- // GPIO_ResetBits(GPIOA, GPIO_Pin_6);
- //}
- //kalmanReset();
- BSP_LED_Off(2);
- while (DEF_TRUE) { /* Task body, always written as an infinite loop. */
- count++;
- if(count % 25 == 0) {
- BSP_LED_Toggle(2);
- }
- OSTimeDlyHMSM(0, 0, 0, 10);
- //ADC_SoftwareStartConvCmd(ADC1, ENABLE);
- //OSSemPend(App_ADCSem, 0, &os_err);
- //readSensors ();
- //state_update();
- //accel2angle();
- //kalmanFilter();
- //printf("N: %4d R: %4d G: %4d X: %4d Y: %4d Z: %4drn", ADC_Mittelwert[ADC_NICK], ADC_Mittelwert[ADC_ROLL], ADC_Mittelwert[ADC_GIER], ADC_Mittelwert[ADC_ACCX], ADC_Mittelwert[ADC_ACCY], ADC_Mittelwert[ADC_ACCZ]);
- //printf("x: %4d y: %4d z: %4drn",gX, gY, gZ);
- //printf("testrn");
- }
- }
- /*
- *********************************************************************************************************
- * App_EventCreate()
- *
- * Description : Create the application events.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : App_TaskStart().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- static void App_EventCreate (void)
- {
- #if (OS_EVENT_NAME_SIZE > 12)
- CPU_INT08U os_err;
- #endif
- App_ADCSem = OSSemCreate(0); /* Create MBOX for communication between Kbd and UserIF.*/
- #if (OS_EVENT_NAME_SIZE > 12)
- OSEventNameSet(App_ADCSem, "ADC Sem", &os_err);
- #endif
- }
- /*
- *********************************************************************************************************
- * App_TaskCreate()
- *
- * Description : Create the application tasks.
- *
- * Argument(s) : none.
- *
- * Return(s) : none.
- *
- * Caller(s) : App_TaskStart().
- *
- * Note(s) : none.
- *********************************************************************************************************
- */
- static void App_TaskCreate (void)
- {
- CPU_INT08U os_err;
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- os_err = OSTaskCreateExt((void (*)(void *)) TerminalTask,
- (void * ) 0,
- (OS_STK * )&TerminalTaskStk[APP_TASK_TERMINAL_STK_SIZE - 1],
- (INT8U ) APP_TASK_TERMINAL_PRIO,
- (INT16U ) APP_TASK_TERMINAL_PRIO,
- (OS_STK * )&TerminalTaskStk[0],
- (INT32U ) APP_TASK_TERMINAL_STK_SIZE,
- (void * ) 0,
- (INT16U )(OS_TASK_OPT_STK_CLR | OS_TASK_OPT_STK_CHK));
- #if OS_TASK_NAME_EN > 0
- OSTaskNameSet(APP_TASK_TERMINAL_PRIO, "Terminal Task", &os_err);
- #endif
- #endif
- }
- /*
- *********************************************************************************************************
- * AppTerminalRx()
- *
- * Description : Callback function for uC/OS-View
- *
- * Argument(s) : rx_data The received data.
- *
- * Return(s) : none.
- *********************************************************************************************************
- */
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- void AppTerminalRx (CPU_INT08U rx_data)
- {
- AppTerminalRxMboxData = rx_data;
- OSMboxPost(AppTerminalRxMbox, &AppTerminalRxMboxData);
- }
- #endif
- /*
- *********************************************************************************************************
- *********************************************************************************************************
- * uC/OS-II APP HOOKS
- *********************************************************************************************************
- *********************************************************************************************************
- */
- #if (OS_APP_HOOKS_EN > 0)
- /*
- *********************************************************************************************************
- * TASK CREATION HOOK (APPLICATION)
- *
- * Description : This function is called when a task is created.
- *
- * Argument(s) : ptcb is a pointer to the task control block of the task being created.
- *
- * Note(s) : (1) Interrupts are disabled during this call.
- *********************************************************************************************************
- */
- void App_TaskCreateHook (OS_TCB *ptcb)
- {
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- OSView_TaskCreateHook(ptcb);
- #endif
- }
- /*
- *********************************************************************************************************
- * TASK DELETION HOOK (APPLICATION)
- *
- * Description : This function is called when a task is deleted.
- *
- * Argument(s) : ptcb is a pointer to the task control block of the task being deleted.
- *
- * Note(s) : (1) Interrupts are disabled during this call.
- *********************************************************************************************************
- */
- void App_TaskDelHook (OS_TCB *ptcb)
- {
- (void)ptcb;
- }
- /*
- *********************************************************************************************************
- * IDLE TASK HOOK (APPLICATION)
- *
- * Description : This function is called by OSTaskIdleHook(), which is called by the idle task. This hook
- * has been added to allow you to do such things as STOP the CPU to conserve power.
- *
- * Argument(s) : none.
- *
- * Note(s) : (1) Interrupts are enabled during this call.
- *********************************************************************************************************
- */
- #if OS_VERSION >= 251
- void App_TaskIdleHook (void)
- {
- }
- #endif
- /*
- *********************************************************************************************************
- * STATISTIC TASK HOOK (APPLICATION)
- *
- * Description : This function is called by OSTaskStatHook(), which is called every second by uC/OS-II's
- * statistics task. This allows your application to add functionality to the statistics task.
- *
- * Argument(s) : none.
- *********************************************************************************************************
- */
- void App_TaskStatHook (void)
- {
- }
- /*
- *********************************************************************************************************
- * TASK SWITCH HOOK (APPLICATION)
- *
- * Description : This function is called when a task switch is performed. This allows you to perform other
- * operations during a context switch.
- *
- * Argument(s) : none.
- *
- * Note(s) : (1) Interrupts are disabled during this call.
- *
- * (2) It is assumed that the global pointer 'OSTCBHighRdy' points to the TCB of the task that
- * will be 'switched in' (i.e. the highest priority task) and, 'OSTCBCur' points to the
- * task being switched out (i.e. the preempted task).
- *********************************************************************************************************
- */
- #if OS_TASK_SW_HOOK_EN > 0
- void App_TaskSwHook (void)
- {
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- OSView_TaskSwHook();
- #endif
- }
- #endif
- /*
- *********************************************************************************************************
- * OS_TCBInit() HOOK (APPLICATION)
- *
- * Description : This function is called by OSTCBInitHook(), which is called by OS_TCBInit() after setting
- * up most of the TCB.
- *
- * Argument(s) : ptcb is a pointer to the TCB of the task being created.
- *
- * Note(s) : (1) Interrupts may or may not be ENABLED during this call.
- *********************************************************************************************************
- */
- #if OS_VERSION >= 204
- void App_TCBInitHook (OS_TCB *ptcb)
- {
- (void)ptcb;
- }
- #endif
- /*
- *********************************************************************************************************
- * TICK HOOK (APPLICATION)
- *
- * Description : This function is called every tick.
- *
- * Argument(s) : none.
- *
- * Note(s) : (1) Interrupts may or may not be ENABLED during this call.
- *********************************************************************************************************
- */
- #if OS_TIME_TICK_HOOK_EN > 0
- void App_TimeTickHook (void)
- {
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- OSView_TickHook();
- #endif
- }
- #endif
- #endif
- #if (OS_VIEW_MODULE == DEF_ENABLED)
- void TerminalTask(void *pdata)
- {
- INT8U s[100];
- INT8U *key;
- INT8U err;
- (void)pdata;
- /* Prevent compiler warning */
- while (1) {
- key = (INT8U *)OSMboxPend(AppTerminalRxMbox, 0, &err);
- switch (*key) {
- case '1':
- sprintf((char *)s, "nCPU Usage = %3u%%n", OSCPUUsage);
- OSView_TxStr(s, 1);
- break;
- case '2':
- sprintf((char *)s, "n#Tasks = %3un", OSTaskCtr);
- OSView_TxStr(s, 1);
- break;
- default:
- OSView_TxStr("nnMicrium, Inc.", 1);
- OSView_TxStr("n1: CPU Usage (%)", 1);
- OSView_TxStr("n2: #Tasks", 1);
- OSView_TxStr("n?: Help (This menu)n", 1);
- break;
- }
- }
- }
- #endif
- #ifdef DEBUG
- /******************************************************************
- * Function name : assert_failed
- * Description : Reports the name of the source file and the source line number
- * where the assert_param error has occurred.
- * Input : - file: pointer to the source file name
- * - line: assert_param error line source number
- * Output : None * Return : None
- ******************************************************************/
- void assert_failed(u8* file, u32 line) {
- printf("Wrong parameters value: file %s on line %drn", file, line);
- while (1) { }
- }
- #endif