Skip to content

Commit 70e8c32

Browse files
committed
Merge branch 'feature/plog-relay' into develop
2 parents a583418 + facf0be commit 70e8c32

File tree

20 files changed

+1033
-34
lines changed

20 files changed

+1033
-34
lines changed

Kconfig

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,11 @@ menu "Target configuration"
6565
select SERVICE_UXB_MASTER
6666
default y
6767

68+
config PLUMPOT_CELLULAR_UXB_VOLTAGE
69+
bool "Measure UXB Vbus voltage"
70+
select SERVICE_STM32_ADC
71+
default y
72+
6873
choice
6974
prompt "Clock speed"
7075

@@ -447,6 +452,11 @@ menu "Enable services"
447452
default y
448453
depends on SERVICE_PLOG_ROUTER
449454

455+
config SERVICE_CLI_SERVICE_PLOG_RELAY
456+
bool "PLOG-relay service configuration"
457+
default y
458+
depends on SERVICE_PLOG_RELAY
459+
450460
config SERVICE_CLI_DEVICE_CLOCK
451461
bool "/device/clock submenu"
452462
default y
@@ -485,6 +495,10 @@ menu "Enable services"
485495
config SERVICE_PLOG_SENSOR_UPLOAD
486496
bool "Service for uploading sensor data over the PLOG message router"
487497
default y
498+
499+
config SERVICE_PLOG_RELAY
500+
bool "Relay data from/to PLOG message router to/from various interfaces"
501+
default y
488502
endmenu
489503

490504
menu "Services implemented over raw UDP/TCP protocols"

hal/modules/module_usart.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,26 @@ void module_usart_interrupt_handler(struct module_usart *usart) {
4545
uint8_t byte = usart_recv(usart->port);
4646

4747
if (usart->rxqueue != NULL) {
48+
BaseType_t woken;
49+
4850
/* Do not check the return value. If the queue is full, the received
4951
* byte will be lost. */
50-
xQueueSendToBackFromISR(usart->rxqueue, &byte, 0);
52+
xQueueSendToBackFromISR(usart->rxqueue, &byte, &woken);
53+
if (woken) {
54+
portYIELD_FROM_ISR(woken);
55+
}
5156
}
5257
}
58+
59+
#if defined(STM32L4)
60+
if ((USART_ISR(usart->port) & USART_ISR_ORE)) {
61+
#else
62+
if ((USART_SR(usart->port) & USART_SR_ORE)) {
63+
#endif
64+
/* Clear the flag by reading USART_SR and USART_DR.
65+
* Ignore the received byte. */
66+
usart_recv(usart->port);
67+
}
5368
}
5469

5570

ports/plumpot-cellular/plumpot_cellular.ld

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
MEMORY
55
{
66
rom (rx) : ORIGIN = LOAD_ADDRESS, LENGTH = 256K
7-
ram (rwx) : ORIGIN = 0x20000000 + 2K, LENGTH = 64K - 2K
7+
ram (rwx) : ORIGIN = 0x20000000 + 2K, LENGTH = 128K - 2K
88
}
99

1010
INCLUDE cortex-m-generic.ld

ports/plumpot-cellular/port.c

Lines changed: 49 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ IServiceLocator *locator;
165165
FsSpiffs spiffs1;
166166
#endif
167167

168+
#if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE)
169+
#include "services/adc-sensor/adc-sensor.h"
170+
AdcSensor sensor_uxb_voltage;
171+
#endif
168172

169173
SystemClock system_clock;
170174
Stm32Rtc rtc;
@@ -302,20 +306,25 @@ int32_t port_init(void) {
302306
"profiler1"
303307
);
304308

309+
/* Configure and release all CS lines. */
310+
gpio_set(GPIOB, GPIO2 | GPIO12);
311+
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO2 | GPIO12);
312+
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO2 | GPIO12);
313+
305314
/* Configure GPIO for radio & flash SPI bus (SPI2), enable SPI2 clock and
306315
* run spibus driver using libopencm3 to access it. */
307316
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO13 | GPIO14 | GPIO15);
308-
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO13 | GPIO14 | GPIO15);
317+
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO13 | GPIO14 | GPIO15);
309318
gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);
310319
rcc_periph_clock_enable(RCC_SPI2);
311-
rcc_periph_reset_pulse(RST_SPI2);
320+
// rcc_periph_reset_pulse(RST_SPI2);
312321
module_spibus_locm3_init(&spi2, "spi2", SPI2);
313322
hal_interface_set_name(&(spi2.iface.descriptor), "spi2");
314323

315324
/* Initialize SPI device on the SPI2 bus. */
316325
gpio_set(GPIOB, GPIO12);
317326
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
318-
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO12);
327+
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO12);
319328
module_spidev_locm3_init(&spi2_flash1, "spi2_flash1", &(spi2.iface), GPIOB, GPIO12);
320329
hal_interface_set_name(&(spi2_flash1.iface.descriptor), "spi2_flash1");
321330

@@ -327,31 +336,49 @@ int32_t port_init(void) {
327336
&(spi_flash_interface(&spi_flash1)->interface),
328337
"spi-flash1"
329338
);
339+
#if defined(CONFIG_SERVICE_FS_SPIFFS)
340+
fs_spiffs_init(&spiffs1);
341+
// fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
342+
if (fs_spiffs_mount(&spiffs1, spi_flash_interface(&spi_flash1)) == FS_SPIFFS_RET_OK) {
343+
iservicelocator_add(
344+
locator,
345+
ISERVICELOCATOR_TYPE_FS,
346+
&(fs_spiffs_interface(&spiffs1)->interface),
347+
"system"
348+
);
349+
}
350+
#endif
330351
}
331-
332-
#if defined(CONFIG_SERVICE_FS_SPIFFS)
333-
fs_spiffs_init(&spiffs1);
334-
// fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
335-
if (fs_spiffs_mount(&spiffs1, spi_flash_interface(&spi_flash1)) == FS_SPIFFS_RET_OK) {
336-
iservicelocator_add(
337-
locator,
338-
ISERVICELOCATOR_TYPE_FS,
339-
&(fs_spiffs_interface(&spiffs1)->interface),
340-
"system"
341-
);
342-
}
343-
#endif
344352
#endif
345353

346354
/* ADC initialization (power metering, prng seeding) */
347355
#if defined(CONFIG_SERVICE_STM32_ADC)
348356
adc_stm32_locm3_init(&adc1, ADC1);
349357
#endif
350358

351-
/* Battery power device (using ADC). */
352-
/** @todo resolve incompatible interfaces */
353-
// module_power_adc_init(&vin1, "vin1", &(adc1.iface), &vin1_config);
354-
// module_power_adc_init(&ubx_voltage, "ubx1", &(adc1.iface), &ubx_voltage_config);
359+
#if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE)
360+
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO6);
361+
362+
adc_sensor_init(
363+
&sensor_uxb_voltage,
364+
&adc1.iface,
365+
6,
366+
&(ISensorInfo) {
367+
.quantity_name = "Voltage",
368+
.quantity_symbol = "U",
369+
.unit_name = "Volt",
370+
.unit_symbol = "V"
371+
},
372+
540,
373+
270
374+
);
375+
iservicelocator_add(
376+
locator,
377+
ISERVICELOCATOR_TYPE_SENSOR,
378+
&sensor_uxb_voltage.iface.interface,
379+
"uxb-voltage"
380+
);
381+
#endif
355382

356383
#if defined(CONFIG_SERVICE_RADIO_AX5243) || defined(CONFIG_SERVICE_RADIO_RFM69)
357384
gpio_set(GPIOB, GPIO2);
@@ -539,9 +566,9 @@ int32_t port_init(void) {
539566
#if defined(CONFIG_PLUMPOT_CELLULAR_MQTT_OVER_GSM)
540567

541568
/** @todo generic service move to the system init */
542-
mqtt_sensor_upload_init(&mqtt_sensor, &mqtt, "plumpot1/s", 120000);
569+
mqtt_sensor_upload_init(&mqtt_sensor, &mqtt, CONFIG_HOSTNAME "/s", 120000);
543570

544-
stream_over_mqtt_init(&mqtt_cli_stream, &mqtt, "plumpot1/cli", 0);
571+
stream_over_mqtt_init(&mqtt_cli_stream, &mqtt, CONFIG_HOSTNAME "/cli", 0);
545572
stream_over_mqtt_start(&mqtt_cli_stream);
546573
service_cli_init(&mqtt_cli, &(mqtt_cli_stream.stream), system_cli_tree);
547574
service_cli_start(&mqtt_cli);

services/cli/SConscript

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ if conf["SERVICE_CLI"] == "y":
2525
if conf["SERVICE_CLI_SERVICE_PLOG_ROUTER"] == "y":
2626
objs.append(env.Object(File("service_plog_router.c")))
2727

28+
if conf["SERVICE_CLI_SERVICE_PLOG_RELAY"] == "y":
29+
objs.append(env.Object(File("service_plog_relay.c")))
30+
2831
if conf["SERVICE_CLI_DEVICE_CLOCK"] == "y":
2932
objs.append(env.Object(File("device_clock.c")))
3033

0 commit comments

Comments
 (0)