Skip to content

sys: factor stdio uart functions out of newlib's syscalls#3161

Merged
OlegHahm merged 1 commit intoRIOT-OS:masterfrom
kaspar030:newlib_factor_out_uart_stdio
Jul 14, 2015
Merged

sys: factor stdio uart functions out of newlib's syscalls#3161
OlegHahm merged 1 commit intoRIOT-OS:masterfrom
kaspar030:newlib_factor_out_uart_stdio

Conversation

@kaspar030
Copy link
Copy Markdown
Contributor

I'll be introducing a musl libc port for RIOT soon. This is groundwork to decouple shared functionality.

@kaspar030 kaspar030 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer labels Jun 4, 2015
@kaspar030 kaspar030 added this to the Release 2015.06 milestone Jun 4, 2015
@jnohlgard
Copy link
Copy Markdown
Member

jnohlgard commented Jun 4, 2015 via email

@haukepetersen
Copy link
Copy Markdown
Contributor

Very much looking forward for working newlib alternatives!

I am not quite sure I understand the idea behind the uart_stdio module, though. I see it cleans up the syscalls.c code a bit, but it does not really bring any architectural improvements. How about a slightly changed approach (which to this point is just a matter of some renaming):

Rename the header from uart_stdio.h to stdio.h and strip it to these three functions:

void stdio_init(void);
int stdio_read(char* buffer, int len);
int stdio_write(const char* buffer, int len);

This interface can now be implemented in different ways (one of them of course being uart) and we can chose during compile time which of the implementation we would like to use. For simplicity it surely makes sense to set the stdio_uart module as default, but this way it can be overwritten in the Makefile with something like USEMODULE += stdio_sockets or so...

Does this make sense?

@kaspar030
Copy link
Copy Markdown
Contributor Author

Does this make sense?

Well, if you'd want to implement a generic stdio_ module, and at some point you want to use uart for a file descriptor, you can use exactly this module. So, this module is a wrapper from uart0 or periph/uart + interrupt handling to posix read/write.

At some point we might have x86_console_stdio, ..., and this module, and in newlibs syscalls, we can have a (either static or dynamic) file descriptor table, mapping e.g. _file_descriptors[0].write to uart_write.

@kaspar030
Copy link
Copy Markdown
Contributor Author

But does musl libc work on systems without an MMU?

edit Yes.

@jnohlgard
Copy link
Copy Markdown
Member

Does this make sense?

Well, if you'd want to implement a generic stdio_ module, and at some point you want to use uart for a file descriptor, you can use exactly this module. So, this module is a wrapper from uart0 or periph/uart + interrupt handling to posix read/write.

At some point we might have x86_console_stdio, ..., and this module, and in newlibs syscalls, we can have a (either static or dynamic) file descriptor table, mapping e.g. _file_descriptors[0].write to uart_write.

@kaspar030 See also the (now removed) device map/device IO stuff in the mulle port in https://github.com/RIOT-OS/RIOT/tree/bdc12b05cda97b7d9f11a079bd9dac9d59e1a8a8/cpu/k60/devio and https://github.com/RIOT-OS/RIOT/blob/bdc12b05cda97b7d9f11a079bd9dac9d59e1a8a8/boards/mulle/devicemap.c

It was deleted when migrating all the Kinetis platforms to the common Cortex-M framework in #3099 (6e12503), but feel free to reuse any parts of it that you find useful.

@jnohlgard
Copy link
Copy Markdown
Member

@haukepetersen I would suggest that the name of the new header be something other than stdio.h because the C library (be it newlib, musl, glibc) will have its printf functions etc. declared in a header with the same name which will cause problems.

@kaspar030
Copy link
Copy Markdown
Contributor Author

;)

@haukepetersen
Copy link
Copy Markdown
Contributor

I dont care about the name, my idea was just to rename the header into something more generic instead of having uart in it...

@kaspar030
Copy link
Copy Markdown
Contributor Author

rename the header into something more generic instead of having uart in it

Are you happy with uart_stdio being the implementation of an stdio interface for uart devices?

@kaspar030 kaspar030 mentioned this pull request Jun 4, 2015
10 tasks
@haukepetersen
Copy link
Copy Markdown
Contributor

yes.

@haukepetersen
Copy link
Copy Markdown
Contributor

I look at it the following way: Take e.g. the _read_r() function in the syscalls. Currently it calls uart_stdio_read(). Say there is now another stdio implementation with the function socket_stdio_read(). When you want to switch to this, you would have another _read_r() function that calls socket_stdio_read(), or have some #ifdef inside _read_r() to decide which of the two above to call.

When now renaming the interace functions to something without the reference to its implementation (e.g. stdio_read() or similar), then you can just compile in one of the implementing modules and there is no need in code changes (or #ifedfs) in syscalls.c.

@kaspar030
Copy link
Copy Markdown
Contributor Author

Well, I look at it this way:
The system calls, e.g., _read_r, take a "file descriptor" as argument. Right know, they only support one file descriptor: 0 (STDIO). Right now, that file descriptor is hard-coded to uart.

In the feature, we will have files, and maybe different simultaneous UARTs, and maybe sockets. They all can use read, write, flush, close.

So we need an interface, e.g.,

struct stdio_fd_interface { fd_read_func_t *read; fd_write_func_t *write; [...] }stdio_fd_interface_t;

An uart implementation:

const stdio_fd_interface_t uart_fd_interface = { .read = uart_stdio_read; .write = uart_stdio_write; }

and in syscalls.c an array with one stdio_interface_t pointer per file descriptor.

@jnohlgard
Copy link
Copy Markdown
Member

jnohlgard commented Jun 4, 2015 via email

@jnohlgard
Copy link
Copy Markdown
Member

jnohlgard commented Jun 4, 2015 via email

@kaspar030 kaspar030 added the CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR label Jun 4, 2015
@haukepetersen
Copy link
Copy Markdown
Contributor

I see, makes sense. Though I am not a 100% content with the file descriptor idea, though I have no hard arguments against it. But this is another discussion, so for this PR I am fine for now.

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch 2 times, most recently from 0aac46a to f6e5eac Compare June 9, 2015 18:01
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • accidently already squashed fix

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason you use a different style of license header here than in the C file? Would be nice if we could keep it consistent throughout RIOT...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 06/16/15 02:48, Hauke Petersen wrote:

Any reason you use a different style of license header here than in the C file?

c&p mistake.

@kaspar030
Copy link
Copy Markdown
Contributor Author

  • fixed license header
  • rebased

@kaspar030 kaspar030 assigned OlegHahm and unassigned haukepetersen Jul 3, 2015
@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from f6e5eac to 282ff23 Compare July 3, 2015 14:16
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for consistency: write @p len bytes from @p buffer into stdio uart

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params and return values are not properly documented - the same applies for the rest

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that doxygen will parse this correctly, leading to incomplete API documentation and warnings while building the documentation. Hence, the answer is no. Sorry, bro!

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again we're writing documentation for Doxygen, not our highly valued users.

What do you think is the purpose of doxygen?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But by letting doxygen alert on missing parameter documentation we can make
sure that the api documents are always up to date with regards to API
changes.
On Jul 7, 2015 4:36 PM, "Kaspar Schleiser" [email protected] wrote:

In sys/include/uart_stdio.h
#3161 (comment):

+#ifndef UART_STDIO_H
+#define UART_STDIO_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**

  • * @brief initialize the module
  • /
    +void uart_stdio_init(void);
    +
    +/
    *
  • * @brief read len bytes from stdio uart into buffer
  • /
    +int uart_stdio_read(char
    buffer, int len);

I think Doxygen will still warn about undocumented parameters.
Again we're writing documentation for Doxygen, not our highly valued users.


Reply to this email directly or view it on GitHub
https://github.com/RIOT-OS/RIOT/pull/3161/files#r34046394.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the C compiler working for us or ware we working for the C compiler? Will you introduce warnings into C code?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removing the source of warnings in C code usually doesn't add uglyness to the compiled program, while in this case in doxygen, it IMHO does. Whatever...

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Jul 7, 2015

Apart from the documentation this seems to be fine.

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from 0688e51 to 851ecfc Compare July 7, 2015 15:58
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • fixed doxygen

@OlegHahm
Copy link
Copy Markdown
Member

OlegHahm commented Jul 7, 2015

ACK. Please squash!

@OlegHahm OlegHahm added CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jul 7, 2015
@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from 851ecfc to 96aad6d Compare July 7, 2015 18:04
@kaspar030 kaspar030 added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: needs squashing Commits in this PR need to be squashed; If set, CI systems will mark this PR as unmergable labels Jul 7, 2015
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/@len/@p len/

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from 53d95d7 to 7482090 Compare July 8, 2015 09:55
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • squashed again

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Warning unused parameter", add

    (void)r;
    (void)fd;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(at least until we add any kind of file descriptor support)

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from 7482090 to e52210f Compare July 13, 2015 22:45
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • addressed @gebart's comment
  • rebased
  • squashed again

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from e52210f to 41cfe59 Compare July 14, 2015 12:27
@kaspar030
Copy link
Copy Markdown
Contributor Author

  • fixed typo
  • squashed

@OlegHahm
Copy link
Copy Markdown
Member

Needs a rebase, too.

@kaspar030 kaspar030 force-pushed the newlib_factor_out_uart_stdio branch from 41cfe59 to 49ea7a3 Compare July 14, 2015 13:14
@kaspar030
Copy link
Copy Markdown
Contributor Author

kaspar030 commented Jul 14, 2015 via email

@kaspar030
Copy link
Copy Markdown
Contributor Author

Travis is happy...

@OlegHahm
Copy link
Copy Markdown
Member

ACK holds - and go!

OlegHahm added a commit that referenced this pull request Jul 14, 2015
sys: factor stdio uart functions out of newlib's syscalls
@OlegHahm OlegHahm merged commit a7f3a3d into RIOT-OS:master Jul 14, 2015
@kaspar030
Copy link
Copy Markdown
Contributor Author

perfect. thanks for reviewing!

@kaspar030 kaspar030 deleted the newlib_factor_out_uart_stdio branch July 15, 2015 09:27
@kaspar030 kaspar030 mentioned this pull request Jul 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Impact: minor The PR is small in size and might only require a quick look of a knowledgeable reviewer Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants