Lines Matching refs:can
16 #define CAN_LOCK(can) rt_mutex_take(&(can->lock), RT_WAITING_FOREVER) argument
17 #define CAN_UNLOCK(can) rt_mutex_release(&(can->lock)) argument
22 struct rt_can_device *can; in rt_can_init() local
25 can = (struct rt_can_device *)dev; in rt_can_init()
28 can->can_rx = RT_NULL; in rt_can_init()
29 can->can_tx = RT_NULL; in rt_can_init()
31 can->hdr = RT_NULL; in rt_can_init()
35 if (can->ops->configure) in rt_can_init()
36 result = can->ops->configure(can, &can->config); in rt_can_init()
46 rt_inline rt_ssize_t _can_int_rx(struct rt_can_device *can, struct rt_can_msg *data, rt_ssize_t msg… in _can_int_rx() argument
50 RT_ASSERT(can != RT_NULL); in _can_int_rx()
53 rx_fifo = (struct rt_can_rx_fifo *) can->can_rx; in _can_int_rx()
70 … if (hdr >= 0 && can->hdr && hdr < can->config.maxhdr && !rt_list_isempty(&can->hdr[hdr].list)) in _can_int_rx()
72 listmsg = rt_list_entry(can->hdr[hdr].list.next, struct rt_can_msg_list, hdrlist); in _can_int_rx()
75 if (can->hdr[hdr].msgs) in _can_int_rx()
77 can->hdr[hdr].msgs--; in _can_int_rx()
114 RT_ASSERT(rx_fifo->freenumbers <= can->config.msgboxsz); in _can_int_rx()
130 rt_inline int _can_int_tx(struct rt_can_device *can, const struct rt_can_msg *data, int msgs) in _can_int_tx() argument
135 RT_ASSERT(can != RT_NULL); in _can_int_tx()
138 tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; in _can_int_tx()
158 if (can->ops->sendmsg(can, data, no) != RT_EOK) in _can_int_tx()
168 can->status.sndchange |= 1<<no; in _can_int_tx()
173 can->status.sndchange &= ~ (1<<no); in _can_int_tx()
192 can->status.sndpkg++; in _can_int_tx()
203 can->status.dropedsndpkg++; in _can_int_tx()
212 rt_inline int _can_int_tx_priv(struct rt_can_device *can, const struct rt_can_msg *data, int msgs) in _can_int_tx_priv() argument
219 RT_ASSERT(can != RT_NULL); in _can_int_tx_priv()
222 tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; in _can_int_tx_priv()
228 if (no >= can->config.sndboxnumber) in _can_int_tx_priv()
244 if (can->ops->sendmsg(can, data, no) != RT_EOK) in _can_int_tx_priv()
248 can->status.sndchange |= 1<<no; in _can_int_tx_priv()
251 can->status.sndchange &= ~ (1<<no); in _can_int_tx_priv()
259 can->status.sndpkg++; in _can_int_tx_priv()
268 can->status.dropedsndpkg++; in _can_int_tx_priv()
279 struct rt_can_device *can; in rt_can_open() local
282 can = (struct rt_can_device *)dev; in rt_can_open()
284 CAN_LOCK(can); in rt_can_open()
288 if (can->can_rx == RT_NULL) in rt_can_open()
296 can->config.msgboxsz * sizeof(struct rt_can_msg_list)); in rt_can_open()
300 rt_memset(rx_fifo->buffer, 0, can->config.msgboxsz * sizeof(struct rt_can_msg_list)); in rt_can_open()
303 rx_fifo->freenumbers = can->config.msgboxsz; in rt_can_open()
304 for (i = 0; i < can->config.msgboxsz; i++) in rt_can_open()
312 can->can_rx = rx_fifo; in rt_can_open()
316 can->ops->control(can, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_RX); in rt_can_open()
320 if (can->can_tx == RT_NULL) in rt_can_open()
328 can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); in rt_can_open()
333 can->config.sndboxnumber * sizeof(struct rt_can_sndbxinx_list)); in rt_can_open()
335 for (i = 0; i < can->config.sndboxnumber; i++) in rt_can_open()
343 rt_sem_init(&(tx_fifo->sem), tmpname, can->config.sndboxnumber, RT_IPC_FLAG_FIFO); in rt_can_open()
344 can->can_tx = tx_fifo; in rt_can_open()
348 can->ops->control(can, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_FLAG_INT_TX); in rt_can_open()
352 can->ops->control(can, RT_DEVICE_CTRL_SET_INT, (void *)RT_DEVICE_CAN_INT_ERR); in rt_can_open()
355 if (can->hdr == RT_NULL) in rt_can_open()
360 phdr = (struct rt_can_hdr *) rt_malloc(can->config.maxhdr * sizeof(struct rt_can_hdr)); in rt_can_open()
362 rt_memset(phdr, 0, can->config.maxhdr * sizeof(struct rt_can_hdr)); in rt_can_open()
363 for (i = 0; i < can->config.maxhdr; i++) in rt_can_open()
368 can->hdr = phdr; in rt_can_open()
372 if (!can->timerinitflag) in rt_can_open()
374 can->timerinitflag = 1; in rt_can_open()
376 rt_timer_start(&can->timer); in rt_can_open()
379 CAN_UNLOCK(can); in rt_can_open()
386 struct rt_can_device *can; in rt_can_close() local
389 can = (struct rt_can_device *)dev; in rt_can_close()
391 CAN_LOCK(can); in rt_can_close()
396 CAN_UNLOCK(can); in rt_can_close()
400 if (can->timerinitflag) in rt_can_close()
402 can->timerinitflag = 0; in rt_can_close()
404 rt_timer_stop(&can->timer); in rt_can_close()
407 can->status_indicate.ind = RT_NULL; in rt_can_close()
408 can->status_indicate.args = RT_NULL; in rt_can_close()
411 if (can->hdr != RT_NULL) in rt_can_close()
413 rt_free(can->hdr); in rt_can_close()
414 can->hdr = RT_NULL; in rt_can_close()
423 can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX); in rt_can_close()
425 rx_fifo = (struct rt_can_rx_fifo *)can->can_rx; in rt_can_close()
430 can->can_rx = RT_NULL; in rt_can_close()
438 can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_TX); in rt_can_close()
440 tx_fifo = (struct rt_can_tx_fifo *)can->can_tx; in rt_can_close()
446 can->can_tx = RT_NULL; in rt_can_close()
449 can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_CAN_INT_ERR); in rt_can_close()
450 can->ops->control(can, RT_CAN_CMD_START, RT_FALSE); in rt_can_close()
451 CAN_UNLOCK(can); in rt_can_close()
461 struct rt_can_device *can; in rt_can_read() local
466 can = (struct rt_can_device *)dev; in rt_can_read()
470 return _can_int_rx(can, buffer, size); in rt_can_read()
481 struct rt_can_device *can; in rt_can_write() local
486 can = (struct rt_can_device *)dev; in rt_can_write()
490 if (can->config.privmode) in rt_can_write()
492 return _can_int_tx_priv(can, buffer, size); in rt_can_write()
496 return _can_int_tx(can, buffer, size); in rt_can_write()
506 struct rt_can_device *can; in rt_can_control() local
511 can = (struct rt_can_device *)dev; in rt_can_control()
527 res = can->ops->configure(can, (struct can_configure *)args); in rt_can_control()
532 if ((rt_uint32_t)(rt_ubase_t)args != can->config.privmode) in rt_can_control()
538 res = can->ops->control(can, cmd, args); in rt_can_control()
540 tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; in rt_can_control()
541 if (can->config.privmode) in rt_can_control()
543 for (i = 0; i < can->config.sndboxnumber; i++) in rt_can_control()
560 for (i = 0; i < can->config.sndboxnumber; i++) in rt_can_control()
574 can->status_indicate.ind = ((rt_can_status_ind_type_t)args)->ind; in rt_can_control()
575 can->status_indicate.args = ((rt_can_status_ind_type_t)args)->args; in rt_can_control()
580 res = can->ops->control(can, cmd, args); in rt_can_control()
581 if (res != RT_EOK || can->hdr == RT_NULL) in rt_can_control()
599 if (pitem->hdr_bank >= can->config.maxhdr || pitem->hdr_bank < 0) in rt_can_control()
607 if (!can->hdr[pitem->hdr_bank].connected) in rt_can_control()
610 rt_memcpy(&can->hdr[pitem->hdr_bank].filter, pitem, in rt_can_control()
613 can->hdr[pitem->hdr_bank].connected = 1; in rt_can_control()
614 can->hdr[pitem->hdr_bank].msgs = 0; in rt_can_control()
615 rt_list_init(&can->hdr[pitem->hdr_bank].list); in rt_can_control()
627 if (pitem->hdr_bank >= can->config.maxhdr || pitem->hdr_bank < 0) in rt_can_control()
635 if (can->hdr[pitem->hdr_bank].connected) in rt_can_control()
637 can->hdr[pitem->hdr_bank].connected = 0; in rt_can_control()
638 can->hdr[pitem->hdr_bank].msgs = 0; in rt_can_control()
639 if (!rt_list_isempty(&can->hdr[pitem->hdr_bank].list)) in rt_can_control()
641 rt_list_remove(can->hdr[pitem->hdr_bank].list.next); in rt_can_control()
644 rt_memset(&can->hdr[pitem->hdr_bank].filter, 0, in rt_can_control()
659 can->bus_hook = (rt_can_bus_hook) args; in rt_can_control()
664 if (can->ops->control != RT_NULL) in rt_can_control()
666 res = can->ops->control(can, cmd, args); in rt_can_control()
683 rt_can_t can; in cantimeout() local
685 can = (rt_can_t)arg; in cantimeout()
686 RT_ASSERT(can); in cantimeout()
687 rt_device_control((rt_device_t)can, RT_CAN_CMD_GET_STATUS, (void *)&can->status); in cantimeout()
689 if (can->status_indicate.ind != RT_NULL) in cantimeout()
691 can->status_indicate.ind(can, can->status_indicate.args); in cantimeout()
694 if(can->bus_hook) in cantimeout()
696 can->bus_hook(can); in cantimeout()
699 if (can->timerinitflag == 1) in cantimeout()
701 can->timerinitflag = 0xFF; in cantimeout()
720 rt_err_t rt_hw_can_register(struct rt_can_device *can, in rt_hw_can_register() argument
726 RT_ASSERT(can != RT_NULL); in rt_hw_can_register()
728 device = &(can->parent); in rt_hw_can_register()
734 can->hdr = RT_NULL; in rt_hw_can_register()
736 can->can_rx = RT_NULL; in rt_hw_can_register()
737 can->can_tx = RT_NULL; in rt_hw_can_register()
738 rt_mutex_init(&(can->lock), "can", RT_IPC_FLAG_PRIO); in rt_hw_can_register()
740 can->bus_hook = RT_NULL; in rt_hw_can_register()
753 can->ops = ops; in rt_hw_can_register()
755 can->status_indicate.ind = RT_NULL; in rt_hw_can_register()
756 can->status_indicate.args = RT_NULL; in rt_hw_can_register()
757 rt_memset(&can->status, 0, sizeof(can->status)); in rt_hw_can_register()
761 can->timerinitflag = 0; in rt_hw_can_register()
762 rt_timer_init(&can->timer, in rt_hw_can_register()
765 (void *)can, in rt_hw_can_register()
766 can->config.ticks, in rt_hw_can_register()
773 void rt_hw_can_isr(struct rt_can_device *can, int event) in rt_hw_can_isr() argument
781 can->status.dropedrcvpkg++; in rt_hw_can_isr()
796 rx_fifo = (struct rt_can_rx_fifo *)can->can_rx; in rt_hw_can_isr()
799 RT_ASSERT(can->parent.open_flag & RT_DEVICE_FLAG_INT_RX); in rt_hw_can_isr()
802 ch = can->ops->recvmsg(can, &tmpmsg, no); in rt_hw_can_isr()
807 can->status.rcvpkg++; in rt_hw_can_isr()
808 can->status.rcvchange = 1; in rt_hw_can_isr()
827 can->status.dropedrcvpkg++; in rt_hw_can_isr()
848 if (can->hdr != RT_NULL) in rt_hw_can_isr()
850 RT_ASSERT(hdr < can->config.maxhdr && hdr >= 0); in rt_hw_can_isr()
851 if (can->hdr[hdr].connected) in rt_hw_can_isr()
853 rt_list_insert_before(&can->hdr[hdr].list, &listmsg->hdrlist); in rt_hw_can_isr()
854 listmsg->owner = &can->hdr[hdr]; in rt_hw_can_isr()
855 can->hdr[hdr].msgs++; in rt_hw_can_isr()
865 if (can->hdr != RT_NULL && can->hdr[hdr].connected && can->hdr[hdr].filter.ind) in rt_hw_can_isr()
868 RT_ASSERT(hdr < can->config.maxhdr && hdr >= 0); in rt_hw_can_isr()
871 rx_length = can->hdr[hdr].msgs * sizeof(struct rt_can_msg); in rt_hw_can_isr()
875 can->hdr[hdr].filter.ind(&can->parent, can->hdr[hdr].filter.args, hdr, rx_length); in rt_hw_can_isr()
881 if (can->parent.rx_indicate != RT_NULL) in rt_hw_can_isr()
892 can->parent.rx_indicate(&can->parent, rx_length); in rt_hw_can_isr()
905 tx_fifo = (struct rt_can_tx_fifo *) can->can_tx; in rt_hw_can_isr()
907 if (can->status.sndchange&(1<<no)) in rt_hw_can_isr()
987 MSH_CMD_EXPORT_ALIAS(cmd_canstat, canstat, stat can device status);