LTlib LaurTec Library
4.0.0 Beta
Open Source C Library for Microchip Microcontrollers based on XC8 Compiler
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
module_CAN.h
Go to the documentation of this file.
1
/*******************************************************************************
2
3
Autore : Mauro Laurenti
4
Versione : 1.2
5
6
Created on Date : 4/11/2007
7
Last update : 15/01/2016
8
9
CopyRight 2006-2015 all rights are reserved
10
11
********************************************************
12
SOFTWARE LICENSE AGREEMENT
13
********************************************************
14
15
The usage of the supplied software imply the acceptance of the following license.
16
17
The software supplied herewith by Mauro Laurenti (the Author) is intended for
18
use solely and exclusively on Microchip PIC Microcontroller (registered mark).
19
The software is owned by the Author, and is protected under applicable
20
copyright laws. All rights are reserved.
21
Any use in violation of the foregoing restrictions may subject the
22
user to criminal sanctions under applicable laws, as well as to civil liability
23
for the breach of the terms and conditions of this license.
24
Commercial use is forbidden without a written acknowledgement with the Author.
25
Personal or educational use is allowed if the application containing the
26
following software doesn't aim to commercial use or monetary earning of any kind.
27
28
THIS SOFTWARE IS PROVIDED IN AN "AS IS" CONDITION. NO WARRANTIES,
29
WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED
30
TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
31
PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. THE AUTHOR SHALL NOT,
32
IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL OR
33
CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
34
35
********************************************************
36
PURPOSES
37
********************************************************
38
39
This library is supposed to be used for CAN bus
40
applications. All the basic functions are included.
41
Standard and Extended messages are supported
42
43
*******************************************************************************/
44
45
#ifndef LTLIB_CAN_MODULE_H
46
#define LTLIB_CAN_MODULE_H
47
48
#ifdef __XC8
49
#include <xc.h>
50
#endif
51
52
//*****************************************
53
// Library Test
54
//*****************************************
55
#include "
LTlib.h
"
56
57
#ifndef CAN_LIBRARY_SUPPORTED
58
#error (LTlib) The MCU you have selected is not supported by module_CAN library.
59
#endif
60
61
62
//*****************************************
63
64
typedef
unsigned
char
BYTE
;
65
66
67
typedef
struct
{
68
unsigned
long
identifier
;
69
BYTE
data[8];
70
BYTE
type
;
//1 = IDE 0=standard
71
BYTE
length
;
// data length
72
BYTE
RTR
;
//Remote flag. 1 it means remote frame
73
74
}
CANmessage
;
75
76
77
//************************************************************************
78
// constants used for CANOperationMode function
79
//************************************************************************
80
81
enum
CAN_OP_MODE
{
82
CAN_OP_MODE_NORMAL
= 0b00000000,
83
CAN_OP_MODE_SLEEP
= 0b00100000,
84
CAN_OP_MODE_LOOP
= 0b01000000,
85
CAN_OP_MODE_LISTEN
= 0b01100000,
86
CAN_OP_MODE_CONFIG
= 0b10000000
87
};
88
89
//************************************************************************
90
// constants used for CANInitialize function
91
//************************************************************************
92
93
enum
CAN_CONFIG_FLAGS
{
94
CAN_CONFIG_DEFAULT
= 0b11111111,
// 11111111
95
96
CAN_CONFIG_PHSEG2_PRG_BIT
= 0b00000001,
97
CAN_CONFIG_PHSEG2_PRG_ON
= 0b11111111,
// XXXXXXX1
98
CAN_CONFIG_PHSEG2_PRG_OFF
= 0b11111110,
// XXXXXXX0
99
100
CAN_CONFIG_LINE_FILTER_BIT
= 0b00000010,
101
CAN_CONFIG_LINE_FILTER_ON
= 0b11111111,
// XXXXXX1X
102
CAN_CONFIG_LINE_FILTER_OFF
= 0b11111101,
// XXXXXX0X
103
104
CAN_CONFIG_SAMPLE_BIT
= 0b00000100,
105
CAN_CONFIG_SAMPLE_ONCE
= 0b11111111,
// XXXXX1XX
106
CAN_CONFIG_SAMPLE_THRICE
= 0b11111011,
// XXXXX0XX
107
108
CAN_CONFIG_MSG_TYPE_BIT
= 0b00001000,
109
CAN_CONFIG_STD_MSG
= 0b11111111,
// XXXX1XXX
110
CAN_CONFIG_XTD_MSG
= 0b11110111,
// XXXX0XXX
111
112
CAN_CONFIG_DBL_BUFFER_BIT
= 0b00010000,
113
CAN_CONFIG_DBL_BUFFER_ON
= 0b11111111,
// XXX1XXXX
114
CAN_CONFIG_DBL_BUFFER_OFF
= 0b11101111,
// XXX0XXXX
115
116
CAN_CONFIG_MSG_BITS
= 0b01100000,
117
CAN_CONFIG_ALL_MSG
= 0b11111111,
// X11XXXXX
118
CAN_CONFIG_VALID_XTD_MSG
= 0b11011111,
// X10XXXXX
119
CAN_CONFIG_VALID_STD_MSG
= 0b10111111,
// X01XXXXX
120
CAN_CONFIG_ALL_VALID_MSG
= 0b10011111
// X00XXXXX
121
};
122
123
124
//************************************************************************
125
// constants used for CAN_send_message function
126
//************************************************************************
127
128
enum
CAN_TX_MSG_FLAGS
{
129
CAN_TX_PRIORITY_MASK
= 0b00000011,
// bit mask
130
CAN_TX_PRIORITY_0
= 0b11111100,
// XXXXXX00
131
CAN_TX_PRIORITY_1
= 0b11111101,
// XXXXXX01
132
CAN_TX_PRIORITY_2
= 0b11111110,
// XXXXXX10
133
CAN_TX_PRIORITY_3
= 0b11111111,
// XXXXXX11
134
135
CAN_TX_FRAME_MASK
= 0b00001000,
// bit mask
136
CAN_TX_STD_FRAME
= 0b11110111,
// XXXX0XXX
137
CAN_TX_XTD_FRAME
= 0b11111111,
// XXXX1XXX
138
139
CAN_TX_RTR_MASK
= 0b01000000,
// bit mask
140
CAN_REMOTE_TX_FRAME
= 0b11111111,
// X1XXXXXX
141
CAN_NORMAL_TX_FRAME
= 0b10111111
// X0XXXXXX
142
};
143
144
//************************************************************************
145
// constants used for MASK function
146
//************************************************************************
147
148
enum
CAN_MASK
{
149
CAN_MASK_B1
= 1,
150
CAN_MASK_B2
= 2,
151
};
152
153
//************************************************************************
154
// constants used for Filter function
155
//************************************************************************
156
157
enum
CAN_FILTER
{
158
CAN_FILTER_B1_F1
,
159
CAN_FILTER_B1_F2
,
160
CAN_FILTER_B2_F1
,
161
CAN_FILTER_B2_F2
,
162
CAN_FILTER_B2_F3
,
163
CAN_FILTER_B2_F4
164
};
165
166
//************************************************************************
167
// constants used for RX errors
168
//************************************************************************
169
170
enum
CAN_RX_ERRORS
{
171
CAN_RX_BUFFER_1_OVFL
= 0b00000001,
172
CAN_RX_BUFFER_2_OVFL
= 0b00000010
173
};
174
175
//************************************************************************
176
// Functions Prototypes
177
//************************************************************************
178
195
void
CAN_open
(
BYTE
propSeg,
BYTE
phaseSeg1,
BYTE
phaseSeg2,
BYTE
SJW,
BYTE
BRP,
enum
CAN_CONFIG_FLAGS
flags);
196
197
206
void
CAN_close
(
void
);
207
208
223
void
CAN_write_message
(
unsigned
long
identifier,
BYTE
*data,
BYTE
dataLength,
enum
CAN_TX_MSG_FLAGS
flags);
224
225
238
unsigned
char
CAN_read_message
(
CANmessage
*msg);
239
240
254
void
CAN_set_mask
(
enum
CAN_MASK
mask_number,
unsigned
long
val,
enum
CAN_CONFIG_FLAGS
type);
255
256
270
void
CAN_set_filter
(
enum
CAN_FILTER
filter_number,
unsigned
long
val,
enum
CAN_CONFIG_FLAGS
type);
271
272
284
void
CAN_operation_mode
(
enum
CAN_OP_MODE
mode);
285
286
295
void
CAN_abort_messages
(
void
);
296
297
307
BYTE
CAN_is_TX_ready
(
void
);
308
309
319
BYTE
CAN_is_RX_ready
(
void
);
320
321
332
BYTE
CAN_is_TX_passive
(
void
);
333
334
345
BYTE
CAN_is_RX_passive
(
void
);
346
347
359
BYTE
CAN_is_TX_warning_ON
(
void
);
360
361
373
BYTE
CAN_is_RX_warning_ON
(
void
);
374
375
384
BYTE
CAN_get_TX_error_count
(
void
);
385
386
395
BYTE
CAN_get_RX_error_count
(
void
);
396
397
408
BYTE
CAN_is_BUS_OFF
(
void
);
409
410
411
#endif
LTlib_v_4.0.0
inc
module_CAN.h
Generated on Sun Feb 21 2016 13:52:59 for LTlib LaurTec Library by
1.8.3.1