/* * Common.h * * Created on: Aug 5, 2024 * Author: fw */ #ifndef __COMMON_H__ #define __COMMON_H__ #include "BLCommon.h" #define NUM_OF_FW_STACKS 3 #define CAN_MESSAGE_PAYLOAD_SIZE 8 #define FIRMWARE_START_ADDRESS 0x00010000 #define FIRMWARE_CRC_TABLE_ADDRESS 0x10020 ///< The starting address of CRC table for firmware image. #define SW_UPDATE_FLASH_BUFFER_SIZE 256 #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 #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 enum BL_Op_Modes { MODE_STAND = 0, MODE_UPDATE, NUM_OF_MODES } BL_OP_MODE_T; typedef enum SW_Mode_Standby_States { STANDBY_CHECK_FOR_UPDATE_STATE = 0, STANDBY_CHECK_FW_AND_FPGA_IMAGES_STATE, STANDBY_IDLE_STATE, NUM_OF_MODE_STANDBY_STATES } MODE_STANDBY_STATE_T; typedef enum SW_Mode_Update_States { SW_UPDATE_UPDATE_STATE = 0, SW_UPDATE_VERIFY_STATE, SW_UPDATE_ABORT_STATE, NUM_OF_MODE_SW_UPDATE_STATES } MODE_SW_UPDATE_STATE_T; typedef enum SW_Update_Destinations { UPDATE_FIRMWARE = 0, UPDATE_FPGA, NUM_OF_UPDATE_DESTS } SW_UPDATE_DESINTATION_T; typedef enum SW_Update_CAN_Mail_Boxes { SW_UPDATE_NOT_USED = 0, // 0 SW_UPDATE_COMMAD, // 0x601 SW_UPDATE_TD_UPDATE, // 0x602 SW_UPDATE_DD_UPDATE, // 0x603 SW_UPDATE_RO_UPDATE, // 0x604 PLACE_HOLDER_TO_REMOVE_CAN, // 0x605 SW_UPDATE_RESP, // 0x606 SW_TEST, // 0x607 // TODO remove NUM_OF_SW_UPDATE_MBOXES, } SW_UPDATE_CAN_MAIL_BOX_T; /*! Normal Protocol: UI->FW: SwUpdateCommand[cmd=start] FW->UI: Secure Ack/Nack loop UI->FW: Data FW->UI: Secure Ack/Nack <- Also flow control. end UI->FW: Verify FW->UI: SwUpdateVerifyResponse UI->FW: Version FW->UI: SwUpdateVerifyResponse UI->FW: Verified UI thinks things are good. FW->UI: ACK/NACK FW has agreed or not and set the FLASH memory that the image is good or not. UI->FW: RunApp Launch the main app. FW->UI: Secure Ack/Nack 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. */ typedef enum SW_Update_Commands { UPDATE_CMD_START = 0, UPDATE_CMD_ABORT, UPDATE_CMD_RUNAPP, // TODO is this needed? UPDATE_CMD_VERIFY, UPDATE_CMD_VERSION, // TODO is this needed? UPDATE_CMD_VERIFIED, UPDATE_CMD_RESYNC, UPDATE_CMD_IDLE, NUM_OF_UPDATE_CMDS } SW_UPDATE_CMD_T; typedef enum Ack_Nack { NACK = 0, ACK, NUM_OF_ACK_NACK } ACK_NACK_STATUS_T; static const SW_UPDATE_CAN_MAIL_BOX_T RECEIVE_MSG_ID[ NUM_OF_FW_STACKS ] = { SW_UPDATE_TD_UPDATE, SW_UPDATE_DD_UPDATE, SW_UPDATE_RO_UPDATE }; #endif