Home / RL-ARM User's Guide (MDK v4)
Event Driven Operation
The event-driven operation of RL-TCPnet allows you to run TCPnet
application in event-driven mode in a multitasking environment.
Instead of calling the polling loop constantly, the system processess
TCPnet events only when needed. The rest of time, TCPnet system
remains idle.
The main_TcpNet()
function is modified to return a busy status indication. If TCPnet
system is busy, this function has to be called again, to complete the
TCP/IP processing. If TCPnet is not busy, TCP/IP processing might be
stalled, until a TCPnet event occurs.
The TCPnet events, which require TCP/IP processing, are:
- ethernet packet received,
- tick timer interval expired,
- serial character received or transmitted.
Event-driven operation optimizes the cpu usage a lot. The
following table lists the cpu time required for TCP/IP processing and
cpu idle time for HTTP_Demo example:
TCP/IP processing |
System Idle time |
247 ms |
85953 ms |
In order to modify the TCPnet application for event-driven
operation, you must make the following changes to your project:
-
ethernet driver
Add the code to send a signal event to tcp_main task in
the ethernet receive interrupt function.
static void interrupt_ethernet (void) __irq {
...
fetch_packet ();
isr_evt_set(0x0001, tcp_task);
...
}
-
tcp_tick task
Add the code to send a signal event to tcp_main task. The
priority of the tcp_tick task should be higher than the
priority of tcp_main task.
__task void tcp_tick (void) {
os_itv_set (10);
while (1) {
os_itv_wait ();
timer_tick ();
os_evt_set(0x0001, tcp_task);
}
}
-
tcp_main task
Add the code to wait for an event in TCPnet tcp_main task.
The priority of tcp_main task should be higher than the
application layer / service layer tasks.
__task void tcp_main (void) {
init_TcpNet ();
while (1) {
os_evt_wait_and(0x0001, 0xFFFF);
while (main_TcpNet() == __TRUE);
}
}