|
|
@@ -1,4 +1,4 @@
|
|
|
-/* Copyright 2018 Espressif Systems (Shanghai) PTE LTD
|
|
|
+/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
|
|
*
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
@@ -17,23 +17,39 @@
|
|
|
#include "serial_comm.h"
|
|
|
#include "serial_comm_prv.h"
|
|
|
#include "serial_io_mock.h"
|
|
|
+#include "esp_loader.h"
|
|
|
#include "serial_io.h"
|
|
|
-#include "loader.h"
|
|
|
#include <string.h>
|
|
|
#include <stdio.h>
|
|
|
+#include <array>
|
|
|
#include <iostream>
|
|
|
#include <algorithm>
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
-#define TEST_SLIP_PACKET '\xdb', 'a', 'b', 'c', '\xc0', '\xdb', \
|
|
|
- 'd', 'e', '\xc0', 'f', '\xdb'
|
|
|
|
|
|
-#define SLIP_ENCODED_PACKET '\xdb', '\xdd', 'a', 'b', 'c', '\xdb', '\xdc', \
|
|
|
- '\xdb', '\xdd', 'd', 'e', '\xdb', '\xdc', 'f', \
|
|
|
- '\xdb', '\xdd'
|
|
|
+#define TEST_SLIP_PACKET 0xdb, 'a', 'b', 'c', 0xc0, 0xdb, 'd', 'e', 0xc0, 'f', 0xdb
|
|
|
|
|
|
-// Wrapper around command_t for easyer
|
|
|
+#define SLIP_ENCODED_PACKET 0xdb, 0xdd, 'a', 'b', 'c', 0xdb, 0xdc, 0xdb, \
|
|
|
+ 0xdd, 'd', 'e', 0xdb, 0xdc, 'f', 0xdb, 0xdd
|
|
|
+
|
|
|
+
|
|
|
+// Helper function for debugging.
|
|
|
+__attribute__((unused))
|
|
|
+static void arrays_match(int8_t *array_1, int8_t *array_2, size_t size)
|
|
|
+{
|
|
|
+ for (size_t i = 0; i < size; i++) {
|
|
|
+ if (array_1[i] != array_2[i]) {
|
|
|
+ printf("\nArrays do NOT match on index: %lu, with values %0x, %0x \n",
|
|
|
+ i, array_1[i], array_2[i]);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ printf("Arrays Match\n");
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+// Wrapper around command_t for convenience
|
|
|
struct __attribute__((packed)) expected_response {
|
|
|
expected_response(command_t cmd)
|
|
|
{
|
|
|
@@ -50,8 +66,7 @@ struct __attribute__((packed)) expected_response {
|
|
|
response_t data;
|
|
|
};
|
|
|
|
|
|
-static_assert(sizeof(expected_response) == sizeof(response_t), "Size NOT equel");
|
|
|
-
|
|
|
+static_assert(sizeof(expected_response) == sizeof(response_t), "Size NOT equal");
|
|
|
|
|
|
inline void queue_response(expected_response &response, size_t size = sizeof(expected_response))
|
|
|
{
|
|
|
@@ -63,30 +78,24 @@ expected_response flash_data_response(FLASH_DATA);
|
|
|
expected_response flash_end_response(FLASH_END);
|
|
|
expected_response write_reg_response(WRITE_REG);
|
|
|
expected_response read_reg_response(READ_REG);
|
|
|
+expected_response attach_response(SPI_ATTACH);
|
|
|
expected_response sync_response(SYNC);
|
|
|
|
|
|
-template<size_t PAYLOAD_SIZE>
|
|
|
-struct __attribute__((packed)) data_frame {
|
|
|
- int8_t delimiter_1 = '\xc0';
|
|
|
- data_command_t data_cmd = {
|
|
|
+
|
|
|
+struct __attribute__((packed)) flash_start_frame {
|
|
|
+ uint8_t delimiter_1 = 0xc0;
|
|
|
+ spi_attach_command_t attach_cmd = {
|
|
|
.common = {
|
|
|
.direction = WRITE_DIRECTION,
|
|
|
- .command = FLASH_DATA,
|
|
|
- .size = 16,
|
|
|
- .checksum = 0xef,
|
|
|
+ .command = SPI_ATTACH,
|
|
|
+ .size = 8,
|
|
|
+ .checksum = 0,
|
|
|
},
|
|
|
- .data_size = PAYLOAD_SIZE,
|
|
|
- .sequence_number = 0,
|
|
|
- .zero_0 = 0,
|
|
|
- .zero_1 = 0,
|
|
|
+ .configuration = 0,
|
|
|
+ .zero = 0
|
|
|
};
|
|
|
- uint8_t payload[PAYLOAD_SIZE];
|
|
|
- int8_t delimiter_2 = '\xc0';
|
|
|
-};
|
|
|
-
|
|
|
-template<size_t DATA_FRAME_SIZE, size_t NUM_OF_DATA_FRAMES>
|
|
|
-struct __attribute__((packed)) write_packet {
|
|
|
- int8_t delimiter_1 = '\xc0';
|
|
|
+ uint8_t delimiter_2 = 0xc0;
|
|
|
+ uint8_t delimiter_3 = 0xc0;
|
|
|
begin_command_t begin_cmd = {
|
|
|
.common = {
|
|
|
.direction = WRITE_DIRECTION,
|
|
|
@@ -94,16 +103,27 @@ struct __attribute__((packed)) write_packet {
|
|
|
.size = 16,
|
|
|
.checksum = 0,
|
|
|
},
|
|
|
- .erase_size = DATA_FRAME_SIZE * 3,
|
|
|
- .packet_count = 3,
|
|
|
- .packet_size = DATA_FRAME_SIZE,
|
|
|
+ .erase_size = 0,
|
|
|
+ .packet_count = 0,
|
|
|
+ .packet_size = 0,
|
|
|
.offset = 0,
|
|
|
};
|
|
|
- int8_t delimiter_2 = '\xc0';
|
|
|
+ uint8_t delimiter_4 = 0xc0;
|
|
|
+
|
|
|
+ flash_start_frame(uint32_t offset, uint32_t image_size, uint32_t block_size)
|
|
|
+ {
|
|
|
+ uint32_t blocks_to_write = (image_size + block_size - 1) / block_size;
|
|
|
|
|
|
- data_frame<DATA_FRAME_SIZE> data[NUM_OF_DATA_FRAMES];
|
|
|
+ begin_cmd.packet_count = blocks_to_write;
|
|
|
+ begin_cmd.erase_size = blocks_to_write * block_size;
|
|
|
+ begin_cmd.packet_size = block_size;
|
|
|
+ begin_cmd.offset = offset;
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
- int8_t delimiter_3 = '\xc0';
|
|
|
+
|
|
|
+struct __attribute__((packed)) flash_finish_frame {
|
|
|
+ uint8_t delimiter_1 = 0xc0;
|
|
|
flash_end_command_t end_cmd = {
|
|
|
.common = {
|
|
|
.direction = WRITE_DIRECTION,
|
|
|
@@ -113,42 +133,112 @@ struct __attribute__((packed)) write_packet {
|
|
|
},
|
|
|
.stay_in_loader = 1,
|
|
|
};
|
|
|
- int8_t delimiter_4 = '\xc0';
|
|
|
+ uint8_t delimiter_2 = 0xc0;
|
|
|
+};
|
|
|
|
|
|
- write_packet()
|
|
|
+
|
|
|
+template<size_t PAYLOAD_SIZE>
|
|
|
+struct __attribute__((packed)) flash_write_frame {
|
|
|
+ uint8_t delimiter_1 = 0xc0;
|
|
|
+ data_command_t data_cmd = {
|
|
|
+ .common = {
|
|
|
+ .direction = WRITE_DIRECTION,
|
|
|
+ .command = FLASH_DATA,
|
|
|
+ .size = 16,
|
|
|
+ .checksum = 0xef,
|
|
|
+ },
|
|
|
+ .data_size = PAYLOAD_SIZE,
|
|
|
+ .sequence_number = 0,
|
|
|
+ .zero_0 = 0,
|
|
|
+ .zero_1 = 0,
|
|
|
+ };
|
|
|
+ array<uint8_t, PAYLOAD_SIZE> payload;
|
|
|
+ uint8_t delimiter_2 = 0xc0;
|
|
|
+
|
|
|
+ flash_write_frame()
|
|
|
{
|
|
|
- for (size_t i = 0; i < NUM_OF_DATA_FRAMES; i++) {
|
|
|
- memset(data[i].payload, 0xFF, FLASH_WRITE_SIZE); // Padding
|
|
|
- data[i].data_cmd.data_size = DATA_FRAME_SIZE;
|
|
|
- data[i].data_cmd.sequence_number = i;
|
|
|
- }
|
|
|
+ payload.fill(0xFF);
|
|
|
+ data_cmd.sequence_number = seq_num++;
|
|
|
}
|
|
|
+
|
|
|
+ ~flash_write_frame()
|
|
|
+ {
|
|
|
+ seq_num--;
|
|
|
+ }
|
|
|
+
|
|
|
+ void fill(uint8_t data, size_t size = PAYLOAD_SIZE)
|
|
|
+ {
|
|
|
+ fill_n(payload.data(), size, data);
|
|
|
+ }
|
|
|
+
|
|
|
+ static uint32_t seq_num;
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+const uint32_t reg_address = 0x1000;
|
|
|
+const uint32_t reg_value = 55;
|
|
|
+
|
|
|
+struct __attribute__((packed)) write_reg_cmd_response {
|
|
|
+ uint8_t delimiter_1 = 0xc0;
|
|
|
+ write_reg_command_t write_reg_cmd = {
|
|
|
+ .common = {
|
|
|
+ .direction = WRITE_DIRECTION,
|
|
|
+ .command = WRITE_REG,
|
|
|
+ .size = 16,
|
|
|
+ .checksum = 0
|
|
|
+ },
|
|
|
+ .address = reg_address,
|
|
|
+ .value = reg_value,
|
|
|
+ .mask = 0xFFFFFFFF,
|
|
|
+ .delay_us = 0
|
|
|
+ };
|
|
|
+ uint8_t delimiter_2 = 0xc0;
|
|
|
};
|
|
|
|
|
|
-int8_t large_data[2500];
|
|
|
|
|
|
-TEST_CASE( "Large payload that does not fit FLASH_WRITE_SIZE is split into \
|
|
|
+template<size_t PAYLOAD_SIZE>
|
|
|
+uint32_t flash_write_frame<PAYLOAD_SIZE>::seq_num = 0;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+TEST_CASE( "Large payload that does not fit BLOCK_SIZE is split into \
|
|
|
multiple data frames. Last data frame is padded with 0xFF" )
|
|
|
{
|
|
|
- write_packet<FLASH_WRITE_SIZE, 3> expected;
|
|
|
- uint32_t remaining_size = sizeof(large_data) - 2 * FLASH_WRITE_SIZE;
|
|
|
+ const uint32_t BLOCK_SIZE = 1024;
|
|
|
+
|
|
|
+ uint8_t data[BLOCK_SIZE];
|
|
|
+ memset(data, 0x11, BLOCK_SIZE);
|
|
|
|
|
|
- memset(large_data, 0x11, sizeof(large_data));
|
|
|
- memcpy(&expected.data[0].payload, large_data, FLASH_WRITE_SIZE);
|
|
|
- memcpy(&expected.data[1].payload, large_data, FLASH_WRITE_SIZE);
|
|
|
- memcpy(&expected.data[2].payload, large_data, remaining_size);
|
|
|
- expected.data[2].data_cmd.data_size = remaining_size;
|
|
|
+ flash_write_frame<BLOCK_SIZE> expected_data[3];
|
|
|
+ expected_data[0].fill(0x11);
|
|
|
+ expected_data[1].fill(0x11);
|
|
|
+ expected_data[2].fill(0x11, 200);
|
|
|
|
|
|
+ flash_start_frame expected_start(0, sizeof(data) * 3, BLOCK_SIZE);
|
|
|
+
|
|
|
+ // Check flash start operation
|
|
|
clear_buffers();
|
|
|
+ queue_response(attach_response);
|
|
|
queue_response(flash_begin_response);
|
|
|
+
|
|
|
+ REQUIRE ( esp_loader_flash_start(0, sizeof(data) * 3, BLOCK_SIZE) == ESP_LOADER_SUCCESS );
|
|
|
+
|
|
|
+ REQUIRE( memcmp(write_buffer_data(), &expected_start, sizeof(expected_start)) == 0 );
|
|
|
+
|
|
|
+
|
|
|
+ // Check flash write operation
|
|
|
+ clear_buffers();
|
|
|
queue_response(flash_data_response);
|
|
|
queue_response(flash_data_response);
|
|
|
queue_response(flash_data_response);
|
|
|
- queue_response(flash_end_response);
|
|
|
|
|
|
- REQUIRE( loader_flash_write(large_data, sizeof(large_data), 0) == ESP_SUCCESS );
|
|
|
+ REQUIRE( esp_loader_flash_write(data, sizeof(data)) == ESP_LOADER_SUCCESS );
|
|
|
+ REQUIRE( esp_loader_flash_write(data, sizeof(data)) == ESP_LOADER_SUCCESS );
|
|
|
+ REQUIRE( esp_loader_flash_write(data, 200) == ESP_LOADER_SUCCESS );
|
|
|
|
|
|
- REQUIRE( memcmp(write_buffer_data(), &expected, sizeof(expected)) == 0 );
|
|
|
+ REQUIRE( memcmp(write_buffer_data(), &expected_data, sizeof(expected_data)) == 0 );
|
|
|
+
|
|
|
+ // queue_response(flash_end_response);
|
|
|
}
|
|
|
|
|
|
|
|
|
@@ -157,16 +247,28 @@ TEST_CASE( "Can connect within specified time " )
|
|
|
clear_buffers();
|
|
|
queue_response(sync_response);
|
|
|
|
|
|
- loader_set_timeout(50);
|
|
|
+ esp_loader_connect_args_t connect_config = {
|
|
|
+ .sync_timeout = 10,
|
|
|
+ .trials = 1
|
|
|
+ };
|
|
|
|
|
|
SECTION( "Can connect" ) {
|
|
|
- serial_set_time_delay(100);
|
|
|
- REQUIRE ( loader_connect() == ESP_SUCCESS );
|
|
|
+ serial_set_time_delay(5);
|
|
|
+ REQUIRE ( esp_loader_connect(&connect_config) == ESP_LOADER_SUCCESS );
|
|
|
}
|
|
|
|
|
|
SECTION( "Timeout error is returned when timeout expires" ) {
|
|
|
- serial_set_time_delay(1000);
|
|
|
- REQUIRE ( loader_connect() == ESP_ERROR_TIMEOUT );
|
|
|
+ serial_set_time_delay(20);
|
|
|
+ REQUIRE ( esp_loader_connect(&connect_config) == ESP_LOADER_ERROR_TIMEOUT );
|
|
|
+ }
|
|
|
+
|
|
|
+ SECTION( "Can connect after several trials within specified time" ) {
|
|
|
+ connect_config.trials = 5;
|
|
|
+ serial_set_time_delay(40);
|
|
|
+ REQUIRE ( esp_loader_connect(&connect_config) == ESP_LOADER_SUCCESS );
|
|
|
+
|
|
|
+ serial_set_time_delay(60);
|
|
|
+ REQUIRE ( esp_loader_connect(&connect_config) == ESP_LOADER_ERROR_TIMEOUT );
|
|
|
}
|
|
|
|
|
|
serial_set_time_delay(0);
|
|
|
@@ -175,59 +277,40 @@ TEST_CASE( "Can connect within specified time " )
|
|
|
TEST_CASE( "Register can be read correctly" )
|
|
|
{
|
|
|
clear_buffers();
|
|
|
+ uint32_t reg_value = 0;
|
|
|
read_reg_response.data.value = 55;
|
|
|
+
|
|
|
queue_response(read_reg_response);
|
|
|
|
|
|
- uint32_t reg_value = 0;
|
|
|
- loader_read_register(0, ®_value);
|
|
|
+ REQUIRE( esp_loader_read_register(0, ®_value) == ESP_LOADER_SUCCESS );
|
|
|
|
|
|
REQUIRE( reg_value == 55 );
|
|
|
}
|
|
|
|
|
|
|
|
|
-const uint32_t reg_address = 0x1000;
|
|
|
-const uint32_t reg_value = 55;
|
|
|
-
|
|
|
-struct __attribute__((packed)) write_reg_cmd_response {
|
|
|
- int8_t delimiter_1 = '\xc0';
|
|
|
- write_reg_command_t write_reg_cmd = {
|
|
|
- .common = {
|
|
|
- .direction = WRITE_DIRECTION,
|
|
|
- .command = WRITE_REG,
|
|
|
- .size = 16,
|
|
|
- .checksum = 0
|
|
|
- },
|
|
|
- .address = reg_address,
|
|
|
- .value = reg_value,
|
|
|
- .mask = 0xFFFFFFFF,
|
|
|
- .delay_us = 0
|
|
|
- };
|
|
|
- int8_t delimiter_2 = '\xc0';
|
|
|
-};
|
|
|
-
|
|
|
-
|
|
|
TEST_CASE( "Register can be written correctly" )
|
|
|
{
|
|
|
write_reg_cmd_response expected;
|
|
|
+ write_reg_response.data.value = 55;
|
|
|
|
|
|
clear_buffers();
|
|
|
queue_response(write_reg_response);
|
|
|
|
|
|
- REQUIRE( loader_write_register(reg_address, reg_value) == ESP_SUCCESS );
|
|
|
+ REQUIRE( esp_loader_write_register(reg_address, reg_value) == ESP_LOADER_SUCCESS );
|
|
|
|
|
|
REQUIRE( memcmp(write_buffer_data(), &expected, sizeof(expected)) == 0 );
|
|
|
}
|
|
|
|
|
|
// -------------------- Serial comm test -----------------------
|
|
|
|
|
|
-TEST_CASE ( "SLIP is enceded correctly" )
|
|
|
+TEST_CASE ( "SLIP is encoded correctly" )
|
|
|
{
|
|
|
- flash_begin_cmd(0, 0, 0, 0); // To reset sequence number counter
|
|
|
+ loader_flash_begin_cmd(0, 0, 0, 0); // To reset sequence number counter
|
|
|
|
|
|
- int8_t data[] = { TEST_SLIP_PACKET };
|
|
|
+ uint8_t data[] = { TEST_SLIP_PACKET };
|
|
|
|
|
|
- int8_t expected[] = {
|
|
|
- '\xc0', // Begin
|
|
|
+ uint8_t expected[] = {
|
|
|
+ 0xc0, // Begin
|
|
|
0x00, // Write direction
|
|
|
0x03, // FLASH_DATA command
|
|
|
16, 0, // Number of characters to send
|
|
|
@@ -237,7 +320,7 @@ TEST_CASE ( "SLIP is enceded correctly" )
|
|
|
0, 0, 0, 0, // zero
|
|
|
0, 0, 0, 0, // zero
|
|
|
SLIP_ENCODED_PACKET,
|
|
|
- '\xc0', // End
|
|
|
+ 0xc0, // End
|
|
|
};
|
|
|
|
|
|
// write_buffer_print();
|
|
|
@@ -246,16 +329,16 @@ TEST_CASE ( "SLIP is enceded correctly" )
|
|
|
clear_buffers();
|
|
|
queue_response(flash_data_response);
|
|
|
|
|
|
- REQUIRE( flash_data_cmd(data, sizeof(data), 0) == ESP_SUCCESS );
|
|
|
+ REQUIRE( loader_flash_data_cmd(data, sizeof(data)) == ESP_LOADER_SUCCESS );
|
|
|
|
|
|
REQUIRE( memcmp(write_buffer_data(), expected, sizeof(expected)) == 0 );
|
|
|
}
|
|
|
|
|
|
|
|
|
-TEST_CASE( "Synd command is constructed correctly" )
|
|
|
+TEST_CASE( "Sync command is constructed correctly" )
|
|
|
{
|
|
|
- int8_t expected[] = {
|
|
|
- '\xc0', // Begin
|
|
|
+ uint8_t expected[] = {
|
|
|
+ 0xc0, // Begin
|
|
|
0x00, // Write direction
|
|
|
0x08, // SYNC command
|
|
|
36, 0, // Number of characters to send
|
|
|
@@ -265,33 +348,28 @@ TEST_CASE( "Synd command is constructed correctly" )
|
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
|
|
|
- '\xc0', // End
|
|
|
+ 0xc0, // End
|
|
|
};
|
|
|
|
|
|
clear_buffers();
|
|
|
queue_response(sync_response);
|
|
|
|
|
|
- REQUIRE( sync_cmd() == ESP_SUCCESS );
|
|
|
+ REQUIRE( loader_sync_cmd() == ESP_LOADER_SUCCESS );
|
|
|
|
|
|
REQUIRE( memcmp(write_buffer_data(), expected, sizeof(expected)) == 0 );
|
|
|
}
|
|
|
|
|
|
+TEST_CASE( "Register can be read and decoded correctly" )
|
|
|
+{
|
|
|
+ clear_buffers();
|
|
|
+ read_reg_response.data.value = 55;
|
|
|
+ queue_response(read_reg_response);
|
|
|
|
|
|
-// TEST_CASE( "Register can be read and decoded correctly" )
|
|
|
-// {
|
|
|
-// clear_buffers();
|
|
|
-// read_reg_response.data.value = 55;
|
|
|
-// queue_response(read_reg_response);
|
|
|
-
|
|
|
-// uint32_t reg_value = 0;
|
|
|
-// read_reg(0, ®_value);
|
|
|
-
|
|
|
-// REQUIRE( reg_value == 55 );
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
+ uint32_t reg_value = 0;
|
|
|
+ esp_loader_read_register(0, ®_value);
|
|
|
|
|
|
-// Test flash offset
|
|
|
+ REQUIRE( reg_value == 55 );
|
|
|
+}
|
|
|
|
|
|
|
|
|
|
|
|
@@ -301,181 +379,39 @@ TEST_CASE( "Synd command is constructed correctly" )
|
|
|
TEST_CASE( "Serial read works correctly" )
|
|
|
{
|
|
|
uint32_t reg_value = 5;
|
|
|
- int8_t readout[sizeof(reg_value) + 2];
|
|
|
- int8_t expected[] = { '\xc0', 5, 0, 0, 0, '\xc0' };
|
|
|
+ uint8_t readout[sizeof(reg_value) + 2];
|
|
|
+ uint8_t expected[] = { 0xc0, 5, 0, 0, 0, 0xc0 };
|
|
|
|
|
|
clear_buffers();
|
|
|
|
|
|
set_read_buffer(®_value, sizeof(reg_value));
|
|
|
|
|
|
SECTION( "Read buffer can be read" ) {
|
|
|
- serial_read(readout, sizeof(readout), 0);
|
|
|
+ loader_port_serial_read(readout, sizeof(readout), 0);
|
|
|
REQUIRE( memcmp(readout, expected, sizeof(readout)) == 0 );
|
|
|
}
|
|
|
|
|
|
SECTION ( "Read buffer can be read in smaller chunks" ) {
|
|
|
- serial_read(&readout[0], 3, 0);
|
|
|
- serial_read(&readout[3], 3, 0);
|
|
|
+ loader_port_serial_read(&readout[0], 3, 0);
|
|
|
+ loader_port_serial_read(&readout[3], 3, 0);
|
|
|
REQUIRE( memcmp(readout, expected, sizeof(readout)) == 0 );
|
|
|
}
|
|
|
|
|
|
- SECTION ( "Timeout is retuned when requested amount of data is not available" ) {
|
|
|
- REQUIRE( serial_read(readout, sizeof(readout) + 1, 0) == ESP_ERROR_TIMEOUT);
|
|
|
+ SECTION ( "Timeout is returned when requested amount of data is not available" ) {
|
|
|
+ REQUIRE( loader_port_serial_read(readout, sizeof(readout) + 1, 0) == ESP_LOADER_ERROR_TIMEOUT);
|
|
|
}
|
|
|
|
|
|
SECTION ( "Read buffer is correctly SLIP encoded " ) {
|
|
|
- int8_t data_to_encode[] = { TEST_SLIP_PACKET };
|
|
|
- int8_t expected[] = { '\xc0', SLIP_ENCODED_PACKET, '\xc0'};
|
|
|
- int8_t encoded[sizeof(expected)];
|
|
|
+ uint8_t data_to_encode[] = { TEST_SLIP_PACKET };
|
|
|
+ uint8_t expected[] = { 0xc0, SLIP_ENCODED_PACKET, 0xc0};
|
|
|
+ uint8_t encoded[sizeof(expected)];
|
|
|
|
|
|
clear_buffers();
|
|
|
|
|
|
fill(encoded, &encoded[sizeof(encoded)], 0);
|
|
|
set_read_buffer(data_to_encode, sizeof(data_to_encode));
|
|
|
- serial_read(encoded, sizeof(encoded), 0);
|
|
|
+ loader_port_serial_read(encoded, sizeof(encoded), 0);
|
|
|
|
|
|
REQUIRE( memcmp(expected, encoded, sizeof(expected)) == 0 );
|
|
|
}
|
|
|
-}
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-// static void arrays_match(int8_t *array_1, int8_t *array_2, size_t size)
|
|
|
-// {
|
|
|
-// for (size_t i = 0; i < size; i++) {
|
|
|
-// if (array_1[i] != array_2[i]) {
|
|
|
-// printf("\nArrays do NOT match on index: %lu, with vaules %0x, %0x \n",
|
|
|
-// i, array_1[i], array_2[i]);
|
|
|
-// return;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// printf("Arrays Match\n");
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-// int8_t expected[] = {
|
|
|
-// '\xc0', // Begin
|
|
|
-// 0x00, // Write direction
|
|
|
-// 0x02, // FLASH_BEGIN command
|
|
|
-// 16, 0, // Number of characters to send
|
|
|
-// 0, 0, 0, 0, // Checksum is ignored for this command
|
|
|
-// sizeof(data), 0, 0, 0, // Size to erase
|
|
|
-// 1, 0, 0, 0, // Number of data packets
|
|
|
-// 0, 4, 0, 0, // Data size in one packet
|
|
|
-// 0, 0, 0, 0, // Flash offset
|
|
|
-// '\xc0', // End
|
|
|
-
|
|
|
-// '\xc0', // Begin
|
|
|
-// 0x00, // Write direction
|
|
|
-// 0x03, // FLASH_DATA command
|
|
|
-// 16, 0, // Number of characters to send
|
|
|
-// 0x33, 0, 0, 0,// Checksum
|
|
|
-// sizeof(data), 0, 0, 0, // Data size
|
|
|
-// 0, 0, 0, 0, // Sequence number
|
|
|
-// 0, 0, 0, 0, // zero
|
|
|
-// 0, 0, 0, 0, // zero
|
|
|
-// SLIP_ENCODED_PACKET,
|
|
|
-// '\xc0', // End
|
|
|
-
|
|
|
-// '\xc0', // Begin
|
|
|
-// 0x00, // Write direction
|
|
|
-// 0x04, // FLASH_END command
|
|
|
-// 4, 0, // Number of characters to send
|
|
|
-// 0, 0, 0, 0, // Checksum is ignored for this command
|
|
|
-// 1, 0, 0, 0, // Do not reboot (1)
|
|
|
-// '\xc0', // End
|
|
|
-// };
|
|
|
-
|
|
|
-
|
|
|
-// write_packet expected = {
|
|
|
-// // Begin command
|
|
|
-// .delimiter_1 = '\xc0',
|
|
|
-// .begin_cmd = {
|
|
|
-// .common = {
|
|
|
-// .direction = WRITE_DIRECTION,
|
|
|
-// .command = FLASH_BEGIN,
|
|
|
-// .size = 16,
|
|
|
-// .checksum = 0,
|
|
|
-// },
|
|
|
-// .erase_size = FLASH_WRITE_SIZE * 3,
|
|
|
-// .packet_count = 3,
|
|
|
-// .packet_size = FLASH_WRITE_SIZE,
|
|
|
-// .offset = 0,
|
|
|
-// },
|
|
|
-// .delimiter_2 = '\xc0',
|
|
|
-
|
|
|
-// // Data frames
|
|
|
-// .data = {
|
|
|
-// {
|
|
|
-// .delimiter_3 = '\xc0',
|
|
|
-// .data_cmd = {
|
|
|
-// .common = {
|
|
|
-// .direction = WRITE_DIRECTION,
|
|
|
-// .command = FLASH_DATA,
|
|
|
-// .size = 16,
|
|
|
-// .checksum = 0xef,
|
|
|
-// },
|
|
|
-// .data_size = FLASH_WRITE_SIZE,
|
|
|
-// .sequence_number = 0,
|
|
|
-// .zero_0 = 0,
|
|
|
-// .zero_1 = 0,
|
|
|
-// },
|
|
|
-// .payload = { 0xFF },
|
|
|
-// .delimiter_4 = '\xc0',
|
|
|
-// },
|
|
|
-
|
|
|
-// {
|
|
|
-// .delimiter_3 = '\xc0',
|
|
|
-// .data_cmd = {
|
|
|
-// .common = {
|
|
|
-// .direction = WRITE_DIRECTION,
|
|
|
-// .command = FLASH_DATA,
|
|
|
-// .size = 16,
|
|
|
-// .checksum = 0xef,
|
|
|
-// },
|
|
|
-// .data_size = FLASH_WRITE_SIZE,
|
|
|
-// .sequence_number = 1,
|
|
|
-// .zero_0 = 0,
|
|
|
-// .zero_1 = 0,
|
|
|
-// },
|
|
|
-// .payload = { 0xFF },
|
|
|
-// .delimiter_4 = '\xc0',
|
|
|
-// },
|
|
|
-
|
|
|
-// {
|
|
|
-// .delimiter_3 = '\xc0',
|
|
|
-// .data_cmd = {
|
|
|
-// .common = {
|
|
|
-// .direction = WRITE_DIRECTION,
|
|
|
-// .command = FLASH_DATA,
|
|
|
-// .size = 16,
|
|
|
-// .checksum = 0xef,
|
|
|
-// },
|
|
|
-// .data_size = remaining_size,
|
|
|
-// .sequence_number = 2,
|
|
|
-// .zero_0 = 0,
|
|
|
-// .zero_1 = 0,
|
|
|
-// },
|
|
|
-// .payload = { 0xFF },
|
|
|
-// .delimiter_4 = '\xc0',
|
|
|
-// },
|
|
|
-// },
|
|
|
-
|
|
|
-// // End command
|
|
|
-// .delimiter_5 = '\xc0',
|
|
|
-// .end_cmd = {
|
|
|
-// .common = {
|
|
|
-// .direction = WRITE_DIRECTION,
|
|
|
-// .command = FLASH_END,
|
|
|
-// .size = 4,
|
|
|
-// .checksum = 0,
|
|
|
-// },
|
|
|
-// .stay_in_loader = 1,
|
|
|
-
|
|
|
-// },
|
|
|
-// .delimiter_6 = '\xc0',
|
|
|
-// };
|
|
|
+}
|