User defined event handling functions
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.
1
void cbAppColdStart(bool_t bInit) {
2
if (bInit == FALSE) {
3
...
4
} else {
5
...
6
ToCoNet_Event_Register_State_Machine(vProcessEvCore);
7
}
8
}
9
10
void vProcessEvCore(
11
tsEvent *pEv,
12
teEvent eEvent,
13
uint32 u32evarg) {
14
// check boot seq
15
if (eEvent == E_EVENT_START_UP) {
16
if (u32evarg & EVARG_START_UP_WAKEUP_RAMHOLD_MASK) {
17
// woke from NORMAL SLEEP (RAMHOLD)
18
}
19
if (u32evarg & EVARG_START_UP_WAKEUP_MASK) {
20
// woke from DEEP SLEEP
21
} else {
22
// COLD boot
23
}
24
}
25
26
switch (pEv->eState) {
27
case E_STATE_IDLE:
28
; // some task
29
ToCoNet_Event_SetState(pEv, E_STATE_APP_NORMAL);
30
break;
31
case E_STATE_APP_NORMAL:
32
; // some task (e.g. send s Tx packet)
33
if (cond) {
34
ToCoNet_Event_SetState(pEv, E_STATE_APP_WAIT_TX);
35
}
36
break;
37
case E_STATE_APP_WAIT_TX:
38
; // some task (e.g. wait until Tx finishes)
39
if (cond) {
40
ToCoNet_Event_SetState(pEv, E_STATE_APP_NORMAL);
41
}
42
break;
43
}
44
}
Copied!

Register

Up to two user-defined event processing functions can be registered with ToCoNet_Event_Register_State_Machine().
User-defined event handling functions must be registered to receive E_EVENT_START_UP events.

The notified event

The following three events are notified. Other events are passed on as function callback calls by the ToCoNet_Event_Process() function.
The following code is an example of communicating the completion of a transmission to the user-defined event processing function vProcessEvCore().
1
cbToCoNet_vTxEvent(uint8 u8CbId, uint8 u8Stat) {
2
ToCoNet_Event_Process(E_EVENT_APP_TX_COMPLETE,
3
u8CbId, vProcessEvCore);
4
}
Copied!
Calling vProcessEvCore() without using ToCoNet_Event_Process() should be avoided. The state transitions shown in the flow diagram will not take place and there will be inconsistencies in the information contained in the management structure of the user-defined event processing function.
It must not be called from an interrupt handler.

About state transitions

The state machine of user-defined event handling functions starts from E_STATE_IDLE (0).
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 (flow diagram).
You can keep the previous state by calling ToCoNet_Event_vKeepStateOnRamHoldSleep() before sleep (hold RAM), and receive E_EVENT_START_UP event after sleep is restored.
最終更新 8mo ago