its working

This commit is contained in:
2021-06-10 21:31:21 +02:00
parent 1611099cb2
commit 621fe97d5d
11 changed files with 396 additions and 278 deletions

View File

@ -1,8 +1,6 @@
#ifndef FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
#define FSFW_HAL_STM32H7_SPI_SPICOMIF_H_
#include "fsfw/tasks/SemaphoreIF.h"
#include "fsfw/devicehandlers/DeviceCommunicationIF.h"
#include "fsfw/objectmanager/SystemObject.h"
@ -24,6 +22,19 @@ enum class TransferStates {
FAILURE
};
/**
* @brief This communication interface allows using generic device handlers with using
* the STM32H7 SPI peripherals
* @details
* This communication interface supports all three major communcation modes:
* - Polling: Simple, but not recommended to real use-cases, blocks the CPU
* - Interrupt: Good for small data only arriving occasionally
* - DMA: Good for large data which also occur regularly. Please note that the number
* of DMA channels in limited
* The device specific information is usually kept in the SpiCookie class. The current
* implementation limits the transfer mode for a given SPI bus.
* @author R. Mueller
*/
class SpiComIF:
public SystemObject,
public DeviceCommunicationIF {
@ -35,7 +46,7 @@ public:
* @param spiHandle
* @param transferMode
*/
SpiComIF(object_id_t objectId, spi::TransferModes transferMode);
SpiComIF(object_id_t objectId);
/**
* Allows the user to disable cache maintenance on the TX buffer. This can be done if the
@ -49,7 +60,7 @@ public:
void setDefaultPollingTimeout(dur_millis_t timeout);
/**
* Add the DMA handles. These need to be set in the DMA transfer mode is used
* Add the DMA handles. These need to be set in the DMA transfer mode is used.
* @param txHandle
* @param rxHandle
*/
@ -68,7 +79,6 @@ protected:
virtual ReturnValue_t readReceivedMessage(CookieIF *cookie,
uint8_t **buffer, size_t *size) override;
private:
struct SpiInstance {
@ -79,13 +89,11 @@ private:
uint32_t defaultPollingTimeout = 50;
spi::TransferModes transferMode;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
SemaphoreIF::TimeoutType timeoutType = SemaphoreIF::TimeoutType::WAITING;
dur_millis_t timeoutMs = 20;
spi::TransferModes currentTransferMode = spi::TransferModes::POLLING;
BinarySemaphore* spiSemaphore = nullptr;
MutexIF* spiMutex = nullptr;
bool cacheMaintenanceOnTxBuffer = true;
using SpiDeviceMap = std::map<address_t, SpiInstance>;
@ -109,7 +117,7 @@ private:
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
ReturnValue_t genericIrqSendSetup(uint8_t* recvPtr, SPI_HandleTypeDef& spiHandle,
SpiCookie& spiCookie, const uint8_t * sendData, size_t sendLen);
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status);
ReturnValue_t halErrorHandler(HAL_StatusTypeDef status, spi::TransferModes transferMode);
static void spiTransferTxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
static void spiTransferRxCompleteCallback(SPI_HandleTypeDef *hspi, void* args);
@ -118,7 +126,7 @@ private:
static void genericIrqHandler(SpiComIF* comIF, TransferStates targetState);
void printCfgError(const char* const type);
};