ESOS32
ESOSOn32-bitProcessors
esos_mail.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2019 J. W. Bruce ("AUTHOR(S)")"
3  * All rights reserved.
4  * (J. W. Bruce, jwbruce_AT_tntech.edu, Tennessee Tech University)
5  *
6  * Permission to use, copy, modify, and distribute this software and its
7  * documentation for any purpose, without fee, and without written agreement is
8  * hereby granted, provided that the above copyright notice, the following
9  * two paragraphs and the authors appear in all copies of this software.
10  *
11  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
12  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
13  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
14  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15  *
16  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
17  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
18  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
19  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
20  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
21  *
22  * Please maintain this header in its entirety when copying/modifying
23  * these files.
24  *
25  *
26  */
27 
34 #include "esos.h"
35 #include "esos_mail.h"
36 
37 // ******** G L O B A L S ***************
38 //MAILBOX __astMailbox[MAX_NUM_USER_TASKS];
39 //uint8_t __au8_MBData[MAX_NUM_USER_TASKS][MAX_SIZE_TASK_MAILBOX];
40 uint8_t __u8_esos_mail_routines_dummy_uint8;
41 
42 /****************************************************************
43 ** F U N C T I O N S
44 ****************************************************************/
45 void __esos_InitMailbox(MAILBOX* pst_Mailbox, uint8_t* pau8_ptr) {
46  __esos_CB_Init( pst_Mailbox->pst_CBuffer, pau8_ptr, MAX_SIZE_TASK_MAILBOX);
47 } // endof esos_InitMailbox()
48 
60 void __esos_SendMailMessage(ESOS_TASK_HANDLE pst_RcvrTask, MAILMESSAGE* pst_Msg ) {
61  uint8_t u8_i;
62 
63  // first message btye: flags in upper nibble, payload length in lower
64  u8_i = ((pst_Msg->u8_flags)<<4) + (pst_Msg->u8_DataLength & 0x0F);
65  __esos_CB_WriteUINT8( pst_RcvrTask->pst_Mailbox->pst_CBuffer, u8_i );
66  // second message word: Task ID of sending task
67  __esos_CB_WriteUINT16( pst_RcvrTask->pst_Mailbox->pst_CBuffer, ESOS_GET_PMSG_FROMTASK(pst_Msg) );
68  // Now, timestamp the message with double word
69  __esos_CB_WriteUINT32( pst_RcvrTask->pst_Mailbox->pst_CBuffer, esos_GetSystemTick() );
70  // Now write the data depending on what type and how many
71  if ( ESOS_GET_PMSG_FLAGS(pst_Msg) & ESOS_MAILMESSAGE_UINT8) {
72  for (u8_i=0; u8_i<ESOS_GET_PMSG_DATA_LENGTH(pst_Msg); u8_i++) {
73  __esos_CB_WriteUINT8( pst_RcvrTask->pst_Mailbox->pst_CBuffer, pst_Msg->au8_Contents[u8_i] );
74  } // end for UINT8s
75  } else if ( ESOS_GET_PMSG_FLAGS(pst_Msg) & ESOS_MAILMESSAGE_UINT16) {
76  for (u8_i=0; u8_i<pst_Msg->u8_DataLength; u8_i++) {
77  __esos_CB_WriteUINT16( pst_RcvrTask->pst_Mailbox->pst_CBuffer, pst_Msg->au16_Contents[u8_i] );
78  } // end for UINT16s
79  } else if ( ESOS_GET_PMSG_FLAGS(pst_Msg) & ESOS_MAILMESSAGE_UINT32) {
80  for (u8_i=0; u8_i<pst_Msg->u8_DataLength; u8_i++) {
81  __esos_CB_WriteUINT32( pst_RcvrTask->pst_Mailbox->pst_CBuffer, pst_Msg->au32_Contents[u8_i] );
82  } // end for UINT32s
83  } else {
84  } // end for STRINGs
85 } // endof __esos_SendMailMessage()
86 
98 void __esos_ReadMailMessage(ESOS_TASK_HANDLE pst_Task, MAILMESSAGE* pst_Message ) {
99  uint8_t u8_i;
100  ESOS_TASK_HANDLE pst_From;
101 
102  /* first message btye: flags in upper nibble, payload length in lower */
103  u8_i = __esos_CB_ReadUINT8( pst_Task->pst_Mailbox->pst_CBuffer );
104  pst_Message->u8_flags = u8_i>>4;
105  pst_Message->u8_DataLength = u8_i & 0x0F;
106  /* second message byte: Task ID of sending task */
107  pst_Message->u16_FromTaskID = __esos_CB_ReadUINT16( pst_Task->pst_Mailbox->pst_CBuffer );
108  /* Now, timestamp the message */
109  pst_Message->u32_Postmark = __esos_CB_ReadUINT32( pst_Task->pst_Mailbox->pst_CBuffer );
110  /* Now write the data depending on what type and how many */
111  if ( ESOS_GET_PMSG_FLAGS(pst_Message) & ESOS_MAILMESSAGE_UINT8) {
112  for (u8_i=0; u8_i<ESOS_GET_PMSG_DATA_LENGTH(pst_Message); u8_i++) {
113  pst_Message->au8_Contents[u8_i] = __esos_CB_ReadUINT8( pst_Task->pst_Mailbox->pst_CBuffer );
114  } // end for UINT8s
115  } else if ( ESOS_GET_PMSG_FLAGS(pst_Message) & ESOS_MAILMESSAGE_UINT16) {
116  for (u8_i=0; u8_i<pst_Message->u8_DataLength; u8_i++) {
117  pst_Message->au16_Contents[u8_i] = __esos_CB_ReadUINT16( pst_Task->pst_Mailbox->pst_CBuffer );
118  } // end for UINT16s
119  } else if ( ESOS_GET_PMSG_FLAGS(pst_Message) & ESOS_MAILMESSAGE_UINT32) {
120  for (u8_i=0; u8_i<pst_Message->u8_DataLength; u8_i++) {
121  pst_Message->au32_Contents[u8_i] = __esos_CB_ReadUINT32( pst_Task->pst_Mailbox->pst_CBuffer );
122  } // end for UINT32s
123  } else {
124  } // end strings
125  /* If sending task requests ACK a.k.a. "delivery confirmation, then do it */
126  if ( ESOS_GET_PMSG_FLAGS(pst_Message) & ESOS_MAILMESSAGE_REQUEST_ACK) {
127  pst_From = esos_GetTaskHandleFromID( ESOS_GET_PMSG_FROMTASK(pst_Message) );
128  if (pst_From != NULLPTR) {
129  __ESOS_CLEAR_TASK_MAILNACK_FLAG( pst_From );
130  } // end if ! NULLPTR
131  } //end if
132 } // __esos_ReadMailMessage()
133 
134 
135 
esos_mail.h
esos_GetTaskHandleFromID
ESOS_TASK_HANDLE esos_GetTaskHandleFromID(uint16_t u16_TaskID)
Definition: esos.c:295
__stMAILMESSAGE
Definition: esos_mail.h:80
__esos_SendMailMessage
void __esos_SendMailMessage(ESOS_TASK_HANDLE pst_RcvrTask, MAILMESSAGE *pst_Msg)
Definition: esos_mail.c:60
NULLPTR
#define NULLPTR
Definition: all_generic.h:435
esos_GetSystemTick
#define esos_GetSystemTick()
Definition: esos.h:418
__stMAILBOX
Definition: esos_mail.h:60
ESOS_TASK_HANDLE
__esos_ReadMailMessage
void __esos_ReadMailMessage(ESOS_TASK_HANDLE pst_Task, MAILMESSAGE *pst_Message)
Definition: esos_mail.c:98
esos.h
__esos_CB_WriteUINT8
void __esos_CB_WriteUINT8(CBUFFER *pst_CBuffer, uint8_t u8_x)
Definition: esos_cb.c:95