/**
******************************************************************************
* @brief Main function of TSL.
* @par Parameters:
* None
* @retval void None
* @par Required preconditions:
* Must be called from main loop to run the library state machine.
******************************************************************************
*/
void TSL_Action(void)
{
switch (TSLState)
{
case TSL_IDLE_STATE:
disableInterrupts();
Local_TickFlag.b.DTO_1sec = TSL_Tick_Flags.b.DTO_1sec;
TSL_Tick_Flags.b.DTO_1sec = 0;
enableInterrupts();
#if NUMBER_OF_ACQUISITION_PORTS != 0 //Can only be true for RC
TSLState = TSL_SCKEY_P1_ACQ_STATE;
break;
case TSL_SCKEY_P1_ACQ_STATE:
TSL_SCKEY_P1_Acquisition();
#if NUMBER_OF_SINGLE_CHANNEL_PORTS > 0
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_SCKEY_P1_PROC_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_SCKEY_P1_PROC_STATE;
#endif //// HW_ACQ
break;
case TSL_SCKEY_P1_PROC_STATE:
for (KeyIndex = 0; KeyIndex < SCKEY_P1_KEY_COUNT; KeyIndex++)
{
TSL_SCKey_Process();
}
#endif // NUMBER_OF_SINGLE_CHANNEL_PORTS > 0
#endif //NUMBER_OF_ACQUISITION_PORTS != 0
#if NUMBER_OF_ACQUISITION_PORTS > 1
TSLState = TSL_SCKEY_P2_ACQ_STATE;
#else
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
TSLState = TSL_MCKEY1_ACQ_STATE;
#else
TSLState = TSL_ECS_STATE;
#endif
#endif
break;
#if NUMBER_OF_ACQUISITION_PORTS > 1
case TSL_SCKEY_P2_ACQ_STATE:
TSL_SCKEY_P2_Acquisition();
#if NUMBER_OF_SINGLE_CHANNEL_PORTS > 1
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_SCKEY_P2_PROC_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_SCKEY_P2_PROC_STATE;
#endif //// HW_ACQ
break;
case TSL_SCKEY_P2_PROC_STATE:
for (KeyIndex = SCKEY_P1_KEY_COUNT; KeyIndex < (SCKEY_P2_KEY_COUNT + SCKEY_P1_KEY_COUNT); KeyIndex++)
{
TSL_SCKey_Process();
}
#endif // NUMBER_OF_SINGLE_CHANNEL_PORTS > 1
#if NUMBER_OF_ACQUISITION_PORTS > 2
TSLState = TSL_SCKEY_P3_ACQ_STATE;
#else
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
TSLState = TSL_MCKEY1_ACQ_STATE;
#else
TSLState = TSL_ECS_STATE;
#endif
#endif
break;
#endif
#if NUMBER_OF_ACQUISITION_PORTS > 2
case TSL_SCKEY_P3_ACQ_STATE:
TSL_SCKEY_P3_Acquisition();
#if NUMBER_OF_SINGLE_CHANNEL_PORTS > 2
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_SCKEY_P3_PROC_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_SCKEY_P3_PROC_STATE;
#endif //// HW_ACQ
break;
case TSL_SCKEY_P3_PROC_STATE:
for (KeyIndex = (SCKEY_P1_KEY_COUNT + SCKEY_P2_KEY_COUNT); KeyIndex < (SCKEY_P3_KEY_COUNT + SCKEY_P1_KEY_COUNT + SCKEY_P2_KEY_COUNT); KeyIndex++)
{
TSL_SCKey_Process();
}
#endif // NUMBER_OF_SINGLE_CHANNEL_PORTS > 2
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
TSLState = TSL_MCKEY1_ACQ_STATE;
#else
TSLState = TSL_ECS_STATE;
#endif
break;
#endif
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 0
case TSL_MCKEY1_ACQ_STATE:
TSL_MCKey1_Acquisition();
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 1
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_MCKEY2_ACQ_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_MCKEY2_ACQ_STATE;
#endif //// HW_ACQ
#else
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_MCKEY_PROC_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_MCKEY_PROC_STATE;
#endif //// HW_ACQ
#endif
break;
#if NUMBER_OF_MULTI_CHANNEL_KEYS > 1
case TSL_MCKEY2_ACQ_STATE:
TSL_MCKey2_Acquisition();
#if (HW_ACQ_MODE != 0) //// HW_ACQ
if ((HW_Acquisition_Step == READY) || //// HW_ACQ
(HW_Acquisition_Step == DONE)) //// HW_ACQ
{ //// HW_ACQ
TSLState = TSL_MCKEY_PROC_STATE; //// HW_ACQ
} //// HW_ACQ
#else //// HW_ACQ
TSLState = TSL_MCKEY_PROC_STATE;
#endif //// HW_ACQ
break;
#endif
case TSL_MCKEY_PROC_STATE:
for (KeyIndex = 0; KeyIndex < NUMBER_OF_MULTI_CHANNEL_KEYS; KeyIndex++)
{
TSL_MCKey_Process();
}
TSLState = TSL_ECS_STATE;
break;
#endif
case TSL_ECS_STATE:
TSL_ECS();
TSL_GlobalSetting.whole = TSL_TempGlobalSetting.whole;
TSL_TempGlobalSetting.whole = 0;
TSL_GlobalState.whole = TSL_TempGlobalState.whole;
TSL_TempGlobalState.whole = 0;
TSLState = TSL_IDLE_STATE;
break;
default:
for (;;)
{
// Wait for Watchdog reset ...
}
}
}
|