EmbeddedRelated.com
Forums

Using both UART with newlib.

Started by "aurelien.courant" August 22, 2007
Hi,

I'm having trouble using both UART with newlib. With this struct :

const struct device_table_entry *device_table[] = {
&com1, /* stdin */
&com1, /* stdout */
&com2, /* stderr */
0 }; /* end of list */

you can associate stdin, stdout and stderr to an &com1 etc... But I
need more than those 3. I would like to add a 4th device in that list
(very simple) but I don't know how to associate it with a FILE* such
as stdin or stdout... (its automaticaly done with thoses ones).

Any ideas ?

Best regards,

Aurien COURANT

An Engineer's Guide to the LPC2100 Series

For any devices *other* than stdin,stdout and stderr (ie. your 4th device) you will need to call "open" to get a file descriptor that you then use. In the case of the std's this step is done for you by the library (in the case of newlib_lpc when you make the first access).
I'm not sure if I'm answering your question though ?
________________________________

From: l... [mailto:l...] On Behalf Of aurelien.courant
Sent: Wednesday, 22 August 2007 10:20 PM
To: l...
Subject: [lpc2000] Using both UART with newlib.

Hi,

I'm having trouble using both UART with newlib. With this struct :

const struct device_table_entry *device_table[] = {
&com1, /* stdin */
&com1, /* stdout */
&com2, /* stderr */
0 }; /* end of list */

you can associate stdin, stdout and stderr to an &com1 etc... But I
need more than those 3. I would like to add a 4th device in that list
(very simple) but I don't know how to associate it with a FILE* such
as stdin or stdout... (its automaticaly done with thoses ones).

Any ideas ?

Best regards,

Aurien COURANT
At 10:35 AM 8/23/2007 +1000, Bruce Paterson wrote:
>For any devices *other* than stdin,stdout and stderr (ie. your 4th device)
>you will need to call "open" to get a file descriptor that you then use.
>In the case of the std's this step is done for you by the library (in the
>case of newlib_lpc when you make the first access).
>I'm not sure if I'm answering your question though ?

Or use fopen to get a FILE * type instead of a file handle.

> From: l... [mailto:l...] On
> Behalf Of aurelien.courant
>
> I'm having trouble using both UART with newlib. With this struct :
>
> const struct device_table_entry *device_table[] = {
> &com1, /* stdin */
> &com1, /* stdout */
> &com2, /* stderr */
> 0 }; /* end of list */
>
> you can associate stdin, stdout and stderr to an &com1 etc... But I
> need more than those 3. I would like to add a 4th device in that list
> (very simple) but I don't know how to associate it with a FILE* such
> as stdin or stdout... (its automaticaly done with thoses ones).
>

There's some extra overhead involved to get stdin, stdout and stderr to
appear to be already open. In many ways it would be a lot cleaner if there
weren't.

Robert

http://www.aeolusdevelopment.com/

From the Divided by a Common Language File (Edited to protect the guilty)
ME - "I'd like to get Price and delivery for connector Part # XXXXX"
Dist./Rep - "$X.XX Lead time 37 days"
ME - "Anything we can do about lead time? 37 days seems a bit high."
Dist./Rep - "that is the lead time given because our stock is live.... we
currently have stock."
Hi,

Thank you, I just had to open a file descriptor
FILE* fd = fopen("com1", "R+"); and use it.

Bye
--- In l..., "Bruce Paterson"
wrote:
>
> For any devices *other* than stdin,stdout and stderr (ie. your 4th
device) you will need to call "open" to get a file descriptor that you
then use. In the case of the std's this step is done for you by the
library (in the case of newlib_lpc when you make the first access).
> I'm not sure if I'm answering your question though ?
> ________________________________
>
> From: l... [mailto:l...] On
Behalf Of aurelien.courant
> Sent: Wednesday, 22 August 2007 10:20 PM
> To: l...
> Subject: [lpc2000] Using both UART with newlib.
>
>
>
> Hi,
>
> I'm having trouble using both UART with newlib. With this struct :
>
> const struct device_table_entry *device_table[] = {
> &com1, /* stdin */
> &com1, /* stdout */
> &com2, /* stderr */
> 0 }; /* end of list */
>
> you can associate stdin, stdout and stderr to an &com1 etc... But I
> need more than those 3. I would like to add a 4th device in that list
> (very simple) but I don't know how to associate it with a FILE* such
> as stdin or stdout... (its automaticaly done with thoses ones).
>
> Any ideas ?
>
> Best regards,
>
> Aurien COURANT
>
>
>
>
>
>
>