PIC24 Support Libraries
app_ecan_sender.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_sender.c - send a message using the CANFactory
28 // *****************************
29 // ESOS application program to send 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_sender ) {
86  uint8_t buf[2];
87 
89 
90  while ( TRUE ) {
91  buf[0] = !SW1;
92  buf[1] = !SW2;
93 
94  LED1 = buf[0];
95  LED2 = buf[1];
96 
97  ESOS_ECAN_SEND( 0x7a0, buf, 2 );
98 
100  }
101 
102  ESOS_TASK_END();
103 }
104 
105 /****************************************************
106  * user_init()
107  ****************************************************
108  */
109 void user_init ( void ) {
110  __esos_unsafe_PutString( HELLO_MSG );
111 
112  CONFIG_LED1();
113  CONFIG_LED2();
114  CONFIG_LED3();
115  CONFIG_SW1();
116  CONFIG_SW2();
117 
118  esos_RegisterTask( heartbeat_LED );
119  esos_RegisterTask( CANFactory );
120  esos_RegisterTask( ecan_sender );
121 }
ESOS_TASK_HANDLE esos_RegisterTask(uint8_t(*taskname)(ESOS_TASK_HANDLE pstTask))
Definition: esos.c:86
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_ECAN_SEND(u16_can_id, pu8_msg, u8_len)
Definition: esos_ecan.h:88
#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