PIC24 Support Libraries
esos_pic24_ecan.c
Go to the documentation of this file.
1 /*
2  * "Copyright (c) 2008 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  * \brief This file contains routines which configure and
37  * use an ECAN interface on the Microchip PIC24 MCUs.
38  */
39 
40 /*** I N C L U D E S *************************************************/
41 #include "esos.h"
42 #include "esos_pic24.h"
43 #include "esos_pic24_ecan.h"
44 #include "pic24_all.h"
45 #include "pic24_ecan.h"
46 
47 /*** T H E C O D E *************************************************/
48 extern __eds__ ECANMSG __esos_ecan_msgBuf[__ESOS_ECAN_HW_NUM_BUFS] __attribute__((space(dma),aligned(__ESOS_ECAN_HW_NUM_BUFS*16),eds));
49 
50 void __esos_ecan_hw_config_ecan ( void ) {
51  uint8_t u8_i;
52 
53  CHANGE_MODE_ECAN1(ECAN_MODE_CONFIGURE);
55 
56  C1CFG1 = 0x00c1;
57  C1CFG2 = 0x45da;
58 
59  C1FCTRL = ECAN_FIFO_START_AREA_1 | ECAN_DMA_BUF_SIZE_8;
60  configRxFilterECAN1( 0, 0x7a0, 0, 15, 0 );
61  configRxMaskECAN1( 0, 0x000, 0, 0 );
63 
64  for ( u8_i = 0; u8_i < 8; u8_i++ ) {
65  if ( u8_i < __ESOS_ECAN_HW_NUM_TX_BUFS ) {
66  configTxRxBufferECAN1( u8_i, ECAN_TX_BUFF, 3 );
67  } else {
68  configTxRxBufferECAN1( u8_i, ECAN_RX_BUFF, 3 );
69  }
70  }
71 
72  __esos_ecan_hw_config_dma_tx();
73  __esos_ecan_hw_config_dma_rx();
74 
75  CONFIG_C1TX_TO_RP(102);
76  RPINR26bits.C1RXR = 101;
77 
78  return;
79 }
80 
81 void __esos_ecan_hw_config_dma_tx ( void ) {
82  DMAPWC = 0;
83  _DMA0IF = 0;
84  DMA0PAD = (unsigned int) &C1TXD;
85  DMA0REQ = DMA_IRQ_ECAN1TX;
86  DMA0STAL = (unsigned int) &__esos_ecan_msgBuf;
87  DMA0STAH = (unsigned int) &__esos_ecan_msgBuf;
88  DMA0CNT = 7;
89  DMA0CON =
90  ( DMA_MODULE_ON |
91  DMA_SIZE_WORD |
92  DMA_DIR_WRITE_PERIPHERAL |
93  DMA_INTERRUPT_FULL |
94  DMA_NULLW_OFF |
95  DMA_AMODE_PERIPHERAL_INDIRECT |
96  DMA_MODE_CONTINUOUS
97  );
98 
99  return;
100 }
101 
102 void __esos_ecan_hw_config_dma_rx ( void ) {
103  _DMA1IF = 0;
104  DMA1PAD = (unsigned int) &C1RXD;
105  DMA1REQ = DMA_IRQ_ECAN1RX;
106  DMA1STAL = (unsigned int) &__esos_ecan_msgBuf;
107  DMA1STAH = (unsigned int) &__esos_ecan_msgBuf;
108  DMA1CNT = 7;
109  DMA1CON =
110  ( DMA_MODULE_ON |
111  DMA_SIZE_WORD |
112  DMA_DIR_READ_PERIPHERAL |
113  DMA_INTERRUPT_FULL |
114  DMA_NULLW_OFF |
115  DMA_AMODE_PERIPHERAL_INDIRECT |
116  DMA_MODE_CONTINUOUS
117  );
118 
119  return;
120 }
121 
122 void __esos_ecan_hw_mark_message_received ( uint16_t u16_rx_buff_id ) {
123  clrRxFullFlagECAN1( u16_rx_buff_id );
125 
126  return;
127 }
128 
129 void __esos_ecan_hw_format_and_send ( ECANMSG *p_temp_Msg, uint16_t u16_can_id, uint8_t u8_payload_len ) {
130  formatStandardDataFrameECAN( p_temp_Msg, u16_can_id, u8_payload_len );
131  __esos_ecan_msgBuf[0] = *p_temp_Msg;
132  startTxECAN1(0);
133 
134  return;
135 }
void clrRxFullOvfFlagsECAN1(void)
Definition: pic24_ecan.c:271
void clrRxFullFlagECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:243
void formatStandardDataFrameECAN(ECANMSG *p_ecanmsg, uint16_t u16_id, uint8_t u8_len)
Definition: pic24_ecan.c:81
void configRxFilterECAN1(uint8_t u8_filtNum, uint32_t u32_id, uint8_t u8_idType, uint8_t u8_bufnum, uint8_t u8_maskReg)
Definition: pic24_ecan.c:393
void configTxRxBufferECAN1(uint8_t u8_bufNum, uint8_t u8_type, uint8_t u8_priority)
Definition: pic24_ecan.c:284
This is the master include file for implementing ESOS on Microchip PIC24 MCUs.
void startTxECAN1(uint8_t u8_bufNum)
Definition: pic24_ecan.c:326
This file contains routines which configure and use an ECAN interface on the Microchip PIC24 MCUs...
#define CONFIG_C1TX_TO_RP(Rxy_RP)
Definition: pic24_ports.h:523
unsigned char uint8_t
An abbreviation for an 8-bit unsigned integer.
Definition: dataXferImpl.h:194
void configBaudECAN1(void)
Definition: pic24_ecan.c:176
void configRxMaskECAN1(uint8_t u8_maskNum, uint32_t u32_idMask, uint8_t u8_idType, uint8_t u8_matchType)
Definition: pic24_ecan.c:451