1 /** 2 * \file 3 * 4 * \brief Special user data area access 5 * 6 * Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries. 7 * 8 * \asf_license_start 9 * 10 * \page License 11 * 12 * Subject to your compliance with these terms, you may use Microchip 13 * software and any derivatives exclusively with Microchip products. 14 * It is your responsibility to comply with third party license terms applicable 15 * to your use of third party software (including open source software) that 16 * may accompany Microchip software. 17 * 18 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, 19 * WHETHER EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, 20 * INCLUDING ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, 21 * AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT WILL MICROCHIP BE 22 * LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE, INCIDENTAL OR CONSEQUENTIAL 23 * LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND WHATSOEVER RELATED TO THE 24 * SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS BEEN ADVISED OF THE 25 * POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE FULLEST EXTENT 26 * ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN ANY WAY 27 * RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY, 28 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE. 29 * 30 * \asf_license_stop 31 * 32 */ 33 34 #ifndef _HPL_USER_DATA_H_INCLUDED 35 #define _HPL_USER_DATA_H_INCLUDED 36 37 #include <stdint.h> 38 39 #ifdef __cplusplus 40 extern "C" { 41 #endif 42 43 /** 44 * \brief Read data from user data area 45 * 46 * The user data area could be the area that stores user data that is not erased 47 * with the flash contents, e.g., 48 * - NVM Software Calibration Area of SAM D/L/C family 49 * - User Signature of SAM E/S/V 70 50 * 51 * \param[in] base The base address of the user area 52 * \param[in] offset The byte offset of the data to be read inside the area 53 * \param[out] buf Pointer to buffer to place the read data 54 * \param[in] size Size of data in number of bytes 55 * 56 * \return Operation status or bytes read. 57 * \retval ERR_NONE Data read successfully 58 * \retval ERR_UNSUPPORTED_OP base address not in any supported user area 59 * \retval ERR_BAD_ADDRESS offset not in right area 60 * \retval ERR_INVALID_ARG offset and size exceeds the right area 61 */ 62 int32_t _user_area_read(const void *base, const uint32_t offset, uint8_t *buf, const uint32_t size); 63 64 /** 65 * \brief Read no more than 32 bits data from user data area 66 * 67 * When reading bits, the bitfield can cross 32-bis boundaries. 68 * 69 * \param[in] base The base address of the user area 70 * \param[in] bit_offset Offset in number of bits 71 * \param[in] n_bits Number of bits to read 72 * \return data read, assert if anything wrong (address not in user area 73 * offset, size error, etc.). 74 */ 75 uint32_t _user_area_read_bits(const void *base, const uint32_t bit_offset, const uint8_t n_bits); 76 77 /** 78 * \brief Write data to user data area 79 * 80 * The user data area could be the area that stores user data that is not erased 81 * with the flash contents, e.g., 82 * - NVM Software Calibration Area of SAM D/L/C family 83 * - User Signature of SAM E/S/V 70 84 * 85 * When assigned offset and size exceeds the data area, error is reported. 86 * 87 * \param[out] base The base address of the user area 88 * \param[in] offset The offset of the data to be written inside the area 89 * \param[in] buf Pointer to buffer to place the written data 90 * \param[in] size Size of data in number of bytes 91 * 92 * \return Operation status or bytes writting. 93 * \retval ERR_NONE Data written successfully 94 * \retval ERR_UNSUPPORTED_OP base address not in any supported user area 95 * \retval ERR_DENIED Security bit is set 96 * \retval ERR_BAD_ADDRESS offset not in right area 97 * \retval ERR_INVALID_ARG offset and size exceeds the right area 98 */ 99 int32_t _user_area_write(void *base, const uint32_t offset, const uint8_t *buf, const uint32_t size); 100 101 /** 102 * \brief Write no more than 32 bits data to user data area 103 * 104 * When writting bits, the bitfield can cross 32-bis boundaries. 105 * 106 * \param[out] base The base address of the user area 107 * \param[in] bit_offset Offset in number of bits 108 * \param[in] bits The data content 109 * \param[in] n_bits Number of bits to write 110 * \return Operation result 111 * \retval ERR_NONE Data written successfully 112 * \retval ERR_UNSUPPORTED_OP base address not in any supported user area 113 * \retval ERR_DENIED Security bit is set 114 * \retval ERR_BAD_ADDRESS offset not in right area 115 * \retval ERR_INVALID_ARG offset and size exceeds the right area 116 */ 117 int32_t _user_area_write_bits(void *base, const uint32_t bit_offset, const uint32_t bits, const uint8_t n_bits); 118 119 #ifdef __cplusplus 120 } 121 #endif 122 123 #endif /* _HPL_USER_DATA_H_INCLUDED */ 124