syscalls.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**************************************************************************//*****
  2. * @file stdio.c
  3. * @brief Implementation of newlib syscall
  4. ********************************************************************************/
  5. #include <stdio.h>
  6. #include <stdarg.h>
  7. #include <sys/types.h>
  8. #include <sys/stat.h>
  9. #undef errno
  10. extern int errno;
  11. extern int _end;
  12. /*This function is used for handle heap option*/
  13. __attribute__ ((used))
  14. caddr_t _sbrk ( int incr )
  15. {
  16. static unsigned char *heap = NULL;
  17. unsigned char *prev_heap;
  18. if (heap == NULL) {
  19. heap = (unsigned char *)&_end;
  20. }
  21. prev_heap = heap;
  22. heap += incr;
  23. return (caddr_t) prev_heap;
  24. }
  25. __attribute__ ((used))
  26. int link(char *old, char *new)
  27. {
  28. return -1;
  29. }
  30. __attribute__ ((used))
  31. int _close(int file)
  32. {
  33. return -1;
  34. }
  35. __attribute__ ((used))
  36. int _fstat(int file, struct stat *st)
  37. {
  38. st->st_mode = S_IFCHR;
  39. return 0;
  40. }
  41. __attribute__ ((used))
  42. int _isatty(int file)
  43. {
  44. return 1;
  45. }
  46. __attribute__ ((used))
  47. int _lseek(int file, int ptr, int dir)
  48. {
  49. return 0;
  50. }
  51. /*Low layer read(input) function*/
  52. __attribute__ ((used))
  53. int _read(int file, char *ptr, int len)
  54. {
  55. #if 0
  56. //user code example
  57. int i;
  58. (void)file;
  59. for(i = 0; i < len; i++)
  60. {
  61. // UART_GetChar is user's basic input function
  62. *ptr++ = UART_GetChar();
  63. }
  64. #endif
  65. return len;
  66. }
  67. /*Low layer write(output) function*/
  68. __attribute__ ((used))
  69. int _write(int file, char *ptr, int len)
  70. {
  71. #if 0
  72. //user code example
  73. int i;
  74. (void)file;
  75. for(i = 0; i < len; i++)
  76. {
  77. // UART_PutChar is user's basic output function
  78. UART_PutChar(*ptr++);
  79. }
  80. #endif
  81. return len;
  82. }
  83. __attribute__ ((used))
  84. void abort(void)
  85. {
  86. /* Abort called */
  87. while(1);
  88. }
  89. /* --------------------------------- End Of File ------------------------------ */