[136] | 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 |
|
---|
| 28 | #define MAX_CHAR_IN_MESSAGE 8
|
---|
| 29 |
|
---|
| 30 | class MCP_CAN
|
---|
| 31 | {
|
---|
| 32 | private:
|
---|
| 33 |
|
---|
| 34 | INT8U SPICS;
|
---|
| 35 |
|
---|
| 36 | /*
|
---|
| 37 | * mcp2515 driver function
|
---|
| 38 | */
|
---|
| 39 | // private:
|
---|
| 40 | private:
|
---|
| 41 |
|
---|
| 42 | void mcp2515_reset(void); /* reset mcp2515 */
|
---|
| 43 |
|
---|
| 44 | INT8U mcp2515_readRegister(const INT8U address); /* read mcp2515's register */
|
---|
| 45 |
|
---|
| 46 | void mcp2515_readRegisterS(const INT8U address,
|
---|
| 47 | INT8U values[],
|
---|
| 48 | const INT8U n);
|
---|
| 49 | void mcp2515_setRegister(const INT8U address, /* set mcp2515's register */
|
---|
| 50 | const INT8U value);
|
---|
| 51 |
|
---|
| 52 | void mcp2515_setRegisterS(const INT8U address, /* set mcp2515's registers */
|
---|
| 53 | const INT8U values[],
|
---|
| 54 | const INT8U n);
|
---|
| 55 |
|
---|
| 56 | void mcp2515_initCANBuffers(void);
|
---|
| 57 |
|
---|
| 58 | void mcp2515_modifyRegister(const INT8U address, /* set bit of one register */
|
---|
| 59 | const INT8U mask,
|
---|
| 60 | const INT8U data);
|
---|
| 61 |
|
---|
| 62 | INT8U mcp2515_readStatus(void); /* read mcp2515's Status */
|
---|
| 63 | INT8U mcp2515_setCANCTRL_Mode(const INT8U newmode); /* set mode */
|
---|
| 64 | INT8U mcp2515_configRate(const INT8U canSpeed); /* set boadrate */
|
---|
| 65 | INT8U mcp2515_init(const INT8U canSpeed); /* mcp2515init */
|
---|
| 66 |
|
---|
| 67 | void mcp2515_write_id( const INT8U mcp_addr, /* write can id */
|
---|
| 68 | const INT8U ext,
|
---|
| 69 | const INT32U id );
|
---|
| 70 |
|
---|
| 71 | void mcp2515_read_id( const INT8U mcp_addr, /* read can id */
|
---|
| 72 | INT8U* ext,
|
---|
| 73 | INT32U* id );
|
---|
| 74 |
|
---|
| 75 | void mcp2515_write_canMsg( INT8U txbid, INT32U id, INT8U len, INT8U *pData, INT8U ext, INT8U rtr); /* write can msg */
|
---|
| 76 | void mcp2515_read_canMsg( INT8U rxbid, INT32U *p_id, INT8U *p_len, INT8U *p_buf, INT8U *p_ext, INT8U *p_rtr); /* read can msg */
|
---|
| 77 | void mcp2515_start_transmit(INT8U txbid); /* start transmit */
|
---|
| 78 | INT8U mcp2515_getNextFreeTXBuf(INT8U *txbuf_n); /* get Next free txbuf */
|
---|
| 79 |
|
---|
| 80 | public:
|
---|
| 81 | MCP_CAN(INT8U _CS);
|
---|
| 82 | INT8U begin(INT8U speedset); /* init can */
|
---|
| 83 | INT8U enableInterrupt(INT8U mask);
|
---|
| 84 | INT8U disableInterrupt(INT8U mask);
|
---|
| 85 | INT8U attachInterrupt(uint32_t ulPin, voidFuncPtr callback);
|
---|
| 86 | INT8U init_Mask(INT8U num, INT32U ulData, INT8U ext = 0); /* init Masks */
|
---|
| 87 | INT8U init_Filter(INT8U num, INT32U ulData, INT8U ext = 0); /* init filters */
|
---|
| 88 | INT8U startReceive(INT8U rxbid); /* Start Receive */
|
---|
| 89 | INT8U sendMsg(INT8U txbid, INT32U id, INT8U len, INT8U *p_buf, INT8U ext, INT8U rtr); /* send msg */
|
---|
| 90 | INT8U sendMsg(INT8U txbid, INT32U id, INT8U len, INT8U *p_buf, INT8U ext); /* send msg */
|
---|
| 91 | INT8U sendMsg(INT8U txbid, INT32U id, INT8U len, INT8U *p_buf); /* send msg */
|
---|
| 92 | INT8U readMsg(INT8U rxbid, INT32U *p_id, INT8U *p_len, INT8U *p_buf, INT8U *p_ext, INT8U *p_rtr); /* read msg */
|
---|
| 93 | INT8U readMsg(INT8U rxbid, INT32U *p_id, INT8U *p_len, INT8U *p_buf, INT8U *p_ext); /* read msg */
|
---|
| 94 | INT8U readMsg(INT8U rxbid, INT32U *p_id, INT8U *p_len, INT8U *p_buf); /* read msg */
|
---|
| 95 | INT8U readMsg(INT8U rxbid, INT8U *p_len, INT8U *p_buf); /* read buf with object ID */
|
---|
| 96 | INT8U checkReceive(INT8U rxbid); /* if something received */
|
---|
| 97 | INT8U checkSend(INT8U txbid); /* if something sent */
|
---|
| 98 | INT8U checkError(void); /* if something error */
|
---|
| 99 | };
|
---|
| 100 |
|
---|
| 101 | #endif
|
---|
| 102 | /*********************************************************************************************************
|
---|
| 103 | END FILE
|
---|
| 104 | *********************************************************************************************************/
|
---|