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
00050 #include <sys/types.h>
00051 #include <sys/device.h>
00052
00057
00058 #define CAN_IF_2A 0x01
00059 #define CAN_IF_2B 0x02
00060
00061
00062
00063
00064
00065 #define CAN_SPEED_10K 0 ///< 10 kbit/s, max. cable length 5000 m
00066 #define CAN_SPEED_20K 1 ///< 20 kbit/s, max. cable length 2500 m
00067 #define CAN_SPEED_50K 2 ///< 50 kbit/s, max. cable length 1000 m
00068 #define CAN_SPEED_100K 3 ///< 100 kbit/s, max. cable length 600 m
00069 #define CAN_SPEED_125K 4 ///< 125 kbit/s, max. cable length 500 m
00070 #define CAN_SPEED_250K 5 ///< 250 kbit/s, max. cable length 250 m
00071 #define CAN_SPEED_500K 6 ///< 500 kbit/s, max. cable length 100 m
00072 #define CAN_SPEED_800K 7 ///< 800 kbit/s, max. cable length 50 m
00073 #define CAN_SPEED_1M 8 ///< 1 Mbit/s, max. cable length 25 m
00074 #define CAN_SPEED_CUSTOM 255
00075
00076
00082 struct _CANFRAME {
00083 uint32_t id;
00084 uint8_t len;
00085 uint8_t byte[8];
00086 uint8_t ext;
00087 uint8_t rtr;
00088 };
00089
00094 typedef struct _CANFRAME CANFRAME;
00095
00100 struct _CANINFO {
00101 HANDLE volatile can_rx_rdy;
00102 HANDLE volatile can_tx_rdy;
00103 uint32_t can_rx_frames;
00104 uint32_t can_tx_frames;
00105 uint32_t can_interrupts;
00106 uint32_t can_overruns;
00107 uint32_t can_errors;
00108 };
00109
00113 typedef struct _CANINFO CANINFO;
00114
00121 struct ifcan {
00122 uint8_t can_type;
00123 uint32_t can_baudrate;
00124 uint8_t can_acc_mask[4];
00125 uint8_t can_acc_code[4];
00126 uint32_t can_rtimeout;
00128 uint8_t (*can_rxavail) (NUTDEVICE *);
00129 uint8_t (*can_txfree) (NUTDEVICE *);
00130 uint8_t (*can_recv) (NUTDEVICE *, CANFRAME *);
00131 void (*can_send) (NUTDEVICE *, CANFRAME *);
00132 void (*can_set_ac) (NUTDEVICE *, uint8_t*);
00133 void (*can_set_am) (NUTDEVICE *, uint8_t*);
00134 uint8_t (*can_set_baud) (NUTDEVICE *, uint32_t);
00135 };
00136
00140 typedef struct ifcan IFCAN;
00141
00142 uint8_t CAN_SetSpeed(NUTDEVICE *dev, uint32_t baudrate);
00143 void CAN_SetFilter(NUTDEVICE *dev, uint8_t *ac, uint8_t *am);
00144
00145 void CAN_TxFrame(NUTDEVICE *dev, CANFRAME *frame);
00146 uint8_t CAN_TryTxFrame(NUTDEVICE *dev, CANFRAME *frame);
00147 uint8_t CAN_TxFree(NUTDEVICE *dev);
00148
00149 uint8_t CAN_RxFrame(NUTDEVICE *dev, CANFRAME *frame);
00150 uint8_t CAN_TryRxFrame(NUTDEVICE *dev, CANFRAME *frame);
00151 uint8_t CAN_RxAvail(NUTDEVICE *dev);
00152 void CAN_SetRxTimeout(NUTDEVICE *dev, uint32_t timeout);
00153
00156 #endif