181 lines
4.6 KiB
C
181 lines
4.6 KiB
C
/**
|
|
******************************************************************************
|
|
* @file task_manager.c
|
|
* @author AMG Energy Solution Team
|
|
* @version V1.0.0
|
|
* @date 07-Feb-2022
|
|
* @brief This file provides all the codes of the task_manager functions.
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
|
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
|
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
|
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
|
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
|
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
|
*
|
|
* <h2><center>© COPYRIGHT 2022 AMG</center></h2>
|
|
******************************************************************************
|
|
*/
|
|
|
|
/** @addtogroup mBMS2
|
|
* @{
|
|
*/
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include <includes.h>
|
|
#include "malloc.h"
|
|
#include "asutil.h"
|
|
#include "console.h"
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* Private define ------------------------------------------------------------*/
|
|
#define OS_MAX_TASK_PRIO 14
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* Private variables ---------------------------------------------------------*/
|
|
OS_TCB AppTaskTCB[OS_MAX_TASK_PRIO - 3]; // 0 ~ 2 Task -> uC/OS
|
|
uint16_t disCPU_Usage[OS_MAX_TASK_PRIO - 3];
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* Private functions ---------------------------------------------------------*/
|
|
void TaksTCBInit(void)
|
|
{
|
|
memset(AppTaskTCB, 0x00, sizeof(OS_TCB) * (OS_MAX_TASK_PRIO - 3));
|
|
}
|
|
|
|
void *GetAppTaskTCB(uint16_t prio)
|
|
{
|
|
return &AppTaskTCB[prio - 3];
|
|
}
|
|
|
|
#ifdef CONSOLE_DEBUG
|
|
|
|
/* Command processing in Task Status Mode STATE */
|
|
int8_t Process_TaskStatus_Data(uint8_t *text, uint16_t size)
|
|
{
|
|
int8_t ret;
|
|
|
|
if (size > 1) {
|
|
if (text[1] != ' ') return(0); /* Invalid command if space is in first position */
|
|
}
|
|
text[size] = 0x00;
|
|
ret = 1;
|
|
switch (text[0]) {
|
|
case 'o':
|
|
screenmode = OP_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 's':
|
|
screenmode = SET_MODE;
|
|
ViewScreen();
|
|
break;
|
|
case 'd':
|
|
screenmode = DIAG_MODE;
|
|
ViewScreen();
|
|
break;
|
|
default:
|
|
ret = 0;
|
|
break;
|
|
}
|
|
return(ret);
|
|
}
|
|
|
|
uint32_t disCPUSum;
|
|
uint32_t bakOSTaskCtxSwCtr;
|
|
uint32_t PerSecOSTaskCtxSwCrt;
|
|
uint32_t disOSTaskCtxSwCtr;
|
|
|
|
uint32_t cswTick = 0;
|
|
|
|
void CalOSTaskCtxSwCtrPerSec(uint32_t tick)
|
|
{
|
|
cswTick += tick;
|
|
|
|
if (cswTick >= 1000)
|
|
{
|
|
PerSecOSTaskCtxSwCrt = OSTaskCtxSwCtr - bakOSTaskCtxSwCtr;
|
|
bakOSTaskCtxSwCtr = OSTaskCtxSwCtr;
|
|
cswTick = 0;
|
|
}
|
|
}
|
|
|
|
static uint16_t disMemUsed;
|
|
|
|
void osDisplayTaskStatus(uint8_t p)
|
|
{
|
|
uint32_t CPUSum = 0;
|
|
uint8_t *text;
|
|
static uint32_t tsCount = 0;
|
|
|
|
if (p || (tsCount <= 0))
|
|
{
|
|
text = mymalloc(100);
|
|
if (text != NULL)
|
|
{
|
|
for (int i = 0; i < OS_MAX_TASK_PRIO - 3; i++)
|
|
{
|
|
if (AppTaskTCB[i].StkPtr == NULL) continue;
|
|
if (p)
|
|
{
|
|
sprintf((char *)text, "%s", AppTaskTCB[i].NamePtr);
|
|
NormalOutXY( 2, 8 + i, text);
|
|
}
|
|
if (p)
|
|
{
|
|
sprintf((char *)text, "%6d %6d %6d",
|
|
AppTaskTCB[i].StkSize,
|
|
AppTaskTCB[i].StkFree,
|
|
AppTaskTCB[i].StkUsed
|
|
);
|
|
NormalOutXY( 18, 8 + i, text);
|
|
}
|
|
if (p ||(disCPU_Usage[i] != AppTaskTCB[i].CPUUsage))
|
|
{
|
|
sprintf((char *)text, "%6.2f(%6.2f)"
|
|
, (float)AppTaskTCB[i].CPUUsage / 100
|
|
, (float)AppTaskTCB[i].CPUUsageMax / 100
|
|
);
|
|
NormalOutXY( 18 + 24, 8 + i, text);
|
|
disCPU_Usage[i] = AppTaskTCB[i].CPUUsage;
|
|
}
|
|
if (p)
|
|
{
|
|
sprintf((char *)text, "%6d", AppTaskTCB[i].TickRemain);
|
|
NormalOutXY( 64, 8 + i, text);
|
|
}
|
|
CPUSum += AppTaskTCB[i].CPUUsage;
|
|
}
|
|
if (p ||(disCPUSum != CPUSum))
|
|
{
|
|
sprintf((char *)text, "%5.1f",
|
|
(float)CPUSum / 100
|
|
);
|
|
GreenOutXY( 42, 20, text);
|
|
disCPUSum = CPUSum;
|
|
}
|
|
if (p || (disOSTaskCtxSwCtr != PerSecOSTaskCtxSwCrt))
|
|
{
|
|
sprintf((char *)text, "%6d", PerSecOSTaskCtxSwCrt);
|
|
GreenOutXY( 70, 20, text);
|
|
disOSTaskCtxSwCtr = PerSecOSTaskCtxSwCrt;
|
|
}
|
|
if (p || (disMemUsed != mem_perused()))
|
|
{
|
|
sprintf((char *)text, "%5.1f", (float)mem_perused() / 10);
|
|
GreenOutXY( 21, 20, text);
|
|
disMemUsed = mem_perused();
|
|
}
|
|
myfree(text);
|
|
}
|
|
tsCount = 200;
|
|
}
|
|
tsCount--;
|
|
}
|
|
|
|
#endif // #ifdef CONSOLE_DEBUG
|
|
|
|
/*******************(C)COPYRIGHT 2022 AMG ********************END OF FILE******/
|