printer.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #include <LowLevelIOInterface.h>
  2. #include "lpuart.h"
  3. /******************************************************************************
  4. *
  5. * Copyright 1998-2017 IAR Systems AB.
  6. *
  7. * This is a template implementation of the "__write" function used by
  8. * the standard library. Replace it with a system-specific
  9. * implementation.
  10. *
  11. * The "__write" function should output "size" number of bytes from
  12. * "buffer" in some application-specific way. It should return the
  13. * number of characters written, or _LLIO_ERROR on failure.
  14. *
  15. * If "buffer" is zero then __write should perform flushing of
  16. * internal buffers, if any. In this case "handle" can be -1 to
  17. * indicate that all handles should be flushed.
  18. *
  19. * The template implementation below assumes that the application
  20. * provides the function "MyLowLevelPutchar". It should return the
  21. * character written, or -1 on failure.
  22. *
  23. ******************************************************************************/
  24. #pragma module_name = "?__write "
  25. int MyLowLevelPutchar(int x)
  26. {
  27. //comSendChar(COM1, x);
  28. LPUart_SendData(M0P_LPUART0, (uint8_t)x); //²éѯ·½Ê½·¢ËÍÊý¾Ý
  29. return x;
  30. }
  31. size_t __write(int handle, const unsigned char * buffer, size_t size)
  32. {
  33. /* Remove the #if #endif pair to enable the implementation */
  34. #if 1
  35. size_t nChars = 0;
  36. if (buffer == 0)
  37. {
  38. /*
  39. * This means that we should flush internal buffers. Since we
  40. * don't we just return. (Remember, "handle" == -1 means that all
  41. * handles should be flushed.)
  42. */
  43. return 0;
  44. }
  45. /* This template only writes to "standard out" and "standard err",
  46. * for all other file handles it returns failure. */
  47. if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR)
  48. {
  49. return _LLIO_ERROR;
  50. }
  51. for (/* Empty */; size != 0; --size)
  52. {
  53. if (MyLowLevelPutchar(*buffer++) < 0)
  54. {
  55. return _LLIO_ERROR;
  56. }
  57. ++nChars;
  58. }
  59. return nChars;
  60. #else
  61. /* Always return error code when implementation is disabled. */
  62. return _LLIO_ERROR;
  63. #endif
  64. }