Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
card10
firmware
Commits
8765f08c
Verified
Commit
8765f08c
authored
Aug 03, 2019
by
Rahix
Browse files
feat(serial): Add epic_uart_read_str() API-call
Signed-off-by:
Rahix
<
rahix@rahix.de
>
parent
32808693
Changes
2
Hide whitespace changes
Inline
Side-by-side
epicardium/epicardium.h
View file @
8765f08c
...
...
@@ -31,7 +31,7 @@ typedef unsigned int size_t;
#define API_SYSTEM_EXEC 0x2
/* TODO */
#define API_UART_WRITE_STR 0x3
#define API_UART_READ_CHAR 0x4
#define API_UART_READ_STR 0x5
/* TODO */
#define API_UART_READ_STR 0x5
#define API_STREAM_READ 0x6
#define API_INTERRUPT_ENABLE 0x7
#define API_INTERRUPT_DISABLE 0x8
...
...
@@ -136,14 +136,27 @@ API(API_UART_WRITE_STR, void epic_uart_write_str(
));
/**
* Try reading a single character from any connected serial device.
*
* Try reading a single character from any connected serial device. If nothing
* is available, :c:func:`epic_uart_read_char` returns ``(-1)``.
* If nothing is available, :c:func:`epic_uart_read_char` returns ``(-1)``.
*
* :return: The byte or ``(-1)`` if no byte was available.
*/
API
(
API_UART_READ_CHAR
,
int
epic_uart_read_char
(
void
));
/**
* Read as many characters as possible from the UART queue.
*
* :c:func:`epic_uart_read_str` will not block if no new data is available. For
* an example, see :c:func:`epic_isr_uart_rx`.
*
* :param char* buf: Buffer to be filled with incoming data.
* :param size_t cnt: Size of ``buf``.
* :returns: Number of bytes read. Can be ``0`` if no data was available.
* Might be a negative value if an error occured.
*/
API
(
API_UART_READ_STR
,
int
epic_uart_read_str
(
char
*
buf
,
size_t
cnt
));
/**
* **Interrupt Service Routine**
*
...
...
epicardium/modules/serial.c
View file @
8765f08c
...
...
@@ -43,6 +43,22 @@ int epic_uart_read_char(void)
return
(
-
1
);
}
/*
* API-call to read data from the queue.
*/
int
epic_uart_read_str
(
char
*
buf
,
size_t
cnt
)
{
int
i
=
0
;
for
(
i
=
0
;
i
<
cnt
;
i
++
)
{
if
(
xQueueReceive
(
read_queue
,
&
buf
[
i
],
0
)
!=
pdTRUE
)
{
break
;
}
}
return
i
;
}
/* Interrupt handler needed for SDK UART implementation */
void
UART0_IRQHandler
(
void
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment