My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

syscalls.c 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. /******************************************************************************
  2. * The MIT License
  3. *
  4. * Copyright (c) 2010 Perry Hung.
  5. * Copyright (c) 2011, 2012 LeafLabs, LLC.
  6. *
  7. * Permission is hereby granted, free of charge, to any person
  8. * obtaining a copy of this software and associated documentation
  9. * files (the "Software"), to deal in the Software without
  10. * restriction, including without limitation the rights to use, copy,
  11. * modify, merge, publish, distribute, sublicense, and/or sell copies
  12. * of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be
  16. * included in all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  19. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  20. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  21. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  22. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  23. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  24. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  25. * SOFTWARE.
  26. *****************************************************************************/
  27. /**
  28. * @file wirish/syscalls.c
  29. * @brief newlib stubs
  30. *
  31. * Low level system routines used by newlib for basic I/O and memory
  32. * allocation. You can override most of these.
  33. */
  34. #include <libmaple/libmaple.h>
  35. #include <sys/stat.h>
  36. #include <errno.h>
  37. #include <stddef.h>
  38. /* If CONFIG_HEAP_START (or CONFIG_HEAP_END) isn't defined, then
  39. * assume _lm_heap_start (resp. _lm_heap_end) is appropriately set by
  40. * the linker */
  41. #ifndef CONFIG_HEAP_START
  42. extern char _lm_heap_start;
  43. #define CONFIG_HEAP_START ((void *)&_lm_heap_start)
  44. #endif
  45. #ifndef CONFIG_HEAP_END
  46. extern char _lm_heap_end;
  47. #define CONFIG_HEAP_END ((void *)&_lm_heap_end)
  48. #endif
  49. /*
  50. * _sbrk -- Increment the program break.
  51. *
  52. * Get incr bytes more RAM (for use by the heap). malloc() and
  53. * friends call this function behind the scenes.
  54. */
  55. void *_sbrk(int incr) {
  56. static void * pbreak = NULL; /* current program break */
  57. void * ret;
  58. if (pbreak == NULL) {
  59. pbreak = CONFIG_HEAP_START;
  60. }
  61. if ((CONFIG_HEAP_END - pbreak < incr) ||
  62. (pbreak - CONFIG_HEAP_START < -incr)) {
  63. errno = ENOMEM;
  64. return (void *)-1;
  65. }
  66. ret = pbreak;
  67. pbreak += incr;
  68. return ret;
  69. }
  70. __weak int _open(const char *path __attribute__((unused)), int flags __attribute__((unused)), ...) {
  71. return 1;
  72. }
  73. __weak int _close(int fd __attribute__((unused))) {
  74. return 0;
  75. }
  76. __weak int _fstat(int fd __attribute__((unused)), struct stat *st) {
  77. st->st_mode = S_IFCHR;
  78. return 0;
  79. }
  80. __weak int _isatty(int fd __attribute__((unused))) {
  81. return 1;
  82. }
  83. __weak int isatty(int fd __attribute__((unused))) {
  84. return 1;
  85. }
  86. __weak int _lseek(int fd __attribute__((unused)), off_t pos __attribute__((unused)), int whence __attribute__((unused))) {
  87. return -1;
  88. }
  89. __weak unsigned char getch(void) {
  90. return 0;
  91. }
  92. __weak int _read(int fd __attribute__((unused)), char *buf, size_t cnt __attribute__((unused))) {
  93. *buf = getch();
  94. return 1;
  95. }
  96. __weak void putch(unsigned char c __attribute__((unused))) {
  97. }
  98. __weak void cgets(char *s, int bufsize) {
  99. char *p;
  100. int c;
  101. int i;
  102. for (i = 0; i < bufsize; i++) {
  103. *(s+i) = 0;
  104. }
  105. // memset(s, 0, bufsize);
  106. p = s;
  107. for (p = s; p < s + bufsize-1;) {
  108. c = getch();
  109. switch (c) {
  110. case '\r' :
  111. case '\n' :
  112. putch('\r');
  113. putch('\n');
  114. *p = '\n';
  115. return;
  116. case '\b' :
  117. if (p > s) {
  118. *p-- = 0;
  119. putch('\b');
  120. putch(' ');
  121. putch('\b');
  122. }
  123. break;
  124. default :
  125. putch(c);
  126. *p++ = c;
  127. break;
  128. }
  129. }
  130. return;
  131. }
  132. __weak int _write(int fd __attribute__((unused)), const char *buf, size_t cnt) {
  133. int i;
  134. for (i = 0; i < cnt; i++)
  135. putch(buf[i]);
  136. return cnt;
  137. }
  138. /* Override fgets() in newlib with a version that does line editing */
  139. __weak char *fgets(char *s, int bufsize, void *f __attribute__((unused))) {
  140. cgets(s, bufsize);
  141. return s;
  142. }
  143. __weak void _exit(int exitcode __attribute__((unused))) {
  144. while (1)
  145. ;
  146. }