PIC24 Support Libraries
esos_ecan.h
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2013 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
3  * All rights reserved.
4  * (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
5  * (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
6  * (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
7  *
8  * Permission to use, copy, modify, and distribute this software and its
9  * documentation for any purpose, without fee, and without written agreement is
10  * hereby granted, provided that the above copyright notice, the following
11  * two paragraphs and the authors appear in all copies of this software.
12  *
13  * IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
14  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
15  * OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
16  * HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
17  *
18  * THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
19  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
20  * AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
23  *
24  * Please maintain this header in its entirety when copying/modifying
25  * these files.
26  *
27  *
28  */
29 
30  /**
31  * \addtogroup ESOS_Task_ECAN_Service
32  * @{
33  */
34 
35  /** \file
36  * This file contains macros, prototypes, and definitions for
37  * ECAN services for ESOS tasks.
38  */
39 
40 #ifndef ESOS_ECAN_H
41 #define ESOS_ECAN_H
42 
43 /* I N C L U D E S **********************************************************/
44 #include "esos.h"
45 
46 /* D E F I N E S ************************************************************/
47 #define MAX_CANFACTORY_CLIENTS 32
48 #define DEFAULT_MSG_ID 0x7a0
49 #define DEBUG_MODE ESOS_USER_FLAG_F
50 
51 #define ENABLE_DEBUG_MODE() esos_SetUserFlag(DEBUG_MODE)
52 #define DISABLE_DEBUG_MODE() esos_ClearUserFlag(DEBUG_MODE)
53 #define CHECK_DEBUG_MODE_ENABLED() esos_IsUserFlagSet(DEBUG_MODE)
54 
55 #define TRUE 1
56 #define FALSE 0
57 
58 /* S T R U C T U R E S ******************************************************/
59 typedef enum {
60  MASKCONTROL_FIELD_NONZERO,
61  MASKCONTROL_EQUAL
62 } maskcontrol_t;
63 
64 typedef struct {
65  uint16_t u16_canID;
66  uint16_t u16_idMask;
67  maskcontrol_t m_idMaskControl;
68  uint8_t (*pf_task) (ESOS_TASK_HANDLE pst_Task);
69  //uint8_t(*pfn) (struct stTask *pst_Task);
70 } client_t;
71 
72 /* P U B L I C P R O T O T Y P E S *****************************************/
73 /**
74  * esos_ecan_send():
75  *
76  * Send a message using the CANFactory user task.
77  *
78  * u16_can_id: CAN ID to be attached to the message. This should follow the
79  * assumed convention of your system. For embedded systems at
80  * MSU, this should be populated with the appropriate data from
81  * the supplied header file.
82  * pu8_msg: Pointer to the byte that is the beginning of u8_len bytes
83  * of sequential data to be sent.
84  * u8_len: Length of message pointed to by pu8_msg in bytes.
85  */
86 //void esos_ecan_send ( uint16_t u16_can_id, uint8_t *pu8_msg, uint8_t u8_len );
87 
88 #define ESOS_ECAN_SEND(u16_can_id,pu8_msg,u8_len) { \
89  do { \
90  ESOS_TASK_HANDLE __esos_ecan_hTask; \
91  MAILMESSAGE __esos_ecan_mailMsg; \
92  uint8_t __esos_mail_msgBuf[ sizeof( uint16_t ) + 8 * sizeof( uint8_t ) ]; \
93  __esos_ecan_hTask = esos_GetTaskHandle( CANFactory ); \
94  if ( ESOS_TASK_MAILBOX_GOT_AT_LEAST_DATA_BYTES( __esos_ecan_hTask, __MAIL_MSG_HEADER_LEN + sizeof( uint8_t ) * u8_len + sizeof( uint16_t ) ) ) { \
95  *( ( uint16_t* ) &__esos_mail_msgBuf[0] ) = u16_can_id; \
96  memcpy( &__esos_mail_msgBuf[ sizeof( uint16_t ) ], pu8_msg, u8_len ); \
97  ESOS_TASK_MAKE_MSG_AUINT8 ( __esos_ecan_mailMsg, __esos_mail_msgBuf, sizeof( uint8_t ) * u8_len + sizeof( uint16_t ) ); \
98  ESOS_TASK_SEND_MESSAGE( __esos_ecan_hTask, &__esos_ecan_mailMsg ); \
99  } \
100  } while ( 0 ); \
101  }
102 
103 /**
104  * esos_ecan_canfactory_subscribe():
105  *
106  * Enroll a task/mask combination in the CANFactory system.
107  *
108  * pst_Task: ESOS user task to be subscribed in the CANFactory. This is
109  * the task that is responsible for receiving relevant
110  * messages through the ESOS mail system.
111  * u16_can_id: CAN ID of the specified task pointed to by pst_Task.
112  * u16_mask: Mask to be used in accordance to the convention specified
113  * by m_mask_control.
114  * m_mask_control: Can be either value of the enumeration maskcontrol_t as
115  * shown below.
116  * MASKCONTROL_FIELD_NONZERO: u16_mask represents a mask that
117  * covers all message headers to
118  * which pst_Task should listen. If
119  * a message header has a bit
120  * lifted underneath the mask, the
121  * message will be sent to the
122  * pst_Task mailbox.
123  * MASKCONTROL_EQUAL: u16_mask represents a mask that
124  * is the exact message header to
125  * which pst_Task should listen. If
126  * a message header does not match
127  * this mask exactly, it will not
128  * be sent to the pst_Task mailbox.
129  */
130 void esos_ecan_canfactory_subscribe(ESOS_TASK_HANDLE pst_Task, uint16_t u16_can_id, uint16_t u16_mask, maskcontrol_t m_mask_control);
131 
132 /**
133  * esos_ecan_canfactory_unsubscribe():
134  *
135  * Unsubscribe a task/mask combination in the CANFactory system.
136  *
137  * pst_Task: Task handle of the task that should be removed from
138  * CANFactory's data structure.
139  * u16_can_id: CAN ID of the task that should be removed from
140  * CANFactory's data structure.
141  * u16_mask: Mask of the task/mask combination that should be
142  * removed from the CANFactory's data structure.
143  * m_mask_control: Mask control specifier of the task/mask combination that
144  * should be removed from the CANFactory's data structure.
145  */
146 void esos_ecan_canfactory_unsubscribe(uint8_t(*pst_Task) (ESOS_TASK_HANDLE), uint16_t u16_can_id, uint16_t u16_mask, maskcontrol_t m_mask_control);
147 
148 /**
149  * esos_ecan_mask_check():
150  *
151  * Check subscribed messages against recieved messages according to the mask.
152  *
153  * u16_subscribed: ID of the subscribed task.
154  *
155  * u16_recieved: CAN ID of the message recieved.
156  *
157  * u16_mask: Mask ID to be checked against.
158  *
159  */
160 BOOL esos_ecan_mask_check (uint16_t u16_subscribed, uint16_t u16_recieved, uint16_t u16_mask);
161 
162 /**
163  * CANFactory user task:
164  *
165  * Handles the management of the ECAN peripheral so that the API can be used.
166  *
167  * Note: the user should register this task from user_init in addition to using the API in this file.
168  */
169 ESOS_USER_TASK ( CANFactory );
170 
171 #endif /* ESOS_ECAN_H */
void esos_ecan_canfactory_subscribe(ESOS_TASK_HANDLE pst_Task, uint16_t u16_can_id, uint16_t u16_mask, maskcontrol_t m_mask_control)
Definition: esos_ecan.c:187
BOOL esos_ecan_mask_check(uint16_t u16_subscribed, uint16_t u16_recieved, uint16_t u16_mask)
Definition: esos_ecan.c:214
BOOL
Definition: all_generic.h:402
ESOS_USER_TASK(CANFactory)
Definition: esos_ecan.c:70
void esos_ecan_canfactory_unsubscribe(uint8_t(*pst_Task)(ESOS_TASK_HANDLE), uint16_t u16_can_id, uint16_t u16_mask, maskcontrol_t m_mask_control)
Definition: esos_ecan.c:196
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194