write.c
Go to the documentation of this file.
1 
34 /*
35  * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
36  */
37 
38 #include "compiler.h"
39 
46 volatile void *volatile stdio_base;
47 int (*ptr_put)(void volatile*, char);
48 
49 
50 #if ( defined(__ICCAVR32__) || defined(__ICCAVR__) || defined(__ICCARM__))
51 
52 #include <yfuns.h>
53 
54 #if (__VER__ < 8010000)
55 // Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf
56 _STD_BEGIN
57 #endif
58 
59 #pragma module_name = "?__write"
60 
74 size_t __write(int handle, const unsigned char *buffer, size_t size)
75 {
76  size_t nChars = 0;
77 
78  if (buffer == 0) {
79  // This means that we should flush internal buffers.
80  return 0;
81  }
82 
83  // This implementation only writes to stdout and stderr.
84  // For all other file handles, it returns failure.
85  if (handle != _LLIO_STDOUT && handle != _LLIO_STDERR) {
86  return _LLIO_ERROR;
87  }
88 
89  for (; size != 0; --size) {
90  if (ptr_put(stdio_base, *buffer++) < 0) {
91  return _LLIO_ERROR;
92  }
93  ++nChars;
94  }
95  return nChars;
96 }
97 
98 #if (__VER__ < 8010000)
99 // Refer http://ftp.iar.se/WWWfiles/arm/webic/doc/EWARM_MigrationGuide.ENU.pdf
100 _STD_END
101 #endif
102 
103 
104 #elif (defined(__GNUC__) && !XMEGA && !MEGA)
105 
106 int __attribute__((weak))
107 _write (int file, const char *ptr, int len);
108 
109 int __attribute__((weak))
110 _write (int file, const char *ptr, int len)
111 {
112  int nChars = 0;
113 
114  if ((file != 1) && (file != 2) && (file!=3)) {
115  return -1;
116  }
117 
118  for (; len != 0; --len) {
119  if (ptr_put(stdio_base, *ptr++) < 0) {
120  return -1;
121  }
122  ++nChars;
123  }
124  return nChars;
125 }
126 
127 #elif (defined(__GNUC__) && (XMEGA || MEGA))
128 
129 int _write (char c, int *f);
130 
131 int _write (char c, int *f)
132 {
133  if (ptr_put(stdio_base, c) < 0) {
134  return -1;
135  }
136  return 1;
137 }
138 #endif
139 
volatile void *volatile stdio_base
Pointer to the base of the USART module instance to use for stdio.
Definition: write.c:46
Commonly used includes, types and macros.
typedef __attribute__
USB Device LPM Descriptor structure.
Definition: d_usartDMA.c:1064
int(* ptr_put)(void volatile *, char)
Pointer to the external low level write function.
Definition: write.c:47


inertial_sense_ros
Author(s):
autogenerated on Sun Feb 28 2021 03:17:58