| Linduino 1.3.0 Linear Technology Arduino-Compatible Demonstration Board

nvm.cpp
Go to the documentation of this file.
1 /*!
2
3 Copyright 2018(c) Analog Devices, Inc.
4
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9 - Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11 - Redistributions in binary form must reproduce the above copyright
12 notice, this list of conditions and the following disclaimer in
13 the documentation and/or other materials provided with the
14 distribution.
15 - Neither the name of Analog Devices, Inc. nor the names of its
16 contributors may be used to endorse or promote products derived
17 from this software without specific prior written permission.
18 - The use of this software may or may not infringe the patent rights
19 of one or more patent holders. This license does not release you
20 from the requirement that you obtain separate licenses from these
21 patent holders to use this software.
22 - Use of the software either in source or binary form, must be run
23 on or directly connected to an Analog Devices Inc. component.
24
25 THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
26 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
27 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
28 IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30 LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
31 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
34 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 */
36
37 //! @ingroup PMBus_SMBus
38 //! @{
39 //! @defgroup LTPSM_InFlightUpdate LTPSM_InFlightUpdate
40 //! @}
41
42 /*! @file
43 @ingroup LTPSM_InFlightUpdate
44 Library File
45 */
46
47 #include "nvm.h"
48
49 #define DEBUG_FLASH 0
50
51 const unsigned char *icpFile;
52 uint32_t flashLocation = 0;
53
54 LT_SMBusNoPec *smbusNoPec__;
55 LT_SMBusPec *smbusPec__;
56
57 uint8_t get_hex_data(void)
58 {
59 uint8_t c = '\0';
60 #if (DEBUG_FLASH)
61 Serial.print("Loc ");
62 Serial.println(flashLocation, HEX);
63 #endif
64 c = pgm_read_byte_near(icpFile + flashLocation++);
65 #if (DEBUG_FLASH)
66 Serial.print("Raw ");
67 Serial.println(c, HEX);
68 #endif
69 if ('\0' != c)
70 return c;
71 else
72 return 0;
73 }
74
75 uint8_t get_filtered_hex_data(void)
76 {
77 return filter_terminations(get_hex_data);
78 }
79
80 uint8_t get_record_data(void)
81 {
82 return parse_hex(get_filtered_hex_data);
83 }
84
85 pRecordHeaderLengthAndType get_record(void)
86 {
87 return parse_record(get_record_data);
88 }
89
90 NVM::NVM(LT_SMBusNoPec *smbusNoPec, LT_SMBusPec *smbusPec)
91 {
92 smbusNoPec__ = smbusNoPec;
93 smbusPec__ = smbusPec;
94 }
95
96 bool NVM::programWithData(const unsigned char *data)
97 {
98 icpFile = data;
99 flashLocation = 0;
100
101 reset_parse_hex();
102 if (processRecordsOnDemand(get_record) == 0)
103 {
104 reset_parse_hex();
105 return 0;
106 }
107 reset_parse_hex();
108 return 1;
109 }
110
111 bool NVM::verifyWithData(const unsigned char *data)
112 {
113 icpFile = data;
114 flashLocation = 0;
115
116 reset_parse_hex();
117 if (verifyRecordsOnDemand(get_record) == 0)
118 {
119 reset_parse_hex();
120 return 0;
121 }
122 reset_parse_hex();
123 return 1;
124 }
NVM::NVM
NVM(LT_SMBusNoPec *, LT_SMBusPec *)
Constructor.
Definition: nvm.cpp:90
icpFile
const unsigned char * icpFile
Definition: nvm.cpp:51
parse_record
pRecordHeaderLengthAndType parse_record(uint8_t(*get_data)(void))
Definition: hex_file_parser.cpp:213
smbusPec__
LT_SMBusPec * smbusPec__
Definition: nvm.cpp:55
smbusPec
static LT_SMBusPec * smbusPec
Definition: device_logger.ino:85
LT_SMBusNoPec
Definition: LT_SMBusNoPec.h:60
verifyRecordsOnDemand
uint8_t verifyRecordsOnDemand(pRecordHeaderLengthAndType(*getRecord)(void))
Definition: main_record_processor.cpp:224
get_hex_data
uint8_t get_hex_data(void)
Definition: nvm.cpp:57
NVM::programWithData
bool programWithData(const unsigned char *)
Program with hex data.
Definition: nvm.cpp:96
smbusNoPec__
LT_SMBusNoPec * smbusNoPec__
Definition: nvm.cpp:54
reset_parse_hex
void reset_parse_hex()
Definition: hex_file_parser.cpp:79
nvm.h
Copyright 2018(c) Analog Devices, Inc.
LT_SMBusPec
Definition: LT_SMBusPec.h:61
parse_hex
uint8_t parse_hex(uint8_t(*get_data)(void))
Definition: hex_file_parser.cpp:95
data
union LT_union_int32_4bytes data
Definition: DC2094A.ino:138
get_record
pRecordHeaderLengthAndType get_record(void)
Definition: nvm.cpp:85
NVM::verifyWithData
bool verifyWithData(const unsigned char *)
Verifies board NVM with hex data.
Definition: nvm.cpp:111
processRecordsOnDemand
uint8_t processRecordsOnDemand(pRecordHeaderLengthAndType(*getRecord)(void))
Definition: main_record_processor.cpp:91
filter_terminations
uint8_t filter_terminations(uint8_t(*get_data)(void))
Definition: hex_file_parser.cpp:53
get_record_data
uint8_t get_record_data(void)
Definition: nvm.cpp:80
tRecordHeader
Basic Record Type Definitions.
Definition: record_type_basic_definitions.h:52
smbusNoPec
static LT_SMBusNoPec * smbusNoPec
Definition: device_logger.ino:84
get_filtered_hex_data
uint8_t get_filtered_hex_data(void)
Definition: nvm.cpp:75
flashLocation
uint32_t flashLocation
Definition: nvm.cpp:52