Hierodule 1.6.2
Utility module set for STM32 MCUs
Loading...
Searching...
No Matches

Elements of the module that are confined to the scope of the compilation unit. Perfectly corresponds to the module's source file, except the IRQ handlers. More...

Functions

static uint8_t ReceiveData (HIERODULE_SPI_Wrapper *Wrapper)
 Reads and returns the data register content of the SPI peripheral.
 
void Enable (HIERODULE_SPI_Wrapper *Wrapper)
 Enables the SPI peripheral.
 
static void Disable (HIERODULE_SPI_Wrapper *Wrapper)
 Disables the SPI peripheral.
 
void SPI_IRQ_Handler (HIERODULE_SPI_Wrapper *Wrapper)
 The base IRQ body to be used for all SPI IRQs.
 

Variables

static HIERODULE_SPI_WrapperSPI1_Wrapper
 SPI wrapper pointer meant for SPI1.
 
static HIERODULE_SPI_WrapperSPI2_Wrapper
 SPI wrapper pointer meant for SPI2.
Requires the device specific macro __STM32F103xB_H or __STM32F401xC_H to be defined.
 
static HIERODULE_SPI_WrapperSPI3_Wrapper
 SPI wrapper pointer meant for SPI3.
Requires the device specific macro __STM32F401xC_H to be defined.
 

Detailed Description

Implements the routines defined in the header file and routines necessary for those in the background. Pointers of SPI wrappers are also defined here.
IRQ definitions with custom ISR implementations are also included at the end of the file.

Function Documentation

◆ Disable()

static void Disable ( HIERODULE_SPI_Wrapper * Wrapper)
static
Parameters
WrapperPointer to the SPI wrapper.
Returns
None

Defined as static to avoid the multiple definition error some compilers throw since a function with the same name also exists within another module; that will be fixed in a future release.

Definition at line 77 of file hierodule_spi.c.

78{
79 CLEAR_BIT(Wrapper->_SPI->CR1, SPI_CR1_SPE);
80}
HIERODULE_USB_Wrapper Wrapper
Extern declaration for the wrapper instance in the source file.

References Wrapper.

Referenced by SPI_IRQ_Handler().

◆ Enable()

void Enable ( HIERODULE_SPI_Wrapper * Wrapper)
Parameters
WrapperPointer to the SPI wrapper.
Returns
None

Self-explanatory code, nothing to elaborate.

Definition at line 65 of file hierodule_spi.c.

66{
67 SET_BIT(Wrapper->_SPI->CR1, SPI_CR1_SPE);
68}

References Wrapper.

Referenced by HIERODULE_SPI_InitWrapper(), and HIERODULE_SPI_TransmitPackage().

◆ ReceiveData()

static uint8_t ReceiveData ( HIERODULE_SPI_Wrapper * Wrapper)
static
Parameters
WrapperPointer to the SPI wrapper.
Returns
uint8_t The byte returned.

Defined as static to avoid the multiple definition error some compilers throw since a function with the same name also exists within another module; that will be fixed in a future release.

Definition at line 54 of file hierodule_spi.c.

55{
56 return (uint8_t)(Wrapper->_SPI->DR);
57}

References Wrapper.

Referenced by SPI_IRQ_Handler().

◆ SPI_IRQ_Handler()

void SPI_IRQ_Handler ( HIERODULE_SPI_Wrapper * Wrapper)
Parameters
WrapperPointer to the SPI wrapper.
Returns
None

Transmission completion callback routine gets Called at the end of an entire transmission in master mode. As for slave mode, the routine gets invoked at the end of each byte transmission.

Definition at line 230 of file hierodule_spi.c.

231{
232 if( Wrapper->Mode == 1 )
233 {
234 if( READ_BIT(Wrapper->_SPI->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE) )
235 {
236 if( READ_BIT(Wrapper->_SPI->SR, SPI_SR_TXE) == (SPI_SR_TXE) )
237 {
238 HIERODULE_SPI_TransmitByte(Wrapper, Wrapper->TX_Buffer[Wrapper->TX_Counter++]);
239 while( READ_BIT(Wrapper->_SPI->SR, SPI_SR_TXE) != (SPI_SR_TXE) );
240
241 while( READ_BIT(Wrapper->_SPI->SR, SPI_SR_RXNE) != (SPI_SR_RXNE) );
245 Wrapper->RX_New++;
246
247 if( Wrapper->TX_Counter == Wrapper->TX_BufferSize )
248 {
249 while( READ_BIT(Wrapper->_SPI->SR, SPI_SR_BSY) == (SPI_SR_BSY) );
251 if( Wrapper->TC_Handler != NULL )
253 }
254 }
255 }
256 }
257 else if( Wrapper->Mode == 0 )
258 {
259 if( READ_BIT(Wrapper->_SPI->SR, SPI_SR_RXNE) == (SPI_SR_RXNE) )
260 {
264 Wrapper->RX_New++;
265
266 HIERODULE_SPI_TransmitByte(Wrapper, Wrapper->TX_Buffer[Wrapper->TX_Counter++]);
267
268 if( Wrapper->TC_Handler != NULL )
270 }
271 }
272}
static uint8_t ReceiveData(HIERODULE_SPI_Wrapper *Wrapper)
Reads and returns the data register content of the SPI peripheral.
static void Disable(HIERODULE_SPI_Wrapper *Wrapper)
Disables the SPI peripheral.
void HIERODULE_SPI_TransmitByte(HIERODULE_SPI_Wrapper *Wrapper, uint8_t Byte)
Writes a byte into the data register of the SPI peripheral.
uint8_t * RX_Buffer
The ring buffer where the data received is appended.
uint32_t RX_New
Number of new bytes in the ring buffer.
uint16_t RX_BufferSize
Number of elements in the ring buffer.
void(* TC_Handler)(void)
Pointer to the callback function to be called on a completed transmission.
uint32_t RX_Index
Index of next-byte-to-be-received in the ring buffer.

References Disable(), HIERODULE_SPI_TransmitByte(), ReceiveData(), HIERODULE_USB_Wrapper::RX_Buffer, HIERODULE_USB_Wrapper::RX_BufferSize, HIERODULE_USB_Wrapper::RX_Index, HIERODULE_USB_Wrapper::RX_New, HIERODULE_USB_Wrapper::TC_Handler, and Wrapper.

Referenced by SPI1_IRQHandler(), SPI2_IRQHandler(), and SPI3_IRQHandler().

Variable Documentation

◆ SPI1_Wrapper

HIERODULE_SPI_Wrapper* SPI1_Wrapper
static

Definition at line 27 of file hierodule_spi.c.

Referenced by HIERODULE_SPI_InitWrapper(), and SPI1_IRQHandler().

◆ SPI2_Wrapper

HIERODULE_SPI_Wrapper* SPI2_Wrapper
static

Definition at line 34 of file hierodule_spi.c.

Referenced by HIERODULE_SPI_InitWrapper(), and SPI2_IRQHandler().

◆ SPI3_Wrapper

HIERODULE_SPI_Wrapper* SPI3_Wrapper
static

Definition at line 43 of file hierodule_spi.c.

Referenced by HIERODULE_SPI_InitWrapper(), and SPI3_IRQHandler().