208 lines
7.1 KiB
C
208 lines
7.1 KiB
C
/** ##########################################################################
|
|
** Filename : SimpleOs.c
|
|
** Project :
|
|
** Module :
|
|
** Processor :
|
|
** Version : 1.0
|
|
** Compiler :
|
|
** Date/Time :
|
|
** Abstract :
|
|
** Contents :
|
|
** Note :
|
|
** (c) Copyright dmdz Co.,Ltd
|
|
** --------------------------------------------------------------------------
|
|
** R E V I S I O N H I S T O R Y
|
|
** --------------------------------------------------------------------------
|
|
** Date Ver Author Description
|
|
|
|
** -20231103- V01-- --Linboyi--- --初版--
|
|
** #########################################################################*/
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
* I N C L U D E F I L E S
|
|
*****************************************************************************/
|
|
#include "Cpu.h"
|
|
#include "SimpleOs_Cfg.h"
|
|
#include "common_memory.h"
|
|
#include "SimpleOs_CallOut.h"
|
|
#include "SimpleOs_Time.h"
|
|
/*****************************************************************************
|
|
* D E F I N E S / M A C R O S
|
|
*****************************************************************************/
|
|
#define OS_TASK_PRE_READY (uint8_t)0
|
|
#define OS_TASK_RUNNING (uint8_t)1
|
|
#define OS_TASK_WAITING (uint8_t)2
|
|
#define OS_TASK_READY (uint8_t)3
|
|
#define OS_TASK_SUSPENDED (uint8_t)4
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
* T Y P E D E F I N I T I O N S
|
|
*****************************************************************************/
|
|
typedef struct
|
|
{
|
|
uint8_t ucTaskState[OS_TASK_MAX_NUM];
|
|
uint8_t ucEventState[OS_EVENT_TASK_MAX_NUM];
|
|
uint8_t ucTaskRunNum;
|
|
uint8_t ucMoreTaskCnt;
|
|
} SimpleOs_Struct_Type;
|
|
/*****************************************************************************
|
|
* G L O B A L V A R I A B L E S
|
|
* only configuration table allowed here,variables are not allowed!
|
|
*****************************************************************************/
|
|
static SimpleOs_Struct_Type SimpleOs_Struct;
|
|
/*****************************************************************************
|
|
* C O N S T A N T S
|
|
*****************************************************************************/
|
|
|
|
/*****************************************************************************
|
|
* F U N C T I O N P R O T O T Y P E
|
|
*****************************************************************************/
|
|
static void SimpleOs_MainFunction(void);
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|Prototype : SimpleOs_Init
|
|
|Called by :
|
|
|Preconditions :
|
|
|Input parameters :
|
|
|Output parameters :
|
|
|Return value :
|
|
|Description :
|
|
*****************************************************************************/
|
|
static void SimpleOs_Init(void)
|
|
{
|
|
common_memory_fill( (uint8_t *)&SimpleOs_Struct, 0u, sizeof(SimpleOs_Struct) / sizeof(uint8_t));
|
|
}
|
|
|
|
|
|
/*****************************************************************************
|
|
|Prototype : SimpleOs_Start
|
|
|Called by :
|
|
|Preconditions :
|
|
|Input parameters :
|
|
|Output parameters :
|
|
|Return value :
|
|
|Description :
|
|
*****************************************************************************/
|
|
void SimpleOs_Start(void)
|
|
{
|
|
(void)SimpleOs_Init();
|
|
(void)SimpleOsTime_Init();
|
|
(void)OS_StartUpHook();
|
|
(void)SimpleOs_MainFunction();
|
|
}
|
|
|
|
|
|
|
|
/*****************************************************************************
|
|
|Prototype : SimpleOs_ActiveTask
|
|
|Called by :
|
|
|Preconditions :
|
|
|Input parameters :
|
|
|Output parameters :
|
|
|Return value :
|
|
|Description :
|
|
*****************************************************************************/
|
|
void SimpleOs_ActiveTask(uint8_t TaskId)
|
|
{
|
|
if(TaskId < (uint8_t)OS_TASK_MAX_NUM)
|
|
{
|
|
if((uint8_t)OS_TASK_PRE_READY == SimpleOs_Struct.ucTaskState[TaskId])
|
|
{
|
|
OS_EnterCriticalArea_0();/*PRQA S 3138*/
|
|
SimpleOs_Struct.ucTaskState[TaskId] = OS_TASK_READY;
|
|
OS_LeaveCriticalArea_0();/*PRQA S 3138*/
|
|
}
|
|
}
|
|
}
|
|
|
|
/*****************************************************************************
|
|
|Prototype : SimpleOs_MainFunction
|
|
|Called by :
|
|
|Preconditions :
|
|
|Input parameters :
|
|
|Output parameters :
|
|
|Return value :
|
|
|Description :
|
|
*****************************************************************************/
|
|
static void SimpleOs_MainFunction(void)
|
|
{
|
|
for(;;)
|
|
{
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task1ms])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task1ms] = OS_TASK_RUNNING;
|
|
OS_Task1msFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task1ms] = OS_TASK_PRE_READY;
|
|
}
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task2ms])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task2ms] = OS_TASK_RUNNING;
|
|
OS_Task2msFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task2ms] = OS_TASK_PRE_READY;
|
|
}
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task5msA])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msA] = OS_TASK_RUNNING;
|
|
OS_Task5msAFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msA] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task5msB])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msB] = OS_TASK_RUNNING;
|
|
OS_Task5msBFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msB] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task5msC])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msC] = OS_TASK_RUNNING;
|
|
OS_Task5msCFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task5msC] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task10msA])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msA] = OS_TASK_RUNNING;
|
|
OS_Task10msAFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msA] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task10msB])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msB] = OS_TASK_RUNNING;
|
|
OS_Task10msBFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msB] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task10msC])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msC] = OS_TASK_RUNNING;
|
|
OS_Task10msCFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msC] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task10msD])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msD] = OS_TASK_RUNNING;
|
|
OS_Task10msDFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msD] = OS_TASK_PRE_READY;
|
|
}
|
|
|
|
if((uint8_t)OS_TASK_READY == SimpleOs_Struct.ucTaskState[OS_Task10msE])
|
|
{
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msE] = OS_TASK_RUNNING;
|
|
OS_Task10msEFun();
|
|
SimpleOs_Struct.ucTaskState[OS_Task10msE] = OS_TASK_PRE_READY;
|
|
}
|
|
(void)OS_ErrorHook();
|
|
}
|
|
} |