Skip to content

Commit cf29aa1

Browse files
committed
Harmonize device config with other branches
Revert "boards: move board specific configurations (#63)" This reverts commit 7e07006. Signed-off-by: Antón Casas <[email protected]>
1 parent 5c6dd91 commit cf29aa1

File tree

7 files changed

+48
-58
lines changed

7 files changed

+48
-58
lines changed

boards/disco_l475_iot1.conf

Lines changed: 0 additions & 7 deletions
This file was deleted.

boards/disco_l475_iot1.overlay

Lines changed: 0 additions & 20 deletions
This file was deleted.

modules/libmicroros/microros_transports/serial-usb/microros_transports.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ char uart_out_buffer[RING_BUF_SIZE];
3333

3434
struct ring_buf out_ringbuf, in_ringbuf;
3535

36-
static void uart_fifo_callback(const struct device *dev, void *user_data){
36+
static void uart_fifo_callback(const struct device *dev, void * user_data){
3737
while (uart_irq_update(dev) && uart_irq_is_pending(dev)) {
3838
if (uart_irq_rx_ready(dev)) {
3939
int recv_len;
@@ -64,15 +64,14 @@ static void uart_fifo_callback(const struct device *dev, void *user_data){
6464
}
6565

6666
bool zephyr_transport_open(struct uxrCustomTransport * transport){
67+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
68+
6769
int ret;
6870
uint32_t baudrate, dtr = 0U;
69-
const struct device *uart_dev;
7071

71-
/* for serial-usb transport we just override the device pointer
72-
* with USB to use the same interface
73-
*/
74-
transport->args = (void *)device_get_binding("CDC_ACM_0");
75-
if (!transport->args) {
72+
73+
params->uart_dev = device_get_binding("CDC_ACM_0");
74+
if (!params->uart_dev) {
7675
printk("CDC ACM device not found\n");
7776
return false;
7877
}
@@ -83,15 +82,13 @@ bool zephyr_transport_open(struct uxrCustomTransport * transport){
8382
return false;
8483
}
8584

86-
uart_dev = (const struct device *)transport->args;
8785
ring_buf_init(&out_ringbuf, sizeof(uart_out_buffer), uart_out_buffer);
8886
ring_buf_init(&in_ringbuf, sizeof(uart_in_buffer), uart_out_buffer);
8987

9088
printk("Waiting for agent connection\n");
9189

9290
while (true) {
93-
94-
uart_line_ctrl_get(uart_dev, UART_LINE_CTRL_DTR, &dtr);
91+
uart_line_ctrl_get(params->uart_dev, UART_LINE_CTRL_DTR, &dtr);
9592
if (dtr) {
9693
break;
9794
} else {
@@ -103,46 +100,47 @@ bool zephyr_transport_open(struct uxrCustomTransport * transport){
103100
printk("Serial port connected!\n");
104101

105102
/* They are optional, we use them to test the interrupt endpoint */
106-
ret = uart_line_ctrl_set(uart_dev, UART_LINE_CTRL_DCD, 1);
103+
ret = uart_line_ctrl_set(params->uart_dev, UART_LINE_CTRL_DCD, 1);
107104
if (ret) {
108105
printk("Failed to set DCD, ret code %d\n", ret);
109106
}
110107

111-
ret = uart_line_ctrl_set(uart_dev, UART_LINE_CTRL_DSR, 1);
108+
ret = uart_line_ctrl_set(params->uart_dev, UART_LINE_CTRL_DSR, 1);
112109
if (ret) {
113110
printk("Failed to set DSR, ret code %d\n", ret);
114111
}
115112

116113
/* Wait 1 sec for the host to do all settings */
117114
k_busy_wait(1000*1000);
118115

119-
ret = uart_line_ctrl_get(uart_dev, UART_LINE_CTRL_BAUD_RATE, &baudrate);
116+
ret = uart_line_ctrl_get(params->uart_dev, UART_LINE_CTRL_BAUD_RATE, &baudrate);
120117
if (ret) {
121118
printk("Failed to get baudrate, ret code %d\n", ret);
122119
}
123120

124-
uart_irq_callback_set(uart_dev, uart_fifo_callback);
121+
uart_irq_callback_set(params->uart_dev, uart_fifo_callback);
125122

126123
/* Enable rx interrupts */
127-
uart_irq_rx_enable(uart_dev);
124+
uart_irq_rx_enable(params->uart_dev);
128125

129126
return true;
130127
}
131128

132129
bool zephyr_transport_close(struct uxrCustomTransport * transport){
133-
(void)transport;
130+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
131+
(void) params;
134132

135133
return true;
136134
}
137135

138136
size_t zephyr_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err){
139-
const struct device * uart_dev = (const struct device *) transport->args;
137+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
140138

141139
size_t wrote;
142140

143141
wrote = ring_buf_put(&out_ringbuf, buf, len);
144-
145-
uart_irq_tx_enable(uart_dev);
142+
143+
uart_irq_tx_enable(params->uart_dev);
146144

147145
while (!ring_buf_is_empty(&out_ringbuf)){
148146
k_sleep(K_MSEC(5));
@@ -152,7 +150,7 @@ size_t zephyr_transport_write(struct uxrCustomTransport* transport, const uint8_
152150
}
153151

154152
size_t zephyr_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err){
155-
const struct device * uart_dev = (const struct device *) transport->args;
153+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
156154

157155
size_t read = 0;
158156
int spent_time = 0;
@@ -162,9 +160,9 @@ size_t zephyr_transport_read(struct uxrCustomTransport* transport, uint8_t* buf,
162160
spent_time++;
163161
}
164162

165-
uart_irq_rx_disable(uart_dev);
163+
uart_irq_rx_disable(params->uart_dev);
166164
read = ring_buf_get(&in_ringbuf, buf, len);
167-
uart_irq_rx_enable(uart_dev);
165+
uart_irq_rx_enable(params->uart_dev);
168166

169167
return read;
170168
}

modules/libmicroros/microros_transports/serial-usb/microros_transports.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ extern "C"
2929
{
3030
#endif
3131

32+
typedef struct {
33+
size_t fd;
34+
const struct device *uart_dev;
35+
} zephyr_transport_params_t;
36+
3237
#define MICRO_ROS_FRAMING_REQUIRED true
38+
static zephyr_transport_params_t default_params;
3339

3440
bool zephyr_transport_open(struct uxrCustomTransport * transport);
3541
bool zephyr_transport_close(struct uxrCustomTransport * transport);

modules/libmicroros/microros_transports/serial/microros_transports.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,20 @@ static void uart_fifo_callback(const struct device * dev, void * args){
5050
}
5151

5252
bool zephyr_transport_open(struct uxrCustomTransport * transport){
53-
const struct device * uart_dev = (const struct device *) transport->args;
53+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
54+
55+
params->uart_dev = DEVICE_DT_GET(UART_NODE);
56+
if (!params->uart_dev) {
57+
printk("Serial device not found\n");
58+
return false;
59+
}
60+
5461
ring_buf_init(&in_ringbuf, sizeof(uart_in_buffer), uart_out_buffer);
5562

56-
uart_irq_callback_set(uart_dev, uart_fifo_callback);
63+
uart_irq_callback_set(params->uart_dev, uart_fifo_callback);
5764

5865
/* Enable rx interrupts */
59-
uart_irq_rx_enable(uart_dev);
66+
uart_irq_rx_enable(params->uart_dev);
6067

6168
return true;
6269
}
@@ -68,18 +75,18 @@ bool zephyr_transport_close(struct uxrCustomTransport * transport){
6875
}
6976

7077
size_t zephyr_transport_write(struct uxrCustomTransport* transport, const uint8_t * buf, size_t len, uint8_t * err){
71-
const struct device * uart_dev = (const struct device *) transport->args;
78+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
7279

7380
for (size_t i = 0; i < len; i++)
7481
{
75-
uart_poll_out(uart_dev, buf[i]);
82+
uart_poll_out(params->uart_dev, buf[i]);
7683
}
7784

7885
return len;
7986
}
8087

8188
size_t zephyr_transport_read(struct uxrCustomTransport* transport, uint8_t* buf, size_t len, int timeout, uint8_t* err){
82-
const struct device * uart_dev = (const struct device *) transport->args;
89+
zephyr_transport_params_t * params = (zephyr_transport_params_t*) transport->args;
8390

8491
size_t read = 0;
8592
int spent_time = 0;
@@ -89,9 +96,9 @@ size_t zephyr_transport_read(struct uxrCustomTransport* transport, uint8_t* buf,
8996
spent_time++;
9097
}
9198

92-
uart_irq_rx_disable(uart_dev);
99+
uart_irq_rx_disable(params->uart_dev);
93100
read = ring_buf_get(&in_ringbuf, buf, len);
94-
uart_irq_rx_enable(uart_dev);
101+
uart_irq_rx_enable(params->uart_dev);
95102

96103
return read;
97104
}

modules/libmicroros/microros_transports/serial/microros_transports.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,13 @@ extern "C"
2929
{
3030
#endif
3131

32+
typedef struct {
33+
size_t fd;
34+
const struct device * uart_dev;
35+
} zephyr_transport_params_t;
36+
3237
#define MICRO_ROS_FRAMING_REQUIRED true
38+
volatile static zephyr_transport_params_t default_params = {.fd = 1};
3339

3440
bool zephyr_transport_open(struct uxrCustomTransport * transport);
3541
bool zephyr_transport_close(struct uxrCustomTransport * transport);

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ int main(void)
4343
{
4444
rmw_uros_set_custom_transport(
4545
MICRO_ROS_FRAMING_REQUIRED,
46-
(void *) DEVICE_DT_GET(DT_ALIAS(uros_serial_port)),
46+
(void *) &default_params,
4747
zephyr_transport_open,
4848
zephyr_transport_close,
4949
zephyr_transport_write,

0 commit comments

Comments
 (0)