NetBurner 3.5.8
PDF Version
coldfire/cpu/MCF5441X/include/dspi.h
1/*NB_REVISION*/
2
3/*NB_COPYRIGHT*/
4
5/* ===========================================================================
6 * Note to NetBurner developers -- where to document functions:
7 *
8 * The Doxygen documentation for the DSPI functions shared by every
9 * platform lives in the flagship header:
10 * arch/cortex-m7/cpu/MIMXRT11xx/include/dspi.h
11 * Doxygen merges same-name, same-parameter-list functions across the
12 * per-architecture dspi.h files onto one page, so documenting the same
13 * signature in two files duplicates the documentation. In THIS file:
14 * - Shared functions (DSPIInit, DSPIStart, DSPIdone) carry plain comments
15 * (// ...) only. Plain comments are invisible to Doxygen and keep this
16 * header readable for developers with a single-platform tools install.
17 * - Only functions unique to this platform (or with a unique signature)
18 * carry Doxygen comments, tagged with a platform @note.
19 * When adding a new function: if it exists on multiple platforms with the
20 * same signature, put its Doxygen comment in the flagship header and a
21 * plain // comment here; if it is unique to this platform, document it
22 * here with a Doxygen comment and a platform @note.
23 * ======================================================================== */
24
29
74
75#ifndef _DMA_SPI_H_INC
76#define _DMA_SPI_H_INC
77#include <nbrtos.h>
78#include <basictypes.h>
79#include <sim5441x.h>
80
81#ifndef __cplusplus
82#error DSPI driver is a C++ only library
83#endif
84
90#define DSPI_OK (0)
91#define DSPI_BUSY (1)
92#define DSPI_ERROR (2)
94
98#define MCR_MASTER_INIT 0x80000C01
99#define MCR_HALT_BIT 0x00000001
100#define MCR_DIS_TXF 0x00002000
101#define MCR_DIS_RXF 0x00001000
102#define MCR_CLR_FIFOS 0x00000C00
104
108#define CTAR_CLOCK_POLARITY 0x04000000
109#define CTAR_CLOCK_PHASE 0x02000000
110#define CTAR_FRAME_16BIT 0x78000000
111#define CTAR_FRAME_4BIT 0x18000000
113
117#define SR_EOQF_MASK 0x10000000
118#define SR_CLR_FLAGS 0x8A0A0000
120
124#define RSER_EOQF_IRQ_ONLY ~0x8B0B0000
125#define RSER_DMA_IRQ_ONLY 0x03030000
127
131#define PUSHR_CONT_BIT 0x80000000
132#define PUSHR_EOQ_BIT 0x08000000
134
138#define DMA_CH_DSPI_0_RX 0x0C
139#define DMA_CH_DSPI_0_TX 0x0D
140#define DMA_CH_DSPI_1_RX 0x0E
141#define DMA_CH_DSPI_1_TX 0x0F
142#define DMA_CH_DSPI_2_RX 0x1C
143#define DMA_CH_DSPI_2_TX 0x1D
144#define DMA_CH_DSPI_3_RX 0x2C
145#define DMA_CH_DSPI_3_TX 0x2D
147
151#define CR_CLEAR_NON_GRP_PRIO ~0x000300FF
152#define CR_SET_RR_CH_ARB 0x00000004
154
158#define TCD_ATTR_8BIT_TRANS 0x0000
159#define TCD_ATTR_16BIT_TRANS 0x0101
160
161#define TCD_XOFF_0uint8_t 0x0000
162#define TCD_XOFF_1uint8_t 0x0001
163#define TCD_XOFF_2uint8_t 0x0002
164
165#define TCD_XITER_CNT_MASK 0x7FFF
166
167#define TCD_CSR_DONE_BIT 0x0080
168#define TCD_CSR_DISABLE_REQ 0xC008
169#define TCD_CSR_DREQ_INT_MAJOR 0xC00A
171
172#define DEFAULT_DSPI_MODULE 1
173#define DSPI_MODULE_COUNT 4
174
189
205
220
226typedef struct
227{
228 bool enabled;
229 uint8_t byteCount;
232 dspistruct savedDSPI;
233 bool csState;
235
238typedef struct
239{
240 volatile uint8_t *pDSPIRxbuf;
241 volatile uint8_t *pDSPITxbuf;
242 uint8_t BitsPerQueue;
243 uint32_t DSPI_SizeLeft;
244 uint16_t Command_Mask;
247 volatile uint8_t DSPI_INT_STATUS;
248 uint32_t WordsToWrite;
250 volatile BOOL DSPIfinished;
253
254// uint8_t DSPIInit( uint8_t SPIModule, uint32_t Baudrate, uint8_t QueueBitSize, uint8_t CS,
255// uint8_t CSPol, uint8_t ClkPolarity, uint8_t ClkPhase, BOOL DoutHiz, uint8_t QCD, uint8_t DTL );
256
264{
265 uint32_t m_moduleNum;
266 uint32_t m_mcr;
267 uint32_t m_ctar0;
268 uint32_t m_ctar1;
269 bool m_enableDMA;
270 uint16_t m_CommandMask;
271 uint8_t m_BitsPerQueue;
272 OS_SEM *m_finishedSem;
273 uint32_t m_actualBaudrate;
274
275 public:
276 bool m_inProgress;
277
278 static DSPIModule *lastCxts[DSPI_MODULE_COUNT];
279 static dspiDriverStruct driverCxt[DSPI_MODULE_COUNT];
280
294
326 uint32_t baudRateInBps,
327 uint8_t transferSizeInBits = 8,
328 uint8_t peripheralChipSelects = 0x00,
329 uint8_t chipSelectPolarity = 0x0F,
330 uint8_t clockPolarity = 0,
331 uint8_t clockPhase = 1,
332 BOOL doutHiz = TRUE,
333 uint8_t csToClockDelay = 0,
334 uint8_t delayAfterTransfer = 0);
335
364 uint8_t Init(uint32_t baudRateInBps = 2000000,
365 uint8_t transferSizeInBits = 8,
366 uint8_t peripheralChipSelects = 0x00,
367 uint8_t chipSelectPolarity = 0x0F,
368 uint8_t clockPolarity = 0,
369 uint8_t clockPhase = 1,
370 BOOL doutHiz = TRUE,
371 uint8_t csToClockDelay = 0,
372 uint8_t delayAfterTransfer = 0);
373
390 uint8_t Start(uint8_t *transmitBufferPtr,
391 volatile uint8_t *receiveBufferPtr,
392 uint32_t byteCount,
393 int csReturnToInactive = DEASSERT_AFTER_LAST);
394
410 inline uint8_t Tx(uint8_t *transmitBufferPtr, uint32_t byteCount, int csReturnToInactive = DEASSERT_AFTER_LAST)
411 {
412 return Start(transmitBufferPtr, NULL, byteCount, csReturnToInactive);
413 }
414
430 inline uint8_t Rx(uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive = DEASSERT_AFTER_LAST)
431 {
432 return Start(NULL, receiveBufferPtr, byteCount, csReturnToInactive);
433 }
434
441 bool EnableDMA(bool enableDMA = true);
446 inline bool DisableDMA() { return EnableDMA(false); }
447
454 bool RegisterSem(OS_SEM *finishedSem);
459 inline bool ClrSem() { return RegisterSem(NULL); }
464 inline OS_SEM *GetSem() { return m_finishedSem; }
465
471 inline bool Done() { return !m_inProgress; }
472
480 static BOOL Done(uint8_t SPIModule);
481
487 inline uint32_t GetActualBaudrate() { return m_actualBaudrate; }
488
497 inline bool SetCS(uint8_t CS)
498 {
499 OSLockObj lock;
500 if (m_inProgress) { return false; }
501 m_CommandMask = (((m_mcr >> 16) ^ CS) & 0xFF);
502 return true;
503 }
504
540 friend uint8_t DSPIInit(uint8_t SPIModule,
541 uint32_t Baudrate,
542 uint8_t QueueBitSize,
543 uint8_t CS,
544 uint8_t CSPol,
545 uint8_t ClkPolarity,
546 uint8_t ClkPhase,
547 BOOL DoutHiz,
548 uint8_t QCD,
549 uint8_t DTL);
550};
551
552// Initialize a DSPI module.
553// SPIModule: SPI module number, 0 - 1.
554// Baudrate: maximum baud rate requested; the driver uses the highest
555// available rate that does not exceed it (max CPU_CLOCK / 3).
556// QueueBitSize: bits per transfer, 8, 16 or 32. Data buffers must be
557// uint8_t / uint16_t / uint32_t aligned respectively.
558// CS: SPI chip select(s) to use for the transfer.
559// CSPol: chip select inactive level, 0 = low, 1 = high.
560// ClkPolarity: clock inactive level, 0 = low, 1 = high.
561// ClkPhase: 0 = data captured on the leading clock edge and changed on
562// the following edge; 1 = changed leading, captured following.
563// DoutHiz: data output high impedance between transfers.
564// QCD: QDLYR delay from chip select assertion to the start of the
565// DSPI clock (0 = one half DSPI clock).
566// DTL: QDLYR delay following the transfer of each uint16_t in the
567// DSPI queue (0 = 17/(fsys/2)).
568// Returns the DSPI bus state (DSPI_OK, DSPI_BUSY, DSPI_ERROR).
570 uint32_t Baudrate = 2000000,
571 uint8_t QueueBitSize = 8,
572 uint8_t CS = 0x00,
573 uint8_t CSPol = 0x0F,
574 uint8_t ClkPolarity = 0,
575 uint8_t ClkPhase = 1,
576 BOOL DoutHiz = TRUE,
577 uint8_t QCD = 0,
578 uint8_t DTL = 0);
579
580// Start a DSPI transfer. Pass NULL for transmitBufferPtr or
581// receiveBufferPtr to skip that direction. If finishedSem is provided, it
582// is posted when the transfer completes (otherwise poll with DSPIdone()).
583// csReturnToInactive selects when the chip select is deasserted.
584// Returns the DSPI bus state (DSPI_OK or DSPI_BUSY).
585uint8_t DSPIStart(uint8_t SPIModule,
586 puint8_t transmitBufferPtr,
587 volatile uint8_t *receiveBufferPtr,
588 uint32_t byteCount,
589 OS_SEM *finishedSem = NULL,
590 uint8_t enableDMA = TRUE,
591 int csReturnToInactive = DEASSERT_AFTER_LAST);
592
593// Check DSPI transfer status: TRUE = finished, FALSE = still active.
594BOOL DSPIdone(uint8_t SPIModule = DEFAULT_DSPI_MODULE);
595
596// QSPI to DSPITranslation macros
597// Translates QSPI calls to DSPI calls
598
599inline uint8_t QSPIInit(uint32_t baudRateInBps = 2000000,
600 uint8_t transferSizeInBits = 8,
601 uint8_t peripheralChipSelects = 0x0F,
602 uint8_t chipSelectPolarity = 1,
603 uint8_t clockPolarity = 0,
604 uint8_t clockPhase = 1,
605 BOOL doutHiz = TRUE,
606 uint8_t csToClockDelay = 0,
607 uint8_t delayAfterTransfer = 0)
608{
609 return DSPIInit(DEFAULT_DSPI_MODULE, baudRateInBps, transferSizeInBits, peripheralChipSelects, chipSelectPolarity, clockPolarity,
610 clockPhase, doutHiz, csToClockDelay, delayAfterTransfer);
611}
612
613inline uint8_t QSPIStart(puint8_t transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, OS_SEM *finishedSem = NULL)
614{
615 return DSPIStart(DEFAULT_DSPI_MODULE, transmitBufferPtr, receiveBufferPtr, byteCount, finishedSem);
616}
617
618inline BOOL QSPIdone()
619{
620 return DSPIdone();
621}
622
623#endif /* ----- #ifndef _DMA_SPI_H_INC ----- */
624
bool EnableDMA(bool enableDMA=true)
EnableDMA configures whether DMA is allowed for qualifying transactions.
bool Done()
Returns whether the previously started transaction is complete.
Definition coldfire/cpu/MCF5441X/include/dspi.h:471
bool SetCS(uint8_t CS)
Modifies the chip select configuration for the driver context such that only the requested chip selec...
Definition coldfire/cpu/MCF5441X/include/dspi.h:497
DSPIModule(uint8_t SPIModule)
The minimum DSPIModule Constructor. Requires that configuration settings be applied after constructio...
uint8_t Start(uint8_t *transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
Start begins a SPI transaction using the provided buffers.
OS_SEM * GetSem()
Gets a pointer to the registered Semaphore.
Definition coldfire/cpu/MCF5441X/include/dspi.h:464
bool DisableDMA()
DisableDMA disables DMA for all transactions.
Definition coldfire/cpu/MCF5441X/include/dspi.h:446
static BOOL Done(uint8_t SPIModule)
Returns whether the previously started transaction for a given hardware module is complete.
friend uint8_t DSPIInit(uint8_t SPIModule, uint32_t Baudrate, uint8_t QueueBitSize, uint8_t CS, uint8_t CSPol, uint8_t ClkPolarity, uint8_t ClkPhase, BOOL DoutHiz, uint8_t QCD, uint8_t DTL)
Initialize a DSPI module.
bool RegisterSem(OS_SEM *finishedSem)
Registers a semaphore to be posted to upon completion of transactions.
uint8_t Init(uint32_t baudRateInBps=2000000, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0)
DSPIModule Full DSPIModule Constructor. Will initialize all hardware settings.
uint32_t GetActualBaudrate()
Returns the actual bus speed to be used.
Definition coldfire/cpu/MCF5441X/include/dspi.h:487
uint8_t Rx(uint8_t *receiveBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
Rx begins a receive only SPI transaction using the provided buffer. Holds output line low during tran...
Definition coldfire/cpu/MCF5441X/include/dspi.h:430
bool ClrSem()
Clears the semaphore registration.
Definition coldfire/cpu/MCF5441X/include/dspi.h:459
uint8_t Tx(uint8_t *transmitBufferPtr, uint32_t byteCount, int csReturnToInactive=DEASSERT_AFTER_LAST)
Tx begins a transmit only SPI transaction using the provided buffer. Silently discards the received d...
Definition coldfire/cpu/MCF5441X/include/dspi.h:410
DSPIModule(uint8_t SPIModule, uint32_t baudRateInBps, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x00, uint8_t chipSelectPolarity=0x0F, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0)
DSPIModule Full DSPIModule Constructor. Will initialize all hardware settings.
A simple wrapper class that helps use OS locks effectively.
Definition nbrtos.h:2510
SPI Peripheral Module Class.
Definition cortex-m7/cpu/SAME70/include/dspi.h:158
csReturnType
Chip select return types.
Definition coldfire/cpu/MCF5441X/include/dspi.h:183
spiChipSelect
Chip select number.
Definition coldfire/cpu/MCF5441X/include/dspi.h:198
spiChipSelectPolarity
Chip select polarity.
Definition coldfire/cpu/MCF5441X/include/dspi.h:216
uint8_t DSPIInit(uint8_t SPIModule=DEFAULT_DSPI_MODULE, uint32_t Baudrate=2000000, uint8_t QueueBitSize=8, uint8_t CS=0x00, uint8_t CSPol=0x0F, uint8_t ClkPolarity=0, uint8_t ClkPhase=1, BOOL DoutHiz=TRUE, uint8_t QCD=0, uint8_t DTL=0)
uint8_t QSPIInit(uint32_t baudRateInBps=2000000, uint8_t transferSizeInBits=8, uint8_t peripheralChipSelects=0x0F, uint8_t chipSelectPolarity=1, uint8_t clockPolarity=0, uint8_t clockPhase=1, BOOL doutHiz=TRUE, uint8_t csToClockDelay=0, uint8_t delayAfterTransfer=0)
Initialize Queued Serial Peripheral Interface (QSPI).
Definition coldfire/cpu/MCF5441X/include/dspi.h:599
uint8_t QSPIStart(puint8_t transmitBufferPtr, volatile uint8_t *receiveBufferPtr, uint32_t byteCount, OS_SEM *finishedSem=NULL)
Start QSPI Data Transfer.
Definition coldfire/cpu/MCF5441X/include/dspi.h:613
#define DEFAULT_DSPI_MODULE
Definition coldfire/cpu/MCF5441X/include/dspi.h:172
BOOL QSPIdone()
Can be called after QSPIStart(). Returns TRUE when transfer is complete. This is an alternative to us...
Definition coldfire/cpu/MCF5441X/include/dspi.h:618
#define DSPI_MODULE_COUNT
Definition coldfire/cpu/MCF5441X/include/dspi.h:173
@ DEASSERT_EVERY_TRANSFER
The chip select should be deasserted between every transfer within the transaction.
Definition coldfire/cpu/MCF5441X/include/dspi.h:187
@ DEASSERT_AFTER_LAST
Definition coldfire/cpu/MCF5441X/include/dspi.h:185
@ DEASSERT_NEVER
The chip select used for the transaction should remain asserted, even after the transaction is comple...
Definition coldfire/cpu/MCF5441X/include/dspi.h:184
@ CHIP_SELECT_2
Configure bit mask for SPI chip select 2.
Definition coldfire/cpu/MCF5441X/include/dspi.h:201
@ CHIP_SELECT_0
Configure bit mask for SPI chip select 0.
Definition coldfire/cpu/MCF5441X/include/dspi.h:199
@ CHIP_SELECT_1
Configure bit mask for SPI chip select 1.
Definition coldfire/cpu/MCF5441X/include/dspi.h:200
@ CHIP_SELECT_3
Configure bit mask for SPI chip select 3.
Definition coldfire/cpu/MCF5441X/include/dspi.h:202
@ CHIP_SELECT_DISABLED
Configure bit mask to disable chip select.
Definition coldfire/cpu/MCF5441X/include/dspi.h:203
@ CS_ASSERT_HIGH
Bit mask configures all active chip selects as inactive low, active high.
Definition coldfire/cpu/MCF5441X/include/dspi.h:218
@ CS_ASSERT_LOW
Bit mask configures all active chip selects as active low, inactive high.
Definition coldfire/cpu/MCF5441X/include/dspi.h:217
Semaphores are used to control access to shared resources or or to communicate between tasks in a mul...
Definition nbrtos.h:407
DSPI DMA structure.
Definition coldfire/cpu/MCF5441X/include/dspi.h:227
bool enabled
Whether or not the driver is using DMA for the transfer.
Definition coldfire/cpu/MCF5441X/include/dspi.h:228
bool rxPresent
Is a receive buffer present?
Definition coldfire/cpu/MCF5441X/include/dspi.h:230
dspistruct savedDSPI
Definition coldfire/cpu/MCF5441X/include/dspi.h:232
bool txPresent
Is a transmit buffer present?
Definition coldfire/cpu/MCF5441X/include/dspi.h:231
uint8_t byteCount
The bytes transferred per DMA call.
Definition coldfire/cpu/MCF5441X/include/dspi.h:229
bool csState
Definition coldfire/cpu/MCF5441X/include/dspi.h:233
Major variables/configurations used for a DSPI transfer.
Definition coldfire/cpu/MCF5441X/include/dspi.h:239
uint8_t BitsPerQueue
Number of bits per transfer, (value = 8 - 32).
Definition coldfire/cpu/MCF5441X/include/dspi.h:242
uint32_t LastWordsToWrite
The amount from the previous ISR.
Definition coldfire/cpu/MCF5441X/include/dspi.h:249
volatile uint8_t * pDSPIRxbuf
Track memory location where data will be read or written to the peripheral.
Definition coldfire/cpu/MCF5441X/include/dspi.h:240
volatile uint8_t * pDSPITxbuf
Track memory location where data will be read or written to the peripheral.
Definition coldfire/cpu/MCF5441X/include/dspi.h:241
dspiDMAStruct dma
Definition coldfire/cpu/MCF5441X/include/dspi.h:251
OS_SEM * DSPI_Sem
Pointer to an external semaphore provided by DSPIStart().
Definition coldfire/cpu/MCF5441X/include/dspi.h:246
uint32_t DSPI_SizeLeft
Number of bytes left in the transfer.
Definition coldfire/cpu/MCF5441X/include/dspi.h:243
uint16_t Command_Mask
Partial configuration for the queue's command reg.
Definition coldfire/cpu/MCF5441X/include/dspi.h:244
uint32_t WordsToWrite
Number of words to write to the command/TX Queues and Read from RX.
Definition coldfire/cpu/MCF5441X/include/dspi.h:248
volatile BOOL DSPIfinished
Definition coldfire/cpu/MCF5441X/include/dspi.h:250
volatile uint8_t DSPI_INT_STATUS
Status of the spi device.
Definition coldfire/cpu/MCF5441X/include/dspi.h:247
csReturnType csReturnToInactive
Definition coldfire/cpu/MCF5441X/include/dspi.h:245