1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- #include <LowLevelIOInterface.h>
- #include "lpuart.h"
- /******************************************************************************
- *
- * Copyright 1998-2017 IAR Systems AB.
- *
- * This is a template implementation of the "__write" function used by
- * the standard library. Replace it with a system-specific
- * implementation.
- *
- * The "__write" function should output "size" number of bytes from
- * "buffer" in some application-specific way. It should return the
- * number of characters written, or _LLIO_ERROR on failure.
- *
- * If "buffer" is zero then __write should perform flushing of
- * internal buffers, if any. In this case "handle" can be -1 to
- * indicate that all handles should be flushed.
- *
- * The template implementation below assumes that the application
- * provides the function "MyLowLevelPutchar". It should return the
- * character written, or -1 on failure.
- *
- ******************************************************************************/
- #pragma module_name = "?__write "
- int MyLowLevelPutchar(int x)
- {
- //comSendChar(COM1, x);
- LPUart_SendData(M0P_LPUART0, (uint8_t)x); //²éѯ·½Ê½·¢ËÍÊý¾Ý
-
- return x;
- }
- size_t __write(int handle, const unsigned char * buffer, size_t size)
- {
- /* Remove the #if #endif pair to enable the implementation */
- #if 1
- size_t nChars = 0;
- if (buffer == 0)
- {
- /*
- * This means that we should flush internal buffers. Since we
- * don't we just return. (Remember, "handle" == -1 means that all
- * handles should be flushed.)
- */
- return 0;
- }
- /* This template only writes to "standard out" and "standard err",
- * for all other file handles it returns failure. */
- if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)
- {
- return _LLIO_ERROR;
- }
- for (/* Empty */; size != 0; --size)
- {
- if (MyLowLevelPutchar(*buffer++) < 0)
- {
- return _LLIO_ERROR;
- }
- ++nChars;
- }
- return nChars;
- #else
- /* Always return error code when implementation is disabled. */
- return _LLIO_ERROR;
- #endif
- }
|