| 503 | } |
| 504 | |
| 505 | static rt_err_t rt_can_close(struct rt_device *dev) |
| 506 | { |
| 507 | struct rt_can_device *can; |
| 508 | |
| 509 | RT_ASSERT(dev != RT_NULL); |
| 510 | can = (struct rt_can_device *)dev; |
| 511 | |
| 512 | CAN_LOCK(can); |
| 513 | |
| 514 | /* this device has more reference count */ |
| 515 | if (dev->ref_count > 1) |
| 516 | { |
| 517 | CAN_UNLOCK(can); |
| 518 | return RT_EOK; |
| 519 | } |
| 520 | |
| 521 | #ifdef RT_CAN_MALLOC_NB_TX_BUFFER |
| 522 | if (can->nb_tx_rb_pool) |
| 523 | { |
| 524 | rt_free(can->nb_tx_rb_pool); |
| 525 | can->nb_tx_rb_pool = RT_NULL; |
| 526 | } |
| 527 | #endif |
| 528 | |
| 529 | if (can->timerinitflag) |
| 530 | { |
| 531 | can->timerinitflag = 0; |
| 532 | |
| 533 | rt_timer_stop(&can->timer); |
| 534 | } |
| 535 | |
| 536 | can->status_indicate.ind = RT_NULL; |
| 537 | can->status_indicate.args = RT_NULL; |
| 538 | |
| 539 | #ifdef RT_CAN_USING_HDR |
| 540 | if (can->hdr != RT_NULL) |
| 541 | { |
| 542 | rt_free(can->hdr); |
| 543 | can->hdr = RT_NULL; |
| 544 | } |
| 545 | #endif |
| 546 | |
| 547 | if (dev->open_flag & RT_DEVICE_FLAG_INT_RX) |
| 548 | { |
| 549 | struct rt_can_rx_fifo *rx_fifo; |
| 550 | |
| 551 | /* clear can rx interrupt */ |
| 552 | can->ops->control(can, RT_DEVICE_CTRL_CLR_INT, (void *)RT_DEVICE_FLAG_INT_RX); |
| 553 | |
| 554 | rx_fifo = (struct rt_can_rx_fifo *)can->can_rx; |
| 555 | RT_ASSERT(rx_fifo != RT_NULL); |
| 556 | |
| 557 | rt_free(rx_fifo); |
| 558 | dev->open_flag &= ~RT_DEVICE_FLAG_INT_RX; |
| 559 | can->can_rx = RT_NULL; |
| 560 | } |
| 561 | |
| 562 | if (dev->open_flag & RT_DEVICE_FLAG_INT_TX) |
nothing calls this directly
no test coverage detected