redlid __getc vs newlib _read

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

redlid __getc vs newlib _read

2,122 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Wed Oct 12 14:11:19 MST 2011
Is it possible in redlib to override stdio input primitive functions to use different file handles for different targets. I have seen examples of this using newlib.

The only example I seen for redlib is the __getc which doesnt have a file descriptor as input.

I want to be able to write stdio output to uart0 and stderr to uart1 I also want to read GPS from uart2 and read user input from uart0.

Is there something like newlib's_open _read _write in redlib which I could override? Is the redlib source available ?
0 Kudos
Reply
10 Replies

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 24 15:39:08 MST 2011

Quote:

...to provide custom io functionality without ...semihosting...

What should that be? Are we talking about retargeting?

http://support.code-red-tech.com/CodeRedWiki/UartPrintf

That's possible with NoHost and stdio :)
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Mon Oct 24 14:11:16 MST 2011

Quote: Zero
Of course :eek:

See:[U] http://support.code-red-tech.com/CodeRedWiki/SwitchingCLibrary[/U]



I understand how to change between the different library versions, my question was more how much of stdio is implemented in nohost ?
Can the __Sys_write and __sys_getc etc ... be overidden in nohost to provide custom io functionality without any of the debugging semihosting code being linked and executed ?

http://support.code-red-tech.com/CodeRedWiki/LibraryVariants
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Oct 24 10:18:27 MST 2011

Quote: tridentsx
Is that normal?



Of course :eek:

See:[U] http://support.code-red-tech.com/CodeRedWiki/SwitchingCLibrary[/U]
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Mon Oct 24 09:43:10 MST 2011
I have one more question, do I have to link the semihosting version for these functions to be called ((__sys_getc __sys_write)? I got it to work when using semihosting but not the other versions of redlib which I find peculiar?

Is that normal? Are the tops of stdio reentrant ?

Regards /// Carl
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Thu Oct 13 17:34:14 MST 2011
Much appriciated thats what I was looking for.

// Carl
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Oct 13 12:56:46 MST 2011
[FONT=Courier New][SIZE=2]__sys_readc() [/SIZE][/FONT]reads a character from stdin.

[FONT=Courier New][SIZE=2]__sys_read() [/SIZE][/FONT]reads from the file that you pass it the handle for as the first parameter.

The spec for these functions is basically take straight from ARM's semihosting specification, as detailed:

http://support.code-red-tech.com/CodeRedWiki/WhatIsSemiHosting

Regards,
CodeRedSupport
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Thu Oct 13 09:52:11 MST 2011
Its the read part that I need, beeing able to read from multiple UARTS, I could roll my own functions but would prefer to use something builtin.

Thanks for the support /// Carl
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Thu Oct 13 09:33:24 MST 2011
If you look at the example code that the FAQ points at, you will see the __sys_write() takes a handle as its first parameter. IIRC stdout will be 1, stderr will be 2.

Regards,
CodeRedSupport.
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tridentsx on Thu Oct 13 06:39:23 MST 2011

Quote: CodeRedSupport
See

http://support.code-red-tech.com/CodeRedWiki/UartPrintf

Regards,
CodeRedSupport




Thanks for the reply, I have read that page before, is it possible in newlib to override read as it is in newlib

[I]read[/I][I]Read from a file. Minimal implementation: [/I][I]int read(int file, char *ptr, int len) { return 0; }[/I]

By overriding this function I could read from different uarts by sending different file descriptor's.

Is there something similar in redlib?

Regards /// CF
0 Kudos
Reply

2,076 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Wed Oct 12 23:49:39 MST 2011
See

http://support.code-red-tech.com/CodeRedWiki/UartPrintf

Regards,
CodeRedSupport
0 Kudos
Reply