ESOS32
ESOSOn32-bitProcessors
esos_hwxxxx_ecan.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 
38 /*** I N C L U D E S *************************************************/
39 #include "esos.h"
40 #include "esos_hwxxx.h"
41 #include "esos_hwxxx_ecan.h"
42 #include "pic24_all.h"
43 #include "pic24_ecan.h"
44 
45 /*** T H E C O D E *************************************************/
46 extern __eds__ ECANMSG __esos_ecan_msgBuf[__ESOS_ECAN_HW_NUM_BUFS] __attribute__((space(dma),aligned(__ESOS_ECAN_HW_NUM_BUFS*16),eds));
47 
48 void __esos_ecan_hw_config_ecan ( void ) {
49  uint8_t u8_i;
50 
51  CHANGE_MODE_ECAN1(ECAN_MODE_CONFIGURE);
52  configBaudECAN1();
53 
54  C1CFG1 = 0x00c1;
55  C1CFG2 = 0x45da;
56 
57  C1FCTRL = ECAN_FIFO_START_AREA_1 | ECAN_DMA_BUF_SIZE_8;
58  configRxFilterECAN1( 0, 0x7a0, 0, 15, 0 );
59  configRxMaskECAN1( 0, 0x000, 0, 0 );
60  clrRxFullOvfFlagsECAN1();
61 
62  for ( u8_i = 0; u8_i < 8; u8_i++ ) {
63  if ( u8_i < __ESOS_ECAN_HW_NUM_TX_BUFS ) {
64  configTxRxBufferECAN1( u8_i, ECAN_TX_BUFF, 3 );
65  } else {
66  configTxRxBufferECAN1( u8_i, ECAN_RX_BUFF, 3 );
67  }
68  }
69 
70  __esos_ecan_hw_config_dma_tx();
71  __esos_ecan_hw_config_dma_rx();
72 
73  CONFIG_C1TX_TO_RP(102);
74  RPINR26bits.C1RXR = 101;
75 
76  return;
77 }
78 
79 void __esos_ecan_hw_config_dma_tx ( void ) {
80  DMAPWC = 0;
81  _DMA0IF = 0;
82  DMA0PAD = (unsigned int) &C1TXD;
83  DMA0REQ = DMA_IRQ_ECAN1TX;
84  DMA0STAL = (unsigned int) &__esos_ecan_msgBuf;
85  DMA0STAH = (unsigned int) &__esos_ecan_msgBuf;
86  DMA0CNT = 7;
87  DMA0CON =
88  ( DMA_MODULE_ON |
89  DMA_SIZE_WORD |
90  DMA_DIR_WRITE_PERIPHERAL |
91  DMA_INTERRUPT_FULL |
92  DMA_NULLW_OFF |
93  DMA_AMODE_PERIPHERAL_INDIRECT |
94  DMA_MODE_CONTINUOUS
95  );
96 
97  return;
98 }
99 
100 void __esos_ecan_hw_config_dma_rx ( void ) {
101  _DMA1IF = 0;
102  DMA1PAD = (unsigned int) &C1RXD;
103  DMA1REQ = DMA_IRQ_ECAN1RX;
104  DMA1STAL = (unsigned int) &__esos_ecan_msgBuf;
105  DMA1STAH = (unsigned int) &__esos_ecan_msgBuf;
106  DMA1CNT = 7;
107  DMA1CON =
108  ( DMA_MODULE_ON |
109  DMA_SIZE_WORD |
110  DMA_DIR_READ_PERIPHERAL |
111  DMA_INTERRUPT_FULL |
112  DMA_NULLW_OFF |
113  DMA_AMODE_PERIPHERAL_INDIRECT |
114  DMA_MODE_CONTINUOUS
115  );
116 
117  return;
118 }
119 
120 void __esos_ecan_hw_mark_message_received ( uint16_t u16_rx_buff_id ) {
121  clrRxFullFlagECAN1( u16_rx_buff_id );
122  clrRxFullOvfFlagsECAN1();
123 
124  return;
125 }
126 
127 void __esos_ecan_hw_format_and_send ( ECANMSG *p_temp_Msg, uint16_t u16_can_id, uint8_t u8_payload_len ) {
128  formatStandardDataFrameECAN( p_temp_Msg, u16_can_id, u8_payload_len );
129  __esos_ecan_msgBuf[0] = *p_temp_Msg;
130  startTxECAN1(0);
131 
132  return;
133 }
esos_hwxxx_ecan.h
This file contains routines which define, configure and allow use of Controller Area Network (CAN) se...
esos_hwxxx.h
This is the master include file template for the target hardware (hwxxxx)
esos.h