PSAS/ PicCore/ docs/ can

pic_can.c: CAN Peripheral Routines

Introduction

The PIC has a totally broken - in the sense of almost unuseable - CAN peripheral. It sucks big time. Sort of unbelieviably so.

All of the routines are now priority based. This means that everything uses a priority queue: messages are sent and received by priority, not by the order that their queued. This implies out of order reception and transmission for packets with different priorities.

Call graph:

pc_can_send_message -> push_message_into_queue -> insert_into_tx_queue_list
                                                  pc_log_pc_errors
                       try_aborting_txb0       -> push_txb_into_queue        -> insert_into_tx_queue_list
                                                                                pc_log_pc_error
                                                  reprioritize_buffers
                       try_aborting_txb1       -> push_txb_into_queue        -> insert_into_tx_queue_list
                                                                                pc_log_pc_error
                                                  reprioritize_buffers
                       try_aborting_txb2       -> push_txb_into_queue        -> insert_into_tx_queue_list
                                                                                pc_log_pc_error
                                                  reprioritize_buffers
                       reprioritize_buffers
                       pc_log_pc_errors

pc_can_tx_isr       -> pop_queue_into_txb
                       clear_txb0_abort        -> push_txb_into_queue_int    -> insert_into_tx_queue_list_int
                                                  pop_queue_to_txb           ->  pc_log_pc_errors
                                                  reprioritize_buffers_int
                       clear_txb1_abort        -> push_txb_into_queue_int    -> insert_into_tx_queue_list_int
                                                  pop_queue_to_txb           ->  pc_log_pc_errors
                                                  reprioritize_buffers_int
                       clear_txb2_abort        -> push_txb_into_queue_int    -> insert_into_tx_queue_list_int
                                                  pop_queue_to_txb           ->  pc_log_pc_errors
                                                  reprioritize_buffers_int
                       reprioritize_buffers_int
                       pc_log_pc_errors

Sending Messages

bit pccansendmessage (CanMessaget) // for mainline routines


Discussion: Send a CAN message.
Arguments: Mainline passes it a CanMessage_t (CAN message).
Returns: A bit specifying if it was successfully buffered or queued (but which does not guarantee transmission).

Receiving Messages

bit pccanmessage_available (void) // for mainline routines


Discussion: Tests whether there are any messages in the receive queue.
Arguments: None.
Returns: A bit specifying if there is one or more messages in the receive queue.

CanMessaget pccangetmessage (void) // for mainline routines


Discussion: Gets a CAN message from out of the receive queue.
Arguments: None.
Returns: A CAN message (surpise).

Back