This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

question about the Msg processing

HI.

   I  met   a   question here.   In  the   function  Onboard_SendKeys( uint8 keys , uint8  state) ,  It  defines  a  pointer  which  is  called  the  msgPtr .  The  msgPtr  is  a  type  of  keyChange_t .  It   is  a  struct  which  contains  osal_event_hdr_t  * hdr , uint8 state  and  uint8 keys . You  can get  it  understood  with  the follows.

/****************definiton of   keyChange_t*******************/

typedef struct
{
  osal_event_hdr_t hdr;
  uint8 state; // shift
  uint8 keys;  // keys
} keyChange_t;

/**************definition  of  keyChange_t  ends **************/

OKay, let  us  go on.  The  function  osal_msg_send (registeredKeyTaskID , (uint8 *) msgPtr ) appears .  //  the  msgPtr  is  the  type  of  the keyChange_t .

The process  of  the osal_msg_send , it  invokes  a  new  function  OSAL_MSG_ID .  Then  the problem  that  I  can  not  understand is  just  as  the  follows.

/*********************question begins**************************/

#define OSAL_MSG_NEXT(msg_ptr)      ((osal_msg_hdr_t *) (msg_ptr) - 1)->next

#define OSAL_MSG_Q_INIT(q_ptr)      *(q_ptr) = NULL

#define OSAL_MSG_Q_EMPTY(q_ptr)     (*(q_ptr) == NULL)

#define OSAL_MSG_Q_HEAD(q_ptr)      (*(q_ptr))

#define OSAL_MSG_LEN(msg_ptr)      ((osal_msg_hdr_t *) (msg_ptr) - 1)->len

#define OSAL_MSG_ID(msg_ptr)      ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id

/*******************question ends*****************************/

Qian

How   can  I  change   the  msg_ptr  into  a  type  of  osal_msg_hdr_t  ?    The  msg_ptr  is  the  type of keyChange_t .

/************the  type  of   osal_msg_hdr_t******************/

typedef struct
{
  void   *next;
  uint16 len;
  uint8  dest_id;
} osal_msg_hdr_t;

/***************************************************************/

Would  you  help  me?

I  am   looking  forward  to  your  answer ..

Brs,

 

  • Hi,

     

    First of all i suggest you to investigate a little the osal_msg_allocate(),

    there you'll probably notice that the real allocated memory (message) consists

    of sizeof(osal_msg_hdr_t) bytes + len bytes, thus the msg_ptr is the address 

    pointing on user's message (the one with "len" bytes length) and before this address

    there is an osal_msg_hdr_t structure, so if you'll do some "pointers math", that is msg_ptr-1,

    where "1" stands not for the one byte, but sizeof(osal_msg_hdr_t) bytes, then the new address

    will be pointing on the start of osal_msg_hdr_t structure and then you can reach its fields, like

    fore example ((osal_msg_hdr_t *) (msg_ptr) - 1)->dest_id;

    Is it clear now?

  • HI, I  GOT  IT.

    May  you  a  lucky day .  Thanks  for  your help  along  the road  very  much  !

     

    Brs.

    Qian