mergCanBus

- Main Page
- Classes
- Files

- File List

All Classes Functions Typedefs
mcp_can.h
1 /*
2 mcp_can.h
3 2012 Copyright (c) Seeed Technology Inc. All right reserved.
4
5 Author:Loovee
6 Contributor: Cory J. Fowler
7 2014-1-16
8 This library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
12
13 This library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public
19 License along with this library; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-
21 1301 USA
22 */
23 #ifndef _MCP2515_H_
24 #define _MCP2515_H_
25
26 #include "mcp_can_dfs.h"
27 #define MAX_CHAR_IN_MESSAGE 8
28 #define HEADER_SIZE 4
29
30 class MCP_CAN
31 {
32 private:
33
34 INT8U m_nExtFlg; /* identifier xxxID */
35 /* 1 if either extended (the 29 LSB) */
36 /* or standard (the 11 LSB) */
37 INT32U m_nID; /* can id */
38 INT8U m_nDlc; /* data length: */
39 INT8U m_nDta[MAX_CHAR_IN_MESSAGE]; /* data */
40 INT8U m_nRtr; /* rtr */
41 INT8U m_nfilhit;
42 INT8U SPICS;
43 INT8U canHeader[HEADER_SIZE];
44 INT8U _prio;//priority
45 INT8U _minprio;//min priority /*can header*/
46 /*
47 * mcp2515 driver function
48 */
49 // private:
50 private:
51
52 void mcp2515_reset(void); /* reset mcp2515 */
53
54 INT8U mcp2515_readRegister(const INT8U address); /* read mcp2515's register */
55
56 void mcp2515_readRegisterS(const INT8U address,
57 INT8U values[],
58 const INT8U n);
59 void mcp2515_setRegister(const INT8U address, /* set mcp2515's register */
60 const INT8U value);
61
62 void mcp2515_setRegisterS(const INT8U address, /* set mcp2515's registers */
63 const INT8U values[],
64 const INT8U n);
65
66 void mcp2515_initCANBuffers(void);
67
68 void mcp2515_modifyRegister(const INT8U address, /* set bit of one register */
69 const INT8U mask,
70 const INT8U data);
71
72 INT8U mcp2515_readStatus(void); /* read mcp2515's Status */
73 INT8U mcp2515_setCANCTRL_Mode(const INT8U newmode); /* set mode */
74 INT8U mcp2515_configRate(const INT8U canSpeed); /* set boadrate */
75 INT8U mcp2515_init(const INT8U canSpeed); /* mcp2515init */
76
77 void mcp2515_write_id( const INT8U mcp_addr, /* write can id */
78 const INT8U ext,
79 const INT32U id );
80
81 void mcp2515_read_id( const INT8U mcp_addr, /* read can id */
82 INT8U* ext,
83 INT32U* id );
84
85 void mcp2515_write_canMsg( const INT8U buffer_sidh_addr ); /* write can msg */
86 void mcp2515_read_canMsg( const INT8U buffer_sidh_addr); /* read can msg */
87 void mcp2515_start_transmit(const INT8U mcp_addr); /* start transmit */
88 INT8U mcp2515_getNextFreeTXBuf(INT8U *txbuf_n); /* get Next free txbuf */
89 void setRTMBit(); /*set the bit in case need to send a Request Transfer Message */
90 void unsetRTMBit(); /*set the bit in case need to send a Request Transfer Message */
91
92 /*
93 * can operator function
94 */
95
96 INT8U setMsg(INT32U id, INT8U ext, INT8U len, INT8U *pData); /* set message */
97 INT8U clearMsg(); /* clear all message to zero */
98 INT8U readMsg(INT8U buf_num); /* read message */
99 INT8U sendMsg(); /* send message */
100
101 public:
102 MCP_CAN(INT8U _CS);
103 MCP_CAN();
104 void set_cs(INT8U _CS);
105 INT8U begin(INT8U speedset); /* init can */
106 INT8U init_Mask(INT8U num, INT8U ext, INT32U ulData); /* init Masks */
107 INT8U init_Filt(INT8U num, INT8U ext, INT32U ulData); /* init filters */
108 INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U len, INT8U *buf); /* send buf */
109 INT8U readMsgBuf(INT8U *len, INT8U *buf,INT8U buf_num); /* read buf */
110 INT8U checkReceive(); /* if something received */
111 INT8U checkError(); /* if something error */
112 INT32U getCanId(); /* get can id when receive */
113 INT8U sendRTMMessage(INT32U id); /* send the request transfer message */
114 INT8U isRTMMessage(); /* check if received message is a request transfer message */
115 void getCanHeader(INT8U *buf);
116 void setPriority(INT8U prio,INT8U minprio); //set the first 2 bits of can header
117 //set the bits 8 and 7 of header
118
119
120 };
121
122 #endif
123 /*********************************************************************************************************
124 END FILE
125 *********************************************************************************************************/
MCP_CAN
Definition: mcp_can.h:30