AtMega CAN Library
Well documented CAN library for AtMega processors utilizing the original Atmel driver
can_library.h
Go to the documentation of this file.
1 /*
2  * <copyright>
3  * Copyright (c) 2014: Tuomas Huuki / Proximia, http://proximia.fi/
4  *
5  * This file is free software; you can redistribute it and/or modify
6  * it under the terms of either the GNU General Public License version 2
7  * or the GNU Lesser General Public License version 2.1, both as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * Lesser GNU General Public License for more details.
14  *
15  * You should have received a copy of the (Lesser) GNU General Public License
16  * along with this program. If not, see <?http://www.gnu.org/licenses/>.
17  * </copyright>
18  */
19 
20 /* $Id$ */
21 
46 #ifndef CAN_LIBRARY_AVR_
47 #define CAN_LIBRARY_AVR_
48 
49 #include "can_drv.h"
50 
78 #ifdef BOOTLOADER
79  #include "loaderconfiguration.h"
80 #else
81  #include "canlibraryconfiguration.h"
82  #ifndef _CANLIBRARYCONFIGURATION_H_
83  #error You need to #include the "configuration.h" file to set port and speed options.
84  #endif
85 #endif
86 
87 #define CAN_BUFFEREMPTY -1
88 
97 #ifdef FILTER_CAN_DEBUG
98  #define MTYPESYNCEMER 0x0080
99  #define NODE_ADDRESS_MASK 0x007F
100 #endif
101 
108 typedef struct _canMessage{
109  uint32_t cantime;
110  uint32_t mesid;
111  uint8_t rtr;
112  uint8_t length;
113  uint8_t data[8];
114 } canMessage;
115 
123 #define NB_TX_MOB (NB_MOB - NB_RX_MOB)
124 
125 #if (NB_TX_MOB < 1)
126  #error You will need at least 1 object buffer to be able to transmit messages.
127 #endif
128 #if (NB_MOB > 8)
129  #error This version of canlib does not support more than 8 MOBs.
130 #endif
131 
132 #define FIRST_TX_MOB NB_RX_MOB
133 
145 uint8_t can_init();
146 
152 void can_close();
153 
176 uint8_t can_sendMessage(canMessage *m);
177 
184 int8_t can_hasFreeTxBuffer();
185 
208 int8_t can_getMessage(canMessage *m);
209 
214 uint8_t can_getRxBufferLength();
215 
228 void can_enableTransciever();
229 void can_disableTransciever();
232 #endif //CAN_LIBRARY_AVR_
This file contains the prototypes and the macros of the low level functions (drivers) of: ...
Definition: can_library.h:108
int8_t can_hasFreeTxBuffer()
Check if there are ant free transmitting MOBs.
Definition: can_library.c:68
uint8_t length
Definition: can_library.h:112
void can_close()
Disable driver & hardware.
Definition: can_library.c:153
uint8_t can_sendMessage(canMessage *m)
Sends a can message.
Definition: can_library.c:170
uint8_t can_getRxBufferLength()
Returns the number of messages in the buffer.
Definition: can_library.c:26
uint8_t data[8]
Definition: can_library.h:113
uint8_t can_init()
Initialize the bus and activate hardware.
Definition: can_library.c:91
uint32_t mesid
Definition: can_library.h:110
uint32_t cantime
Definition: can_library.h:109
int8_t can_getMessage(canMessage *m)
Gets a can message from the reception buffer.
Definition: can_library.c:202
uint8_t rtr
Definition: can_library.h:111