diff options
Diffstat (limited to 'src/import')
-rw-r--r-- | src/import/chips/ocmb/explorer/procedures/hwp/memory/lib/i2c/exp_i2c_fields.H | 32 | ||||
-rw-r--r-- | src/import/generic/memory/lib/utils/mss_field.H | 94 |
2 files changed, 81 insertions, 45 deletions
diff --git a/src/import/chips/ocmb/explorer/procedures/hwp/memory/lib/i2c/exp_i2c_fields.H b/src/import/chips/ocmb/explorer/procedures/hwp/memory/lib/i2c/exp_i2c_fields.H index df60c4e5..dd9fa1f6 100644 --- a/src/import/chips/ocmb/explorer/procedures/hwp/memory/lib/i2c/exp_i2c_fields.H +++ b/src/import/chips/ocmb/explorer/procedures/hwp/memory/lib/i2c/exp_i2c_fields.H @@ -50,25 +50,25 @@ namespace i2c /// /// @class fields /// @brief Explorer I2C command fields +/// @tparam E Endian type /// struct fields { // First value is byte index, then buffer extract start bit, and extract data length // Part of EXP_FW_BOOT_CONFIG - static constexpr mss::field_t BOOT_MODE{0, 0, 1}; - static constexpr mss::field_t LANE_MODE{0, 1, 3}; - static constexpr mss::field_t SERDES_FREQ{0, 4, 4}; - - static constexpr mss::field_t FW_MODE{1, 2, 1}; - static constexpr mss::field_t LOOPBACK_TEST{1, 3, 1}; - static constexpr mss::field_t TRANSPORT_LAYER{1, 4, 2}; - static constexpr mss::field_t DL_LAYER_BOOT_MODE{1, 6, 2}; + static constexpr mss::field_t<mss::endian::BIG> BOOT_MODE{0, 0, 1}; + static constexpr mss::field_t<mss::endian::BIG> LANE_MODE{0, 1, 3}; + static constexpr mss::field_t<mss::endian::BIG> SERDES_FREQ{0, 4, 4}; + static constexpr mss::field_t<mss::endian::BIG> FW_MODE{1, 2, 1}; + static constexpr mss::field_t<mss::endian::BIG> LOOPBACK_TEST{1, 3, 1}; + static constexpr mss::field_t<mss::endian::BIG> TRANSPORT_LAYER{1, 4, 2}; + static constexpr mss::field_t<mss::endian::BIG> DL_LAYER_BOOT_MODE{1, 6, 2}; // Part of EXP_FW_STATUS - static constexpr mss::field_t CMD_ID{0, 0, 8}; - static constexpr mss::field_t STATUS_CODE{1, 0, 8}; - static constexpr mss::field_t BOOT_STAGE{2, 6, 2}; + static constexpr mss::field_t<mss::endian::BIG> CMD_ID{0, 0, 8}; + static constexpr mss::field_t<mss::endian::BIG> STATUS_CODE{1, 0, 8}; + static constexpr mss::field_t<mss::endian::BIG> BOOT_STAGE{2, 6, 2}; }; /// @@ -76,7 +76,7 @@ struct fields /// @brief Traits assoiated with the Explorer I2C commands /// @tparam F the Explorer I2C field /// -template < const field_t& F > +template < const mss::field_t<endian::BIG>& F > struct fieldTraits; /// @@ -230,7 +230,7 @@ struct fieldTraits<fields::BOOT_STAGE> /// @param[out] o_value the output value received /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< const mss::field_t<endian::BIG>& F, typename IT, typename OT, typename TT = fieldTraits<F> > @@ -238,7 +238,7 @@ inline fapi2::ReturnCode get_field(const fapi2::Target<fapi2::TARGET_TYPE_OCMB_C const std::vector<IT>& i_data, OT& o_value) { - return mss::get_field<F, TT>(i_target, i_data, EXP_I2C_GET_FIELD, o_value); + return mss::get_field<endian::BIG, F, TT>(i_target, i_data, EXP_I2C_GET_FIELD, o_value); } /// @@ -251,7 +251,7 @@ inline fapi2::ReturnCode get_field(const fapi2::Target<fapi2::TARGET_TYPE_OCMB_C /// @param[in,out] io_data the buffer as a reference to a vector /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< const mss::field_t<endian::BIG>& F, typename IT, typename OT, typename TT = fieldTraits<F> > @@ -260,7 +260,7 @@ inline fapi2::ReturnCode set_field(const fapi2::Target<fapi2::TARGET_TYPE_OCMB_C const IT i_value) { - return mss::set_field<F, TT>(i_target, i_value, EXP_I2C_SET_FIELD, io_data); + return mss::set_field<endian::BIG, F, TT>(i_target, i_value, EXP_I2C_SET_FIELD, io_data); } namespace boot_cfg diff --git a/src/import/generic/memory/lib/utils/mss_field.H b/src/import/generic/memory/lib/utils/mss_field.H index f0a9abd5..92bf014b 100644 --- a/src/import/generic/memory/lib/utils/mss_field.H +++ b/src/import/generic/memory/lib/utils/mss_field.H @@ -44,10 +44,21 @@ namespace mss { /// +/// @brief endian fields for use as a template selecor +/// +enum class endian +{ + BIG, + LITTLE, +}; + +/// /// @class field_t /// @brief data structure for byte fields +/// @tparam E endian type for this field /// @note holds byte index, start bit, and bit length of a decoded field /// +template< endian E > class field_t { private: @@ -84,10 +95,7 @@ class field_t /// @brief Byte index getter /// @return the byte index for this field /// - constexpr size_t get_byte() const - { - return iv_byte; - } + const size_t get_byte(const std::vector<uint8_t>& i_data) const; /// /// @brief Starting bit getter @@ -110,6 +118,26 @@ class field_t };// field_t /// +/// @brief Byte index getter - big endian specialization +/// @return the byte index for this field +/// +template<> +inline const size_t field_t<mss::endian::BIG>::get_byte(const std::vector<uint8_t>& i_data) const +{ + return ( i_data.size() - 1 ) - iv_byte; +} + +/// +/// @brief Byte index getter - big endian specialization +/// @return the byte index for this field +/// +template<> +inline const size_t field_t<mss::endian::LITTLE>::get_byte(const std::vector<uint8_t>& i_data) const +{ + return iv_byte; +} + +/// /// @brief Checks input field against a custom conditional /// @tparam T field input type /// @tparam F Callable object type @@ -119,15 +147,16 @@ class field_t /// @return boolean true or false /// template < typename T, typename F > -bool conditional(const T i_field, - const size_t i_comparison_val, - const F i_op) +inline bool conditional(const T i_field, + const size_t i_comparison_val, + const F i_op) { return i_op(i_field, i_comparison_val); } /// /// @brief Helper function to extract byte information +/// @tparam E endian type /// @tparam F the field to extract /// @tparam T the fapi2 target type /// @tparam IT data input type @@ -139,17 +168,18 @@ bool conditional(const T i_field, /// @param[out] o_value raw value for this field /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< mss::endian E, + const mss::field_t<E>& F, fapi2::TargetType T, typename IT, typename OT, typename FFDC > -fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target, - const std::vector<IT>& i_data, - const FFDC i_ffdc_codes, - OT& o_value) +inline fapi2::ReturnCode get_field(const fapi2::Target<T>& i_target, + const std::vector<IT>& i_data, + const FFDC i_ffdc_codes, + OT& o_value) { - constexpr size_t BYTE = F.get_byte(); + const size_t BYTE = F.get_byte(i_data); FAPI_ASSERT( BYTE < i_data.size(), fapi2::MSS_OUT_OF_BOUNDS_INDEXING() @@ -184,6 +214,7 @@ fapi_try_exit: /// /// @brief Helper function to set byte field information +/// @tparam E endian type /// @tparam F the field to extract /// @tparam T the fapi2 target type /// @tparam IT data input type @@ -195,17 +226,18 @@ fapi_try_exit: /// @param[in,out] io_data the data to modify /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< mss::endian E, + const mss::field_t<E>& F, fapi2::TargetType T, typename IT, typename OT, typename FFDC > -fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target, - const IT i_setting, - const FFDC i_ffdc_codes, - std::vector<OT>& io_data) +inline fapi2::ReturnCode set_field(const fapi2::Target<T>& i_target, + const IT i_setting, + const FFDC i_ffdc_codes, + std::vector<OT>& io_data) { - constexpr size_t BYTE = F.get_byte(); + const size_t BYTE = F.get_byte(io_data); FAPI_ASSERT( BYTE < io_data.size(), fapi2::MSS_OUT_OF_BOUNDS_INDEXING() @@ -242,6 +274,7 @@ fapi_try_exit: /// /// @brief byte field reader +/// @tparam E endian type /// @tparam F the byte field to read /// @tparam TT traits associated with F - required /// @tparam T the fapi2 target type @@ -253,7 +286,8 @@ fapi_try_exit: /// @param[out] o_value raw value for this field /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< mss::endian E, + const mss::field_t<E>& F, typename TT, fapi2::TargetType T, typename IT, @@ -265,7 +299,7 @@ inline fapi2::ReturnCode get_field( const fapi2::Target<T>& i_target, OT& o_value ) { IT l_temp = 0; - FAPI_TRY( get_field<F>(i_target, i_data, i_ffdc_codes, l_temp), + FAPI_TRY( (get_field<E, F>(i_target, i_data, i_ffdc_codes, l_temp)), "Failed get_field() for %s", spd::c_str(i_target) ); // Test if retrieved data seems valid @@ -273,7 +307,7 @@ inline fapi2::ReturnCode get_field( const fapi2::Target<T>& i_target, conditional( l_temp, TT::COMPARISON_VAL, typename TT::template COMPARISON_OP<IT>() ), - F.get_byte(), + F.get_byte(i_data), l_temp, i_ffdc_codes), "Failed fail_for_invalid_value() for %s", spd::c_str(i_target) ); @@ -301,6 +335,7 @@ fapi_try_exit: /// /// @brief byte field writer +/// @tparam E endian type /// @tparam F the byte field to read /// @tparam TT traits associated with writer /// @tparam T the fapi2 target type @@ -313,18 +348,19 @@ fapi_try_exit: /// @param[in,out] io_data the data to modify /// @return FAPI2_RC_SUCCESS iff okay /// -template< const field_t& F, +template< mss::endian E, + const mss::field_t<E>& F, typename TT, fapi2::TargetType T, typename IT, typename OT, typename FFDC > -fapi2::ReturnCode set_field( const fapi2::Target<T>& i_target, - const IT i_setting, - const FFDC i_ffdc_codes, - std::vector<OT>& io_data ) +inline fapi2::ReturnCode set_field( const fapi2::Target<T>& i_target, + const IT i_setting, + const FFDC i_ffdc_codes, + std::vector<OT>& io_data ) { - constexpr size_t BYTE = F.get_byte(); + const size_t BYTE = F.get_byte(io_data); // Test if the data we want to set is valid for this field FAPI_TRY( check::invalid_value(i_target, @@ -336,7 +372,7 @@ fapi2::ReturnCode set_field( const fapi2::Target<T>& i_target, i_ffdc_codes), "Failed fail_for_invalid_value() for %s", spd::c_str(i_target) ); - FAPI_TRY( set_field<F>(i_target, i_setting, i_ffdc_codes, io_data), + FAPI_TRY( (set_field<E, F>(i_target, i_setting, i_ffdc_codes, io_data)), "Failed set_field() for %s", spd::c_str(i_target) ); FAPI_INF("%s: Set value of 0x%02x. Data for buffer at byte %d, is now 0x%02x for %s", |