I've made a board that uses a SAME51 for the canbus peripheral. Now I am trying to adopt some atmel code into an arduino library.
The canbus peripheral seems to be split into two halves, the configuration registers and then some working message ram for storing canbus data, filters, and other related things. Part of the requirement of this memory is that it all resides below 64KB in SRAM.
I understand how to calculate the size of this RAM, and move around inside to extract message data and similar functions from the atmel code, but what I don't know how to do is assign a specific set of memory just for this purpose.
I am thinking I might be able to modify the CMSIS-Atmel or DFU files (same51g19a.h, in my case) so that the SRAM start address is after my chunk of message ram, but that doesn't seem like the proper way to do it, and I'm not sure pointers to the original SRAM base address to use the memory would actually work?
Further, the size of message ram is calculated by defines, like this. So it would be nice if the offset to SRAM could be calculated off however these values are configured. Is this possible?
#define CAN_RAM_BUF_HDR_SIZE (2u) // Length (in 32b words) of CAN Header Packet #define CAN_RAM_FILT_STD_SIZE (1u) // Length (in 32b words) of a standard CAN filter #define CAN_RAM_FILT_EXT_SIZE (2u) // Length (in 32b words) of a extened CAN filter #define CAN_RAM_TX_EVT_SIZE (2u) // Length (in 32b words) of a TX event #define RAM_ARRAY_SIZE_FILT_STD (32u) // Number of standard filters #define RAM_ARRAY_SIZE_FILT_EXT (32u) // Number of extended filters #define RAM_FIFO_SIZE_RX0 (64u) // Number of RX FIFO0 elements #define RAM_FIFO_SIZE_RX1 (32u) // Number of RX FIFO1 elements #define RAM_ARRAY_SIZE_RX (8u) // Number of dedicated RX recieve buffers #define RAM_ARRAY_SIZE_TX (8u) // Number of dedicated TX buffers #define RAM_FIFO_SIZE_TX (16u) // Number of TX FIFO elements #define RAM_TX_EVENT_SIZE (8u) // Number of TX Event elements #define RAM_FIFO_DATA_SIZE_RX0 (8u) // Length of data (in bytes) in RX FIFO0 #define RAM_FIFO_DATA_SIZE_RX1 (8u) // Length of data (in bytes) in RX FIFO1 #define RAM_ARRAY_DATA_SIZE_RX (8u) // Length of data (in bytes) in array buffer #define RAM_ARRAY_DATA_SIZE_TX (8u) // Length of data (in bytes) in array buffer/fifo #define MSG_RAM_SIZE ( \ // Formula for calculating the total CAN Message RAM usage (RAM_ARRAY_SIZE_FILT_STD * CAN_RAM_FILT_STD_SIZE) \ + (RAM_ARRAY_SIZE_FILT_EXT * CAN_RAM_FILT_EXT_SIZE) \ + (RAM_TX_EVENT_SIZE * CAN_RAM_TX_EVT_SIZE) \ + (RAM_FIFO_SIZE_RX0 * (CAN_RAM_BUF_HDR_SIZE + (RAM_FIFO_DATA_SIZE_RX0 / 4))) \ + (RAM_FIFO_SIZE_RX1 * (CAN_RAM_BUF_HDR_SIZE + (RAM_FIFO_DATA_SIZE_RX1 / 4))) \ + (RAM_ARRAY_SIZE_RX * (CAN_RAM_BUF_HDR_SIZE + (RAM_ARRAY_DATA_SIZE_RX / 4))) \ + (RAM_ARRAY_SIZE_TX * (CAN_RAM_BUF_HDR_SIZE + (RAM_ARRAY_DATA_SIZE_TX / 4))) \ + (RAM_FIFO_SIZE_TX * (CAN_RAM_BUF_HDR_SIZE + (RAM_ARRAY_DATA_SIZE_TX / 4))) )