Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
TivaSPI.cxx
Go to the documentation of this file.
1
34#include "TivaSPI.hxx"
35
36#include "inc/hw_memmap.h"
37#include "driverlib/sysctl.h"
38#include "driverlib/rom.h"
39#include "driverlib/rom_map.h"
40#include "driverlib/interrupt.h"
41
44
45TivaSPI::TivaSPI(const char *name, unsigned long base, uint32_t interrupt,
46 ChipSelectMethod cs_assert, ChipSelectMethod cs_deassert,
47 OSMutex *bus_lock,
48 size_t dma_threshold,
49 uint32_t dma_channel_index_tx,
50 uint32_t dma_channel_index_rx)
51 : SPI(name, cs_assert, cs_deassert, bus_lock)
52 , base_(base)
53 , interrupt_(interrupt)
54 , dmaThreshold_(dma_threshold)
55 , dmaChannelIndexTx_(dma_channel_index_tx)
56 , dmaChannelIndexRx_(dma_channel_index_rx)
57{
58 uint32_t p = 0;
59 switch(base_) {
60 case SSI0_BASE:
61 p = SYSCTL_PERIPH_SSI0;
62 sem_ = sem + 0;
63 break;
64 case SSI1_BASE:
65 p = SYSCTL_PERIPH_SSI1;
66 sem_ = sem + 1;
67 break;
68 case SSI2_BASE:
69 p = SYSCTL_PERIPH_SSI2;
70 sem_ = sem + 2;
71 break;
72 case SSI3_BASE:
73 p = SYSCTL_PERIPH_SSI3;
74 sem_ = sem + 3;
75 break;
76 default:
77 DIE("Unknown SPI peripheral.");
78 }
79 MAP_SysCtlPeripheralEnable(p);
80 MAP_SysCtlPeripheralReset(p);
81
83}
84
88
90{
91}
92
94{
95}
96
101{
102 unsigned long new_mode;
103
104 switch (mode_)
105 {
106 default:
107 case SPI_MODE_0:
108 new_mode = SSI_FRF_MOTO_MODE_0;
109 break;
110 case SPI_MODE_1:
111 new_mode = SSI_FRF_MOTO_MODE_1;
112 break;
113 case SPI_MODE_2:
114 new_mode = SSI_FRF_MOTO_MODE_2;
115 break;
116 case SPI_MODE_3:
117 new_mode = SSI_FRF_MOTO_MODE_3;
118 break;
119 }
120
121 HASSERT(bitsPerWord <= 16);
122
123 uint32_t clock = cm3_cpu_clock_hz;
124 /* The SPI peripheral only supoprts certain frequencies and driverlib does
125 * not properly round down. We can do some math to make sure that driverlib
126 * makes the correct selection.
127 */
128 if (speedHz > (clock / 2))
129 {
130 speedHz = clock / 2;
131 }
132 else if ((clock % speedHz) != 0)
133 {
134 speedHz = clock / ((clock / speedHz) + 1);
135 }
136
137 MAP_SSIDisable(base_);
138 MAP_SSIConfigSetExpClk(base_, clock, new_mode, SSI_MODE_MASTER,
140 MAP_IntPrioritySet(interrupt_, configKERNEL_INTERRUPT_PRIORITY);
141 MAP_IntEnable(interrupt_);
142 MAP_SSIEnable(base_);
143
144 // these values are used to quickly program instance local configuration
145 // settings
146 spiCr0_ = HWREG(base_ + SSI_O_CR0);
147 spiCr1_ = HWREG(base_ + SSI_O_CR1);
148 spiPrescaler_ = HWREG(base_ + SSI_O_CPSR);
149
150 return 0;
151}
152
156__attribute__((optimize("-O3")))
157void TivaSPI::config_dma(struct spi_ioc_transfer *msg)
158{
159 DIE("DMA transfer is not yet implemented.");
160}
161
162__attribute__((optimize("-O3")))
163void TivaSPI::interrupt_handler()
164{
165 DIE("SPI interrupt is not yet implemented.");
166}
167
OSSem sem[1]
One semaphore required per instance pointer.
Definition CC32xxSPI.cxx:55
OSSem sem[4]
One semaphore per peripheral.
Definition TivaSPI.cxx:43
mode_t mode_
File open mode, such as O_NONBLOCK.
Definition Devtab.hxx:590
This class provides a mutex API.
Definition OS.hxx:427
This class provides a counting semaphore API.
Definition OS.hxx:243
Private data for an SPI device.
Definition SPI.hxx:53
uint32_t speedHz
Max default speed in Hz.
Definition SPI.hxx:190
uint8_t bitsPerWord
number of bits per word transaction
Definition SPI.hxx:193
OSSem * sem_
reference to the semaphore belonging to this bus
Definition TivaSPI.hxx:305
void disable() override
Function to disable device.
Definition TivaSPI.cxx:93
TivaSPI(const char *name, unsigned long base, uint32_t interrupt, ChipSelectMethod cs_assert, ChipSelectMethod cs_deassert, OSMutex *bus_lock=nullptr, size_t dma_threshold=DEFAULT_DMA_THRESHOLD_BYTES, uint32_t dma_channel_index_tx=UDMA_CH11_SSI0TX, uint32_t dma_channel_index_rx=UDMA_CH10_SSI0RX)
Constructor.
Definition TivaSPI.cxx:45
uint16_t spiCr1_
Configuration register 1 local copy.
Definition TivaSPI.hxx:313
unsigned long base_
base address of this device
Definition TivaSPI.hxx:306
uint16_t spiPrescaler_
Prescale register local copy.
Definition TivaSPI.hxx:314
int update_configuration() override
Update the configuration of the bus.
Definition TivaSPI.cxx:100
void enable() override
Function to enable device.
Definition TivaSPI.cxx:89
~TivaSPI()
Destructor.
Definition TivaSPI.cxx:85
unsigned long interrupt_
interrupt of this device
Definition TivaSPI.hxx:307
uint16_t spiCr0_
Configuration register 0 local copy.
Definition TivaSPI.hxx:312
#define HASSERT(x)
Checks that the value of expression x is true, else terminates the current process.
Definition macros.h:138
#define DIE(MSG)
Unconditionally terminates the current process with a message.
Definition macros.h:143