Skip to content

Commit a64fda5

Browse files
committed
use one mutex per uart
1 parent 61cc258 commit a64fda5

File tree

5 files changed

+29
-30
lines changed

5 files changed

+29
-30
lines changed

drivers/include/slipmux.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ typedef struct {
159159
* @brief Device state (decoder-, powerstate)
160160
*/
161161
uint8_t state;
162+
#if IS_USED(MODULE_SLIPMUX_STDIO) || IS_USED(MODULE_SLIPMUX_COAP)
163+
/**
164+
* @brief Mutex to synchronize write operations to the UART between stdio,
165+
* coap and net / SLIP sub-modules.
166+
*/
167+
mutex_t mutex;
168+
#endif
162169
} slipmux_t;
163170

164171
#ifdef __cplusplus

drivers/slipmux/coap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,16 @@ void slipmux_coap_notify(slipmux_t *dev)
3636
}
3737
}
3838

39-
void slipmux_coap_send(uint8_t *buf, size_t len, const slipmux_t *dev)
39+
void slipmux_coap_send(uint8_t *buf, size_t len, slipmux_t *dev)
4040
{
4141
uint16_t fcs_sum = crc16_ccitt_fcs_finish(SPECIAL_INIT_FCS, buf, len);
4242

43-
slipmux_lock();
43+
slipmux_lock(dev);
4444
slipmux_write_byte(dev->config.uart, SLIPMUX_COAP_START);
4545
slipmux_write_bytes(dev->config.uart, buf, len);
4646
slipmux_write_bytes(dev->config.uart, (uint8_t *) &fcs_sum, 2);
4747
slipmux_write_byte(dev->config.uart, SLIPMUX_END);
48-
slipmux_unlock();
48+
slipmux_unlock(dev);
4949
}
5050

5151
int slipmux_coap_recv(uint8_t *buf, size_t buf_size, slipmux_t *dev)

drivers/slipmux/include/slipmux_internal.h

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <stddef.h>
2222
#include <stdint.h>
2323

24-
#include "isrpipe.h"
2524
#include "periph/uart.h"
2625
#include "mutex.h"
2726

@@ -36,22 +35,11 @@ extern "C" {
3635
*/
3736
#define SLIPMUX_DEV_NUM ARRAY_SIZE(slipmux_params)
3837

39-
/**
40-
* @brief ISR pipe to hand read bytes to stdin
41-
*/
42-
extern isrpipe_t slipmux_stdio_isrpipe;
43-
4438
/**
4539
* @brief List of slipmux devices.
4640
*/
4741
extern slipmux_t slipmux_devs[SLIPMUX_DEV_NUM];
4842

49-
/**
50-
* @brief Mutex to synchronize write operations to the UART between stdio,
51-
* coap and net / SLIP sub-modules.
52-
*/
53-
extern mutex_t slipmux_mutex;
54-
5543
/**
5644
* @name SLIP marker bytes
5745
* @see [RFC 1055](https://tools.ietf.org/html/rfc1055)
@@ -150,28 +138,32 @@ void slipmux_write_bytes(uart_t uart, const uint8_t *data, size_t len);
150138

151139
/**
152140
* @brief Acquire exclusive access for writing
141+
* Guarded for _stdio or _coap, the idea being that if only _net is
142+
* used, you are most likely to care about performance.
153143
*/
154-
static inline void slipmux_lock(void)
144+
static inline void slipmux_lock(slipmux_t *dev)
155145
{
156-
if (IS_USED(MODULE_SLIPMUX_STDIO) || IS_USED(MODULE_SLIPMUX_COAP)) {
157-
mutex_lock(&slipmux_mutex);
158-
}
146+
(void) dev;
147+
#if IS_USED(MODULE_SLIPMUX_STDIO) || IS_USED(MODULE_SLIPMUX_COAP)
148+
mutex_lock(&dev->mutex);
149+
#endif
159150
}
160151

161152
/**
162153
* @brief Release the exclusive access
163154
*/
164-
static inline void slipmux_unlock(void)
155+
static inline void slipmux_unlock(slipmux_t *dev)
165156
{
166-
if (IS_USED(MODULE_SLIPMUX_STDIO) || IS_USED(MODULE_SLIPMUX_COAP)) {
167-
mutex_unlock(&slipmux_mutex);
168-
}
157+
(void) dev;
158+
#if IS_USED(MODULE_SLIPMUX_STDIO) || IS_USED(MODULE_SLIPMUX_COAP)
159+
mutex_unlock(&dev->mutex);
160+
#endif
169161
}
170162

171163
#if IS_USED(MODULE_SLIPMUX_COAP)
172164
/**
173165
* @brief Initialise the CoAP handling
174-
*
166+
*
175167
* @param[in] dev The Slipmux device to initialise.
176168
* @param[in] index Device number.
177169
*/
@@ -188,7 +180,7 @@ void slipmux_coap_notify(slipmux_t *dev);
188180
#if IS_USED(MODULE_SLIPMUX_NET)
189181
/**
190182
* @brief Initialise the network handling
191-
*
183+
*
192184
* @param[in] dev The Slipmux device to initialise.
193185
* @param[in] index Device number.
194186
*/

drivers/slipmux/net.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,14 +90,14 @@ static int _send(netdev_t *netdev, const iolist_t *iolist)
9090
return bytes;
9191
}
9292

93-
slipmux_lock();
93+
slipmux_lock(dev);
9494
for (const iolist_t *iol = iolist; iol; iol = iol->iol_next) {
9595
uint8_t *data = iol->iol_base;
9696
slipmux_write_bytes(dev->config.uart, data, iol->iol_len);
9797
bytes += iol->iol_len;
9898
}
9999
slipmux_write_byte(dev->config.uart, SLIPMUX_END);
100-
slipmux_unlock();
100+
slipmux_unlock(dev);
101101
return bytes;
102102
}
103103

drivers/slipmux/stdio.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static void _isrpipe_write(void *arg, uint8_t data)
2727

2828
static void _init(void)
2929
{
30-
/* intentionally overwritten in netdev init so we have stdio before
30+
/* intentionally overwritten in slipmux init so we have stdio before
3131
* the network device is initialized */
3232
uart_init(slipmux_params[0].uart, slipmux_params[0].baudrate,
3333
_isrpipe_write, &stdin_isrpipe);
@@ -37,11 +37,11 @@ static void _init(void)
3737

3838
static ssize_t _write(const void *buffer, size_t len)
3939
{
40-
slipmux_lock();
40+
slipmux_lock(&slipmux_devs[0]);
4141
slipmux_write_byte(slipmux_params[0].uart, SLIPMUX_STDIO_START);
4242
slipmux_write_bytes(slipmux_params[0].uart, buffer, len);
4343
slipmux_write_byte(slipmux_params[0].uart, SLIPMUX_END);
44-
slipmux_unlock();
44+
slipmux_unlock(&slipmux_devs[0]);
4545
return len;
4646
}
4747

0 commit comments

Comments
 (0)