Skip to content

Commit

Permalink
Feat/swarinfo 538 remove data read from isr (#141)
Browse files Browse the repository at this point in the history
* Add message ID

* Make the user call retrieveRxFrame()

* Update function calls in states

* Refactor angle received state

* Fix issues

* Fixes

* Everything working

* Fix build

* Format
  • Loading branch information
cquesnel authored Oct 11, 2021
1 parent 138b787 commit 6385763
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 275 deletions.
98 changes: 51 additions & 47 deletions src/bsp/src/stm32/src/interloc/include/interloc/Decawave.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,36 +61,36 @@ class Decawave {
void setSpeed(UWBSpeed speed);

/**
* @brief Starts listening for a packet and blocks until received
* @param frame [out] Variable in which all frame data will be put once packet is received
* @brief Starts listening for a packet and blocks until received. Once received, the packet
* data can be retrieved with retrieveRxFrame().
* @param timeoutUs Timeout in microseconds. 0 to block indefinitely
* @return The status of the reception.
*/
void receive(UWBRxFrame& frame, uint16_t timeoutUs);
UWBRxStatus receive(uint16_t timeoutUs);

/**
* @brief Starts listening for a packet at a given timestamp and blocks until received
* @param frame [out] Variable in which all frame data will be put once packet is received
* @brief Starts listening for a packet at a given timestamp and blocks until received. Once
* received, the packet data can be retrieved with retrieveRxFrame().
* @param timeoutUs Timeout in microseconds. 0 to block indefinitely
* @param rxStartTime DW timestamp at which to start the RX
* @return The status of the reception.
*/
void receiveDelayed(UWBRxFrame& frame, uint16_t timeoutUs, uint64_t rxStartTime);
UWBRxStatus receiveDelayed(uint16_t timeoutUs, uint64_t rxStartTime);

/**
* @brief Starts listening for a packet without blocking. The user should poll the frame.status
* @brief Starts listening for a packet without blocking. The user should poll getRxStatus()
* to see if transmission has been received.
* @param frame [out] Variable in which all frame data will be put once packet is received
* @param timeoutUs Timeout in microseconds. 0 to block indefinitely
*/
void receiveAsync(UWBRxFrame& frame, uint16_t timeoutUs);
void receiveAsync(uint16_t timeoutUs);

/**
* @brief Starts listening for a packet at a given timestamp without blocking. The user should
* poll the frame.status to see if transmission has been received.
* @param frame [out] Variable in which all frame data will be put once packet is received
* poll getRxStatus() to see if transmission has been received.
* @param timeoutUs Timeout in microseconds. 0 to block indefinitely
* @param rxStartTime DW timestamp at which to start the RX
*/
void receiveAsyncDelayed(UWBRxFrame& frame, uint16_t timeoutUs, uint64_t rxStartTime);
void receiveAsyncDelayed(uint16_t timeoutUs, uint64_t rxStartTime);

/**
* @brief Transmits data over UWB
Expand All @@ -114,46 +114,40 @@ class Decawave {
* @param buf Buffer to transmit
* @param length Length of the data
* @param rxAfterTxTimeUs Number of microseconds between the TX and the start of the RX
* @param frame [out] Variable in which all frame data will be put once packet is received
* @param rxTimeoutUs Timeout in microseconds. 0 to block indefinitely
* @return True if successful, false otherwise.
* @return An UWBRxStatus if successful, false otherwise.
*/
bool transmitAndReceive(uint8_t* buf,
uint16_t length,
uint32_t rxAfterTxTimeUs,
UWBRxFrame& frame,
uint16_t rxTimeoutUs);
std::optional<UWBRxStatus> transmitAndReceive(uint8_t* buf,
uint16_t length,
uint32_t rxAfterTxTimeUs,
uint16_t rxTimeoutUs);

/**
* @brief Transmits data over UWB and blocks until response is received
* @param buf Buffer to transmit
* @param length Length of the data
* @param txTimestamp DW timestamp at which to start the transmission
* @param rxAfterTxTimeUs Number of microseconds between the TX and the start of the RX
* @param frame [out] Variable in which all frame data will be put once packet is received
* @param rxTimeoutUs Timeout in microseconds. 0 to block indefinitely
* @return True if successful, false otherwise.
* @return An UWBRxStatus if successful, false otherwise.
*/
bool transmitDelayedAndReceive(uint8_t* buf,
uint16_t length,
uint64_t txTimestamp,
uint32_t rxAfterTxTimeUs,
UWBRxFrame& frame,
uint16_t rxTimeoutUs);
std::optional<UWBRxStatus> transmitDelayedAndReceive(uint8_t* buf,
uint16_t length,
uint64_t txTimestamp,
uint32_t rxAfterTxTimeUs,
uint16_t rxTimeoutUs);
/**
* @brief Transmits data over UWB and blocks until response is received
* @param buf Buffer to transmit
* @param length Length of the data
* @param rxStartDelayUS Number of microseconds between the TX and the start of the RX
* @param frame [out] Variable in which all frame data will be put once packet is received
* @param rxTimeoutUs Timeout in microseconds. 0 to block indefinitely
* @return True if successful, false otherwise.
* @return An UWBRxStatus if successful, false otherwise.
*/
bool transmitAndReceiveDelayed(uint8_t* buf,
uint16_t length,
uint32_t rxStartDelayUS,
UWBRxFrame& frame,
uint16_t rxTimeoutUs);
std::optional<UWBRxStatus> transmitAndReceiveDelayed(uint8_t* buf,
uint16_t length,
uint32_t rxStartDelayUS,
uint16_t rxTimeoutUs);

/**
* Prepares the DW1000 for a clock sync
Expand Down Expand Up @@ -195,7 +189,7 @@ class Decawave {
* @brief Retrieves reception timestamp in DecawaveTimeUnits
* @param rxTimestamp Reception timestamp in DecawaveTimeUnits
*/
void getRxTimestamp(uint64_t* rxTimestamp);
void getRxTimestamp(uint64_t* rxTimestamp) const;

/**
* @brief Retrieves present time DecawaveTimeUnits
Expand Down Expand Up @@ -229,6 +223,24 @@ class Decawave {
*/
bool isReady() const;

/**
* @brief Retrieves RX frame information from the Decawave's internal registers
* @param frame A reference to the frame in which to save the information
*/
void retrieveRxFrame(UWBRxFrame& frame) const;

/**
* @brief Returns the status of the last RX operation
* @return Status
*/
UWBRxStatus getRxStatus() const;

/**
* @brief Blocks until the ongoing RX operation is finished, returning the RxStatus
* @return Status of the finished RX operation
*/
UWBRxStatus awaitRx();

private:
decaDevice_t m_spiDevice;
dwt_config_t m_dwConfig;
Expand All @@ -241,33 +253,25 @@ class Decawave {
TaskHandle_t m_trxTaskHandle;
dwt_cb_data_t m_callbackData;

BaseTask<configMINIMAL_STACK_SIZE> m_rxAsyncTask;
UWBRxFrame* m_rxFrame;

std::array<uint8_t, UWB_MAX_LENGTH> m_txBuffer;

DW_STATE m_state;

UWBRxStatus m_rxStatus;

bool m_isReady;

void configureDW();
bool transmitInternal(uint8_t* buf, uint16_t length, uint8_t flags);

void receiveInternal(UWBRxFrame& frame,
uint16_t timeoutUs,
uint8_t flags,
bool rxStarted = false);
void receiveAsyncInternal(UWBRxFrame& frame,
uint16_t timeoutUs,
uint8_t flags,
bool rxStarted = false);

void retrieveRxFrame(UWBRxFrame* frame);
UWBRxStatus receiveInternal(uint16_t timeoutUs, uint8_t flags, bool rxStarted = false);
void receiveAsyncInternal(uint16_t timeoutUs, uint8_t flags, bool rxStarted = false);

static void rxCallback(const dwt_cb_data_t* callbackData, void* context);
static void txCallback(const dwt_cb_data_t* callbackData, void* context);
static void isrCallback(void* context);
static void rxAsyncTask(void* context);
};
// user manual : https://www.decawave.com/sites/default/files/resources/dw1000_user_manual_2.11.pdf
// datasheet : https://www.decawave.com/sites/default/files/resources/dw1000-datasheet-v2.09.pdf
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
*/
class DecawaveArray {
public:
constexpr static uint8_t angleAntennaArraySize = (DWT_NUM_DW_DEV < 3) ? 0 : 3; // MAXIMUM 3

DecawaveArray() = default;
virtual ~DecawaveArray() = default;

Expand All @@ -26,10 +28,14 @@ class DecawaveArray {
std::optional<std::reference_wrapper<Decawave>> getMasterAntenna();
std::optional<std::reference_wrapper<Decawave>> getLeftAntenna();
std::optional<std::reference_wrapper<Decawave>> getRightAntenna();
std::array<std::optional<std::reference_wrapper<Decawave>>, angleAntennaArraySize>&
getAngleAntennaArray();

private:
uint8_t m_workingDecasLength = 0;

void initializeAngleAntennaArray();

// Because the Decawave class is not copyable or moveable (atomic variable inside of a task), we
// have to assign the arrays here
#ifdef STM32F4
Expand All @@ -39,6 +45,9 @@ class DecawaveArray {
Decawave(DW_B0), Decawave(DW_B1),
Decawave(DW_C0), Decawave(DW_C1)};
#endif

std::array<std::optional<std::reference_wrapper<Decawave>>, angleAntennaArraySize>
m_angleAntennaArray;
};

#endif //__DECAWAVEARRAY_H__
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ class InterlocManager : public IInterlocManager {

InterlocStateDTO m_state;

bool isFrameOk(UWBRxFrame frame);
static uint8_t powerCorrection(double twrDistance);
};

Expand Down
2 changes: 0 additions & 2 deletions src/bsp/src/stm32/src/interloc/include/interloc/UWBRxFrame.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ enum class UWBRxStatus { ONGOING, FINISHED, TIMEOUT, ERROR };
struct UWBRxFrame {
uint16_t m_length = 0;
uint64_t m_rxTimestamp = 0;
UWBRxStatus m_status = UWBRxStatus::ONGOING;
uint32_t m_statusReg = 0;
uint8_t m_sfdAngleRegister = 0;
uint8_t m_firstPathAccumulator[ACCUMULATOR_DATA_SIZE]{};

Expand Down
Loading

0 comments on commit 6385763

Please sign in to comment.