-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcan_lib.h
180 lines (160 loc) · 6.24 KB
/
can_lib.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
* can_lib.h
The contents of this file were originally from the CAN Software Library
provided by Atmel. Use of this file is subject to Atmel's End User
License Agreement.
*/
//******************************************************************************
//! @file $RCSfile: can_lib.h,v $
//!
//! Copyright (c) 2007 Atmel.
//!
//! Use of this program is subject to Atmel's End User License Agreement.
//! Please read file license.txt for copyright notice.
//!
//! @brief This file contains the prototypes and the macros of the
//! library of functions of:
//! - CAN (Controller Array Network)
//! - for AT90CAN128/64/32.
//!
//! This file can be parsed by Doxygen for automatic documentation generation.
//! This file has been validated with AVRStudio-413528/WinAVR-20070122.
//!
//! @version $Revision: 3.20 $ $Name: jtellier $
//!
//! @todo
//! @bug
//******************************************************************************
#ifndef _CAN_LIB_H_
#define _CAN_LIB_H_
//_____ I N C L U D E S ________________________________________________________
#include "can_drv.h"
//_____ D E F I N I T I O N S __________________________________________________
// ----------
// @brief This constant is used as return value for "can_cmd" function.
#define CAN_CMD_REFUSED 0xFF
// ----------
// @brief This constant is used as return value for "can_cmd" function.
#define CAN_CMD_ACCEPTED 0x00
// ----------
// @brief This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_COMPLETED 0x00
// ----------
// @brief This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_NOT_COMPLETED 0x01
// ----------
// @brief This constant is used as return value for "can_get_status" function.
#define CAN_STATUS_ERROR 0x02
// ----------
// @brief This enumeration is used to select an action for a specific message
// declared in st_cmd_t structure.
typedef enum {
CMD_NONE,
CMD_TX,
CMD_TX_DATA,
CMD_TX_REMOTE,
CMD_RX,
CMD_RX_DATA,
CMD_RX_REMOTE,
CMD_RX_MASKED,
CMD_RX_DATA_MASKED,
CMD_RX_REMOTE_MASKED,
CMD_REPLY,
CMD_REPLY_MASKED,
CMD_ABORT
} can_cmd_t;
// ----------
// @brief This union defines a CAN identifier and allows to access it in mode
// standard, extended or through a table.
typedef union{
uint32_t ext;
uint16_t std;
uint8_t tab[4];
} can_id_t;
// ----------
// @brief This structure defines some specific information as RTR bit and
// IDE bit
// Modified by John Fritz (jfri2)
typedef struct{
uint8_t rtr; // changed Bool type to uint8_t
uint8_t ide; // changed Bool type to uint8_t
} can_ctrl_t;
// ----------
// @brief This structure allows to define a specific action on CAN network.
// 1) handle: manage by the library.
// 2) cmd : initialize by the application to select the operation.
// 3) id : initialize by the application in transmission
// complete by the library in reception.
// 4) dlc : initialize by the application to give the number of data to
// transmit complete by the library in reception.
// 5) pt_data: pointer on the table which contains the data to send or
// received.
// 6) status: manage by the library.
// 7) ctrl : field ide to signal a extended frame .
typedef struct{
uint8_t handle;
can_cmd_t cmd;
can_id_t id;
uint8_t dlc;
uint8_t* pt_data;
uint8_t status;
can_ctrl_t ctrl;
} st_cmd_t;
//_____ D E C L A R A T I O N S ________________________________________________
//------------------------------------------------------------------------------
// @fn can_init
//!
//! CAN macro initialization. Reset the CAN peripheral, initialize the bit
//! timing, initialize all the registers mapped in SRAM to put MObs in
//! inactive state and enable the CAN macro.
//!
//! @warning The CAN macro will be enable after seen on CAN bus a receceive
//! level as long as of an inter frame (hardware feature).
//!
//! @param Mode (for "can_fixed_baudrate" param not used)
//! ==0: start CAN bit timing evaluation from faster baudrate
//! ==1: start CAN bit timing evaluation with CANBTx registers
//! contents
//!
//! @return Baudrate Status
//! ==0: research of bit timing configuration failed
//! ==1: baudrate performed
//!
extern uint8_t can_init(uint8_t mode);
//------------------------------------------------------------------------------
// @fn can_cmd
//!
//! This function takes a CAN descriptor, analyses the action to do:
//! transmit, receive or abort.
//! This function returns a status (CAN_CMD_ACCEPTED or CAN_CMD_REFUSED) if
//! a MOb for Rx or Tx has been found. If no MOB has been found, the
//! application must be retry at a later date.
//! This function also updates the CAN descriptor status (MOB_PENDING or
//! MOB_NOT_REACHED) if a MOb for Rx or Tx has been found. If aborting
//! is performed, the CAN descriptor status will be set to STATUS_CLEARED.
//!
//! @param st_cmd_t* - Can_descriptor pointer on CAN descriptor structure
//! to select the action to do.
//!
//! @return CAN_CMD_ACCEPTED - command is accepted
//! CAN_CMD_REFUSED - command is refused
//!
extern uint8_t can_cmd (st_cmd_t *);
//------------------------------------------------------------------------------
// @fn can_get_status
//!
//! This function allows to return if the command has been performed or not.
//! In an reception case, all the CAN message is stored in the structure.
//! This function also updates the CAN descriptor status (MOB_TX_COMPLETED,
//! MOB_RX_COMPLETED, MOB_RX_COMPLETED_DLCW or MOB_???_ERROR).
//!
//! @param st_cmd_t* pointer on CAN descriptor structure.
//!
//! @return CAN_STATUS_COMPLETED - Rx or Tx is completed
//! CAN_STATUS_NOT_COMPLETED - Rx or Tx is not completed
//! CAN_STATUS_ERROR - Error in configuration or in the
//! CAN communication
//!
extern uint8_t can_get_status (st_cmd_t *);
//______________________________________________________________________________
#endif // _CAN_LIB_H_