for use w/_write(), how to create new FILE object for use with fprintf

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

I've over-ridden the _write() function so that printf output is directed to a device (one of several UARTs) of my choosing.  The _write() method takes a file descriptor int which is used to specific which device the output is bound for.  

   

However, I have several 'devices' that I'd like to send output to with fprintf, thus think I need to create a FILE object and set the file descriptor.  Unfortunately, calling fprintf with my own FILE objects is resulting in a call to _write().  I've even tried to copy stderr as follows without success.

   

Any ideas?

   

Thanks,

   

Chris

   

main() {

   

FILE fobj;

   

memcpy(&fobj, stderr, sizeof(FILE))

   

fobj._file = FD_UART_2;

   

fprintf(&fobj,"something\n");

   

 } // main

   

 

   

int _write(int file, char *ptr, int len) {

   

  LED_Y_Write(~LED_Y_Read()); // how I know its not getting called w/fprintf

   

 

   

switch(file) {

   

  case stdout: 

   

  case stderr :

   

  UART_1_PutArray(ptr, len); 

   

  break;

   

case FD_UART_2 : 

   

  UART_2_PutArray(ptr, len);

   

break;

   

  } // switch
 

   

} // _write

0 Likes
1 Reply
Anonymous
Not applicable

Can you please create a tech support case and attach the coplete project so that we can take it from there to debug the issue.

   

https://secure.cypress.com/myaccount/?id=25&source=CY-ENG-HEADER

   

 

   

Thanks,

   

Keerthi

0 Likes