Index: firmware/App/Common.h =================================================================== diff -u -rf2652e85c8676d0356fea2690cfd9cac716ca795 -rc74c1d99a011dd0fb7f98f183faecda675221fce --- firmware/App/Common.h (.../Common.h) (revision f2652e85c8676d0356fea2690cfd9cac716ca795) +++ firmware/App/Common.h (.../Common.h) (revision c74c1d99a011dd0fb7f98f183faecda675221fce) @@ -1,50 +1,98 @@ -/* - * Common.h - * - * Created on: Aug 5, 2024 - * Author: fw - */ #ifndef __COMMON_H__ #define __COMMON_H__ -#define SW_UPDATE_FLASH_BUFFER_SIZE 128 +#include "BLCommon.h" +/** + * @defgroup CommonHeader CommonHeader + * @brief Provides commonly used definitions and macros. + * + * @addtogroup CommonHeader + * @{ + */ + +// ********** public definitions ********** + +#define NUM_OF_FW_STACKS 3 ///< Number of firmware stacks (TD, DD, RO). +#define CAN_MESSAGE_PAYLOAD_SIZE 8 ///< CAN message payload size in bytes. +#define FIRMWARE_START_ADDRESS 0x00010000 ///< Firmware start address. +#define FIRMWARE_CRC_TABLE_ADDRESS 0x10020 ///< The starting address of CRC table for firmware image. +#define SW_UPDATE_FLASH_BUFFER_SIZE 256 ///< Software update flash buffer bytes. +#define MASK_OFF_MSB 0x00FF ///< Bits to mask off the most significant byte of a 2-byte word +#define MASK_OFF_LSB 0xFF00 ///< Bits to mask off the least significant byte of a 2-byte word +#define SHIFT_8_BITS_FOR_BYTE_SHIFT 8 ///< Number of bits to shift in order to shift a byte +#define MASK_OFF_NIBBLE_MSB 0x0F ///< Bits to mask off the most significant nibble of a byte + +#define NUM_OF_CMD_CAN_FRAMES 1 ///< Number of command CAN frames. + +#define GET_LSB_OF_WORD(w) ((U08)((w) & MASK_OFF_MSB)) ///< Macro returns the least signficant byte of a 2-byte word. +#define GET_MSB_OF_WORD(w) ((U08)(((w) >> SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_MSB)) ///< Macro returns the most signficant byte of a 2-byte word. +#define MAKE_WORD_OF_BYTES(h, l) ((((U16)(h) << SHIFT_8_BITS_FOR_BYTE_SHIFT) & MASK_OFF_LSB) \ + | ((U16)(l) & MASK_OFF_MSB)) ///< Macro merges two bytes into a 2-byte word. +#define INC_WRAP(v, l, u) ((v) >= (u) ? (l) : ((v) + 1)) ///< Macro increments a value and wraps to a minimum when a maximum is reached. + // **** Types **** -typedef float F32; ///< 32-bit floating point type -typedef double F64; ///< 64-bit floating point type -typedef long long S64; ///< 64-bit signed integer type -typedef unsigned int U32; ///< 32-bit unsigned integer type -typedef int S32; ///< 32-bit signed integer type -typedef unsigned short U16; ///< 16-bit unsigned integer type -typedef short S16; ///< 16-bit signed integer type -typedef unsigned char U08; ///< 8-bit unsigned integer type -typedef unsigned int BOOL; ///< 32-bit boolean type -typedef unsigned char BYTE; ///< 8-bit byte type +typedef float F32; ///< 32-bit floating point type. +typedef double F64; ///< 64-bit floating point type. +typedef long long S64; ///< 64-bit signed integer type. +typedef unsigned int U32; ///< 32-bit unsigned integer type. +typedef int S32; ///< 32-bit signed integer type. +typedef unsigned short U16; ///< 16-bit unsigned integer type. +typedef short S16; ///< 16-bit signed integer type. +typedef unsigned char U08; ///< 8-bit unsigned integer type. +typedef unsigned int BOOL; ///< 32-bit boolean type. +typedef unsigned char BYTE; ///< 8-bit byte type. +/// Bootloader operations modes enumeration +typedef enum BL_Op_Modes +{ + MODE_STAND = 0, ///< Mode standby. + MODE_UPDATE, ///< Mode update. + NUM_OF_MODES ///< Number of modes. +} BL_OP_MODE_T; +/// Mode standby states enumeration +typedef enum SW_Mode_Standby_States +{ + STANDBY_CHECK_FOR_UPDATE_STATE = 0, ///< Standby check for update state. + STANDBY_CHECK_FW_AND_FPGA_IMAGES_STATE, ///< Standby check firmware and FPGA images state. + STANDBY_IDLE_STATE, ///< Standby idle state. + NUM_OF_MODE_STANDBY_STATES ///< Number of standby states. +} MODE_STANDBY_STATE_T; + +/// Mode update states enumeration +typedef enum SW_Mode_Update_States +{ + SW_UPDATE_UPDATE_STATE = 0, ///< Update update state. + SW_UPDATE_VERIFY_STATE, ///< Update verify state. + SW_UPDATE_ABORT_STATE, ///< Update abort state. + NUM_OF_MODE_SW_UPDATE_STATES ///< Number of update states. +} MODE_SW_UPDATE_STATE_T; + +/// Software update destinations enumeration typedef enum SW_Update_Destinations { - //UPDATE_NONE = 0, - UPDATE_FIRMWARE = 0, - UPDATE_FPGA, - NUM_OF_UPDAT_DESTS -} SW_UPDATE_DESINTATIONS_T; + UPDATE_FIRMWARE = 0, ///< Update firmware. + UPDATE_FPGA, ///< Update FPGA. + NUM_OF_UPDATE_DESTS ///< Number of update destinations. +} SW_UPDATE_DESINTATION_T; +/// Software update CAN mailboxes enumeration typedef enum SW_Update_CAN_Mail_Boxes { - SW_UPDATE_NOT_USED = 0, - SW_UPDATE_COMMAD, - SW_UPDATE_TD_UPDATE, - SW_UPDATE_DD_UPDATE, - SW_UPDATE_RO_UPDATE, - PLACE_HOLDER_TO_REMOVE_CAN, - SW_UPDATE_RESP, - NUM_OF_SW_UPDATE_MBOXES, -} SW_UPDATE_CAN_MAIL_BOXES_T; + SW_UPDATE_NOT_USED = 0, // 0 ///< Software update not used mailbox. + SW_UPDATE_COMMAD, // 0x601 ///< Software update command mailbox. + SW_UPDATE_TD_UPDATE, // 0x602 ///< Software update TD update mailbox. + SW_UPDATE_DD_UPDATE, // 0x603 ///< Software update DD update mailbox. + SW_UPDATE_RO_UPDATE, // 0x604 ///< Software update RO update mailbox. + PLACE_HOLDER_TO_REMOVE_CAN, // 0x605 // TODO remove + SW_UPDATE_RESP, // 0x606 ///< Software update respond mailbox. + SW_TEST, // 0x607 // TODO remove + NUM_OF_SW_UPDATE_MBOXES, ///< Number of software update mailboxes. +} SW_UPDATE_CAN_MAIL_BOX_T; - /*! Normal Protocol: UI->FW: SwUpdateCommand[cmd=start] @@ -69,31 +117,36 @@ If streaming encounters problems we use a command with Resync so that the FW will dump it's indexes and be ready for new data. */ +/// Software update commands enumeration typedef enum SW_Update_Commands { - UPDATE_CMD_START = 0, - UPDATE_CMD_ABORT, + UPDATE_CMD_START = 0, ///< Update command start. + UPDATE_CMD_ABORT, ///< Update command abort. UPDATE_CMD_RUNAPP, // TODO is this needed? - UPDATE_CMD_VERIFY, + UPDATE_CMD_VERIFY, ///< Update command verify. UPDATE_CMD_VERSION, // TODO is this needed? - UPDATE_CMD_VERIFIED, - UPDATE_CMD_RESYNC, - NUM_OF_UPDATE_CMDS -} SW_UPDATE_CMDS_T; + UPDATE_CMD_VERIFIED, // TODO is this needed? + UPDATE_CMD_RESYNC, ///< Update command resync. + UPDATE_CMD_IDLE, ///< Update command idle. + NUM_OF_UPDATE_CMDS ///< Number of update commands. +} SW_UPDATE_CMD_T; +/// Acknowledge or not acknowledge enumeration typedef enum Ack_Nack { - NACK = 0, - ACK, - NUM_OF_ACK_NACK + NACK = 0, ///< Nack. + ACK, ///< Ack. + NUM_OF_ACK_NACK ///< Number of ack/nack states. } ACK_NACK_STATUS_T; - -typedef struct +/// Software update corresponding stack mailbox +static const SW_UPDATE_CAN_MAIL_BOX_T RECEIVE_MSG_ID[ NUM_OF_FW_STACKS ] = { - BOOL isSWUpdateBufferReady; - SW_UPDATE_DESINTATIONS_T dest; -} SW_UPDATE_BUFFER_STATUS_T; + SW_UPDATE_TD_UPDATE, ///< Software update TD. + SW_UPDATE_DD_UPDATE, ///< Software update DD. + SW_UPDATE_RO_UPDATE ///< Software update RO. +}; +/**@}*/ #endif