PIC24 Support Libraries
app_ecan_receiver.c
1 // .. "Copyright (c) 2008 Robert B. Reese, Bryan A. Jones, J. W. Bruce ("AUTHORS")"
2 // All rights reserved.
3 // (R. Reese, reese_AT_ece.msstate.edu, Mississippi State University)
4 // (B. A. Jones, bjones_AT_ece.msstate.edu, Mississippi State University)
5 // (J. W. Bruce, jwbruce_AT_ece.msstate.edu, Mississippi State University)
6 //
7 // Permission to use, copy, modify, and distribute this software and its
8 // documentation for any purpose, without fee, and without written agreement is
9 // hereby granted, provided that the above copyright notice, the following
10 // two paragraphs and the authors appear in all copies of this software.
11 //
12 // IN NO EVENT SHALL THE "AUTHORS" BE LIABLE TO ANY PARTY FOR
13 // DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
14 // OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE "AUTHORS"
15 // HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16 //
17 // THE "AUTHORS" SPECIFICALLY DISCLAIMS ANY WARRANTIES,
18 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
19 // AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
20 // ON AN "AS IS" BASIS, AND THE "AUTHORS" HAS NO OBLIGATION TO
21 // PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS."
22 //
23 // Please maintain this header in its entirety when copying/modifying
24 // these files.
25 //
26 // *****************************
27 // app_ecan_receiver.c - receive a message using the CANFactory
28 // *****************************
29 // ESOS application program to receive a mail message using the CANFactory task.
30 
31 // Includes
32 #include <string.h>
33 #include "esos.h"
34 #include "esos_pic24.h"
35 #include "esos_ecan.h"
36 
37 // Defines
38 #define TRUE 1
39 #define FALSE 0
40 
41 #define CONFIG_LED1() CONFIG_RF4_AS_DIG_OUTPUT()
42 #define CONFIG_LED2() CONFIG_RB14_AS_DIG_OUTPUT()
43 #define CONFIG_LED3() CONFIG_RB15_AS_DIG_OUTPUT()
44 #define LED1 _LATF4
45 #define LED2 _LATB14
46 #define LED3 _LATB15
47 
48 #define CONFIG_SW1() { CONFIG_RB13_AS_DIG_INPUT(); \
49  ENABLE_RB13_PULLUP(); \
50  DELAY_US( 1 ); \
51  }
52 #define CONFIG_SW2() { CONFIG_RB12_AS_DIG_INPUT(); \
53  ENABLE_RB12_PULLUP(); \
54  DELAY_US( 1 ); \
55  }
56 #define SW1 _RB13
57 #define SW2 _RB12
58 
59 // Prototypes
60 
61 // Globals
62 
63 /************************************************************************
64  * User supplied functions
65  ************************************************************************
66  */
67 
68 /*
69  * An ESOS task to mimic the heartbeat LED found
70  * in the PIC24 support library code used in Chapters 8-13.
71  *
72  * Toggle LED3, wait 250ms, repeat forever.
73  *
74  * \hideinitializer
75  */
76 ESOS_USER_TASK ( heartbeat_LED ) {
78  while (TRUE) {
79  LED3 = !LED3;
80  ESOS_TASK_WAIT_TICKS( 500 );
81  }
82  ESOS_TASK_END();
83 }
84 
85 ESOS_USER_TASK ( ecan_receiver ) {
86  uint8_t buf[8] = {0};
87  uint8_t u8_len;
88  uint16_t u16_can_id;
89 
91 
92  esos_ecan_canfactory_subscribe( __pstSelf, 0x7a0, 0xffff, MASKCONTROL_FIELD_NONZERO );
93 
94  while ( TRUE ) {
95  static MAILMESSAGE msg;
96 
98  ESOS_TASK_GET_NEXT_MESSAGE( &msg );
99  u16_can_id = msg.au16_Contents[0];
100  u8_len = ESOS_GET_PMSG_DATA_LENGTH( ( &msg - sizeof( uint16_t ) ) );
101  memcpy( buf, &msg.au8_Contents[ sizeof( uint16_t ) ], u8_len );
102 
103  LED1 = buf[0];
104  LED2 = buf[1];
105 
106  ESOS_TASK_YIELD();
107  }
108 
109  ESOS_TASK_END();
110 }
111 
112 /****************************************************
113  * user_init()
114  ****************************************************
115  */
116 void user_init ( void ) {
117  __esos_unsafe_PutString( HELLO_MSG );
118 
119  CONFIG_LED1();
120  CONFIG_LED2();
121  CONFIG_LED3();
122  CONFIG_SW1();
123  CONFIG_SW2();
124 
125  esos_RegisterTask( heartbeat_LED );
126  esos_RegisterTask( CANFactory );
127  esos_RegisterTask( ecan_receiver );
128 }
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
ESOS_TASK_HANDLE esos_RegisterTask(uint8_t(*taskname)(ESOS_TASK_HANDLE pstTask))
Definition: esos.c:86
#define ESOS_TASK_WAIT_FOR_MAIL()
Definition: esos_mail.h:150
#define ESOS_TASK_YIELD()
Definition: esos_task.h:590
void user_init(void)
This is the master include file for implementing ESOS on Microchip PIC24 MCUs.
#define ESOS_TASK_WAIT_TICKS(u32_duration)
Definition: esos_task.h:376
#define ESOS_TASK_END()
Definition: esos_task.h:272
#define ESOS_TASK_BEGIN()
Definition: esos_task.h:260
ESOS_USER_TASK(CANFactory)
Definition: esos_ecan.c:70
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194