diff --git a/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml b/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml index c5f3c1af9c0f8ef19a8aa2de6a236099c3d3b6a1..4151161c0e9f1eff73f574078411a97ac439e2d9 100644 --- a/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml +++ b/zephyr/boards/arm/owntech_board/dts/bindings/gpio-device.yaml @@ -2,12 +2,6 @@ description: GPIO-controllable device compatible: "gpio-device" -properties: - label: - required: true - type: string - description: Name of the peripheral (used as device_get_binding() argument) - child-binding: description: GPIO node properties: diff --git a/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi b/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi index 5185624b0e4360c4aadb8bb2d9741e60ac87f601..020cf99466093d426353ba741061fb6c8096c0d5 100644 --- a/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi +++ b/zephyr/boards/arm/owntech_board/dts/can-standby-switch.dtsi @@ -7,7 +7,6 @@ / { can-standby-switch { compatible = "gpio-device"; - label = "CAN_STANDBY"; can-standby-gpio-pin { gpios = <&gpiob 10 GPIO_ACTIVE_HIGH>; label = "CAN Standby output"; diff --git a/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi b/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi index 09a0e48370c5738b6270628233588310f1dee6b4..cde9c3f06ed7198ada36f785e07b1b9ea77c0a0c 100644 --- a/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi +++ b/zephyr/boards/arm/owntech_board/dts/ngnd.dtsi @@ -7,7 +7,6 @@ / { ngnd: ngnd-switch { compatible = "gpio-device"; - label = "NGND"; ngnd-gpio-pin { gpios = <&gpiob 11 GPIO_ACTIVE_HIGH>; label = "Neutral to GND shunt"; diff --git a/zephyr/modules/owntech_adc_driver/zephyr/src/adc_channels.c b/zephyr/modules/owntech_adc_driver/zephyr/src/adc_channels.c index 7e3ab484bcbc82e4384798276e7a4f6e2d46073d..7091a92084acbdf6d02b348f7618c46ba1708eba 100644 --- a/zephyr/modules/owntech_adc_driver/zephyr/src/adc_channels.c +++ b/zephyr/modules/owntech_adc_driver/zephyr/src/adc_channels.c @@ -57,7 +57,7 @@ typedef struct #define ADC_INPUTS_NODELABEL DT_NODELABEL(mychannels) // Channel properties -#define CHANNEL_NAME(node_id) DT_LABEL(node_id) +#define CHANNEL_NAME(node_id) DT_PROP(node_id, label) #define CHANNEL_IS_DIFF(node_id) DT_PROP(node_id, differential) #define CHANNEL_NUMBER(node_id) DT_PHA_BY_IDX(node_id, io_channels, 0, input) #define CHANNEL_ADC(node_id) DT_PROP_BY_PHANDLE_IDX(node_id, io_channels, 0, label) diff --git a/zephyr/modules/owntech_communication/zephyr/src/can.h b/zephyr/modules/owntech_communication/zephyr/src/can.h index ddaec8c7cde77e37b508495e460acb9b1e942fa1..84efe2f8f3bf6d2ec624ef200cedfe59f2f417b8 100644 --- a/zephyr/modules/owntech_communication/zephyr/src/can.h +++ b/zephyr/modules/owntech_communication/zephyr/src/can.h @@ -4,7 +4,6 @@ #include <zephyr.h> -#define CAN_DEVICE DT_LABEL(DT_NODELABEL(can1)) #define CAN_STANDBY_DEVICE DT_CHILD(DT_PATH(can_standby_switch), can_standby_gpio_pin) diff --git a/zephyr/modules/owntech_communication/zephyr/src/thingset_isotp.cpp b/zephyr/modules/owntech_communication/zephyr/src/thingset_isotp.cpp index 937eacd4d31e385dc6caadefd500f579063e4de0..8977d6fc38bf9cbe98b285f85497d10474a3f743 100644 --- a/zephyr/modules/owntech_communication/zephyr/src/thingset_isotp.cpp +++ b/zephyr/modules/owntech_communication/zephyr/src/thingset_isotp.cpp @@ -5,9 +5,11 @@ */ /** + * @date 2022 * @author Martin Jäger <martin@libre.solar> * @author Jean Alinei <jean.alinei@laas.fr> * @author Luiz Villa <luiz.villa@laas.fr> + * @author Clément Foucher <clement.foucher@laas.fr> */ #include <canbus/isotp.h> @@ -16,6 +18,7 @@ extern ThingSet ts; extern uint16_t can_node_addr; +static const struct device* can_dev = DEVICE_DT_GET(DT_NODELABEL(can1)); #define RX_THREAD_STACK_SIZE 1024 #define RX_THREAD_PRIORITY 2 @@ -53,8 +56,6 @@ void can_isotp_thread() static uint8_t rx_buffer[600]; // large enough to receive a 512k flash page for DFU static uint8_t tx_buffer[1000]; - const struct device* can_dev = device_get_binding(CAN_DEVICE); - enable_can(); if (!device_is_ready(can_dev)) { diff --git a/zephyr/modules/owntech_communication/zephyr/src/thingset_pub_sub.cpp b/zephyr/modules/owntech_communication/zephyr/src/thingset_pub_sub.cpp index 5b25ffb4bac26ce1284e66b830df07ccad26546f..0116157ad3c281adad868b7f4f862bbf42033cd6 100644 --- a/zephyr/modules/owntech_communication/zephyr/src/thingset_pub_sub.cpp +++ b/zephyr/modules/owntech_communication/zephyr/src/thingset_pub_sub.cpp @@ -5,9 +5,11 @@ */ /** + * @date 2022 * @author Martin Jäger <martin@libre.solar> * @author Jean Alinei <jean.alinei@laas.fr> * @author Luiz Villa <luiz.villa@laas.fr> + * @author Clément Foucher <clement.foucher@laas.fr> */ @@ -29,6 +31,7 @@ extern ThingSet ts; extern uint16_t can_node_addr; uint16_t broadcast_time = 10; //the time of the measurement variables broadcast (multiples of 100ms) uint16_t control_time = 10; //the time of the control variables broadcast/receive (multiples of 100ms) +static const struct device* can_dev = DEVICE_DT_GET(DT_NODELABEL(can1)); // below defines should go into the ThingSet library #define TS_CAN_SOURCE_GET(id) (((uint32_t)id & TS_CAN_SOURCE_MASK) >> TS_CAN_SOURCE_POS) @@ -51,8 +54,6 @@ void can_pub_isr(uint32_t err_flags, void *arg) void can_pub_send(uint32_t can_id, uint8_t can_data[8], uint8_t data_len) { - const struct device* can_dev = device_get_binding(CAN_DEVICE); - if (!device_is_ready(can_dev)) { return; @@ -119,8 +120,6 @@ void can_pubsub_thread() { enable_can(); - const struct device* can_dev = device_get_binding(CAN_DEVICE); - if (!device_is_ready(can_dev)) { return; diff --git a/zephyr/modules/owntech_dac_driver/zephyr/public_api/dac.h b/zephyr/modules/owntech_dac_driver/zephyr/public_api/dac.h index bd35c6d0528f7d1d27f795d8f935124880315879..158c19c8723ad020ad013045569a45f0579fed38 100644 --- a/zephyr/modules/owntech_dac_driver/zephyr/public_api/dac.h +++ b/zephyr/modules/owntech_dac_driver/zephyr/public_api/dac.h @@ -38,9 +38,9 @@ extern "C" { ///// // Public devices names -#define DAC1_DEVICE DT_LABEL(DT_NODELABEL(dac1)) -#define DAC2_DEVICE DT_LABEL(DT_NODELABEL(dac2)) -#define DAC3_DEVICE DT_LABEL(DT_NODELABEL(dac3)) +#define DAC1_DEVICE DT_NODELABEL(dac1) +#define DAC2_DEVICE DT_NODELABEL(dac2) +#define DAC3_DEVICE DT_NODELABEL(dac3) ///// diff --git a/zephyr/modules/owntech_data_acquisition/zephyr/dma/dma.c b/zephyr/modules/owntech_data_acquisition/zephyr/dma/dma.c index 20538a65e9c2f070dc1a5670a9a296b93b853e6a..5faebacab147db17a22911997678523fa150b51e 100644 --- a/zephyr/modules/owntech_data_acquisition/zephyr/dma/dma.c +++ b/zephyr/modules/owntech_data_acquisition/zephyr/dma/dma.c @@ -51,10 +51,7 @@ ///// // DT definitions -#define DMA1_NODELABEL DT_NODELABEL(dma1) -#define DMA1_LABEL DT_PROP(DMA1_NODELABEL, label) - -static const struct device* dma1; +static const struct device* dma1 = DEVICE_DT_GET(DT_NODELABEL(dma1)); ///// @@ -154,18 +151,19 @@ static void _dma_channel_init(uint8_t adc_num, uint32_t source_address, uint32_t void dma_configure_and_start(uint8_t adc_count) { - dma1 = device_get_binding(DMA1_LABEL); - half_buffer_1 = k_malloc(adc_count * sizeof(uint16_t*)); half_buffer_2 = k_malloc(adc_count * sizeof(uint16_t*)); - for (uint8_t adc_index = 0 ; adc_index < adc_count ; adc_index++) + if (device_is_ready(dma1) == true) { - uint8_t adc_num = adc_index +1; - if (adc_get_enabled_channels_count(adc_num) > 0) + for (uint8_t adc_index = 0 ; adc_index < adc_count ; adc_index++) { - _dma_channel_init(adc_num, source_registers[adc_index], source_triggers[adc_index]); - dma_start(dma1, adc_num); + uint8_t adc_num = adc_index +1; + if (adc_get_enabled_channels_count(adc_num) > 0) + { + _dma_channel_init(adc_num, source_registers[adc_index], source_triggers[adc_index]); + dma_start(dma1, adc_num); + } } } } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp index 2b15ba9e4f07c50a2210deadc95b840812ce9aa5..b213ff5134496d9a823deb9027ada158d859e93a 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/dac_configuration.cpp @@ -31,31 +31,35 @@ #include "dac.h" +static const struct device* dac1 = DEVICE_DT_GET(DAC1_DEVICE); +static const struct device* dac3 = DEVICE_DT_GET(DAC3_DEVICE); + + void dac_config_dac1_dac3_current_mode_init() { - const struct device* dac1 = device_get_binding(DAC1_DEVICE); - const struct device* dac3 = device_get_binding(DAC3_DEVICE); - - // DAC 1 - dac_function_config_t function_config = + if ( (device_is_ready(dac1) == true) && (device_is_ready(dac3) == true) ) { - .dac_function = dac_function_sawtooth, - .reset_trigger_source = hrtim_trig1, - .step_trigger_source = hrtim_trig1, - .polarity = dac_polarity_decrement, - .reset_data = 4000, - .step_data = 200 - }; - - dac_set_function(dac1, 1, &function_config); - dac_pin_configure(dac1, 1, dac_pin_internal); - dac_start(dac1, 1); - - // DAC 3 - function_config.reset_trigger_source = hrtim_trig2; - function_config.step_trigger_source = hrtim_trig2; - - dac_set_function(dac3, 1, &function_config); - dac_pin_configure(dac3, 1, dac_pin_internal); - dac_start(dac3, 1); + // DAC 1 + dac_function_config_t function_config = + { + .dac_function = dac_function_sawtooth, + .reset_trigger_source = hrtim_trig1, + .step_trigger_source = hrtim_trig1, + .polarity = dac_polarity_decrement, + .reset_data = 4000, + .step_data = 200 + }; + + dac_set_function(dac1, 1, &function_config); + dac_pin_configure(dac1, 1, dac_pin_internal); + dac_start(dac1, 1); + + // DAC 3 + function_config.reset_trigger_source = hrtim_trig2; + function_config.step_trigger_source = hrtim_trig2; + + dac_set_function(dac3, 1, &function_config); + dac_pin_configure(dac3, 1, dac_pin_internal); + dac_start(dac3, 1); + } } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp index d9167c8dbd1c3ea6257da3341f93bcccc8faa318..d227309d7b20fa1213dc3c641439da5cac11d940 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/hardware_auto_configuration.cpp @@ -41,6 +41,7 @@ // Owntech driver #include "dac.h" +static const struct device* dac2 = DEVICE_DT_GET(DAC2_DEVICE); ///// // Functions to be run @@ -57,11 +58,12 @@ static int _vrefbuf_init(const struct device* dev) static int _dac2_init(const struct device* dev) { - const struct device* dac2 = device_get_binding(DAC2_DEVICE); - - dac_set_const_value(dac2, 1, 2048U); - dac_pin_configure(dac2, 1, dac_pin_external); - dac_start(dac2, 1); + if (device_is_ready(dac2) == true) + { + dac_set_const_value(dac2, 1, 2048U); + dac_pin_configure(dac2, 1, dac_pin_external); + dac_start(dac2, 1); + } return 0; } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp index 0d6efc6f4dca24ad1930a5c50a8ec30f2f3ef9db..301288038eecea41b90be39328e9fe190e14cf09 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/ngnd_configuration.cpp @@ -25,25 +25,21 @@ #include "ngnd.h" -static const struct device* ngnd_switch = nullptr; +static const struct device* ngnd_switch = DEVICE_DT_GET(NGND_DEVICE); void ngnd_config_on() { - if (ngnd_switch == NULL) + if (device_is_ready(ngnd_switch) == true) { - ngnd_switch = device_get_binding(NGND_DEVICE); + ngnd_set(ngnd_switch, 1); } - - ngnd_set(ngnd_switch, 1); } void ngnd_config_off() { - if (ngnd_switch == NULL) + if (device_is_ready(ngnd_switch) == true) { - ngnd_switch = device_get_binding(NGND_DEVICE); + ngnd_set(ngnd_switch, 0); } - - ngnd_set(ngnd_switch, 0); } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp index 3fa04a63458741dd7ba823f208805db0fbaac4f3..e0cbd8a7749a2eff599065073a4eee898a50df9c 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/timer_configuration.cpp @@ -25,7 +25,7 @@ #include "timer.h" -static const struct device* timer4 = NULL; +static const struct device* timer4 = DEVICE_DT_GET(TIMER4_DEVICE); static bool timer4init = false; static bool timer4started = false; @@ -33,17 +33,19 @@ static bool timer4started = false; static void _timer_incremental_encoder_tim4_init() { - // Configure timer - timer4 = device_get_binding(TIMER4_DEVICE); - struct timer_config_t timer_cfg = + if (device_is_ready(timer4) == true) { - .timer_enable_irq = 0, - .timer_enable_encoder = 1, - .timer_enc_pin_mode = pull_up + // Configure timer + struct timer_config_t timer_cfg = + { + .timer_enable_irq = 0, + .timer_enable_encoder = 1, + .timer_enc_pin_mode = pull_up - }; - timer_config(timer4, &timer_cfg); - timer4init = true; + }; + timer_config(timer4, &timer_cfg); + timer4init = true; + } } void timer_incremental_encoder_tim4_start() @@ -55,8 +57,11 @@ void timer_incremental_encoder_tim4_start() if (timer4started == false) { - timer_start(timer4); - timer4started = true; + if (device_is_ready(timer4) == true) + { + timer_start(timer4); + timer4started = true; + } } } diff --git a/zephyr/modules/owntech_hardware_configuration/zephyr/src/uart_configuration.cpp b/zephyr/modules/owntech_hardware_configuration/zephyr/src/uart_configuration.cpp index 58f5462a2d3d642da0a30dd9de8fda2582144131..2c0fe7ffc73624448c06b8dbb8eccee1b73ca1c9 100644 --- a/zephyr/modules/owntech_hardware_configuration/zephyr/src/uart_configuration.cpp +++ b/zephyr/modules/owntech_hardware_configuration/zephyr/src/uart_configuration.cpp @@ -32,18 +32,20 @@ ///// -//USART 1 defines +// USART 1 defines + #define CONFIG_OWNTECH_SERIAL_TX_BUF_SIZE 5 #define CONFIG_OWNTECH_SERIAL_RX_BUF_SIZE 5 #define USART1_DEVICE DT_PROP(DT_NODELABEL(usart1), label) -static const struct device* uart_dev = NULL; +static const struct device* uart_dev = DEVICE_DT_GET(DT_NODELABEL(usart1)); static char buf_req[CONFIG_OWNTECH_SERIAL_RX_BUF_SIZE]; static bool command_flag = false; +///// +// USART 1 private functions - -void _uart_usart1_process_input(const struct device *dev, void* user_data) +static void _uart_usart1_process_input(const struct device *dev, void* user_data) { uint8_t c; @@ -60,6 +62,9 @@ void _uart_usart1_process_input(const struct device *dev, void* user_data) } } +///// +// USART 1 public functions + void uart_usart1_init() { const struct uart_config usart1_config = @@ -71,10 +76,12 @@ void uart_usart1_init() .flow_ctrl = UART_CFG_FLOW_CTRL_NONE }; - uart_dev = device_get_binding(USART1_DEVICE); - uart_configure(uart_dev, &usart1_config); - uart_irq_callback_user_data_set(uart_dev, _uart_usart1_process_input, NULL); - uart_irq_rx_enable(uart_dev); + if (device_is_ready(uart_dev) == true) + { + uart_configure(uart_dev, &usart1_config); + uart_irq_callback_user_data_set(uart_dev, _uart_usart1_process_input, NULL); + uart_irq_rx_enable(uart_dev); + } } char uart_usart1_get_data() @@ -89,7 +96,10 @@ char uart_usart1_get_data() void uart_usart1_write_single(char data) { - uart_poll_out(uart_dev,data); + if (device_is_ready(uart_dev) == true) + { + uart_poll_out(uart_dev,data); + } } void uart_lpuart1_swap_rx_tx() diff --git a/zephyr/modules/owntech_ngnd_driver/zephyr/public_api/ngnd.h b/zephyr/modules/owntech_ngnd_driver/zephyr/public_api/ngnd.h index 5a5e89941ad5e1ae7219e7a6cfb4a63ab9439c48..3f230c2220fd701c360cb5fa24ad7f8e018703a3 100644 --- a/zephyr/modules/owntech_ngnd_driver/zephyr/public_api/ngnd.h +++ b/zephyr/modules/owntech_ngnd_driver/zephyr/public_api/ngnd.h @@ -40,7 +40,7 @@ extern "C" { ///// // Public device name -#define NGND_DEVICE DT_LABEL(DT_NODELABEL(ngnd)) +#define NGND_DEVICE DT_NODELABEL(ngnd) ///// diff --git a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp index ed6186c52cf747776b34b073c0a4d3338461da8c..cc5777ca37ed85f6cc92358abe50e857c380d195 100644 --- a/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp +++ b/zephyr/modules/owntech_scheduling/zephyr/public_api/Scheduling.cpp @@ -33,7 +33,7 @@ ///// // Static variables -const struct device* Scheduling::timer6 = NULL; +const struct device* Scheduling::timer6 = DEVICE_DT_GET(TIMER6_DEVICE); const int Scheduling::DEFAULT_PRIORITY = 5; @@ -68,10 +68,9 @@ void Scheduling::threadEntryPoint(void* thread_function_p, void*, void*) void Scheduling::startControlTask(void (*periodic_task)(), uint32_t task_period_us) { - if (periodic_task != NULL) + if ( (periodic_task != NULL) && (device_is_ready(timer6) == true) ) { - // Configure timer - timer6 = device_get_binding(TIMER6_DEVICE); + // Configure and start timer struct timer_config_t timer_cfg = {0}; timer_cfg.timer_enable_irq = 1; diff --git a/zephyr/modules/owntech_timer_driver/zephyr/public_api/timer.h b/zephyr/modules/owntech_timer_driver/zephyr/public_api/timer.h index 3957cebf14d20a345f80ab240cbeb0d67baa5896..f65f7a4bd85283adc1b1078abeadf65c7ccaea88 100644 --- a/zephyr/modules/owntech_timer_driver/zephyr/public_api/timer.h +++ b/zephyr/modules/owntech_timer_driver/zephyr/public_api/timer.h @@ -51,9 +51,9 @@ extern "C" { ///// // Public devices names -#define TIMER4_DEVICE DT_LABEL(DT_NODELABEL(timers4)) -#define TIMER6_DEVICE DT_LABEL(DT_NODELABEL(timers6)) -#define TIMER7_DEVICE DT_LABEL(DT_NODELABEL(timers7)) +#define TIMER4_DEVICE DT_NODELABEL(timers4) +#define TIMER6_DEVICE DT_NODELABEL(timers6) +#define TIMER7_DEVICE DT_NODELABEL(timers7) /////