1 /******************************************************************************
3 @file oad_storage.h
5 @brief OAD Storage Header
7 Group: WCS LPC
8 $Target Devices: Linux: AM335x, Embedded Devices: CC1310, CC1350, CC1352$
10 ******************************************************************************
11 $License: BSD3 2016 $
13 Copyright (c) 2015, Texas Instruments Incorporated
14 All rights reserved.
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions
18 are met:
20 * Redistributions of source code must retain the above copyright
21 notice, this list of conditions and the following disclaimer.
23 * Redistributions in binary form must reproduce the above copyright
24 notice, this list of conditions and the following disclaimer in the
25 documentation and/or other materials provided with the distribution.
27 * Neither the name of Texas Instruments Incorporated nor the names of
28 its contributors may be used to endorse or promote products derived
29 from this software without specific prior written permission.
31 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
32 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
33 THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
34 PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
35 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
36 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
37 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
38 OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
39 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
40 OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
41 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 ******************************************************************************
43 $Release Name: TI-15.4Stack Linux x64 SDK$
44 $Release Date: Sept 27, 2017 (2.04.00.13)$
45 *****************************************************************************/
46 #ifndef OADStorage_H
47 #define OADStorage_H
49 #ifdef __cplusplus
50 extern "C"
51 {
52 #endif
54 /*********************************************************************
55 * INCLUDES
56 */
57 #include <stdint.h>
58 #include <stdbool.h>
60 #include "oad_image_header.h"
62 /*********************************************************************
63 * CONSTANTS
64 */
65 // OAD payload overheads
66 #define OAD_ATT_OVERHEAD 3
67 #define OAD_BLK_NUM_HDR_SZ 4
69 #define OAD_DEFAULT_BLOCK_SIZE 128
71 #define BIM_START 0x1F000
73 /// OADStorage_Status_t status codes
74 typedef enum {
75 OADStorage_Status_Success, ///< Success
76 OADStorage_Failed, ///< Fail
77 OADStorage_CrcError, ///< Acknowledgment or Response Timed out
78 OADStorage_FlashError, ///< flash access error
79 OADStorage_Aborted, ///< Canceled by application
80 OADStorage_Rejected, ///< OAD request rejected by application
81 } OADStorage_Status_t;
83 /* Image Identify Payload */
84 typedef struct __attribute__((packed))
85 {
86 uint8_t imgID[8]; //!< User-defined Image Identification bytes. */
87 uint8_t bimVer; //!< BIM version */
88 uint8_t metaVer; //!< Metadata version */
89 uint8_t imgCpStat; //!< Image copy status bytes */
90 uint8_t crcStat; //!< CRC status */
91 uint8_t imgType; //!< Image Type */
92 uint8_t imgNo; //!< Image number of 'image type' */
93 uint32_t len; //!< Image length in octets
94 uint8_t softVer[4]; //!< Software version of the image */
95 } OADStorage_imgIdentifyPld_t;
97 /*********************************************************************
98 * MACROS
99 */
101 /*********************************************************************
102 * TYPEDEFS
103 */
105 /*********************************************************************
106 * EXTERNAL VARIABLES
107 */
110 /*********************************************************************
111 * FUNCTIONS
112 */
114 /*********************************************************************
115 * @fn OADStorage_init
116 *
117 * @brief Initialise the OAD Target Profile.
118 *
119 * @param None.
120 *
121 * @return None.
122 */
123 extern void OADStorage_init(void);
125 #if NOT_PORTED
126 /*********************************************************************
127 * @fn OADStorage_imgIdentifyRead
128 *
129 * @brief Read Image header and return number of blocks.
130 *
131 * @param imageType - image type indicating which image to read
132 * @param pImgHdr - pointer to image header data
133 *
134 * @return Total Blocks if image accepted, 0 if Image invalid
135 */
136 uint16_t OADStorage_imgIdentifyRead(uint8_t imageType, OADTarget_ImgHdr_t *pImgHdr);
137 #endif
139 /*********************************************************************
140 * @fn OADStorage_imgIdentifyWrite
141 *
142 * @brief Process the Image Identify Write. Determine from the received OAD
143 * Image Header if the Downloaded Image should be acquired.
144 *
145 * @param pValue - pointer to data to be written
146 *
147 * @return Total Blocks if image accepted, 0 if Image rejected
148 */
149 extern uint16_t OADStorage_imgIdentifyWrite(uint8_t *pValue);
151 /*********************************************************************
152 * @fn OADStorage_imgBlockRead
153 *
154 * @brief Read Image Block.
155 *
156 * @param blockNum - block number to be written
157 * @param pBlockData - pointer for data to be read
158 *
159 * @return none
160 */
161 extern void OADStorage_imgBlockRead(uint16_t blockNum, uint8_t *pBlockData);
163 /*********************************************************************
164 * @fn OADStorage_imgInfoRead
165 *
166 * @brief Read an Image info.
167 *
168 * @param pimgInfo - pointer for data to be read
169 *
170 * @return none
171 */
172 extern void OADStorage_imgInfoRead(uint8_t *pimgInfo);
174 /*********************************************************************
175 * @fn OADStorage_imgBlockWrite
176 *
177 * @brief Write Image Block.
178 *
179 * @param blockNum - block number to be written
180 * @param pBlockData - pointer to data to be written
181 * @param len - length fo block
182 *
183 * @return status
184 */
185 extern uint8_t OADStorage_imgBlockWrite(uint32_t blockNum, uint8_t *pBlockData, uint8_t len);
187 /*********************************************************************
188 * @fn OADStorage_imgFinalise
189 *
190 * @brief Process the Image Block Write.
191 *
192 * @param none
193 *
194 * @return status
195 */
196 extern OADStorage_Status_t OADStorage_imgFinalise(void);
198 /*********************************************************************
199 * @fn OADStorage_close
200 *
201 * @brief Releases the resource required for OAD stoarage.
202 *
203 * @param none
204 *
205 * @return none
206 */
207 extern void OADStorage_close(void);
209 /*********************************************************************
210 *********************************************************************/
212 #ifdef __cplusplus
213 }
214 #endif
216 #endif /* OADStorage_H */