2021-11-01 12:41:20 +01:00
|
|
|
#ifndef LINUX_OBC_PDECCONFIG_H_
|
|
|
|
#define LINUX_OBC_PDECCONFIG_H_
|
|
|
|
|
2023-02-15 10:21:35 +01:00
|
|
|
#include <string>
|
2021-11-01 12:41:20 +01:00
|
|
|
|
2023-02-13 11:28:27 +01:00
|
|
|
#include "bsp_q7s/fs/SdCardManager.h"
|
2023-02-23 15:27:24 +01:00
|
|
|
#include "bsp_q7s/memory/LocalParameterHandler.h"
|
2022-08-24 17:27:47 +02:00
|
|
|
#include "fsfw/returnvalues/returnvalue.h"
|
2023-02-13 11:28:27 +01:00
|
|
|
#include "pdec.h"
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2021-11-01 12:41:20 +01:00
|
|
|
/**
|
2021-11-02 11:11:38 +01:00
|
|
|
* @brief This class generates the configuration words for the configuration memory of the PDEC
|
|
|
|
* IP Cores.
|
|
|
|
*
|
2023-02-13 11:28:27 +01:00
|
|
|
* @details Fields are initialized according to specification in PDEC datasheet section 6.11.3.1
|
2021-11-02 11:11:38 +01:00
|
|
|
* PROM usage.
|
2021-11-01 12:41:20 +01:00
|
|
|
*
|
|
|
|
* @author J. Meier
|
|
|
|
*/
|
2021-11-02 11:11:38 +01:00
|
|
|
class PdecConfig {
|
2022-01-17 15:58:27 +01:00
|
|
|
public:
|
2023-02-23 15:27:24 +01:00
|
|
|
/**
|
|
|
|
* @brief Constructor
|
|
|
|
*/
|
2022-01-17 15:58:27 +01:00
|
|
|
PdecConfig();
|
|
|
|
virtual ~PdecConfig();
|
|
|
|
|
|
|
|
/**
|
2023-02-13 11:28:27 +01:00
|
|
|
* @brief Sets the memory base address pointer
|
|
|
|
*/
|
|
|
|
void setMemoryBaseAddress(uint32_t* memoryBaseAddress_);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Will write the config to the PDEC configuration memory. New config
|
|
|
|
* becomes active after resetting PDEC.
|
|
|
|
*/
|
|
|
|
ReturnValue_t write();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Returns the value to write to the interrupt mask register. This
|
|
|
|
* value defines which interrupts should be enabled/disabled.
|
2022-01-17 15:58:27 +01:00
|
|
|
*/
|
2022-10-25 19:12:04 +02:00
|
|
|
uint32_t getImrReg();
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-02-13 11:28:27 +01:00
|
|
|
ReturnValue_t setPositiveWindow(uint8_t pw);
|
|
|
|
ReturnValue_t setNegativeWindow(uint8_t nw);
|
|
|
|
|
2023-02-21 14:13:46 +01:00
|
|
|
ReturnValue_t getPositiveWindow(uint8_t& positiveWindow);
|
|
|
|
ReturnValue_t getNegativeWindow(uint8_t& negativeWindow);
|
2023-02-13 11:28:27 +01:00
|
|
|
|
2023-08-07 17:08:33 +02:00
|
|
|
/**
|
2023-08-14 15:06:22 +02:00
|
|
|
* @brief Creates the first word of the PDEC configuration
|
|
|
|
*
|
|
|
|
* @param word The created word will be written to this pointer
|
|
|
|
*
|
|
|
|
* @return OK if successful, otherwise error return value
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
ReturnValue_t createFirstWord(uint32_t* word);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Creates the second word of the PDEC configuration
|
|
|
|
*
|
|
|
|
* @param word The created word will be written to this pointer
|
|
|
|
*
|
|
|
|
* @return OK if successful, otherwise error return value
|
|
|
|
*/
|
|
|
|
ReturnValue_t createSecondWord(uint32_t* word);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads first config word from the config memory
|
|
|
|
*
|
|
|
|
* @return The config word
|
|
|
|
*/
|
|
|
|
uint32_t readbackFirstWord();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Reads the second config word from the config memory
|
|
|
|
*
|
|
|
|
* @return The config word
|
|
|
|
*/
|
|
|
|
uint32_t readbackSecondWord();
|
2023-08-07 17:08:33 +02:00
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
private:
|
|
|
|
// TC transfer frame configuration parameters
|
|
|
|
static const uint8_t VERSION_ID = 0;
|
|
|
|
// BD Frames
|
|
|
|
static const uint8_t BYPASS_FLAG = 1;
|
|
|
|
static const uint8_t CONTROL_COMMAND_FLAG = 0;
|
|
|
|
|
|
|
|
static const uint8_t VIRTUAL_CHANNEL = 0;
|
|
|
|
static const uint8_t RESERVED_FIELD_A = 0;
|
2023-01-31 14:05:40 +01:00
|
|
|
static const uint16_t SPACECRAFT_ID = 0x3DC;
|
2022-01-17 15:58:27 +01:00
|
|
|
static const uint16_t DUMMY_BITS = 0;
|
|
|
|
static const uint8_t HIGH_AU_MAP_ID = 0xF;
|
|
|
|
static const uint8_t ENABLE_DERANDOMIZER = 1;
|
|
|
|
|
|
|
|
static const uint8_t CONFIG_WORDS_NUM = 2;
|
|
|
|
|
2023-02-13 11:28:27 +01:00
|
|
|
// 0x200 / 4 = 0x80
|
2023-02-23 15:27:24 +01:00
|
|
|
static const uint32_t FRAME_HEADER_OFFSET = 0x80;
|
2023-08-11 16:15:56 +02:00
|
|
|
static const uint32_t OFFSET_FIRST_CONFIG_WORD = 0;
|
|
|
|
static const uint32_t OFFSET_SECOND_CONFIG_WORD = 1;
|
2023-02-23 15:27:24 +01:00
|
|
|
|
|
|
|
static const uint32_t MAP_ADDR_LUT_OFFSET = 0xA0;
|
|
|
|
static const uint32_t MAP_CLK_FREQ_OFFSET = 0x90;
|
|
|
|
// MAP clock frequency. Must be a value between 1 and 13 otherwise the TC segment will be
|
|
|
|
// discarded
|
|
|
|
static const uint8_t MAP_CLK_FREQ = 2;
|
|
|
|
|
|
|
|
static const uint8_t MAX_MAP_ADDR = 63;
|
|
|
|
// Writing this to the map address in the look up table will invalidate a MAP ID.
|
|
|
|
static const uint8_t NO_DESTINATION = 0;
|
|
|
|
static const uint8_t VALID_POSITION = 6;
|
|
|
|
static const uint8_t PARITY_POSITION = 7;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TCs with map addresses (also know as Map IDs) assigned to this channel will be stored in
|
|
|
|
* the PDEC memory.
|
|
|
|
*/
|
|
|
|
static const uint8_t PM_BUFFER = 7;
|
2023-02-13 11:28:27 +01:00
|
|
|
|
|
|
|
uint32_t* memoryBaseAddress = nullptr;
|
|
|
|
|
|
|
|
// Pointer to object providing access to persistent configuration parameters
|
|
|
|
LocalParameterHandler localParameterHandler;
|
|
|
|
|
2022-01-17 15:58:27 +01:00
|
|
|
uint32_t configWords[CONFIG_WORDS_NUM];
|
2022-10-25 19:12:04 +02:00
|
|
|
bool enableTcNewIrq = true;
|
|
|
|
bool enableTcAbortIrq = true;
|
|
|
|
bool enableNewFarIrq = true;
|
2022-01-17 15:58:27 +01:00
|
|
|
|
2023-02-21 14:13:46 +01:00
|
|
|
ReturnValue_t initializePersistentParameters();
|
|
|
|
/**
|
|
|
|
* @brief If the json file containing the persistent config parameters does
|
|
|
|
* not exist it will be created here.
|
|
|
|
*/
|
|
|
|
ReturnValue_t createPersistentConfig();
|
|
|
|
|
2023-08-07 17:08:33 +02:00
|
|
|
ReturnValue_t writeFrameHeaderFirstWord();
|
|
|
|
ReturnValue_t writeFrameHeaderSecondWord();
|
2023-02-23 15:27:24 +01:00
|
|
|
void writeMapConfig();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This function calculates the entry for the configuration of the MAP ID routing.
|
|
|
|
*
|
|
|
|
* @param mapAddr The MAP ID to configure
|
|
|
|
* @param moduleId The destination module where all TCs with the map id mapAddr will be routed
|
|
|
|
* to.
|
|
|
|
*
|
|
|
|
* @details The PDEC has different modules where the TCs can be routed to. A lookup table is
|
|
|
|
* used which links the MAP ID field to the destination module. The entry for this
|
|
|
|
* lookup table is created by this function and must be stored in the configuration
|
|
|
|
* memory region of the PDEC. The entry has a specific format
|
|
|
|
*/
|
|
|
|
uint8_t calcMapAddrEntry(uint8_t moduleId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief This functions calculates the odd parity of the bits in number.
|
|
|
|
*
|
|
|
|
* @param number The number from which to calculate the odd parity.
|
|
|
|
*/
|
|
|
|
uint8_t getOddParity(uint8_t number);
|
2021-11-01 12:41:20 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* LINUX_OBC_PDECCONFIG_H_ */
|