kfsw-platform/src/semihost.c
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | #include <errno.h> | ||
| 2 | #include <zephyr/sys/atomic.h> | ||
| 3 | #include <kfsw/platform/semihost.h> | ||
| 4 | |||
| 5 | #include "semihost_internal.h" | ||
| 6 | |||
| 7 | static atomic_t writing; | ||
| 8 | |||
| 9 | 96 | int kfsw_semihost_write(const char *text, size_t size) | |
| 10 | { | ||
| 11 | int result; | ||
| 12 | long unwritten; | ||
| 13 | |||
| 14 | 96 | if ((text == NULL) || (size == 0U) || (size > KFSW_SEMIHOST_MAX_WRITE)) { | |
| 15 | 12 | return -EINVAL; | |
| 16 | } | ||
| 17 | 84 | result = kfsw_semihost_context(); | |
| 18 | 84 | if (result != 0) { | |
| 19 | 16 | return result; | |
| 20 | } | ||
| 21 | 68 | if (!atomic_cas(&writing, 0, 1)) { | |
| 22 | 24 | return -EBUSY; | |
| 23 | } | ||
| 24 | 44 | unwritten = kfsw_semihost_target_write(text, size); | |
| 25 | 44 | atomic_clear(&writing); | |
| 26 | 44 | return unwritten == 0L ? 0 : -EIO; | |
| 27 | } | ||
| 28 |