/** * CAN user/application example test * There is no checking done in this example to keep it simple! */ #include #include #define DI_CAN_CFG_NODEID 31U #define DI_CAN_CFG_FRAME_SIZE 32U #define DI_CAN_CFG_MSG_SIZE 16U #define DI_CAN_CFG_MSG_DATA_SIZE 4096U static struct di_can_ctx can_ctx; DI_CAN_FRAME_RX_DECL_ARRAY(can_frames, DI_CAN_CFG_FRAME_SIZE); DI_CAN_MSG_DECL_ARRAY(can_msg_list, DI_CAN_CFG_MSG_SIZE, DI_CAN_CFG_MSG_DATA_SIZE); static di_errno_t can_send_cb(const struct di_can_frame_tx *frame) { printf("[%08x] buf %p, size %zu { ", frame->canid, frame->buf, frame->size); for (size_t n = 0; n < frame->size; n++) printf("%02x ", frame->buf[n]); printf("}\n"); return DNOK; } static di_errno_t can_recv_cb(struct di_can_frame_rx *frame) { (void)frame; return DNOK; } TEST(can_example, init) { DI_CAN_MSG_INIT_ARRAY(&can_ctx, can_msg_list, DI_CAN_CFG_MSG_SIZE, DI_CAN_CFG_MSG_DATA_SIZE); /* Initialize the different can subsystems */ di_can_init(&can_ctx); di_can_frame_init(&can_ctx, can_frames, DI_CAN_CFG_FRAME_SIZE); di_can_msg_init(&can_ctx, can_msg_list, DI_CAN_CFG_MSG_SIZE); can_ctx.send = can_send_cb; can_ctx.recv = can_recv_cb; } TEST(can_example, canid_only) { struct di_can_msg *msg = di_can_msg_alloc(&can_ctx); msg->canid = 0x12345678; msg->size = 0; di_can_send(&msg); } TEST(can_example, very_small) { struct di_can_msg *msg = di_can_msg_alloc(&can_ctx); msg->size = 1; *(uint8_t *)msg->buf->cur = 0x55; di_can_send(&msg); } TEST(can_example, small) { struct di_can_msg *msg = di_can_msg_alloc(&can_ctx); di_can_send(&msg); } TEST(can_example, big) { struct di_can_msg *msg = di_can_msg_alloc(&can_ctx); printf("msg->msg = %p\n", msg->msg); printf("msg->buf->data = %p\n", msg->buf); printf("msg->buf->cur = %p\n", msg->buf->cur); printf("msg->size = %zu\n", msg->size); di_can_send(&msg); } TEST(can_example, recv) { struct di_can_msg *msg = di_can_recv(&can_ctx, DI_CAN_MSGTYPE_RPC); di_can_msg_free(&msg); }