Go to the documentation of this file.00001 #ifndef _CAN_DEV_H_
00002 #define _CAN_DEV_H_
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068 #include <sys/types.h>
00069 #include <sys/device.h>
00070
00075
00076 #define CAN_IF_2A 0x01
00077 #define CAN_IF_2B 0x02
00078
00079
00080
00081
00082
00083 #define CAN_SPEED_10K 0 ///< 10 kbit/s, max. cable length 5000 m
00084 #define CAN_SPEED_20K 1 ///< 20 kbit/s, max. cable length 2500 m
00085 #define CAN_SPEED_50K 2 ///< 50 kbit/s, max. cable length 1000 m
00086 #define CAN_SPEED_100K 3 ///< 100 kbit/s, max. cable length 600 m
00087 #define CAN_SPEED_125K 4 ///< 125 kbit/s, max. cable length 500 m
00088 #define CAN_SPEED_250K 5 ///< 250 kbit/s, max. cable length 250 m
00089 #define CAN_SPEED_500K 6 ///< 500 kbit/s, max. cable length 100 m
00090 #define CAN_SPEED_800K 7 ///< 800 kbit/s, max. cable length 50 m
00091 #define CAN_SPEED_1M 8 ///< 1 Mbit/s, max. cable length 25 m
00092 #define CAN_SPEED_CUSTOM 255
00093
00094
00100 struct _CANFRAME {
00101 uint32_t id;
00102 uint8_t len;
00103 uint8_t byte[8];
00104 uint8_t ext;
00105 uint8_t rtr;
00106 };
00107
00112 typedef struct _CANFRAME CANFRAME;
00113
00118 struct _CANINFO {
00119 HANDLE volatile can_rx_rdy;
00120 HANDLE volatile can_tx_rdy;
00121 uint32_t can_rx_frames;
00122 uint32_t can_tx_frames;
00123 uint32_t can_interrupts;
00124 uint32_t can_overruns;
00125 uint32_t can_errors;
00126 };
00127
00131 typedef struct _CANINFO CANINFO;
00132
00139 struct ifcan {
00140 uint8_t can_type;
00141 uint32_t can_baudrate;
00142 uint8_t can_acc_mask[4];
00143 uint8_t can_acc_code[4];
00144 uint32_t can_rtimeout;
00146 uint8_t (*can_rxavail) (NUTDEVICE *);
00147 uint8_t (*can_txfree) (NUTDEVICE *);
00148 uint8_t (*can_recv) (NUTDEVICE *, CANFRAME *);
00149 void (*can_send) (NUTDEVICE *, CANFRAME *);
00150 void (*can_set_ac) (NUTDEVICE *, uint8_t*);
00151 void (*can_set_am) (NUTDEVICE *, uint8_t*);
00152 uint8_t (*can_set_baud) (NUTDEVICE *, uint32_t);
00153 };
00154
00158 typedef struct ifcan IFCAN;
00159
00160 uint8_t CAN_SetSpeed(NUTDEVICE *dev, uint32_t baudrate);
00161 void CAN_SetFilter(NUTDEVICE *dev, uint8_t *ac, uint8_t *am);
00162
00163 void CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame);
00164 uint8_t CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame);
00165 uint8_t CAN_TxFree(NUTDEVICE *dev);
00166
00167 uint8_t CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame);
00168 uint8_t CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame);
00169 uint8_t CAN_RxAvail(NUTDEVICE *dev);
00170 void CAN_SetRxTimeout(NUTDEVICE *dev, uint32_t timeout);
00171
00174 #endif