Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Acceptance tests for PR #1097 (OTA/YModem update result) #1153

Merged
merged 18 commits into from
Nov 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
d88001e
OTA/YModem update result:
avtolstoy Aug 7, 2016
4d71b9c
Reject received file only when the host has requested to end the session
avtolstoy Oct 29, 2016
3dc6f6a
Wiring library: Vector class, JSON tools; unit test helper tools
sergeuz Sep 20, 2016
e4e1a6e
Make compile-dependency on strtol() and strtod() optional
sergeuz Sep 29, 2016
7d404a8
Minor fix
sergeuz Oct 16, 2016
cbda226
Runtime logging configuration; asynchronous USB requests; helper tool…
sergeuz Sep 20, 2016
d81371e
Allow logging from an ISR when DEBUG_BUILD=y
avtolstoy Oct 29, 2016
be9c07a
Do not use ATOMIC_BLOCK() in spark_wiring_logging.cpp on PLATFORM=3 i…
avtolstoy Oct 29, 2016
8d5663e
Merge remote-tracking branch 'origin/feature/usb_logging_1_of_2' into…
avtolstoy Oct 29, 2016
92ae191
Merge remote-tracking branch 'origin/feature/usb_logging_2_of_2' into…
avtolstoy Oct 29, 2016
b974e17
user/tests/accept: device_ctl support script: renaming 'listen' mode …
avtolstoy Oct 29, 2016
39889fb
user/tests/accept: fixing usb PID/VID for Electron and P1
avtolstoy Oct 29, 2016
05604fc
user/tests/accept: Adding @log_config tag to log_config test suite
avtolstoy Oct 29, 2016
edc219e
user/tests/accept: update_result test suite for PR #1097
avtolstoy Oct 29, 2016
02e4760
user/tests/accept: Some OSX fixes
avtolstoy Oct 30, 2016
c4e7ba3
user/tests/accept: Enter into DFU using USB vendor requests before fl…
avtolstoy Oct 30, 2016
6bb3318
usb_hal: Initiate data stage anyway, if vendor request handler return…
avtolstoy Oct 30, 2016
48987b9
Merge remote-tracking branch 'origin/feature/usb_logging_2_of_2' into…
avtolstoy Oct 30, 2016
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/build_boost.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pushd $BOOST_ROOT
./bootstrap.sh
./b2 --with-thread --with-system --with-program_options --with-random --threading=single
./b2 --with-thread --with-system --with-program_options --with-random --with-regex --threading=single
popd
3 changes: 2 additions & 1 deletion ci/install_boost.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ test -d $BOOST_ROOT || (
mv boost_$BOOST_VERSION $BOOST_HOME
)
test -d $BOOST_ROOT || ( echo "boost root $BOOST_ROOT not created." && exit 1)
export DYLD_LIBRARY_PATH=$BOOST_ROOT/stage/lib
export DYLD_LIBRARY_PATH="$BOOST_ROOT/stage/lib:$DYLD_LIBRARY_PATH"
export LD_LIBRARY_PATH="$BOOST_ROOT/stage/lib:$LD_LIBRARY_PATH"
2 changes: 1 addition & 1 deletion ci/run_tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
cd "$( dirname "${BASH_SOURCE[0]}" )/.."
source ./ci/install_boost.sh
./ci/unit_tests.sh &&
./ci/build_boost.sh &&
./ci/unit_tests.sh &&
./ci/enumerate_build_matrix.sh
2 changes: 1 addition & 1 deletion hal/inc/hal_dynalib_ota.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ DYNALIB_FN(4, hal_ota, HAL_OTA_Flashed_ResetStatus, void(void))

DYNALIB_FN(5, hal_ota, HAL_FLASH_Begin, bool(uint32_t, uint32_t, void*))
DYNALIB_FN(6, hal_ota, HAL_FLASH_Update, int(const uint8_t*, uint32_t, uint32_t, void*))
DYNALIB_FN(7, hal_ota, HAL_FLASH_End, hal_update_complete_t(void*))
DYNALIB_FN(7, hal_ota, HAL_FLASH_End, hal_update_complete_t(hal_module_t*))

DYNALIB_END(hal_ota)

Expand Down
3 changes: 2 additions & 1 deletion hal/inc/ota_flash_hal.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ typedef struct {
} module_bounds_t;

typedef enum {
MODULE_VALIDATION_PASSED = 0,
MODULE_VALIDATION_INTEGRITY = 1<<1,
MODULE_VALIDATION_DEPENDENCIES = 1<<2,
MODULE_VALIDATION_RANGE = 1<<3,
Expand Down Expand Up @@ -131,7 +132,7 @@ typedef enum {
HAL_UPDATE_APPLIED
} hal_update_complete_t;

hal_update_complete_t HAL_FLASH_End(void* reserved);
hal_update_complete_t HAL_FLASH_End(hal_module_t* module);

uint32_t HAL_FLASH_ModuleAddress(uint32_t address);
uint32_t HAL_FLASH_ModuleLength(uint32_t address);
Expand Down
2 changes: 1 addition & 1 deletion hal/src/core/ota_flash_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ int HAL_FLASH_Update(const uint8_t *pBuffer, uint32_t address, uint32_t bufferSi
return FLASH_Update(pBuffer, address, bufferSize);
}

hal_update_complete_t HAL_FLASH_End( void* reserved)
hal_update_complete_t HAL_FLASH_End(hal_module_t* reserved)
{
FLASH_End();
return HAL_UPDATE_APPLIED_PENDING_RESTART;
Expand Down
2 changes: 1 addition & 1 deletion hal/src/gcc/ota_flash_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ int HAL_FLASH_Update(const uint8_t *pBuffer, uint32_t address, uint32_t length,
return 0;
}

hal_update_complete_t HAL_FLASH_End(void* reserved)
hal_update_complete_t HAL_FLASH_End(hal_module_t* mod)
{
fclose(output_file);
output_file = NULL;
Expand Down
6 changes: 5 additions & 1 deletion hal/src/stm32f2xx/ota_flash_hal_stm32f2xx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ int HAL_FLASH_Update(const uint8_t *pBuffer, uint32_t address, uint32_t length,
return FLASH_Update(pBuffer, address, length);
}

hal_update_complete_t HAL_FLASH_End(void* reserved)
hal_update_complete_t HAL_FLASH_End(hal_module_t* mod)
{
hal_module_t module;
hal_update_complete_t result = HAL_UPDATE_ERROR;
Expand Down Expand Up @@ -252,6 +252,10 @@ hal_update_complete_t HAL_FLASH_End(void* reserved)
{
WARN("OTA module not applied");
}
if (mod)
{
memcpy(mod, &module, sizeof(hal_module_t));
}
return result;
}

Expand Down
4 changes: 2 additions & 2 deletions hal/src/stm32f2xx/usb_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ uint8_t HAL_USB_Handle_Vendor_Request(USB_SETUP_REQ* req, uint8_t dataStage)
USB_SetupRequest.data = NULL;
ret = USB_Vendor_Request_Callback(&USB_SetupRequest, USB_Vendor_Request_Ptr);

if (ret == USBD_OK && USB_SetupRequest.data != NULL && USB_SetupRequest.wLength) {
if (ret == USBD_OK && ((USB_SetupRequest.data != NULL && USB_SetupRequest.wLength) || !USB_SetupRequest.wLength)) {
if (USB_SetupRequest.data != USB_SetupRequest_Data &&
USB_SetupRequest.wLength <= USBD_EP0_MAX_PACKET_SIZE) {
USB_SetupRequest.wLength <= USBD_EP0_MAX_PACKET_SIZE && USB_SetupRequest.wLength) {
// Don't use user buffer if wLength <= USBD_EP0_MAX_PACKET_SIZE
// and copy into internal buffer
memcpy(USB_SetupRequest_Data, USB_SetupRequest.data, USB_SetupRequest.wLength);
Expand Down
2 changes: 1 addition & 1 deletion hal/src/template/ota_flash_hal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ int HAL_FLASH_Update(const uint8_t *pBuffer, uint32_t address, uint32_t length,
return 0;
}

hal_update_complete_t HAL_FLASH_End(void* reserved)
hal_update_complete_t HAL_FLASH_End(hal_module_t* mod)
{
return HAL_UPDATE_ERROR;
}
Expand Down
8 changes: 6 additions & 2 deletions services/inc/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,13 @@
#undef DEBUG_BUILD
#endif

#if defined(DEBUG_BUILD) && !defined(LOG_INCLUDE_SOURCE_INFO)
#define LOG_INCLUDE_SOURCE_INFO
#ifndef LOG_INCLUDE_SOURCE_INFO
#ifdef DEBUG_BUILD
#define LOG_INCLUDE_SOURCE_INFO 1
#else
#define LOG_INCLUDE_SOURCE_INFO 0
#endif
#endif // !defined(LOG_INCLUDE_SOURCE_INFO)

#define MAX_SEC_WAIT_CONNECT 8 // Number of second a TCP, spark will wait
#define MAX_FAILED_CONNECTS 2 // Number of time a connect can fail
Expand Down
10 changes: 7 additions & 3 deletions services/inc/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@
Following macros configure logging module at compile time:

LOG_INCLUDE_SOURCE_INFO - allows to include source info (file name, function name, line number)
into messages generated by the logging macros. By default, this macro is defined only for debug
builds (see config.h).
into messages generated by the logging macros. Default value is 0 for release builds and 1 for
debug builds (see config.h).

LOG_COMPILE_TIME_LEVEL - allows to strip any logging output that is below of certain logging level
at compile time. Default value is LOG_LEVEL_ALL meaning that no compile-time filtering is applied.
Expand Down Expand Up @@ -236,6 +236,10 @@ extern void HAL_Delay_Microseconds(uint32_t delay);
#define LOG_MAX_STRING_LENGTH 160
#endif

#ifndef LOG_INCLUDE_SOURCE_INFO
#define LOG_INCLUDE_SOURCE_INFO 0
#endif

// Sets log message attribute
#define LOG_ATTR_SET(_attr, _name, _val) \
do { \
Expand Down Expand Up @@ -308,7 +312,7 @@ static const char* const _log_category = NULL;

#endif // !defined(__cplusplus)

#ifdef LOG_INCLUDE_SOURCE_INFO
#if LOG_INCLUDE_SOURCE_INFO
#define _LOG_ATTR_SET_SOURCE_INFO(_attr) \
LOG_ATTR_SET(_attr, file, __FILE__); \
LOG_ATTR_SET(_attr, line, __LINE__); \
Expand Down
35 changes: 20 additions & 15 deletions services/src/logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,21 @@ void log_set_callbacks(log_message_callback_type log_msg, log_write_callback_typ
}

void log_message_v(int level, const char *category, LogAttributes *attr, void *reserved, const char *fmt, va_list args) {
if (!log_msg_callback && (!log_compat_callback || level < log_compat_level)) {
const log_message_callback_type msg_callback = log_msg_callback;
if (!msg_callback && (!log_compat_callback || level < log_compat_level)) {
return;
}
// Set default attributes
if (!attr->has_time) {
LOG_ATTR_SET(*attr, time, HAL_Timer_Get_Milli_Seconds());
}
char buf[LOG_MAX_STRING_LENGTH];
if (log_msg_callback) {
if (msg_callback) {
const int n = vsnprintf(buf, sizeof(buf), fmt, args);
if (n > (int)sizeof(buf) - 1) {
buf[sizeof(buf) - 2] = '~';
}
log_msg_callback(buf, level, category, attr, 0);
msg_callback(buf, level, category, attr, 0);
} else {
// Using compatibility callback
const char* const levelName = log_level_name(level, 0);
Expand Down Expand Up @@ -127,8 +128,9 @@ void log_write(int level, const char *category, const char *data, size_t size, v
if (!size) {
return;
}
if (log_write_callback) {
log_write_callback(data, size, level, category, 0);
const log_write_callback_type write_callback = log_write_callback;
if (write_callback) {
write_callback(data, size, level, category, 0);
} else if (log_compat_callback && level >= log_compat_level) {
// Compatibility callback expects null-terminated strings
if (!data[size - 1]) {
Expand All @@ -148,7 +150,8 @@ void log_write(int level, const char *category, const char *data, size_t size, v
}

void log_printf_v(int level, const char *category, void *reserved, const char *fmt, va_list args) {
if (!log_write_callback && (!log_compat_callback || level < log_compat_level)) {
const log_write_callback_type write_callback = log_write_callback;
if (!write_callback && (!log_compat_callback || level < log_compat_level)) {
return;
}
char buf[LOG_MAX_STRING_LENGTH];
Expand All @@ -157,8 +160,8 @@ void log_printf_v(int level, const char *category, void *reserved, const char *f
buf[sizeof(buf) - 2] = '~';
n = sizeof(buf) - 1;
}
if (log_write_callback) {
log_write_callback(buf, n, level, category, 0);
if (write_callback) {
write_callback(buf, n, level, category, 0);
} else {
log_compat_callback(buf); // Compatibility callback
}
Expand All @@ -172,7 +175,8 @@ void log_printf(int level, const char *category, void *reserved, const char *fmt
}

void log_dump(int level, const char *category, const void *data, size_t size, int flags, void *reserved) {
if (!size || (!log_write_callback && (!log_compat_callback || level < log_compat_level))) {
const log_write_callback_type write_callback = log_write_callback;
if (!size || (!write_callback && (!log_compat_callback || level < log_compat_level))) {
return;
}
static const char hex[] = "0123456789abcdef";
Expand All @@ -184,17 +188,17 @@ void log_dump(int level, const char *category, const void *data, size_t size, in
buf[offs++] = hex[b >> 4];
buf[offs++] = hex[b & 0x0f];
if (offs == sizeof(buf) - 1) {
if (log_write_callback) {
log_write_callback(buf, sizeof(buf) - 1, level, category, 0);
if (write_callback) {
write_callback(buf, sizeof(buf) - 1, level, category, 0);
} else {
log_compat_callback(buf);
}
offs = 0;
}
}
if (offs) {
if (log_write_callback) {
log_write_callback(buf, offs, level, category, 0);
if (write_callback) {
write_callback(buf, offs, level, category, 0);
} else {
buf[offs] = 0;
log_compat_callback(buf);
Expand All @@ -203,8 +207,9 @@ void log_dump(int level, const char *category, const void *data, size_t size, in
}

int log_enabled(int level, const char *category, void *reserved) {
if (log_enabled_callback) {
return log_enabled_callback(level, category, 0);
const log_enabled_callback_type enabled_callback = log_enabled_callback;
if (enabled_callback) {
return enabled_callback(level, category, 0);
}
if (log_compat_callback && level >= log_compat_level) { // Compatibility callback
return 1;
Expand Down
2 changes: 1 addition & 1 deletion system-dynalib/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ SYSTEM_DYNALIB_MODULE_PATH=.

TARGET_TYPE = a
BUILD_PATH_EXT = $(SYSTEM_DYNALIB_BUILD_PATH_EXT)
DEPENDENCIES = system dynalib
DEPENDENCIES = system dynalib hal

include ../build/arm-tlm.mk
32 changes: 31 additions & 1 deletion system/inc/active_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@

#pragma once

#include <cstddef>

#if PLATFORM_THREADING

#include <functional>
#include <mutex>
#include <thread>
#include <future>

#include "channel.h"
#include "concurrent_hal.h"

Expand Down Expand Up @@ -435,4 +438,31 @@ class ActiveObjectThreadQueue : public ActiveObjectQueue



#endif
#endif // PLATFORM_THREADING

/**
* This class implements a queue of asynchronous calls that can be scheduled from an ISR and then
* invoked from an event loop running in a regular thread.
*/
class ISRTaskQueue {
public:
typedef void(*TaskFunc)(void*);

explicit ISRTaskQueue(size_t size);
~ISRTaskQueue();

bool enqueue(TaskFunc func, void* data = nullptr); // Called from an ISR
bool process(); // Called from the primary thread

private:
struct Task {
TaskFunc func;
void* data;
Task* next;
};

Task* tasks_;
Task* availTask_; // Task pool
Task* firstTask_; // Task queue
Task* lastTask_;
};
Loading