This is the multi-page printable view of this section. Click here to print...

Return to the regular view of this page

As of 2025-07-24

Callback Functions

Various callback functions
These are callback functions where the application description is written. Callback means that it is called from the system (library). By defining several callback functions, the user describes the behavior of the system.

The following callback functions are mandatory definitions.

  • setup()
  • loop()

Functions other than these will be linked as empty functions that do nothing if not defined.

Normal callback invocation order

init_coldboot()
  ↓ (TWENET internal processing: Initialization 1)
setup()
  ↓ (TWENET internal processing: Initialization 2)
begin() --- only once
  ↓
loop() <--+
  ↓       | Event processing, behavior processing
CPU DOZE -+

Callback invocation order when waking up from sleep

the_twelite.sleep()
  ↓ sleeping...


init_warmboot()
  ↓ (TWENET internal processing: Initialization 3)
wakeup()
  ↓ (TWENET internal processing: Initialization 4)
loop() <--+
  ↓       | Event processing, behavior processing
CPU DOZE -+

1 - setup()

Initialization process
Called at the beginning of code execution; write initialization code here.

2 - begin()

Initialization process (after TWENET initialization)
Called only once just before the first call of the loop() function. Since TWENET initialization is complete, there is no need to consider constraints like those in setup().

Mainly used in the following situations:

  • Displaying the startup message
  • Writing test code
  • Transitioning to sleep immediately after startup
  • Processing that is problematic in setup() (wireless packet processing, timer operation, etc.)

3 - loop()

Loop processing
This is the main loop of the application. After the loop ends, the CPU transitions to DOZE mode and waits for the next interrupt with low power consumption.

In Act, most processing is written inside this loop.

4 - wakeup()

Processing after waking from sleep
Called before transitioning to loop() after waking from sleep, this function includes procedures for initialization after waking and branching processes according to the wake-up state.

5 - init_coldboot()

Initialization process (before peripheral initialization)
Called at the re-initialization of code execution, before peripheral API and initialization have been performed.

6 - init_warmboot()

Process after waking from sleep (before peripheral initialization)
Called again after waking from sleep, before the peripheral API is initialized.

7 - on_rx_packet()

Processing upon packet reception
Describes the process when a received packet is received.
void on_rx_packet(mwx::packet_rx& pkt, bool_t &b_handled)

When a wireless packet is received, this function is called from within the MWX library with the data stored in pkt as packet_rx. If this function is not defined in the application, a weak function that does nothing will be linked.

If true is set to b_handled within this function, it notifies the MWX library that the received packet has been processed within the application. When marked as processed, unnecessary processing is suppressed (the processing of the_twelite.receiver is not performed).

8 - on_tx_comp()

Processing upon packet transmission completion
Describes the processing performed when the transmission is completed.
void on_tx_comp(mwx::packet_ev_tx& ev, bool_t &b_handled)

This function is called within the MWX library when the wireless packet transmission is finished, with data stored in ev as packet_ev_tx. If this function is not defined in the application, a do-nothing weak function is linked.

ev.u8CbId is the ID at transmission, and ev.bStatus is a flag indicating transmission success (1) or failure (0).

If true is set to b_handled within this function, it informs the MWX library that the received packet has been processed within the application. When marked as processed, unnecessary processing is suppressed (event callback functions are not called for the_twelite.app, .board, or .settings).