AnsweredAssumed Answered

How to customize 'FILE' operations on a 9S12XDP512 under CodeWarrier 5.9.0 and Metroworks C

Question asked by John Dammeyer on Jul 25, 2014
Latest reply on Jan 1, 2015 by John Dammeyer

Starting with this statement in my application:

USBDevice = fopen("USB1:", "r+");  // Calls TERMIO_Init()

Following fopen(LIBDEF_ConstStringPtr name, LIBDEF_ConstStringPtr mode) in the debugger I find I'm taken to TERMIO_Init() without any arguments to let me expand on the file i/o system.  The code for this is in embedded.c.  Not only that, stdlib.c has the one single declaration for FILE channels[1];  In stdio.h we have extern FILE channels[1]; and the FILE struct itself declared in stdio.h.

 

What I'd like to be able to do is handle multiple FILE channels so I can support the two UARTs, a USB connection and possibly a few others.  To do that it looks like I have to remove embedded.c and recompile into the library the stdlib.c to get rid of the channels declaration.  Shouldn't really be there in the first place since it's not used within the entire library that I can find with grep.

The run time library routines all have

   Copyright (c) Metrowerks, Basel, Switzerland

               All rights reserved

                  Do not modify!

So is there by chance an application note with code that has most of the work done to redirect the system functions like fopen, close, fputc etc. as contained in embedded.c?

Or am I on my own here?

The longer term project is to possibly add SD card and file name support.  Perhaps there's an app note that handles the fopen with file names?

Thanks

John

Outcomes