Skip to content

Commit

Permalink
Merge branch 'feature/plog-relay' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
iqyx committed Jan 31, 2021
2 parents a583418 + facf0be commit 70e8c32
Show file tree
Hide file tree
Showing 20 changed files with 1,033 additions and 34 deletions.
14 changes: 14 additions & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ menu "Target configuration"
select SERVICE_UXB_MASTER
default y

config PLUMPOT_CELLULAR_UXB_VOLTAGE
bool "Measure UXB Vbus voltage"
select SERVICE_STM32_ADC
default y

choice
prompt "Clock speed"

Expand Down Expand Up @@ -447,6 +452,11 @@ menu "Enable services"
default y
depends on SERVICE_PLOG_ROUTER

config SERVICE_CLI_SERVICE_PLOG_RELAY
bool "PLOG-relay service configuration"
default y
depends on SERVICE_PLOG_RELAY

config SERVICE_CLI_DEVICE_CLOCK
bool "/device/clock submenu"
default y
Expand Down Expand Up @@ -485,6 +495,10 @@ menu "Enable services"
config SERVICE_PLOG_SENSOR_UPLOAD
bool "Service for uploading sensor data over the PLOG message router"
default y

config SERVICE_PLOG_RELAY
bool "Relay data from/to PLOG message router to/from various interfaces"
default y
endmenu

menu "Services implemented over raw UDP/TCP protocols"
Expand Down
17 changes: 16 additions & 1 deletion hal/modules/module_usart.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,26 @@ void module_usart_interrupt_handler(struct module_usart *usart) {
uint8_t byte = usart_recv(usart->port);

if (usart->rxqueue != NULL) {
BaseType_t woken;

/* Do not check the return value. If the queue is full, the received
* byte will be lost. */
xQueueSendToBackFromISR(usart->rxqueue, &byte, 0);
xQueueSendToBackFromISR(usart->rxqueue, &byte, &woken);
if (woken) {
portYIELD_FROM_ISR(woken);
}
}
}

#if defined(STM32L4)
if ((USART_ISR(usart->port) & USART_ISR_ORE)) {
#else
if ((USART_SR(usart->port) & USART_SR_ORE)) {
#endif
/* Clear the flag by reading USART_SR and USART_DR.
* Ignore the received byte. */
usart_recv(usart->port);
}
}


Expand Down
2 changes: 1 addition & 1 deletion ports/plumpot-cellular/plumpot_cellular.ld
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
MEMORY
{
rom (rx) : ORIGIN = LOAD_ADDRESS, LENGTH = 256K
ram (rwx) : ORIGIN = 0x20000000 + 2K, LENGTH = 64K - 2K
ram (rwx) : ORIGIN = 0x20000000 + 2K, LENGTH = 128K - 2K
}

INCLUDE cortex-m-generic.ld
Expand Down
71 changes: 49 additions & 22 deletions ports/plumpot-cellular/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ IServiceLocator *locator;
FsSpiffs spiffs1;
#endif

#if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE)
#include "services/adc-sensor/adc-sensor.h"
AdcSensor sensor_uxb_voltage;
#endif

SystemClock system_clock;
Stm32Rtc rtc;
Expand Down Expand Up @@ -302,20 +306,25 @@ int32_t port_init(void) {
"profiler1"
);

/* Configure and release all CS lines. */
gpio_set(GPIOB, GPIO2 | GPIO12);
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO2 | GPIO12);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO2 | GPIO12);

/* Configure GPIO for radio & flash SPI bus (SPI2), enable SPI2 clock and
* run spibus driver using libopencm3 to access it. */
gpio_mode_setup(GPIOB, GPIO_MODE_AF, GPIO_PUPD_NONE, GPIO13 | GPIO14 | GPIO15);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO13 | GPIO14 | GPIO15);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO13 | GPIO14 | GPIO15);
gpio_set_af(GPIOB, GPIO_AF5, GPIO13 | GPIO14 | GPIO15);
rcc_periph_clock_enable(RCC_SPI2);
rcc_periph_reset_pulse(RST_SPI2);
// rcc_periph_reset_pulse(RST_SPI2);
module_spibus_locm3_init(&spi2, "spi2", SPI2);
hal_interface_set_name(&(spi2.iface.descriptor), "spi2");

/* Initialize SPI device on the SPI2 bus. */
gpio_set(GPIOB, GPIO12);
gpio_mode_setup(GPIOB, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO12);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_50MHZ, GPIO12);
gpio_set_output_options(GPIOB, GPIO_OTYPE_PP, GPIO_OSPEED_2MHZ, GPIO12);
module_spidev_locm3_init(&spi2_flash1, "spi2_flash1", &(spi2.iface), GPIOB, GPIO12);
hal_interface_set_name(&(spi2_flash1.iface.descriptor), "spi2_flash1");

Expand All @@ -327,31 +336,49 @@ int32_t port_init(void) {
&(spi_flash_interface(&spi_flash1)->interface),
"spi-flash1"
);
#if defined(CONFIG_SERVICE_FS_SPIFFS)
fs_spiffs_init(&spiffs1);
// fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
if (fs_spiffs_mount(&spiffs1, spi_flash_interface(&spi_flash1)) == FS_SPIFFS_RET_OK) {
iservicelocator_add(
locator,
ISERVICELOCATOR_TYPE_FS,
&(fs_spiffs_interface(&spiffs1)->interface),
"system"
);
}
#endif
}

#if defined(CONFIG_SERVICE_FS_SPIFFS)
fs_spiffs_init(&spiffs1);
// fs_spiffs_format(&spiffs1, spi_flash_interface(&spi_flash1));
if (fs_spiffs_mount(&spiffs1, spi_flash_interface(&spi_flash1)) == FS_SPIFFS_RET_OK) {
iservicelocator_add(
locator,
ISERVICELOCATOR_TYPE_FS,
&(fs_spiffs_interface(&spiffs1)->interface),
"system"
);
}
#endif
#endif

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

/* Battery power device (using ADC). */
/** @todo resolve incompatible interfaces */
// module_power_adc_init(&vin1, "vin1", &(adc1.iface), &vin1_config);
// module_power_adc_init(&ubx_voltage, "ubx1", &(adc1.iface), &ubx_voltage_config);
#if defined(CONFIG_PLUMPOT_CELLULAR_UXB_VOLTAGE)
gpio_mode_setup(GPIOA, GPIO_MODE_ANALOG, GPIO_PUPD_NONE, GPIO6);

adc_sensor_init(
&sensor_uxb_voltage,
&adc1.iface,
6,
&(ISensorInfo) {
.quantity_name = "Voltage",
.quantity_symbol = "U",
.unit_name = "Volt",
.unit_symbol = "V"
},
540,
270
);
iservicelocator_add(
locator,
ISERVICELOCATOR_TYPE_SENSOR,
&sensor_uxb_voltage.iface.interface,
"uxb-voltage"
);
#endif

#if defined(CONFIG_SERVICE_RADIO_AX5243) || defined(CONFIG_SERVICE_RADIO_RFM69)
gpio_set(GPIOB, GPIO2);
Expand Down Expand Up @@ -539,9 +566,9 @@ int32_t port_init(void) {
#if defined(CONFIG_PLUMPOT_CELLULAR_MQTT_OVER_GSM)

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

stream_over_mqtt_init(&mqtt_cli_stream, &mqtt, "plumpot1/cli", 0);
stream_over_mqtt_init(&mqtt_cli_stream, &mqtt, CONFIG_HOSTNAME "/cli", 0);
stream_over_mqtt_start(&mqtt_cli_stream);
service_cli_init(&mqtt_cli, &(mqtt_cli_stream.stream), system_cli_tree);
service_cli_start(&mqtt_cli);
Expand Down
3 changes: 3 additions & 0 deletions services/cli/SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ if conf["SERVICE_CLI"] == "y":
if conf["SERVICE_CLI_SERVICE_PLOG_ROUTER"] == "y":
objs.append(env.Object(File("service_plog_router.c")))

if conf["SERVICE_CLI_SERVICE_PLOG_RELAY"] == "y":
objs.append(env.Object(File("service_plog_relay.c")))

if conf["SERVICE_CLI_DEVICE_CLOCK"] == "y":
objs.append(env.Object(File("device_clock.c")))

Expand Down
Loading

0 comments on commit 70e8c32

Please sign in to comment.