Updates on the IODevice structure.

Display and Logger fully functional.
Keypad task completed - yet to be tested

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@219 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-09-28 14:30:36 +00:00
parent d54c2c497c
commit 83cce4ba74
21 changed files with 615 additions and 232 deletions

View File

@@ -28,6 +28,7 @@ OBJECTS = \
stm32f10x_it.o \
led.o \
spi.o \
spiDevice.o \
uart.o \
oli_stm32_h107.o \

View File

@@ -1,3 +1,4 @@
// -----------------------------------------------------------------------------
/// @file led.h
/// @brief File description
@@ -34,6 +35,7 @@
#include <stdbool.h>
#include "platform.h"
#include "IODevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
@@ -47,6 +49,7 @@
struct Led
{
struct IODevice device;
T_PL_GPIO ledGpio;
bool status;
};
@@ -56,6 +59,8 @@ struct Led
// -----------------------------------------------------------------------------
ErrorStatus LED_construct (struct Led* self);
/** ----------------------------------------------------------------------------
* LED_turnOn
* Turns on the LED identified with the ID
@@ -68,7 +73,7 @@ struct Led
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus LED_turnOn(struct Led* const led);
extern ErrorStatus LED_turnOn(struct Led* led);
/** ----------------------------------------------------------------------------
* LED_turnOff
@@ -82,6 +87,6 @@ extern ErrorStatus LED_turnOn(struct Led* const led);
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus LED_turnOff(struct Led* const led);
extern ErrorStatus LED_turnOff(struct Led* led);
#endif /* LED_INC_LED_H_ */

View File

@@ -38,6 +38,7 @@
#include "semphr.h"
#include "platform.h"
#include "IODevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
@@ -69,7 +70,7 @@ struct Spi
SPI_TypeDef* SPI_TypeDef;
SPI_InitTypeDef SPI_InitStruct;
T_PL_GPIO SPI_CLK;
T_PL_GPIO* SPI_CE;
const T_PL_GPIO* SPI_CE;
T_PL_GPIO SPI_MOSI;
T_PL_GPIO SPI_MISO;
SemaphoreHandle_t spiClaimed; //! Semaphore to protect SPI bus
@@ -97,13 +98,6 @@ struct SpiParameters
UBaseType_t rxQueueSize;
};
struct SpiDevice
{
struct Spi* spi;
struct SpiParameters* spiParameters;
T_PL_GPIO SPI_CE;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
@@ -121,7 +115,7 @@ struct SpiDevice
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters);
extern ErrorStatus SPI_construct(struct Spi* self, const struct SpiParameters* parameters);
/** ----------------------------------------------------------------------------
@@ -154,19 +148,4 @@ extern ErrorStatus SPI_destruct(struct Spi* self);
extern ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters);
/** ----------------------------------------------------------------------------
* Spi_Write
* Write the data in buffer to the SPI in argument self
*
* @param self The UART class object
* @param buffer Message string to send
* @parm length Message length
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length);
#endif /* MISC_INC_SPI_H_ */

View File

@@ -0,0 +1,78 @@
// -----------------------------------------------------------------------------
/// @file spiDevice.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2015 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file spiDevice.h
/// @ingroup {group_name}
#ifndef PLATFORM_INC_SPIDEVICE_H_
#define PLATFORM_INC_SPIDEVICE_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "IODevice.h"
#include "spi.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
struct SpiDevice
{
struct IODevice device;
struct Spi* spi;
struct SpiParameters parameters;
T_PL_GPIO SPI_CE;
};
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
extern ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE);
/** ----------------------------------------------------------------------------
* Spi_Write
* Write the data in buffer to the SPI in argument self
*
* @param self The UART class object
* @param buffer Message string to send
* @parm length Message length
*
* @return ErrorStatus SUCCESS if writing message was successful
* ERROR otherwise
*
* @todo
* -----------------------------------------------------------------------------
*/
extern ErrorStatus SpiDevice_write (const struct SpiDevice* self, const char* buffer, int length);
#endif /* PLATFORM_INC_SPIDEVICE_H_ */

View File

@@ -45,17 +45,53 @@
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus LED_turnOn(struct Led* const led)
ErrorStatus LED_construct (struct Led* self)
{
ErrorStatus returnValue = SUCCESS;
IODevice_construct(&self->device, read, write);
return returnValue;
}
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
{
(void)length;
if (buffer != 0)
{
return LED_turnOn((struct Led*)self);
}
else
{
return LED_turnOff((struct Led*)self);
}
}
static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength)
{
struct Led* led = (struct Led*)self;
(void)length;
*actualLength = 1;
*buffer = (char)led->status;
return SUCCESS;
}
ErrorStatus LED_turnOn(struct Led* led)
{
ErrorStatus returnValue = SUCCESS;

View File

@@ -31,6 +31,7 @@
#include "stm32f10x_it.h"
#include "platform.h"
#include "spiDevice.h"
#include "led.h"
#include "spi.h"
#include "uart.h"
@@ -66,6 +67,9 @@
#define SPI_LCD_EEPROM_Direction (SPI_Direction_2Lines_FullDuplex)
#define SPI_LCD_EEPROM_RX_QUEUE (32)
#define SPI_LCD_EEPROM_TX_QUEUE (32)
// Keypad Settings
#define KEYPAD_DEBOUNCE_TIME_MS (20)
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
@@ -88,28 +92,35 @@ static struct UartParameters _uart1Parameters;
// SPI
static struct Spi _spi1;
static struct SpiParameters _spi1Parameters;
static struct SpiDevice _spiDAC;
static struct Spi _spi3;
static struct SpiParameters _spi3Parameters;
static struct SpiParameters _spi3DisplayParameters;
static struct SpiParameters _spi3EEPROMParameters;
static struct SpiDevice _spiDisplay;
static struct SpiDevice _spiEEPROM;
// Keypad
static struct Keypad _keypad;
static struct KeypadParameters _keypadParameters;
// The following pointers are for export (see platform.h) and external use.
// Note that the pointer content is marked "const"
struct Led* const ledGreen = &_ledGreen;
struct Led* const ledOrange = &_ledOrange;
struct Uart* const uart1 = &_uart1;
struct Spi* const spi1 = &_spi1;
struct Spi* const spi3 = &_spi3;
struct SpiDevice* const spiDAC = &_spiDAC;
struct SpiDevice* const spiDisplay = &_spiDisplay;
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
struct Led* const ledGreen = &_ledGreen;
struct Led* const ledOrange = &_ledOrange;
struct Keypad* const keypad = &_keypad;
struct Uart* const uart1 = &_uart1;
struct UartParameters* uartLoggerParam = &_uart1Parameters;
struct Spi* const spi1 = &_spi1;
struct Spi* const spi3 = &_spi3;
struct SpiDevice* const spiDAC = &_spiDAC;
struct SpiDevice* const spiDisplay = &_spiDisplay;
struct SpiParameters* const spiDisplayParam = &_spi3DisplayParameters;
struct SpiDevice* const spiEEPROM = &_spiEEPROM;
struct SpiParameters* const spiEEPROMParam = &_spi3EEPROMParameters;
struct Keypad* const keypad = &_keypad;
struct KeypadParameters* const keypadParam = &_keypadParameters;
// -----------------------------------------------------------------------------
// Function declarations
@@ -131,36 +142,42 @@ ErrorStatus initPlatform(void)
{
returnValue = initIO();
LED_construct(ledGreen);
LED_construct(ledOrange);
// Initialize the Console UART
IRQ_setInterruptProperties(USART1_IRQn, 15, 15, ENABLE);
uart1->USART_TypeDef = UART_LOG_TYPEDEF;
Uart_getDefaultParameters(&_uart1Parameters);
Uart_getDefaultParameters(uartLoggerParam);
// Adjust to higher baudrate for intensive logging
_uart1Parameters.baudrate = UART_LOG_BAUDRATE;
uartLoggerParam->baudrate = UART_LOG_BAUDRATE;
// Adjust the TX queue size for intensive logging
_uart1Parameters.txQueueSize = UART_LOG_TX_QUEUE;
returnValue = Uart_construct(uart1, &_uart1Parameters);
uartLoggerParam->txQueueSize = UART_LOG_TX_QUEUE;
returnValue = Uart_construct(uart1, uartLoggerParam);
IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
spi1->initialized = false;
spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
SPI_getDefaultParameters(&_spi1Parameters);
SPI_construct(spi1, &_spi1Parameters);
// IRQ_setInterruptProperties(SPI1_IRQn, 11, 11, ENABLE);
// spi1->initialized = false;
// spi1->SPI_TypeDef = SPI_DAC_TYPEDEF;
// SPI_getDefaultParameters(&_spi1Parameters);
// SPI_construct(spi1, &_spi1Parameters);
IRQ_setInterruptProperties(SPI3_IRQn, 12, 12, ENABLE);
spi3->initialized = false;
spi3->SPI_TypeDef = SPI_LCD_EEPROM_TYPEDEF;
// Get the SPI parameters from the NHD0420 driver. They are more critical than the parameters from the EEPROM
NHD0420_getSpiParameters(&_spi3Parameters);
NHD0420_getSpiParameters(spiDisplayParam);
// In order to use multiple slaves on this bus (and to increase performance), some parameters are altered
// Use full-duples instead of TX only, because the EEPROM is both write- and readable
_spi3Parameters.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
spiDisplayParam->SPI_Direction = SPI_Direction_2Lines_FullDuplex;
// Adjust the RX and TX queues for multiple use
_spi3Parameters.rxQueueSize = SPI_LCD_EEPROM_RX_QUEUE;
_spi3Parameters.txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
SPI_construct(spi3, &_spi3Parameters);
spiDisplayParam->rxQueueSize = SPI_LCD_EEPROM_RX_QUEUE;
spiDisplayParam->txQueueSize = SPI_LCD_EEPROM_TX_QUEUE;
///TODO SPI_CE should be initialized individually
GPIO_SetBits(spiDisplay->SPI_CE.GPIO_Typedef, spiDisplay->SPI_CE.GPIO_InitStruct.GPIO_Pin);
SpiDevice_construct(spiDisplay, spi3, spiDisplayParam, spiDisplay->SPI_CE);
SpiDevice_construct(spiEEPROM, spi3, spiEEPROMParam, spiEEPROM->SPI_CE);
// Enable the interrupts for the Keypad columns
// Set-up the interrupts for the Keypad columns
keypad->column[0].EXTI_InitStruct.EXTI_Line = EXTI_Line4;
keypad->column[0].EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
keypad->column[0].EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising_Falling;
@@ -188,6 +205,9 @@ ErrorStatus initPlatform(void)
IRQ_setInterruptProperties(EXTI4_IRQn, 11, 0, ENABLE);
IRQ_setInterruptProperties(EXTI9_5_IRQn, 11, 0, ENABLE);
Keypad_getDefaultParameters(keypadParam);
Keypad_construct(keypad, keypadParam, KEYPAD_DEBOUNCE_TIME_MS);
}
@@ -227,18 +247,18 @@ static ErrorStatus initIO (void)
/*LED IO initialisation --------------------------------------------------*/
// Init LED Green
_ledGreen.ledGpio.GPIO_Typedef = GPIOC;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
_ledGreen.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_ledGreen.ledGpio.GPIO_Typedef, &_ledGreen.ledGpio.GPIO_InitStruct);
ledGreen->ledGpio.GPIO_Typedef = GPIOC;
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_6;
ledGreen->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(ledGreen->ledGpio.GPIO_Typedef, &ledGreen->ledGpio.GPIO_InitStruct);
// Init LED Orange
_ledOrange.ledGpio.GPIO_Typedef = GPIOC;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
_ledOrange.ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(_ledOrange.ledGpio.GPIO_Typedef, &_ledOrange.ledGpio.GPIO_InitStruct);
ledOrange->ledGpio.GPIO_Typedef = GPIOC;
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
ledOrange->ledGpio.GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(ledOrange->ledGpio.GPIO_Typedef, &ledOrange->ledGpio.GPIO_InitStruct);
/* USART1 initialisation -------------------------------------------------*/
// Init TX line

View File

@@ -44,22 +44,23 @@
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
ErrorStatus SPI_construct(struct Spi* self, const struct SpiParameters* parameters)
{
ErrorStatus returnValue = SUCCESS;
if (!self->initialized)
{
//! Create semaphore to synchronize with USART interrupt handler
vSemaphoreCreateBinary(self->txSemaphore);
@@ -83,9 +84,9 @@ ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
//! Enable USART interface
SPI_Cmd(self->SPI_TypeDef, ENABLE);
//! Create a new FREERTOS queue to handle data from app to USART output
//! Create a new FREERTOS queue to handle data from app to SPI output
self->txQueue = xQueueCreate(parameters->txQueueSize, sizeof(struct spiQueueItem));
//! Create a new FREERTOS queue to handle data from USART input to app
//! Create a new FREERTOS queue to handle data from SPI input to app
self->rxQueue = xQueueCreate(parameters->rxQueueSize, sizeof(struct spiQueueItem));
//! Queue identifier must not be 0 (0 means that the queue is not available)
if (self->txQueue == 0)
@@ -110,7 +111,7 @@ ErrorStatus SPI_construct(struct Spi* self, struct SpiParameters* parameters)
if (returnValue == SUCCESS)
{
//! Enable the UART RX not empty interrupt
SPI_I2S_ITConfig(self->SPI_TypeDef, SPI_I2S_IT_RXNE, ENABLE);
// SPI_I2S_ITConfig(self->SPI_TypeDef, SPI_I2S_IT_RXNE, ENABLE);
}
if (returnValue == SUCCESS)
@@ -151,76 +152,3 @@ ErrorStatus SPI_getDefaultParameters(struct SpiParameters* parameters)
return returnValue;
}
ErrorStatus SPI_write (struct SpiDevice* self, const uint8_t* buffer, int length)
{
struct spiQueueItem txItem;
ErrorStatus returnValue = SUCCESS; //! Define return variable
int txCounter; //! Define a loop counter var
xSemaphoreTake(self->spi->spiClaimed, portMAX_DELAY);
self->spi->SPI_CE = &self->SPI_CE;
// De-select the current device to avoid start-issues
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
//! Copy the incoming data into BLUETOOTH data structure
for (txCounter = 0; txCounter < length; txCounter++)
{
txItem.byte = buffer[txCounter]; //! Copy current data in struct
//! Add the current set of data to bluetooth transmission queue
if (pdTRUE != xQueueSend(self->spi->txQueue, &txItem, 0))
{
//! Adding item was NOT successful - break out of loop
returnValue = ERROR; //! Set return value to FALSE
break;
}
}
if (returnValue == SUCCESS)
{
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
//! Semaphore has been taken
//! Enable the SPI TXE (transmission empty) interrupt
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_IT_TXE, ENABLE);
//! Try to take Semaphore - If the USART transmission is still busy, the
//! Semaphore cannot be taken - FREERTOS will suspend this task until the
//! Semaphore is released again
xSemaphoreTake(self->spi->txSemaphore, portMAX_DELAY);
/** Enabling the TX interrupt will immediately cause an interrupt because
* the transmission register is still empty. The ISR will get the data
* from the uart transmission queue and transmit byte-wise until the
* queue is empty.
* An empty queue will cause the transmission complete flag (TC) to be set,
* which is polled
*/
while (SPI_I2S_GetFlagStatus(self->spi->SPI_TypeDef, SPI_I2S_FLAG_BSY) == SET)
{
//! The software must wait until TXE=1. The TXE flag remains cleared during
//! all data transfers and it is set by hardware at the last frame's
//! end of transmission
}
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
xSemaphoreGive(self->spi->spiClaimed);
}
else
{
//! Do nothing
}
return (returnValue); //! Return result to caller
}

View File

@@ -0,0 +1,160 @@
// -----------------------------------------------------------------------------
/// @file spiDevice.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file spiDevice.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdio.h>
#include "stm32f10x.h"
#include "spiDevice.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
//static ErrorStatus read(const struct IODevice* self, char* buffer, size_t length, size_t* actualLength);
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
ErrorStatus SpiDevice_construct(struct SpiDevice* self, struct Spi* spi, const struct SpiParameters* parameters, T_PL_GPIO SPI_CE)
{
ErrorStatus returnValue = SUCCESS;
IODevice_construct(&self->device, NULL, write);
SPI_construct(self->spi, parameters);
return returnValue;
}
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
{
return SpiDevice_write((const struct SpiDevice*)self, buffer, length);
}
ErrorStatus SpiDevice_write (const struct SpiDevice* self, const char* buffer, int length)
{
struct spiQueueItem txItem;
ErrorStatus returnValue = SUCCESS; //! Define return variable
int txCounter; //! Define a loop counter var
xSemaphoreTake(self->spi->spiClaimed, portMAX_DELAY);
self->spi->SPI_CE = &self->SPI_CE;
//! Copy the incoming data into SPI data structure
for (txCounter = 0; txCounter < length; txCounter++)
{
txItem.byte = buffer[txCounter]; //! Copy current data in struct
if (uxQueueSpacesAvailable(self->spi->txQueue) == 2)
{
// Prevent locking in case that more data than queue-space should be send
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_IT_TXE, ENABLE);
}
//! Add the current set of data to SPI transmission queue
if (pdTRUE != xQueueSend(self->spi->txQueue, &txItem, portMAX_DELAY ))
{
//! Adding item was NOT successful - break out of loop
returnValue = ERROR; //! Set return value to FALSE
break;
}
}
if (returnValue == SUCCESS)
{
// De-select the current device to avoid start-issues
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_ResetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
SPI_I2S_ITConfig(self->spi->SPI_TypeDef, SPI_I2S_IT_TXE, ENABLE);
//! Try to take Semaphore - If the USART transmission is still busy, the
//! Semaphore cannot be taken - FREERTOS will suspend this task until the
//! Semaphore is released again
xSemaphoreTake(self->spi->txSemaphore, portMAX_DELAY);
/** Enabling the TX interrupt will immediately cause an interrupt because
* the transmission register is still empty. The ISR will get the data
* from the uart transmission queue and transmit byte-wise until the
* queue is empty.
* An empty queue will cause the transmission complete flag (TC) to be set,
* which is polled
*/
while (SPI_I2S_GetFlagStatus(self->spi->SPI_TypeDef, SPI_I2S_FLAG_BSY) == SET)
{
//! The software must wait until TXE=1. The TXE flag remains cleared during
//! all data transfers and it is set by hardware at the last frame's
//! end of transmission
}
if (self->spi->SPI_InitStruct.SPI_NSS == SPI_NSS_Soft)
{
GPIO_SetBits(self->spi->SPI_CE->GPIO_Typedef, self->spi->SPI_CE->GPIO_InitStruct.GPIO_Pin);
}
xSemaphoreGive(self->spi->spiClaimed);
}
// else
{
//! Do nothing
}
return returnValue; //! Return result to caller
}
ErrorStatus SpiDevice_read(const struct SpiDevice* self, char* buffer, size_t length, size_t* actualLength)
{
ErrorStatus returnValue = SUCCESS;
return returnValue;
}

View File

@@ -54,7 +54,7 @@
// -----------------------------------------------------------------------------
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length);
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length);
// -----------------------------------------------------------------------------
// Function definitions
@@ -144,7 +144,7 @@ ErrorStatus Uart_getDefaultParameters(struct UartParameters* parameters)
}
static ErrorStatus write(struct IODevice* self, const char* buffer, size_t length)
static ErrorStatus write(const struct IODevice* self, const char* buffer, size_t length)
{
return Uart_Write((struct Uart*)self, buffer, length);
}
@@ -156,12 +156,16 @@ ErrorStatus Uart_Write(struct Uart* self, const char* buffer, int length)
ErrorStatus returnValue = SUCCESS; //! Define return variable
int txCounter; //! Define a loop counter var
//! Copy the incoming data into BLUETOOTH data structure
//! Copy the incoming data into UART data structure
for (txCounter = 0; txCounter < length; txCounter++)
{
usartTxItem.byte = buffer[txCounter]; //! Copy current data in struct
//! Add the current set of data to bluetooth transmission queue
if (pdTRUE != xQueueSend(self->txQueue, &usartTxItem, 0))
if (uxQueueSpacesAvailable(self->txQueue) == 2)
{
USART_ITConfig(self->USART_TypeDef, USART_IT_TXE, ENABLE);
}
//! Add the current set of data to UART transmission queue
if (pdTRUE != xQueueSend(self->txQueue, &usartTxItem, portMAX_DELAY))
{
//! Adding item was NOT successful - break out of loop
returnValue = ERROR; //! Set return value to FALSE