Scs (#3)
* Add send scs * Create scs dict * Fix compilation errors * Fix compile error * Change default include * Add Timer SCS manager * Remove unused files * Fix bugs * Add documentation * Add SCS manager bozza * Refactor * Use same naming convention * Add tick provider * Update header * Fix header bit translation * Test HandleNext OK * Remove linting * Remove indents * Add documentation * Improve docs * Remove pointer * Remove mailbox * Remove useless comment * Add newline * Fix compile errors * Separate scs entries from manager * Refactor * Fix include guards Co-authored-by: nicolagutierrez <nicolagutierrez.ng@gmail.com>
This commit was merged in pull request #3.
This commit is contained in:
committed by
GitHub
parent
7aa61ed9ad
commit
4d5c1934a4
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* @file mmr_can_scs_manager.h
|
||||
* @brief
|
||||
* Provides utilities for managing the scs messages,
|
||||
* such as transmission, retransmission and timeout error.
|
||||
*/
|
||||
|
||||
#ifndef INC_MMR_CAN_SCS_H_
|
||||
#define INC_MMR_CAN_SCS_H_
|
||||
|
||||
#include "mmr_can.h"
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* The maximum number of scs messages that
|
||||
* can be tracked at any given time.
|
||||
*/
|
||||
#ifndef MMR_CAN_SCS_ENTRIES_COUNT
|
||||
#define MMR_CAN_SCS_ENTRIES_COUNT 5
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Maximum timeout before first retransmission,
|
||||
* in milliseconds
|
||||
*/
|
||||
#ifndef MMR_CAN_MAX_TIMEOUT
|
||||
#define MMR_CAN_MAX_TIMEOUT 500
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* It depends on how many bits the board devotes to the timer
|
||||
* Check the datasheet
|
||||
*/
|
||||
typedef uint32_t TimerRange;
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Represents the base-struct to manage a single RTR
|
||||
* and allows to interface with the associated SCS's timer
|
||||
*/
|
||||
typedef struct {
|
||||
/**
|
||||
* @brief
|
||||
* The header used to index this entry.
|
||||
*/
|
||||
MmrCanHeader header;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* The time at which this message was sent,
|
||||
* represented as milliseconds since the board
|
||||
* was turned on.
|
||||
*/
|
||||
TimerRange counter;
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Number of retransmissions for this message.
|
||||
*
|
||||
* == 0 -> No retransmission occurred.
|
||||
* >= 1 -> The scs was retransmitted.
|
||||
*/
|
||||
int rtr;
|
||||
} MmrCanScsEntry;
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* The results of an scsCheck operation.
|
||||
*/
|
||||
typedef enum {
|
||||
/**
|
||||
* @brief No timeout error.
|
||||
*/
|
||||
MMR_CAN_SCS_CHECK_OK,
|
||||
|
||||
/**
|
||||
* @brief The message should be retransmitted.
|
||||
*/
|
||||
MMR_CAN_SCS_CHECK_RTR,
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* The message has timed out and has already been
|
||||
* retransmitted, fail.
|
||||
*/
|
||||
MMR_CAN_SCS_CHECK_ERROR,
|
||||
} MmrCanScsCheckResult;
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Tries to handle an acknowledgment for a particular scs.
|
||||
*
|
||||
* This function MUST be called every time a
|
||||
* message is received, as it might potentially be an
|
||||
* ACK.
|
||||
*
|
||||
* @param header The header to check.
|
||||
* @return true The message was an ACK and was cleared accordingly.
|
||||
* @return false The message wasn't an ACK.
|
||||
*/
|
||||
bool MMR_CAN_MaybeHandleAck(MmrCanHeader header);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Checks the array with the stored scs messages and
|
||||
* retransmits the message if no ack was received.
|
||||
*
|
||||
* This function MUST be called at every loop.
|
||||
*
|
||||
* @return HalStatus
|
||||
* The result of the operation.
|
||||
* HAL_ERROR should immediately be handled as a safe state.
|
||||
*/
|
||||
HalStatus MMR_CAN_HandleNextScs(CanHandle *hcan);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Send an acknowledgment packet based on the
|
||||
* given scs header.
|
||||
*
|
||||
* @param originalHeader The scs header to acknowledge.
|
||||
*/
|
||||
HalStatus MMR_CAN_SendAck(
|
||||
CanHandle *hcan,
|
||||
MmrCanHeader originalHeader
|
||||
);
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Sends an Scs message.
|
||||
*
|
||||
* @param scsId The MMR_CAN_MESSAGE_ID_SCS_xx id.
|
||||
* @param senderId The id of this board.
|
||||
*/
|
||||
HalStatus MMR_CAN_SendScs(
|
||||
CanHandle *hcan,
|
||||
MmrCanMessageId scsId,
|
||||
CanId senderId
|
||||
);
|
||||
|
||||
|
||||
MmrCanScsEntry* MMR_CAN_GetNextScsEntry();
|
||||
MmrCanScsEntry* MMR_CAN_PutScsEntry(MmrCanHeader header);
|
||||
MmrCanScsEntry* MMR_CAN_ClearScsEntry(MmrCanHeader header);
|
||||
MmrCanScsEntry* MMR_CAN_FindScsEntry(MmrCanHeader header);
|
||||
|
||||
#endif // !INC_MMR_CAN_SCS_H_
|
||||
Reference in New Issue
Block a user