continued spi com if

This commit is contained in:
2021-06-04 17:13:14 +02:00
parent cb121b9faf
commit c50868c9dc
4 changed files with 183 additions and 7 deletions

View File

@ -2,6 +2,7 @@
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
#include "fsfw/tasks/SemaphoreIF.h"
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
#include "fsfw/objectmanager/SystemObject.h"
@ -9,11 +10,40 @@
#include "stm32h7xx_hal_spi.h"
#include "stm32h743xx.h"
#include <vector>
#include <map>
class SpiComIF:
public SystemObject,
public DeviceCommunicationIF {
public:
SpiComIF(object_id_t objectId, SPI_TypeDef* spiInstance, spi::TransferModes transferMode);
/**
* Create a SPI communication interface for the given SPI peripheral (spiInstance)
* @param objectId
* @param spiInstance
* @param spiHandle
* @param transferMode
*/
SpiComIF(object_id_t objectId, SPI_TypeDef* spiInstance, SPI_HandleTypeDef* spiHandle,
spi::TransferModes transferMode);
/**
* Allows the user to disable cache maintenance on the TX buffer. This can be done if the
* TX buffers are places and MPU protected properly like specified in this link:
* https://community.st.com/s/article/FAQ-DMA-is-not-working-on-STM32H7-devices
* The cache maintenace is enabled by default.
* @param enable
*/
void configureCacheMaintenanceOnTxBuffer(bool enable);
/**
* Add the DMA handles. These need to be set in the DMA transfer mode is used
* @param txHandle
* @param rxHandle
*/
void addDmaHandles(DMA_HandleTypeDef* txHandle, DMA_HandleTypeDef* rxHandle);
ReturnValue_t initialize() override;
protected:
// DeviceCommunicationIF overrides
@ -25,8 +55,21 @@ protected:
size_t requestLen) override;
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t *size) override;
private:
SPI_HandleTypeDef spiHandle;
struct SpiInstance {
std::vector<uint8_t> replyBuffer;
};
spi::TransferModes transferMode;
SPI_HandleTypeDef* spiHandle;
SemaphoreIF* spiSemaphore;
bool cacheMaintenanceOnTxBuffer = true;
using SpiDeviceMap = std::map<address_t, SpiInstance>;
using SpiDeviceMapIter = SpiDeviceMap::iterator;
SpiDeviceMap spiDeviceMap;
};