RKH

Files

file  rkhevt.h
 Defines event data type and other related macros.
 
file  rkhfwk_dynevt.h
 Specifies the interface of dynamic event support.
 

Data Structures

struct  RKH_EVT_T
 Represents events without parameters. More...
 

Macros

#define RKH_EVT_CAST(_e)    ((RKH_EVT_T *)(_e))
 Perform cast to pointer to RKH event structure (RKH_EVT_T*).
 
#define RKH_ALLOC_EVT(et, e, sender_)   (et *)rkh_fwk_ae((RKH_ES_T)sizeof(et),(RKH_SIG_T)(e), sender_)
 This macro dynamically creates a new event of type et with its signal. More...
 
#define RKH_FWK_GC(e, sender_)    rkh_fwk_gc(e, sender_)
 Recycle a dynamic event. More...
 
#define RKH_FWK_RSV(e)    rkh_fwk_reserve(e)
 Reserve the dynamic event to be recycled. More...
 
#define RKH_SET_STATIC_EVENT(ev_obj, ev_sig)   MK_SET_EVT(ev_obj, ev_sig)
 This macro initialize an event e with es signal and establishes it as one static event. More...
 
#define RKH_STATIC_EVENT(ev_obj, ev_sig)   MK_EVT(ev_obj, ev_sig)
 This macro declares and initializes the event structure ev_ob with ev_sig signal number and establishes it as one static event. More...
 
#define RKH_ROM_STATIC_EVENT(ev_obj, ev_sig)   MK_ROM_EVT(ev_obj, ev_sig)
 This macro declares and initializes the event structure ev_ob with ev_sig signal number and establishes it as one static event. More...
 
#define RKH_INIT_STATIC_EVT(ev_sig)   MK_EVT_STRUCT(ev_sig)
 Initializes the attibutes of a RKH's event object structure. More...
 

Functions

void rkh_dynEvt_init (void)
 Initializes the dynamic event manager.
 
void rkh_fwk_registerEvtPool (void *sstart, rui32_t ssize, RKH_ES_T esize)
 Registers a new event pool into the event pool list. More...
 
RKH_EVT_Trkh_fwk_ae (RKH_ES_T esize, RKH_SIG_T e, const void *const sender)
 Allocates an event from the previously created event pool. More...
 
void rkh_fwk_gc (RKH_EVT_T *e, const void *const sender)
 Recycle a dynamic event. More...
 
void rkh_fwk_reserve (RKH_EVT_T *e)
 Reserve the dynamic event to be recycled. More...
 

Detailed Description

Macro Definition Documentation

#define RKH_ALLOC_EVT (   et,
  e,
  sender_ 
)    (et *)rkh_fwk_ae((RKH_ES_T)sizeof(et),(RKH_SIG_T)(e), sender_)

This macro dynamically creates a new event of type et with its signal.

The basic policy is to allocate the event from the first pool that has a block size big enough to fit the requested event size. RKH can manage up to three event pools (e.g., small, medium, and large events, like shirt sizes). It returns a pointer to the event already cast to the event type (et*).

Parameters
[in]ettype of event
[in]eevent signal
[in]sender_pointer to the actor that request a memory block. It is not necessarily a pointer to an active object. In fact, if RKH_ALLOC_EVT() is called from an interrupt or other context, it can create a unique object just to unambiguously identify the publisher of the event.
Note
The assertions inside rkh_fwk_ae() function guarantee that the pointer is valid, so you don't need to check the pointer returned from rkh_fwk_ae(), unlike the value returned from malloc(), which you should check.
Usage
Here is an example of dynamic event allocation with the macro RKH_ALLOC_EVT():
1 MYEVT_T *mye = RKH_ALLOC_EVT(MYEVT_T, DATA, me);
2 mye->y = mye->x = 0;
3 ...

Definition at line 102 of file rkhfwk_dynevt.h.

#define RKH_FWK_GC (   e,
  sender_ 
)    rkh_fwk_gc(e, sender_)

Recycle a dynamic event.

This macro implements a simple garbage collector for the dynamic events. Only dynamic events are candidates for recycling. (A dynamic event is one that is allocated from an event pool, which is determined as non-zero e->nref attribute.) Next, the function decrements the reference counter of the event, and recycles the event only if the counter drops to zero (meaning that no more references are outstanding for this event). The dynamic event is recycled by returning it to the pool from which it was originally allocated. The pool-of-origin information is stored in the e->pool member.

Parameters
[in]epointer to event to be potentially recycled.
[in]sender_Pointer to the actor that request a memory block. It is not necessarily a pointer to an active object. In fact, if RKH_FWK_GC() is called from an interrupt or other context, it can create a unique object just to unambiguously identify the publisher of the event.
Note
This function is internal to RKH and the user application should not call it. Instead, use RKH_FWK_GC() macro.
The garbage collector must be explicitly invoked at all appropriate contexts, when an event can become garbage (automatic garbage collection).
When setting RKH_CFG_FWK_DYN_EVT_EN = 0 the garbage collector has not effect, thus it's eliminated in compile-time.

Definition at line 146 of file rkhfwk_dynevt.h.

#define RKH_FWK_RSV (   e)    rkh_fwk_reserve(e)

Reserve the dynamic event to be recycled.

This is the complement to RKH_FWK_GC(). It increments the reference count of a dynamic event so the event can be saved by an SMA (AO). Sometime later the SMA should manually release the event with RKH_FWK_GC().

Parameters
[in]epointer to event to be reserved.

Definition at line 165 of file rkhfwk_dynevt.h.

#define RKH_SET_STATIC_EVENT (   ev_obj,
  ev_sig 
)    MK_SET_EVT(ev_obj, ev_sig)

This macro initialize an event e with es signal and establishes it as one static event.

Parameters
[in]ev_objname of event structure (object).
[in]ev_sigevent signal. The RKH takes this value for triggering a state transition.
See also
RKH_ROM_STATIC_EVENT() and RKH_STATIC_EVENT() macros.
Usage
1 typedef struct
2 {
3  RKH_EVT_T e;
4  rui8_t cmd;
5 } RPC_REQ_T;
6 
7 typedef struct
8 {
9  RPC_REQ_T e;
10  rkhui8_t txtsz;
11  EADR_T dst;
12  EADR_T sc;
13  char txt[ PDU_SIZEOF_UD_ASCII ];
14 } REQ_SEND_SMS_T;
15 
16 ...
17 static REQ_SEND_SMS_T ev_txsm;
18 
19 ...
20 some_function( ... )
21 {
22  RKH_SET_STATIC_EVENT( &ev_txsm, REQ_SEND_SMS );
23  ev_txsm.e.cmd = RPC_SEND_SMS;
24  ...
25 }

Definition at line 212 of file rkhfwk_dynevt.h.

#define RKH_STATIC_EVENT (   ev_obj,
  ev_sig 
)    MK_EVT(ev_obj, ev_sig)

This macro declares and initializes the event structure ev_ob with ev_sig signal number and establishes it as one static event.

Parameters
[in]ev_objname of event structure (object).
[in]ev_sigevent signal. The RKH takes this value for triggering a state transition.
See also
RKH_SET_STATIC_EVENT() and RKH_ROM_STATIC_EVENT() macros.
Usage
1 ...
2 static RKH_STATIC_EVENT( ev_udrej, UPG_DIC_REJ );
3 
4 void
5 dm_upgdic_rej( ... )
6 {
7  ...
8  rkh_put_fifo( drpc, &ev_udrej );
9 }

Definition at line 241 of file rkhfwk_dynevt.h.

#define RKH_ROM_STATIC_EVENT (   ev_obj,
  ev_sig 
)    MK_ROM_EVT(ev_obj, ev_sig)

This macro declares and initializes the event structure ev_ob with ev_sig signal number and establishes it as one static event.

Parameters
[in]ev_objname of event structure (object).
[in]ev_sigevent signal. The RKH takes this value for triggering a state transition.
See also
RKH_SET_STATIC_EVENT() and RKH_STATIC_EVENT() macros.
Warning
The created event object is explicitly placed at ROM.
Usage
1 ...
2 static RKH_ROM_STATIC_EVENT( ev_timer, RPC_TIMER_RET );
3 
4 void
5 offhook( void )
6 {
7  ...
8  rkh_put_fifo( qphone, &ev_timer );
9 }

Definition at line 273 of file rkhfwk_dynevt.h.

#define RKH_INIT_STATIC_EVT (   ev_sig)    MK_EVT_STRUCT(ev_sig)

Initializes the attibutes of a RKH's event object structure.

Usage
1 typedef struct
2 {
3  RKH_EVT_T e;
4  rui8_t cmd;
5 } RPC_REQ_T;
6 
7 ...
8 static RKHROM RPC_REQ_T ev_ssreq =
9 {
10  RKH_INIT_STATIC_EVT( REQ_SEND_SMS_REQ ),
11  RPC_SEND_SMS_REQ
12 };
13 
14 ...
15 void
16 some_function(void)
17 {
18  RKH_SMA_POST_FIFO(drpc, RKH_EVT_CAST(&ev_ssreq), 0);
19  ...
20 }

Definition at line 306 of file rkhfwk_dynevt.h.

Function Documentation

void rkh_fwk_registerEvtPool ( void *  sstart,
rui32_t  ssize,
RKH_ES_T  esize 
)

Registers a new event pool into the event pool list.

Before using dynamic events (or event with arguments) the application code must register the event pools, which stores the events as a fixed-sized memory block. Each event pool must be registered with the RKH framework, by means of the rkh_fwk_registerEvtPool() function.

This function initializes one event pool at a time and must be called exactly once for each event pool before the pool can be used.

The application code might initialize the event pools by making calls to the rkh_fwk_registerEvtPool() function. However, for the simplicity of the internal implementation, the application code initialize event pools in the ascending order of the event size.

Many RTOSes provide fixed block-size heaps, a.k.a. memory pools that can be adapted for RKH event pools. In case such support is missing, RKH provides a native RKH event pool manager implementation. See rkhfwk_evtpool.c.

For adapting RKH event pools to any fixed-size memory block service RTOS provided the application code must provides the implementation of the rkhfwk_etpoo.h interface.

The dynamic allocation of events is optional then if the RKH_CFGPORT_NATIVE_DYN_EVT_EN is set to 1 and the native fixed-size memory block facility is enabled (see RKH_CFG_MP_EN) then RKH will include its own implementation of dynamic memory management. When RKH_CFGPORT_NATIVE_DYN_EVT_EN is enabled RKH also will provide the event pool manager implementation based on its native memory pool module.

Parameters
[in]sstartstorage start. Pointer to memory from which memory blocks are allocated.
[in]ssizestorage size. Size of the memory pool storage in bytes.
[in]esizeevent size. This number determines the size of each memory block in the pool.
Usage
1 #define SIZEOF_EP0STO 64
2 #define SIZEOF_EP0_BLOCK sizeof( TOUT_T )
3 
4 #define SIZEOF_EP1STO 32
5 #define SIZEOF_EP1_BLOCK sizeof( DIAL_T )
6 
7 #define SIZEOF_EP2STO 32
8 #define SIZEOF_EP2_BLOCK sizeof( SETUP_T )
9 
10 typedef struct
11 {
12  RKH_EVT_T evt; // base structure
13  int timerno; // parameter 'timerno'
14 } TOUT_T;
15 
16 typedef struct
17 {
18  RKH_EVT_T evt; // base structure
19  char dial[ MAX_SIZE_DIAL ]; // parameter 'dial'
20  int qty; // parameter 'qty'
21 } DIAL_T;
22 
23 typedef struct
24 {
25  RKH_EVT_T evt; // base structure
26  int volume; // parameter 'volume'
27  int baud_rate; // parameter 'baud_rate'
28  char name[ MAX_SIZE_NAME ]; // parameter 'name'
29  int iloop; // parameter 'iloop'
30 } SETUP_T;
31 
32 // declares the storage memory of event pool
33 static rui8_t ep0sto[ SIZEOF_EP0STO ],
34  ep1sto[ SIZEOF_EP1STO ],
35  ep2sto[ SIZEOF_EP2STO ];
36 ...
37 rkh_fwk_registerEvtPool( ep0sto, SIZEOF_EP0STO, SIZEOF_EP0_BLOCK );
38 rkh_fwk_registerEvtPool( ep1sto, SIZEOF_EP1STO, SIZEOF_EP1_BLOCK );
39 rkh_fwk_registerEvtPool( ep2sto, SIZEOF_EP2STO, SIZEOF_EP2_BLOCK );
40 ...
RKH_EVT_T* rkh_fwk_ae ( RKH_ES_T  esize,
RKH_SIG_T  e,
const void *const  sender 
)

Allocates an event from the previously created event pool.

Parameters
[in]esizesize of event [in bytes].
[in]eevent signal.
[in]senderpointer to the actor that request a memory block. It is not necessarily a pointer to an active object. In fact, if RKH_ALLOC_EVT() is called from an interrupt or other context, it can create a unique object just to unambiguously identify the publisher of the event.
Note
This function is internal to RKH and the user application should not call it. Instead, use RKH_ALLOC_EVT() macro.
See also
rkh_put_fifo(), rkh_put_lifo(), rkh_alloc_event(), rkh_set_static_event() and rkh_fwk_gc().
void rkh_fwk_gc ( RKH_EVT_T e,
const void *const  sender 
)

Recycle a dynamic event.

Parameters
[in]eEvent signal.
[in]senderPointer to the actor that request a memory block. It is not necessarily a pointer to an active object. In fact, if RKH_FWK_GC() is called from an interrupt or other context, it can create a unique object just to unambiguously identify the publisher of the event.
void rkh_fwk_reserve ( RKH_EVT_T e)

Reserve the dynamic event to be recycled.

Parameters
[in]eevent signal.