111 lines
1.7 KiB
C
111 lines
1.7 KiB
C
/**
|
|
* can/can.h avr8 can bus interface api
|
|
*
|
|
* (c) 2016 Harald Christian Joachim Wolff
|
|
*
|
|
**/
|
|
#pragma once
|
|
|
|
#include <sys/mutex.h>
|
|
#include <sys/types.h>
|
|
#include <sys/threads.h>
|
|
|
|
#include <util/list.h>
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#define CAN_SPEED_MASK 0x000F
|
|
#define CAN_1MBIT 0x0001
|
|
#define CAN_125KBIT 0x0002
|
|
|
|
typedef union {
|
|
uint8_t bytes[4];
|
|
uint16_t words[2];
|
|
struct {
|
|
uint32_t addr:29;
|
|
uint32_t rtr:1;
|
|
uint32_t reserved:1;
|
|
uint32_t ide:1;
|
|
};
|
|
uint32_t value;
|
|
} canid_t;
|
|
|
|
typedef struct {
|
|
uint8_t tx:1;
|
|
uint8_t error:1;
|
|
uint8_t reserve:2;
|
|
uint8_t len:4;
|
|
} canflags_t;
|
|
|
|
typedef union {
|
|
uint8_t bytes[8];
|
|
uint16_t words[4];
|
|
uint32_t dwords[2];
|
|
uint64_t qword;
|
|
|
|
int8_t i8[8];
|
|
int16_t i16[4];
|
|
int32_t i32[2];
|
|
int64_t i64;
|
|
} canpayload_t;
|
|
|
|
typedef struct {
|
|
|
|
canflags_t flags;
|
|
canid_t id;
|
|
canpayload_t
|
|
payload;
|
|
|
|
uint16_t frame_id;
|
|
|
|
list_t list;
|
|
|
|
thread_t *notify;
|
|
|
|
} canframe_t;
|
|
|
|
typedef struct {
|
|
canid_t id;
|
|
canid_t mask;
|
|
|
|
uint16_t last_seen_frame_id;
|
|
|
|
list_t list;
|
|
} canfilter_t;
|
|
|
|
typedef struct {
|
|
uint32_t setup;
|
|
|
|
int rxpool_next;
|
|
int rxpool_length;
|
|
canframe_t *rxpool;
|
|
|
|
int frame_id_tx,
|
|
frame_id_rx;
|
|
|
|
list_t rx_filters;
|
|
list_t tx_queue;
|
|
|
|
} _can_device_t;
|
|
|
|
int can_init_device(uint32_t config,int rxpool_length);
|
|
uint32_t can_get_device_config(void);
|
|
|
|
int can_send(canframe_t *frame);
|
|
int can_send_simple(canid_t cid,uint8_t len,canpayload_t payload);
|
|
|
|
int can_recv(canfilter_t *filter,canframe_t *frame);
|
|
int can_recv_timeout(canfilter_t *filter,canframe_t *frame,int ms);
|
|
|
|
|
|
/** OLD API **/
|
|
|
|
void can_interface_enable(void) __attribute__((weak));
|
|
void can_interface_disable(void) __attribute__((weak));
|
|
|
|
|
|
|
|
|
|
|