1#include "spi_flash/include/spi_flash.h"
6 uint32_t
test = 0x11223344;
7 uint8_t *pTest =
reinterpret_cast<uint8_t *
>(&
test);
8 return pTest[0] == 0x11;
16 uint8_t *pFrom =
reinterpret_cast<uint8_t *
>(&from);
18 to = pFrom[0]; to <<= 8;
19 to |= pFrom[1]; to <<= 8;
20 to |= pFrom[2]; to <<= 8;
31 uint8_t *pFrom =
reinterpret_cast<uint8_t *
>(&from);
33 to = pFrom[0]; to <<= 8;
52 uint16_t payloadLength;
59#define CMD_READ_FLASH 0x01
60#define CMD_WRITE_FLASH 0x02
61#define CMD_ERASE_FLASH 0x03
62#define CMD_MAX_PAYLOAD_SIZE 0x50
67 int ret = chnReadTimeout(&
SDU1, &buf, 1, TIME_MS2I(1));
78 uint8_t *p =
reinterpret_cast<uint8_t *
>(
pkt);
94 l =
pkt->payloadLength;
110 chnWriteTimeout(&
SDU1, data, length, TIME_MS2I(100));
114 size_t len = strlen(str);
115 serialPrint(
reinterpret_cast<const uint8_t*
>(str), len);
121 if (M2M_SUCCESS != m2m_wifi_download_mode()) {
135 chThdSleepMilliseconds(1);
140 if (
pkt.command == CMD_HELLO) {
141 if (
pkt.address == 0x11223344 &&
pkt.arg1 == 0x55667788) {
146 if (
pkt.command == CMD_MAX_PAYLOAD_SIZE) {
148 serialPrint(
reinterpret_cast<uint8_t *
>(&res),
sizeof(res));
151 if (
pkt.command == CMD_READ_FLASH) {
152 uint32_t address =
pkt.address;
153 uint32_t len =
pkt.arg1;
154 if (spi_flash_read(
payload, address, len) != M2M_SUCCESS) {
162 if (
pkt.command == CMD_WRITE_FLASH) {
163 uint32_t address =
pkt.address;
164 uint32_t len =
pkt.payloadLength;
165 if (spi_flash_write(
payload, address, len) != M2M_SUCCESS) {
172 if (
pkt.command == CMD_ERASE_FLASH) {
173 uint32_t address =
pkt.address;
174 uint32_t len =
pkt.arg1;
175 if (spi_flash_erase(address, len) != M2M_SUCCESS) {
typedef __attribute__
Ignition Mode.
A base class for a controller that requires its own thread.
virtual void ThreadTask()=0
bool is_usb_serial_ready()
void usb_serial_start(void)
Main function of PDL.
static uint16_t flashSize()
static uint16_t toNetwork16(uint16_t to)
static uint8_t payload[MAX_PAYLOAD_SIZE]
static void serialPrint(const uint8_t *data, size_t length)
static uint32_t fromNetwork32(uint32_t from)
static const int MAX_PAYLOAD_SIZE
static bool isBigEndian()
static uint16_t fromNetwork16(uint16_t from)
static void receivePacket(UartPacket *pkt, uint8_t *payload)
static uint32_t toNetwork32(uint32_t to)
static void serialPrintStr(const char *str)
static WifiUpdaterThread wifiUpdater