This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

freopen and SCI_open from F2837xS_sci_io.c on F28377S LaunchPad

Other Parts Discussed in Thread: CONTROLSUITE

Hi,

i need to reroute both the stdout and stdin streams. I tried the following code.

    status = add_device("scia", _MSA, SCI_open, SCI_close, SCI_read, SCI_write, SCI_lseek, SCI_unlink, SCI_rename);
    UartOutfp = freopen("scia:in", "r", stdin);
    setvbuf(stdin, NULL, _IONBF, 0);
    UartInfp = freopen("scia:out", "w", stdout);
    setvbuf(stdout, NULL, _IONBF, 0);

I noticed that the second reopen always fails. This is due to the implementation of the function SCI_open from F2837xS_sci_io.c .

The SCI_open function is defined as follows:

int SCI_open(const char * path, unsigned flags, int llv_fd)
{
    if(deviceOpen){
        return (-1);
    }else{
        ...
        deviceOpen = 1;
        return (1);    
    } 

Freopen calls SCI_open. So the first call to SCI_open will set deviceOpen to 1 and subsequent calls of the function will return -1. This is why the second call to freopen fails. Is this behavior reasonable?

So do i always return 1 or am i doing something wrong about rerouting the std streams?

Best Regards,

Waldemar Isbrecht

  • Hi Waldemar,

    What are you trying to accomplish in your system? Are you using controlSUITE?

    Where is freopen() defined?

    There are some other functions that may be useful for you in F2837x_common\utils\.
  • Hi Sal,

    thanks for your reply. Yes sure i'm using controlSUITE. I'm just trying to make printf and all the other standard C I/O functions work with the UART. Therefor i'm using the add_device function. Also i need to reroute stdout and stdin simultaneously. All the examples i found sofar only reroute stdout. So the obviosus next thing to do was to just call freopen a second time. But this turned out to fail due to SCI_open returning -1 when being called a second time. I also investigated the F2837x_common\utils\ folder and found all the other functions exept for cmdline.h/c not to meet my needs. I just want to implement a simple commandline interface (yes, i'm gonna use cmdline.h from F2837xS_common\utils).

    So i was wandering if it's intended behavior of SCI_open to return -1 on second call?

    freopen is defined in stdio.h

    Best Regards,
    Waldemar

  • Hi Waldemar,

    I am not sure when these files/functions were created and implemented for C28x, but looking at the functions, they seem to only offer some of the functionality. They are not complete functions.

    If you are trying to read and right from the UART, I suggest UARTprintf() and UARTgetc() in usartstdio.c

    You can also see uart.c in \F283xD_common\driverlib.

    sal