These three file pointers are automatically defined when a program executes and provide access to the keyboard and screen.
stdin example program.
| Top | Master Index | C Keywords | Functions |
//Replace the gcc default connectors for stdin and stdout
int _write(int file, char *ptr, int len) {
int i;
file = file;
for (i = 0; i < len; i++) {
UART_UartPutChar(*ptr++);
}
return len;
}
int _read (int fd, const void *buf, size_t count) {
size_t CharCnt = 0x00;
(void)fd; /* Parameter is not used, suppress unused argument warning */
for (;count > 0x00; --count) {
/* Save character received by UARTx device into the receive buffer */
while(!(*(uint8_t*)buf = (unsigned char)UART_UartGetChar()));
CharCnt++; /* Increase char counter */
/* Stop reading if CR (Ox0D) character is received */
if (*(uint8_t*)buf == 0x0DU) { /* New line character (CR) received ? */
*(uint8_t*)buf = '\n'; /* Yes, convert LF to '\n' char. */
break; /* Stop loop and return received char(s) */
}
buf++; /* Increase buffer pointer */
}
//return 1; /* WRONG! */
return CharCnt;
}
In this example, UART_UartPutChar and UART_UartGetChar are unique to the processor being used and would be replaced with whatever routine transmits or receives a character via the desired IO channel. E.g. it might be a write to LCD routine or a read from voice input.