VitroIO SDK
Software development kit for Vitro Shard.
Loading...
Searching...
No Matches
upgrade_controller.h
Go to the documentation of this file.
1#ifndef VITROIO_SDK_UPGRADE_CONTROLLER_H
2#define VITROIO_SDK_UPGRADE_CONTROLLER_H
3
4#include <mbed.h>
5
8
9#include <vitroio-sdk/types.h>
10
11namespace vitroio
12{
13
14namespace sdk
15{
16
17namespace impl
18{
19
31#define VITROIO_UPGRADE_CONTROLLER_DEFAULT_EVENT_QUEUE_SIZE 32
32
33class FlashInterface;
34
38class UpgradeController : private NonCopyable<UpgradeController>
39{
40public:
45 typedef Callback<void()> OnNewFirmwareAvailableCallback;
46
64 FlashInterface* flash,
65 FirmwareId fwId,
66 Version fwVersion,
68 EventQueue* eventQueue
69 );
70
75
84 bool isValid() const;
85
95 void configure(FlashSpace flashSpace);
96
103 void processData(const uint8_t* data, uint32_t size);
104
105private:
110 class SegmentDecoder
111 {
112 public:
113 static SegmentDecoder* create(const uint8_t* data, uint32_t size);
114
115 ~SegmentDecoder();
116
117 uint32_t segment();
118 uint32_t segmentsCount();
119 uint8_t* data();
120 const uint8_t* data() const;
121 uint32_t dataSize();
122
123 bool setBuffer(const uint8_t* data, uint32_t size);
124
125 static uint32_t allocated();
126 static uint32_t deleted();
127
128 private:
129 SegmentDecoder();
130
131 static const uint8_t dataOffset_ = 4;
132 static uint32_t allocated_;
133 static uint32_t deleted_;
134
135 Buffer buffer_;
136 };
137
138 bool valid_;
139
140 FlashInterface* flash_;
141 FirmwareId fwId_;
142 Version fwVersion_;
143 FlashSpace flashSpace_;
144 OnNewFirmwareAvailableCallback onNewFirmwareAvailableCallback_;
145
146 EventQueue* eventQueue_;
147 Mutex mutex_;
148
149 uint32_t nextSegment_;
150 Buffer sectorBuffer_;
151 FlashSpace currentFlashSpace_;
152 uint32_t flashedBytes_;
153 bool upgradeProcessRunning_;
154 bool breakIncorrectUpdate;
155 //
156 // TODO:
157 // - consider make sizes of these queues configurable
158 //
159 Queue<SegmentDecoder, 64> segmentsToProcessQueue_;
160 Queue<SegmentDecoder, 64> notUsedSegmentsQueue_;
161
162 void processSegments();
163 bool processSegment(SegmentDecoder* sd);
164
165 void cleanup();
166
167 bool writeSectorBufferToFlash();
168
169 //
170 // Inserts segment into notUsedSegmentsQueue_ or deletes it
171 // when the queue is full.
172 //
173 void setSegmentNotUsed(SegmentDecoder* segment);
174
175 //
176 // Returns not used segment or NULL when there aren't not used segments.
177 //
178 SegmentDecoder* getNotUsedSegment();
179
180 //
181 // Inserts segment to segmentsToProcessQueue_.
182 // Returns true on success or false when the queue is full.
183 //
184 bool setSegmentToProcess(SegmentDecoder* segment);
185
186 //
187 // Returns segment from segmentsToProcessQueue_ or NULL when the queue
188 // is empty.
189 //
190 SegmentDecoder* getSegmentToProcess();
191};
192
197} // namespace impl
198
199} // namespace sdk
200
201} // namespace vitroio
202
203#endif // VITROIO_SDK_UPGRADE_CONTROLLER_H
Definition: buffer.h:16
Class is a wrapper for mbed::FlashIAP module.
Definition: flash_interface.h:26
Class is responsible for handling upgrade data.
Definition: upgrade_controller.h:39
bool isValid() const
Function allows to check whether the controller is in valid state.
void processData(const uint8_t *data, uint32_t size)
Function processes upgrade data.
void configure(FlashSpace flashSpace)
Function configures the controller.
Callback< void()> OnNewFirmwareAvailableCallback
Type defines signature of the callback function which is to be called when the new firmware will be a...
Definition: upgrade_controller.h:45
UpgradeController(FlashInterface *flash, FirmwareId fwId, Version fwVersion, OnNewFirmwareAvailableCallback callback, EventQueue *eventQueue)
Constructor.
The namespace contains all of components of vitro-shard-sdk and components based on the sdk....
Definition: can_layer.h:9
Definition: types.h:22
Structure representing space of flash memory.
Definition: types.h:79
Structure representing version in format major.minor.patch.
Definition: types.h:47
The file contains types used by vitro-shard-sdk.