From 5ed17dce6f99e897ac1c03c590ab55d9841aeb03 Mon Sep 17 00:00:00 2001 From: Jakub Smejkal Date: Wed, 13 Oct 2021 20:13:59 +0200 Subject: [PATCH] platformio update --- .gitignore | 14 +-- .travis.yml | 42 ++++----- app/application.c | 154 --------------------------------- {app => include}/application.h | 2 + platformio.ini | 31 +++++++ sdk | 1 - src/application.c | 154 +++++++++++++++++++++++++++++++++ 7 files changed, 212 insertions(+), 186 deletions(-) delete mode 100644 app/application.c rename {app => include}/application.h (83%) create mode 100644 platformio.ini delete mode 160000 sdk create mode 100644 src/application.c diff --git a/.gitignore b/.gitignore index b0959b3..2578b34 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,7 @@ -/obj/ -/out/ -.cproject -.project -stm32_flash.ld -Debug/ -.settings/ +obj/ +out/ +.gitmodules +.DS_Store +firmware.bin +.pio/ +.vscode/ diff --git a/.travis.yml b/.travis.yml index 4903ace..6616c11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,25 +1,19 @@ -dist: trusty - -language: c - -addons: - apt: - sources: - - sourceline: 'ppa:team-gcc-arm-embedded/ppa' - packages: - - gcc-arm-embedded - -script: ./build.sh - +language: python +env: + - VERSION=${TRAVIS_TAG:-vdev} +install: + - pip install -U platformio +script: + - export PLATFORMIO_BUILD_FLAGS="-D'VERSION=\"${VERSION}\"'" + - pio run -e release + - mv .pio/build/release/firmware.bin twr-skeleton-${VERSION}.bin + - ls -lha deploy: - skip_cleanup: true - file_glob: true - file: "out/release/*.bin" - api_key: "${GITHUB_KEY}" - provider: releases - overwrite: true - on: - tags: true - -notifications: - email: false + skip_cleanup: true + file_glob: true + file: ./*.bin + api_key: ${GITHUB_KEY} + provider: releases + overwrite: true + on: + tags: true diff --git a/app/application.c b/app/application.c deleted file mode 100644 index 8bb42a3..0000000 --- a/app/application.c +++ /dev/null @@ -1,154 +0,0 @@ -#include - -#define BATTERY_VOLTAGE_DATA_STREAM_SAMPLES 6 -#define SIGFOX_FIRST_REPORT_SECONDS (10) -#define SIGFOX_REPORT_INTERVAL_SECONDS (15 * 60) -#define BATTERY_MODULE_UPDATE_INTERVAL_SECONDS (SIGFOX_REPORT_INTERVAL_SECONDS / BATTERY_VOLTAGE_DATA_STREAM_SAMPLES) - -#define HEADER_EVENT_ERROR 0xff -#define HEADER_EVENT_UPDATE 0x00 - -BC_DATA_STREAM_INT_BUFFER(stream_buffer_battery_voltage_mv, BATTERY_VOLTAGE_DATA_STREAM_SAMPLES) -bc_data_stream_t stream_battery_voltage_mv; - -bc_led_t led; -bc_module_sigfox_t sigfox_module; -bc_button_t button; -uint8_t header = HEADER_EVENT_UPDATE; -unsigned int channel_a_overflow_count = 0; -unsigned int channel_b_overflow_count = 0; - -void pulse_counter_event_handler(bc_module_sensor_channel_t channel, bc_pulse_counter_event_t event, void *event_param) -{ - (void) event_param; - - if (event == BC_PULSE_COUNTER_EVENT_OVERFLOW) - { - if (channel == BC_MODULE_SENSOR_CHANNEL_A) - { - channel_a_overflow_count++; - } - else - { - channel_b_overflow_count++; - } - } -} - -void battery_module_event_handler(bc_module_battery_event_t event, void *event_param) -{ - (void) event_param; - - float voltage; - - if (event == BC_MODULE_BATTERY_EVENT_UPDATE) - { - if (bc_module_battery_get_voltage(&voltage)) - { - int battery_voltage_mv; - battery_voltage_mv = (int)voltage * 1000; - bc_data_stream_feed(&stream_battery_voltage_mv, &battery_voltage_mv); - } - } -} - -void sigfox_module_event_handler(bc_module_sigfox_t *self, bc_module_sigfox_event_t event, void *event_param) -{ - (void) self; - (void) event_param; - - if (event == BC_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START) - { - bc_led_pulse(&led, 100); - } - else if (event == BC_MODULE_SIGFOX_EVENT_ERROR) - { - bc_led_set_mode(&led, BC_LED_MODE_BLINK); - } -} - -void button_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) -{ - (void) self; - (void) event_param; - - if (event == BC_BUTTON_EVENT_HOLD) - { - bc_scheduler_plan_now(0); - } -} - -void application_init(void) -{ - bc_data_stream_init(&stream_battery_voltage_mv, 1, &stream_buffer_battery_voltage_mv); - - bc_led_init(&led, BC_GPIO_LED, false, false); - bc_led_set_mode(&led, BC_LED_MODE_FLASH); - - bc_pulse_counter_init(BC_MODULE_SENSOR_CHANNEL_A, BC_PULSE_COUNTER_EDGE_FALL); - bc_pulse_counter_set_event_handler(BC_MODULE_SENSOR_CHANNEL_A, pulse_counter_event_handler, NULL); - bc_pulse_counter_init(BC_MODULE_SENSOR_CHANNEL_B, BC_PULSE_COUNTER_EDGE_FALL); - bc_pulse_counter_set_event_handler(BC_MODULE_SENSOR_CHANNEL_B, pulse_counter_event_handler, NULL); - - bc_module_battery_init(); - bc_module_battery_set_update_interval(BATTERY_MODULE_UPDATE_INTERVAL_SECONDS * 1000); - bc_module_battery_set_event_handler(battery_module_event_handler, NULL); - - bc_module_sigfox_init(&sigfox_module, BC_MODULE_SIGFOX_REVISION_R2); - bc_module_sigfox_set_event_handler(&sigfox_module, sigfox_module_event_handler, NULL); - - bc_button_init(&button, BC_GPIO_BUTTON, BC_GPIO_PULL_DOWN, false); - bc_button_set_event_handler(&button, button_event_handler, NULL); - - bc_scheduler_plan_absolute(0, SIGFOX_FIRST_REPORT_SECONDS * 1000); -} - -void application_task(void *param) -{ - (void) param; - - if (!bc_module_sigfox_is_ready(&sigfox_module)) - { - bc_scheduler_plan_current_now(); - return; - } - - uint8_t buffer[12]; - uint32_t channel_count_a; - uint32_t channel_count_b; - int battery_voltage; - uint16_t battery_voltage_mv; - - channel_count_a = bc_pulse_counter_get(BC_MODULE_SENSOR_CHANNEL_A); - channel_count_b = bc_pulse_counter_get(BC_MODULE_SENSOR_CHANNEL_B); - bc_data_stream_get_average(&stream_battery_voltage_mv, &battery_voltage); - - if ((channel_a_overflow_count > 0xff) || (channel_b_overflow_count > 0xff)) - { - header = HEADER_EVENT_ERROR; - } - - battery_voltage_mv = (uint16_t)battery_voltage; - - buffer[0] = header; - buffer[1] = (((channel_a_overflow_count << 4) & 0xf0) | ((channel_b_overflow_count) & 0x0f)); - buffer[2] = channel_count_a; - buffer[3] = channel_count_a >> 8; - buffer[4] = channel_count_a >> 16; - buffer[5] = channel_count_a >> 24; - buffer[6] = channel_count_b; - buffer[7] = channel_count_b >> 8; - buffer[8] = channel_count_b >> 16; - buffer[9] = channel_count_b >> 24; - buffer[10] = battery_voltage_mv; - buffer[11] = battery_voltage_mv >> 8; - - if (bc_module_sigfox_send_rf_frame(&sigfox_module, &buffer, sizeof(buffer))) - { - bc_scheduler_plan_current_relative(SIGFOX_REPORT_INTERVAL_SECONDS * 1000); - } - else - { - bc_scheduler_plan_current_relative(1000); - } -} diff --git a/app/application.h b/include/application.h similarity index 83% rename from app/application.h rename to include/application.h index abb6809..7624f55 100644 --- a/app/application.h +++ b/include/application.h @@ -2,5 +2,7 @@ #define _APPLICATION_H #include +#include + #endif // _APPLICATION_H diff --git a/platformio.ini b/platformio.ini new file mode 100644 index 0000000..78ac62c --- /dev/null +++ b/platformio.ini @@ -0,0 +1,31 @@ +; https://docs.platformio.org/page/projectconf.html + +[platformio] +default_envs = debug + +[env] +platform = hardwario-tower +board = core_module +framework = stm32cube +lib_deps = twr-sdk +monitor_speed = 115200 +monitor_filters = default, send_on_enter +monitor_flags = --echo + +[env:debug] +upload_protocol = serial + +[env:release] +upload_protocol = serial +build_flags = + ${env.build_flags} + -D RELEASE + +[env:debug-jlink] +build_type = debug +upload_protocol = jlink +debug_init_break = tbreak application_init +debug_svd_path = .pio/libdeps/debug/twr-sdk/sys/svd/stm32l0x3.svd +build_flags = + ${env.build_flags} + -D DEBUG diff --git a/sdk b/sdk deleted file mode 160000 index e4a7628..0000000 --- a/sdk +++ /dev/null @@ -1 +0,0 @@ -Subproject commit e4a7628724b9761e479f5684c5576a4afcad57b6 diff --git a/src/application.c b/src/application.c new file mode 100644 index 0000000..73a0082 --- /dev/null +++ b/src/application.c @@ -0,0 +1,154 @@ +#include + +#define BATTERY_VOLTAGE_DATA_STREAM_SAMPLES 6 +#define SIGFOX_FIRST_REPORT_SECONDS (10) +#define SIGFOX_REPORT_INTERVAL_SECONDS (15 * 60) +#define BATTERY_MODULE_UPDATE_INTERVAL_SECONDS (SIGFOX_REPORT_INTERVAL_SECONDS / BATTERY_VOLTAGE_DATA_STREAM_SAMPLES) + +#define HEADER_EVENT_ERROR 0xff +#define HEADER_EVENT_UPDATE 0x00 + +TWR_DATA_STREAM_INT_BUFFER(stream_buffer_battery_voltage_mv, BATTERY_VOLTAGE_DATA_STREAM_SAMPLES) +twr_data_stream_t stream_battery_voltage_mv; + +twr_led_t led; +twr_module_sigfox_t sigfox_module; +twr_button_t button; +uint8_t header = HEADER_EVENT_UPDATE; +unsigned int channel_a_overflow_count = 0; +unsigned int channel_b_overflow_count = 0; + +void pulse_counter_event_handler(twr_module_sensor_channel_t channel, twr_pulse_counter_event_t event, void *event_param) +{ + (void) event_param; + + if (event == TWR_PULSE_COUNTER_EVENT_OVERFLOW) + { + if (channel == TWR_MODULE_SENSOR_CHANNEL_A) + { + channel_a_overflow_count++; + } + else + { + channel_b_overflow_count++; + } + } +} + +void battery_module_event_handler(twr_module_battery_event_t event, void *event_param) +{ + (void) event_param; + + float voltage; + + if (event == TWR_MODULE_BATTERY_EVENT_UPDATE) + { + if (twr_module_battery_get_voltage(&voltage)) + { + int battery_voltage_mv; + battery_voltage_mv = (int)voltage * 1000; + twr_data_stream_feed(&stream_battery_voltage_mv, &battery_voltage_mv); + } + } +} + +void sigfox_module_event_handler(twr_module_sigfox_t *self, twr_module_sigfox_event_t event, void *event_param) +{ + (void) self; + (void) event_param; + + if (event == TWR_MODULE_SIGFOX_EVENT_SEND_RF_FRAME_START) + { + twr_led_pulse(&led, 100); + } + else if (event == TWR_MODULE_SIGFOX_EVENT_ERROR) + { + twr_led_set_mode(&led, TWR_LED_MODE_BLINK); + } +} + +void button_event_handler(twr_button_t *self, twr_button_event_t event, void *event_param) +{ + (void) self; + (void) event_param; + + if (event == TWR_BUTTON_EVENT_HOLD) + { + twr_scheduler_plan_now(0); + } +} + +void application_init(void) +{ + twr_data_stream_init(&stream_battery_voltage_mv, 1, &stream_buffer_battery_voltage_mv); + + twr_led_init(&led, TWR_GPIO_LED, false, false); + twr_led_set_mode(&led, TWR_LED_MODE_FLASH); + + twr_pulse_counter_init(TWR_MODULE_SENSOR_CHANNEL_A, TWR_PULSE_COUNTER_EDGE_FALL); + twr_pulse_counter_set_event_handler(TWR_MODULE_SENSOR_CHANNEL_A, pulse_counter_event_handler, NULL); + twr_pulse_counter_init(TWR_MODULE_SENSOR_CHANNEL_B, TWR_PULSE_COUNTER_EDGE_FALL); + twr_pulse_counter_set_event_handler(TWR_MODULE_SENSOR_CHANNEL_B, pulse_counter_event_handler, NULL); + + twr_module_battery_init(); + twr_module_battery_set_update_interval(BATTERY_MODULE_UPDATE_INTERVAL_SECONDS * 1000); + twr_module_battery_set_event_handler(battery_module_event_handler, NULL); + + twr_module_sigfox_init(&sigfox_module, TWR_MODULE_SIGFOX_REVISION_R2); + twr_module_sigfox_set_event_handler(&sigfox_module, sigfox_module_event_handler, NULL); + + twr_button_init(&button, TWR_GPIO_BUTTON, TWR_GPIO_PULL_DOWN, false); + twr_button_set_event_handler(&button, button_event_handler, NULL); + + twr_scheduler_plan_absolute(0, SIGFOX_FIRST_REPORT_SECONDS * 1000); +} + +void application_task(void *param) +{ + (void) param; + + if (!twr_module_sigfox_is_ready(&sigfox_module)) + { + twr_scheduler_plan_current_now(); + return; + } + + uint8_t buffer[12]; + uint32_t channel_count_a; + uint32_t channel_count_b; + int battery_voltage; + uint16_t battery_voltage_mv; + + channel_count_a = twr_pulse_counter_get(TWR_MODULE_SENSOR_CHANNEL_A); + channel_count_b = twr_pulse_counter_get(TWR_MODULE_SENSOR_CHANNEL_B); + twr_data_stream_get_average(&stream_battery_voltage_mv, &battery_voltage); + + if ((channel_a_overflow_count > 0xff) || (channel_b_overflow_count > 0xff)) + { + header = HEADER_EVENT_ERROR; + } + + battery_voltage_mv = (uint16_t)battery_voltage; + + buffer[0] = header; + buffer[1] = (((channel_a_overflow_count << 4) & 0xf0) | ((channel_b_overflow_count) & 0x0f)); + buffer[2] = channel_count_a; + buffer[3] = channel_count_a >> 8; + buffer[4] = channel_count_a >> 16; + buffer[5] = channel_count_a >> 24; + buffer[6] = channel_count_b; + buffer[7] = channel_count_b >> 8; + buffer[8] = channel_count_b >> 16; + buffer[9] = channel_count_b >> 24; + buffer[10] = battery_voltage_mv; + buffer[11] = battery_voltage_mv >> 8; + + if (twr_module_sigfox_send_rf_frame(&sigfox_module, &buffer, sizeof(buffer))) + { + twr_scheduler_plan_current_relative(SIGFOX_REPORT_INTERVAL_SECONDS * 1000); + } + else + { + twr_scheduler_plan_current_relative(1000); + } +}