92 lines
1.4 KiB
C
92 lines
1.4 KiB
C
#include "SWM320.h"
|
|
#include "debug.h"
|
|
#include "userTimer.h"
|
|
#include "BoardCfg.h"
|
|
static void task1()
|
|
{
|
|
Printf(".");
|
|
}
|
|
|
|
/**
|
|
* @brief 统计系统空闲了多久
|
|
*
|
|
*/
|
|
static u32 sysWaitCnt[1] ={0};
|
|
static u32 sysWaitCnt2[1] ={0};
|
|
static void task2(){
|
|
Printf("[Idle:%d]\n",sysWaitCnt2[0]);
|
|
}
|
|
/**
|
|
* @brief 空闲任务
|
|
*
|
|
*/
|
|
void TaskIdle(void)
|
|
{
|
|
static u32 Systick=0;
|
|
extern volatile u32 ptSysTick;
|
|
while (ptSysTick <= Systick)
|
|
{
|
|
//系统空闲情况检测
|
|
sysWaitCnt[0]++;
|
|
|
|
}
|
|
//拷贝系统检测结果
|
|
sysWaitCnt2[0] = sysWaitCnt[0];
|
|
//开启新一轮监测
|
|
static u32 CoreCnt=0;
|
|
CoreCnt++;
|
|
if (CoreCnt==1000){
|
|
CoreCnt=0;
|
|
sysWaitCnt[0] = 0;
|
|
}
|
|
//如果有个任务时间特别长,那么就尽快追上任务
|
|
if(Systick<ptSysTick)
|
|
Systick ++;
|
|
//如果有个任务时间特别长,还是要重新等待时间,因为系统认为只过了1个时间片
|
|
// Systick = ptSysTick;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(void)
|
|
{
|
|
uint32_t chr;
|
|
uint32_t err;
|
|
SystemInit();
|
|
DebugInit();
|
|
BoardInit();
|
|
Printf("\nSystemInit\n");
|
|
UserTimerAdd(task1,NULL,1000);
|
|
//设置系统定时器为1ms
|
|
SysTick_Config(SystemCoreClock/1000);
|
|
|
|
#include "uart_Net.h"
|
|
NetInit();
|
|
while (1)
|
|
{
|
|
//1个时间片任务
|
|
UserTimerTask();
|
|
TaskIdle();
|
|
}
|
|
}
|
|
/**
|
|
* @brief 系统定时器中断
|
|
*
|
|
*/
|
|
void SysTick_Handler(void)
|
|
{
|
|
extern volatile u32 ptSysTick;
|
|
ptSysTick++;
|
|
}
|
|
// /**
|
|
// * @brief time0定时器中断
|
|
// *
|
|
// */
|
|
// void TIMR0_Handler(void)
|
|
// {
|
|
// TIMR_INTClr(TIMR0);
|
|
// extern volatile u32 ptSysTick;
|
|
// ptSysTick++;
|
|
// }
|