35#ifndef MCAN_H_INCLUDED
36#define MCAN_H_INCLUDED
39#include <mcan_internal.h>
83#define DONT_WAIT (0xFFFFFFFF)
124const uint32_t CONF_MCAN_RTR_CHANNELS = 8;
140 uint32_t TxBufferIndex;
142 volatile uint32_t standard_receive_index = 0;
143 volatile uint32_t extended_receive_index = 0;
145 __attribute__((__aligned__(0x0800)))
159 void enable_peripheral_clock();
160 void message_memory_init();
161 void set_configuration(
struct mcan_config *config);
162 void clean_up_pending_tx();
164 void process_isr(
void);
167 void ack_tx(uint32_t index);
171 static inline void dispatch_isr(
int n) {
if(this_Ref[n]) this_Ref[n]->process_isr(); };
172 friend void MCAN0_Handler(
void );
173 friend void MCAN1_Handler(
void );
175 void set_baudrate(uint32_t baudrate);
176 void fd_set_baudrate(uint32_t baudrate);
179 void enable_fd_mode();
180 void disable_fd_mode();
181 void enable_restricted_operation_mode();
182 void disable_restricted_operation_mode();
183 void enable_bus_monitor_mode();
184 void disable_bus_monitor_mode();
185 void enable_sleep_mode();
186 void disable_sleep_mode();
187 void enable_test_mode();
188 void disable_test_mode();
189 enum status_code set_rx_standard_filter(
struct mcan_standard_message_filter_element *sd_filter, uint32_t index);
194 enum status_code set_tx_buffer_element (
struct mcan_tx_element *tx_element, uint32_t index);
195 enum status_code get_tx_event_fifo_element(
struct mcan_tx_event_element *tx_event_element, uint32_t index);
204 inline uint16_t read_timestamp_count_value(){
return hw->MCAN_TSCV;};
213 inline uint16_t read_timeout_count_value(){
return hw->MCAN_TOCV;};
222 inline uint32_t read_error_count(){
return hw->MCAN_ECR;};
231 inline uint32_t read_protocal_status(){
return hw->MCAN_PSR;};
240 inline uint32_t read_high_priority_message_status(){
return hw->MCAN_HPMS;}
253 inline bool rx_get_buffer_status(uint32_t index)
257 if (hw->MCAN_NDAT1 & (1 << index))
267 if (hw->MCAN_NDAT2 & (1 << index))
283 inline void rx_clear_buffer_status(uint32_t index)
287 hw->MCAN_NDAT1 = (1 << index);
291 hw->MCAN_NDAT2 = (1 << index);
303 inline uint32_t rx_get_fifo_status(
bool fifo_number)
307 return hw->MCAN_RXF0S;
310 return hw->MCAN_RXF1S;
321 inline void rx_fifo_acknowledge(
bool fifo_number, uint32_t index)
325 hw->MCAN_RXF0A = MCAN_RXF0A_F0AI(index);
328 hw->MCAN_RXF1A = MCAN_RXF1A_F1AI(index);
339 inline uint32_t tx_get_fifo_queue_status()
341 return hw->MCAN_TXFQS;
351 inline uint32_t tx_get_pending_status()
353 return hw->MCAN_TXBRP;
367 inline enum status_code tx_transfer_request( uint32_t trig_mask)
369 if (hw->MCAN_CCCR & MCAN_CCCR_CCE)
373 hw->MCAN_TXBAR = trig_mask;
388 inline enum status_code tx_cancel_request( uint32_t trig_mask)
390 if (hw->MCAN_CCCR & MCAN_CCCR_CCE)
392 return STATUS_ERR_BUSY;
394 hw->MCAN_TXBCR = trig_mask;
405 inline uint32_t tx_get_transmission_status()
407 return hw->MCAN_TXBTO;
417 inline uint32_t tx_get_cancellation_status()
419 return hw->MCAN_TXBCF;
429 inline uint32_t tx_get_event_fifo_status()
431 return hw->MCAN_TXEFS;
440 inline void tx_event_fifo_acknowledge( uint32_t index)
442 hw->MCAN_TXEFA = MCAN_TXEFA_EFAI(index);
453 hw->MCAN_IE |= source;
464 hw->MCAN_IE &= ~source;
472 inline uint32_t read_interrupt_status()
487 hw->MCAN_IR = source;
633#define CAN_EXTENDED_ID_BIT (0x20000000)
638#define ExtToNbId(id ) (id | CAN_EXTENDED_ID_BIT)
643#define NormToNbId(id) (id & 0x7ff)
650#define IsNBIdExt(id) ( (id & CAN_EXTENDED_ID_BIT)!=0)
655#define NbToExtId(id) (id & 0x1FFFFFFF)
664#define NbToNormId(id) (id & 0x7FF)
808#define CAN_DATA_STORE_SIZE (512)
812struct PrivateCanData;
820 PrivateCanData *pData;
840 uint8_t
CopyData( uint8_t *buffer, uint8_t max_len );
MCAN extended message ID filter element structure.
Definition mcan_internal.h:414
Class to hold received CAN messages.
Definition mcan.h:818
BOOL IsValid()
Check to verify the CanRxMessage is a valid message.
~CanRxMessage()
Destructor.
uint32_t GetId()
Returns the ID of the message.
uint8_t CopyData(uint8_t *buffer, uint8_t max_len)
Copy the data in the message up to max_len.
const uint8_t * GetData()
Returns a pointer to the message data.
BOOL GetNewMessage(OS_FIFO *pFifo, uint32_t timeout=WAIT_FOREVER)
Get a new message from the FIFO. If no message is available, wait up to the timeout for one to be rec...
uint8_t GetLength()
Returns the amount of data stored in the message.
uint16_t GetTimeStamp()
Returns the time stamp of the message.
CanRxMessage(OS_FIFO *pFifo, uint32_t timeout=WAIT_FOREVER)
Build a CanRxMessage from a FIFO.
MCAN configuration structure.
Definition mcan.h:678
uint8_t rx_fifo_1_watermark
Definition mcan.h:727
uint8_t rx_fifo_0_watermark
Definition mcan.h:723
bool tx_queue_mode
Definition mcan.h:729
bool run_in_standby
Definition mcan.h:681
bool protocol_exception_handling
Definition mcan.h:689
bool transmit_pause
Definition mcan.h:685
enum mcan_timeout_mode timeout_mode
Definition mcan.h:701
uint8_t watchdog_configuration
Definition mcan.h:683
uint8_t tx_event_fifo_watermark
Definition mcan.h:731
bool remote_frames_standard_reject
Definition mcan.h:715
void set_config_defaults()
Initializes an MCAN configuration structure to defaults.
Definition mcan.h:768
bool remote_frames_extended_reject
Definition mcan.h:717
bool clock_stop_acknowledge
Definition mcan.h:695
bool clock_stop_request
Definition mcan.h:693
bool automatic_retransmission
Definition mcan.h:691
uint8_t delay_compensation_offset
Definition mcan.h:707
bool rx_fifo_1_overwrite
Definition mcan.h:725
bool timeout_enable
Definition mcan.h:703
uint8_t timestamp_prescaler
Definition mcan.h:697
uint32_t extended_id_mask
Definition mcan.h:719
uint8_t delay_compensation_filter_window_length
Definition mcan.h:709
bool tdc_enable
Definition mcan.h:705
enum mcan_nonmatching_frames_action nonmatching_frames_action_extended
Definition mcan.h:713
uint16_t timeout_period
Definition mcan.h:699
enum mcan_nonmatching_frames_action nonmatching_frames_action_standard
Definition mcan.h:711
bool rx_fifo_0_overwrite
Definition mcan.h:721
bool edge_filtering
Definition mcan.h:687
MCAN Module Class.
Definition mcan.h:137
void init(Mcan *phw, struct mcan_config *config, uint32_t baud)
Initialize a MCAN module.
int RegisterRxFifoRange(uint32_t composite_id_low, uint32_t composite_id_hi, OS_FIFO *pFifo, int channel=-1)
Register a FIFO to receive messages in the specified numeric range of addresses from low to high.
void send_message(uint32_t id_value, uint8_t *data, uint32_t data_length, OS_SEM *pSem=0)
Send a MCAN message.
int MultiCanReplaceRTRMessage(int channel, uint8_t *data, uint8_t len)
Modifies/updates the response for the RTR message registered wotj MultiCanSetRTRMessage().
int MultiCanStopRTRMessage(int channel)
Unregister the RTR message for the specified channel.
int RegisterRxFifoMask(uint32_t composite_id, uint32_t mask, OS_FIFO *pFifo, int channel=-1)
Register a FIFO to receive messages as specified by the address bit mask. A value of 1 = match,...
mcan_module(Mcan *phw, uint32_t baud)
Create a MCAN module instance.
int MultiCanSetRTRMessage(uint32_t id, uint8_t *data, uint8_t len, int channel=-1)
Enable an auto-reply to a CAN RTR message for the specified CAN ID. The reply message is specified by...
int UnRegisterFifo(int channel)
Unregister the FIFO for the specified CAN channel.
int RegisterRxFifo(uint32_t composite_id, OS_FIFO *pFifo, int channel=-1)
Register a FIFO to receive CAN messages.
bool blocking_send_message(uint32_t id_value, uint8_t *data, uint32_t data_length, uint32_t TimeOut)
Send a MCAN message and block until sent.
mcan_timeout_mode
Can time out modes.
Definition mcan_internal.h:546
mcan_nonmatching_frames_action
Can non-matching frames action.
Definition mcan_internal.h:562
mcan_interrupt_source
Can module interrupt source.
Definition mcan_internal.h:579
@ MCAN_TIMEOUT_CONTINUES
Definition mcan_internal.h:548
@ MCAN_NONMATCHING_FRAMES_REJECT
Definition mcan_internal.h:568
const uint32_t CONF_MCAN_RX_EXTENDED_ID_FILTER_NUM
Range: 1..64.
Definition mcan.h:112
const uint32_t CONF_MCAN_TX_EVENT_FIFO
Range: 1..32.
Definition mcan.h:106
const uint32_t CONF_MCAN_RX_FIFO_1_NUM
Range: 1..64.
Definition mcan.h:94
const uint32_t CONF_MCAN_RX_STANDARD_ID_FILTER_NUM
Range: 1..128.
Definition mcan.h:109
const uint32_t CONF_MCAN_TX_FIFO_QUEUE_NUM
Range: 1..16.
Definition mcan.h:103
const uint32_t CONF_MCAN_TX_BUFFER_NUM
Range: 1..16.
Definition mcan.h:100
const uint32_t CONF_MCAN_RX_BUFFER_NUM
Range: 1..64.
Definition mcan.h:97
const uint32_t CONF_MCAN_RX_FIFO_0_NUM
Range: 1..64.
Definition mcan.h:91
#define WAIT_FOREVER
Parameter macro used for timeout parameters that have a 0 value and wait forever.
Definition nbrtos.h:81
#define STATUS_OK
OK, no errors.
Definition mailto.h:28
mcanMODM7AE70 namespace
Definition mcan.h:46
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:407
MCAN receive element structure for buffer.
Definition mcan_internal.h:79
MCAN transfer element structure.
Definition mcan_internal.h:191
MCAN transfer event FIFO element structure.
Definition mcan_internal.h:270