Browse Source

update lib/can.*

Signed-off-by: surenyi <surenyi82@163.com>
master
surenyi 5 years ago
parent
commit
a6bc7d268d
  1. 16
      lib/can.c
  2. 23
      lib/can.h

16
lib/can.c

@ -172,12 +172,6 @@ void can_setup(struct canbus *can, int baudrate)
can->setup(can);
__canx_init(can, baudrate);
if (can->fifo == 0) {
CAN_ITConfig(can->base, CAN_IT_FMP0, ENABLE);
} else {
CAN_ITConfig(can->base, CAN_IT_FMP1, ENABLE);
}
}
static int __do_send_data(struct canbus *can, int is_extend, int remote, unsigned char id, const void *data, unsigned char len)
@ -226,11 +220,19 @@ int can_send_remote(struct canbus *can, int is_extend, unsigned int id, const vo
return __do_send_data(can, is_extend, 1, id, data, len);
}
void can_attach_rx(struct canbus *can, void *user, void (*rx)(struct canbus *can, void *user, struct canrx_msg *msg))
void can_set_rx_callback(struct canbus *can, void *user, void (*rx)(struct canbus *can, void *user, struct canrx_msg *msg))
{
NVIC_DisableIRQ(can->irq);
can->user = user;
can->callback = rx;
if (can->fifo == 0) {
CAN_ITConfig(can->base, CAN_IT_FMP0, ENABLE);
} else {
CAN_ITConfig(can->base, CAN_IT_FMP1, ENABLE);
}
NVIC_EnableIRQ(can->irq);
}

23
lib/can.h

@ -18,8 +18,29 @@ int can_set_baudrate(struct canbus *can, unsigned int baudrate);
* return > 0 on success.
*/
int can_send_data(struct canbus *can, int is_extend, unsigned int id, const void *data, unsigned char len);
int can_send_remote(struct canbus *can, int is_extend, unsigned int id, const void *data, unsigned char len);
static inline int can_send_std_data(struct canbus *can, unsigned int id, const void *data, unsigned char len)
{
return can_send_data(can, 0, id, data, len);
}
static inline int can_send_std_remote(struct canbus *can, unsigned int id, const void *data, unsigned char len)
{
return can_send_remote(can, 0, id, data, len);
}
static inline int can_send_extend_data(struct canbus *can, unsigned int id, const void *data, unsigned char len)
{
return can_send_data(can, 1, id, data, len);
}
static inline int can_send_extend_remote(struct canbus *can, unsigned int id, const void *data, unsigned char len)
{
return can_send_remote(can, 1, id, data, len);
}
/*
* set receive rx handler
*
@ -35,7 +56,7 @@ struct canrx_msg {
const void *data;
};
void can_attach_rx(struct canbus *can, void *user, void (*rx)(struct canbus *can, void *user, struct canrx_msg *msg));
void can_set_rx_callback(struct canbus *can, void *user, void (*rx)(struct canbus *can, void *user, struct canrx_msg *msg));
void can_close(struct canbus *can);

Loading…
Cancel
Save