A user-defined event handling function is a function defined by the user for the purpose of performing event handling in the form of a callback from TWENET. Although we call them functions, they behave as state transition machines.
void cbAppColdStart(bool_t bInit) {
if (bInit == FALSE) {
...
} else {
...
ToCoNet_Event_Register_State_Machine(vProcessEvCore);
}
}
void vProcessEvCore(
tsEvent *pEv,
teEvent eEvent,
uint32 u32evarg) {
// check boot seq
if (eEvent == E_EVENT_START_UP) {
if (u32evarg & EVARG_START_UP_WAKEUP_RAMHOLD_MASK) {
// woke from NORMAL SLEEP (RAMHOLD)
}
if (u32evarg & EVARG_START_UP_WAKEUP_MASK) {
// woke from DEEP SLEEP
} else {
// COLD boot
}
}
switch (pEv->eState) {
case E_STATE_IDLE:
; // some task
ToCoNet_Event_SetState(pEv, E_STATE_APP_NORMAL);
break;
case E_STATE_APP_NORMAL:
; // some task (e.g. send s Tx packet)
if (cond) {
ToCoNet_Event_SetState(pEv, E_STATE_APP_WAIT_TX);
}
break;
case E_STATE_APP_WAIT_TX:
; // some task (e.g. wait until Tx finishes)
if (cond) {
ToCoNet_Event_SetState(pEv, E_STATE_APP_NORMAL);
}
break;
}
}
Register
The notified event
The following code is an example of communicating the completion of a transmission to the user-defined event processing function vProcessEvCore().
Up to two user-defined event processing functions can be registered with .
User-defined event handling functions must be registered to receive events.
The following three events are notified. Other events are passed on as function callback calls by the function.
: on start-up
: every tick timer fired (4ms default)
: every 1sec
Calling vProcessEvCore() without using ToCoNet_Event_Process() should be avoided. The state transitions shown in will not take place and there will be inconsistencies in the information contained in the management structure of the user-defined event processing function.
When a user-defined event processing function is called, a state transition is declared by calling the ToCoNet_Event_SetState() function. After declaring the state transition and exiting the user defined event handling function, the function is called again with the E_EVENT_NEW_STATE event as a parameter. This process is continuous as long as the state transition continues ().
You can keep the previous state by calling before sleep (hold RAM), and receive E_EVENT_START_UP event after sleep is restored.