osal_start_system(); //运行系统【OSAL.c】<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />
//此函数是任务系统的主循环函数,他将轮询所有任务事件然后调用相关的任务处理函数,没有任务时将进入休眠状态。
void osal_start_system( void )
{
#if !defined ( ZBIT )
//虽然搞不清楚这个ZBIT什么东西,不过应该是没有定义的,如果定义了的话所有函数只会顺序跑下来,跑完这个函数整个系统就结束了,没有意义,这里看到这个无限循环应该就是整个系统的运行方式了
for(;;)
#endif
{
uint8 idx = 0;
Hal_ProcessPoll(); // This replaces MT_SerialPoll() and osal_check_timer().
//OSAL调用此函数来推送UART,TIMER。。。【hal_drivers.c】
void Hal_ProcessPoll ()
{
//选取定时器
HalTimerTick();
//检查定时器的计数溢出【hal_timer.c】
void HalTimerTick (void)
{
if (!halTimerRecord[HW_TIMER_1].intEnable)
{
halProcessTimer1 ();
//处理TIMER1事件
void halProcessTimer1 (void)
{
if (halTimerRecord[halTimerRemap(HAL_TIMER_3)].channelMode == HAL_TIMER_CH_MODE_OUTPUT_COMPARE)
//处理通道模式为输出比较时的情况
{
if (T1CTL & T1CTL_CH0IF)
//检查通道0中断标志看是否达到设定的中断要求
{
T1CTL &= ~(T1CTL_CH0IF);
//清除中断标志
halTimerSendCallBack (HAL_TIMER_3, HAL_TIMER_CHANNEL_A, HAL_TIMER_CH_MODE_OUTPUT_COMPARE);
//给回调函数发送回应
void halTimerSendCallBack (uint8 timerId, uint8 channel, uint8 channelMode)
{
uint8 hwtimerid;
hwtimerid = halTimerRemap (timerId);
if (halTimerRecord[hwtimerid].callBackFunc)
(halTimerRecord[hwtimerid].callBackFunc) (timerId, channel, channelMode);
}
}
if (T1CTL & T1CTL_CH1IF)
{
T1CTL &= ~(T1CTL_CH1IF);
halTimerSendCallBack (HAL_TIMER_3, HAL_TIMER_CHANNEL_B, HAL_TIMER_CH_MODE_OUTPUT_COMPARE);
}
if (T1CTL & T1CTL_CH2IF)
{
T1CTL &= ~(T1CTL_CH2IF);
halTimerSendCallBack (HAL_TIMER_3, HAL_TIMER_CHANNEL_C, HAL_TIMER_CH_MODE_OUTPUT_COMPARE);
}
}
else if (halTimerRecord[halTimerRemap(HAL_TIMER_3)].channelMode == HAL_TIMER_CH_MODE_OVERFLOW)
{
if (T1CTL & T1CTL_OVFIF)
{
T1CTL &= ~(T1CTL_OVFIF);
halTimerSendCallBack (HAL_TIMER_3, HAL_TIMER_CHANNEL_SINGLE, HAL_TIMER_CH_MODE_OVERFLOW);
}
}
}
}
if (!halTimerRecord[HW_TIMER_3].intEnable)
{
halProcessTimer3 ();
}
if (!halTimerRecord[HW_TIMER_4].intEnable)
{
halProcessTimer4 ();
}
}
/* UART的选取*/
#if (defined HAL_UART) && (HAL_UART == TRUE)
HalUARTPoll();
//【hal_uart.c】
typedef struct
{
uint8 *rxBuf;
uint8 rxHead;
uint8 rxTail;
uint8 rxMax;
uint8 rxCnt;
uint8 rxTick;
uint8 rxHigh;
uint8 *txBuf;
#if HAL_UART_BIG_TX_BUF
uint16 txHead;
uint16 txTail;
uint16 txMax;
uint16 txCnt;
#else
uint8 txHead;
uint8 txTail;
uint8 txMax;
uint8 txCnt;
#endif
uint8 txTick;
uint8 flag;
halUARTCBack_t rxCB;
} uartCfg_t;//UART数据结构,这个数据结构在文档中没有提到,估计是串口缓存区的配置串口需要掌握的是HalUARTOpen函数和halUARTCfg_t数据结构
#endif
}
do {
if (tasksEvents[idx]) //轮询检查任务
{
break;
}
} while (++idx < tasksCnt);
if (idx < tasksCnt)
{
uint16 events;
halIntState_t intState;
HAL_ENTER_CRITICAL_SECTION(intState);
events = tasksEvents[idx];
tasksEvents[idx] = 0; // Clear the Events for this task.
HAL_EXIT_CRITICAL_SECTION(intState);
events = (tasksArr[idx])( idx, events );
//根据事件的类型执行相关的任务处理函数
HAL_ENTER_CRITICAL_SECTION(intState);
tasksEvents[idx] |= events; // Add back unprocessed events to the current task.
HAL_EXIT_CRITICAL_SECTION(intState);
}
#if defined( POWER_SAVING )
else // Complete pass through all task events with no activity?
{
osal_pwrmgr_powerconserve(); // Put the processor/system into sleep
}
#endif
}
}
} // main()
//到此main函数我们就分析完了
文章评论(0条评论)
登录后参与讨论