forked from hackingvolvo/SardineCAN-Arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
usbcan.h
100 lines (85 loc) · 3.36 KB
/
usbcan.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
//*****************************************************************************
//
// Title : AVR based USB<>CAN adaptor
// Authors : Michael Wolf
// File Name : 'main.h'
// Date : August 24, 2005
// Version : 1.00
// Target MCU : Atmel AVR ATmega162
// Editor Tabs : 2
//
// NOTE: The authors in no way will be responsible for damages that you
// coul'd be using this code.
// Use this code at your own risk.
//
// This code is distributed under the GNU Public License
// which can be found at http://www.gnu.org/licenses/gpl.txt
//
// Change Log
//
// Version When Who What
// ------- ---- --- ----
// 1.00 24/08/2005 Michael Wolf Initial Release
// 1.01 29/08/2005 Michael Wolf + L, R, W command
// 1.04 22/10/2005 Michael Wolf * changed R command to G
// + added R and r command for remote
// frame support
// 1.05 12/10/2006 Michael Wolf + added definitions for new command 'v'
//
//*****************************************************************************
#ifndef __MAIN_H__
#define __MAIN_H__
#include <Arduino.h>
#define USBCAN_SERIAL "0001" // device serial number
#if !defined(CR)
#define CR 13 // command end tag (ASCII CR)
#endif
#if !defined(ERROR)
#define ERROR 7 // error tag (ASCII BEL)
#endif
#define SET_BITRATE 'S' // set CAN bit rate
#define SET_BTR 's' // set CAN bit rate via
#define OPEN_CAN_CHAN 'O' // open CAN channel
#define CLOSE_CAN_CHAN 'C' // close CAN channel
#define SEND_11BIT_ID 't' // send CAN message with 11bit ID
#define SEND_29BIT_ID 'T' // send CAN message with 29bit ID
#define SEND_R11BIT_ID 'r' // send CAN remote message with 11bit ID
#define SEND_R29BIT_ID 'R' // send CAN remote message with 29bit ID
#define READ_STATUS 'F' // read status flag byte
#define SET_ACR 'M' // set Acceptance Code Register
#define SET_AMR 'm' // set Acceptance Mask Register
#define GET_VERSION 'V' // get hardware and software version
#define GET_SW_VERSION 'v' // get software version only
#define GET_SERIAL 'N' // get device serial number
#define TIME_STAMP 'Z' // toggle time stamp setting
#define READ_ECR 'E' // read Error Capture Register
#define READ_ALCR 'A' // read Arbritation Lost Capture Register
#define READ_REG 'G' // read register conten from SJA1000
#define WRITE_REG 'W' // write register content to SJA1000
#define LISTEN_ONLY 'L' // switch to listen only mode
//#define TIME_STAMP_TICK 1000 // microseconds
/*
define command receive buffer length
minimum length is define as follow:
1 byte : command identifier
8 byte : CAN identifier (for both 11bit and 29bit ID)
1 byte : CAN data length (0-8 byte)
2*8 byte: CAN data (one data byte is send as two ASCII chars)
1 byte : [CR] command end tag
---
27 byte
*/
#define CMD_BUFFER_LENGTH 30
/*
// calculate timer0 overflow value
#define OCR_VALUE ((unsigned char)((unsigned long)(TIME_STAMP_TICK) / (1000000L / (float)((unsigned long)MCU_XTAL / 64L))))
extern volatile uint16_t CAN_flags;
extern volatile uint8_t last_ecr;
extern volatile uint8_t last_alc;
*/
namespace UsbCAN {
void dispatch_CAN_message( tCAN * message );
int handle_host_message( char * cmd_buf );
int init_protocol();
}
#endif // __MAIN_H__