Callback Function Funda

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Callback Function Funda as PDF for free.

More details

  • Words: 775
  • Pages: 5
CALLBACK FUNCTION FUNDA Let’s take an example the SMS messages need to be posted to the UI along with other status messages etc.In this case the Ui task registers three callbacks with the SMS task for receiving the SMS messages, SMS message status and the various events which may be posted from the SMS task at a later time wheneevr it has anything to be sent to the Ui task. UI Task Callbacks are called from the SMS task

Initial registration of the callbacks SMS task

For this the UI task makes a function call inside the ui_init( ) which is the initialization routine for the UI task . Ui_init( ) { //callback function registrion (void) uasms_config_listeners( uiuasms_msg_listener, uiuasms_status_listener, uiuasms_event_listener ); } The callback functions will be called inside the lower layer task in this case the SMS task in order to pass on any information to the UI task . So registration of the callback task is done in the UI task while the actual calling of the callback functions is done in the sms task. //Callback function definitions //this function is called from the SMS task . This function just posts a command to the Ui task using the regular means. – fill the command pointer , get a free buffer on the Ui’s command queue and signal the UI task. Uiuasms_msg_listener ( ) // call back function { //form a command cmd_ptr->sms.data = sms_msg; cmd_ptr->hdr.cmd = UI_SMS_F; cmd_ptr->hdr.task_ptr = NULL;

cmd_ptr->hdr.done_q_ptr = &ui_cmd_free_q; MSG_LOW ("UI cmd %d",cmd_ptr->hdr.cmd,0,0); ui_cmd(cmd_ptr); } ui_cmd( ui_cmd_type *cmd_ptr ) { (void) q_link( cmd_ptr, &cmd_ptr->hdr.link ); /* init link */ q_put( &ui_cmd_q, &cmd_ptr->hdr.link ); /* and queue it */ (void) rex_set_sigs( &ui_tcb, UI_CMD_Q_SIG ); /* signal the UI task */ } How registration of the callback functions is done. The registries of the callback functions is done at the ui_init using the following uasms_config_listeners( ); In this registration function a buffer is acquired from the SMS task’s command queue . The buffer acquired is now populated/ filled up. A signal is now posted to the SMS task then. This completes the operation of function registries. //This function registers the listener functions for receiving messages, statuses and events. uasms_status_e_type uasms_config_listeners ( uasms_message_listener_type message_listener_f, uasms_status_listener_type status_listener_f, uasms_event_listener_type event_listener_f ) { //acquire a free buffer of the SMS task’s command queue cmd_ptr = uasms_get_cmd_buffer(); //fill up the command cmd_ptr->hdr.id = UASMS_CMD_CONF_LISTENERS_F; cmd_ptr->hdr.task_ptr = NULL; /* don't report result */ cmd_ptr->conf_listeners.msg_l = message_listener_f; cmd_ptr->conf_listeners.status_l = status_listener_f; cmd_ptr->conf_listeners.event_l = event_listener_f; // Send it to UASMS task command queue uasms_cmd( cmd_ptr ); } void uasms_cmd( uasms_cmd_type * cmd_ptr )

{ (void) q_link( cmd_ptr, &cmd_ptr->hdr.link ); /* init link */ q_put( & sm.cmd_q, & cmd_ptr->hdr.link ); /* and queue it */ (void) rex_set_sigs( & uasms_tcb, UASMS_CMD_Q_SIG ); /* signal the task */ } How/When the SMS task calls the call back functions MT processing in DMSS struct uasms_db_struct { /* Client info */ struct uasms_client_profile_struct { uasms_message_listener_type message_listener_f; uasms_status_listener_type status_listener_f; uasms_event_listener_type event_listener_f; boolean DTC_auto_disconnect; dword DTC_idle_timeout; // in ms } client_profile; uasms_OTA_message_type OTA_msg; uasms_client_message_type cl_msg; uasms_tl_message_type tl_msg; uasms_event_info_type event_info; } sm = { 0 }; uasms_process_mt_msg_I( ) { if(OTA_format == CDMA) { uasms_process_mt_CDMA( ); } } uasms_process_mt_CDMA( ) { st = uasmsx_decode_CDMA_tl ( OTA_ptr, /* IN */

& sm.tl_msg ,/* OUT & sm.cl_msg.raw_bd /* OUT */ ); if( sm.tl_msg.tl_message_type == UASMS_TL_TYPE_ACK ) { // deliver status to client, using client’s listener function uasms_client_msg_status( );//internally calls the callback status_listener( ) } if( if it a Point to point or a broadcast message) { //deliver message to the client using the client’s listener function sm.client_profile.message_listener_f( tid, & sm.cl_msg ); } } //KEYPAD SCANNING FUNDA Read a keycode from the keypad hs_scan_keypad( ) { // Pass a keycode from the Handset task to the receiver. This involves queueing the keycode on the ring buffer, and signaling the task which registered as the receiver task, by calling hs_key_init(). pass_key_code( ); } pass_key_code( ) { if (hs_key_rcvr_sig) (void) rex_set_sigs( hs_key_rcvr_tcb_ptr, hs_key_rcvr_sig ); } The ui_task registers for some keyad signal using the following function Ui_init( ) { hs_key_init( rex_self(), UI_KEY_SIG ); } void hs_key_init

( rex_tcb_type *task_ptr, rex_sigs_type key_signal

/* Task to signal when keycodes arrive */ /* Signal to send task when keycodes arrive */

) { hs_key_rcvr_tcb_ptr = task_ptr; hs_key_rcvr_sig = key_signal;

/* remember task to signal /* remember signal to send

*/ */

/* If one or more keys are already in the buffer, and the task is properly registered, then send the signal NOW! */ if (hs_key_buffer.wr_idx != hs_key_buffer.rd_idx) /* Buffer NOT Empty */ { if (hs_key_rcvr_sig) /* But Task IS Registered */ { (void) rex_set_sigs( hs_key_rcvr_tcb_ptr, hs_key_rcvr_sig ); } } } /* end of hs_key_init */

Related Documents

Callback Function Funda
November 2019 5
C++ Callback
August 2019 13
Surat Callback
October 2019 14
Callback Malay
June 2020 7
Electricity Funda
May 2020 14