SAM4SD32 (SAM4S-EK2)
Loading...
Searching...
No Matches
stdio_serial.h
Go to the documentation of this file.
1
37/*
38 * Support and FAQ: visit <a href="https://www.microchip.com/support/">Microchip Support</a>
39 */
40
41
42#ifndef _STDIO_SERIAL_H_
43#define _STDIO_SERIAL_H_
44
54
55#include <stdio.h>
56#include "compiler.h"
57#ifndef SAMD20
58# include "sysclk.h"
59#endif
60#include "serial.h"
61
62#if (XMEGA || MEGA_RF) && defined(__GNUC__)
63 extern int _write (char c, int *f);
64 extern int _read (int *f);
65#endif
66
67
69extern volatile void *volatile stdio_base;
71extern int (*ptr_put)(void volatile*, char);
72
74extern void (*ptr_get)(void volatile*, char*);
75
82static inline void stdio_serial_init(volatile void *usart, const usart_serial_options_t *opt)
83{
84 stdio_base = (void *)usart;
85 ptr_put = (int (*)(void volatile*,char))&usart_serial_putchar;
86 ptr_get = (void (*)(void volatile*,char*))&usart_serial_getchar;
87# if (XMEGA || MEGA_RF)
88 usart_serial_init((USART_t *)usart,opt);
89# elif UC3
91# elif SAM
93# else
94# error Unsupported chip type
95# endif
96
97# if defined(__GNUC__)
98# if (XMEGA || MEGA_RF)
99 // For AVR GCC libc print redirection uses fdevopen.
100 fdevopen((int (*)(char, FILE*))(_write),(int (*)(FILE*))(_read));
101# endif
102# if UC3 || SAM
103 // For AVR32 and SAM GCC
104 // Specify that stdout and stdin should not be buffered.
105 setbuf(stdout, NULL);
106 setbuf(stdin, NULL);
107 // Note: Already the case in IAR's Normal DLIB default configuration
108 // and AVR GCC library:
109 // - printf() emits one character at a time.
110 // - getchar() requests only 1 byte to exit.
111# endif
112# endif
113}
114
118
119#endif // _STDIO_SERIAL_H_
int(* ptr_put)(void volatile *, char)
Pointer to the external low level write function.
static void stdio_serial_init(volatile void *usart, const usart_serial_options_t *opt)
Initializes the stdio in Serial Mode.
void(* ptr_get)(void volatile *, char *)
Pointer to the external low level read function.
volatile void *volatile stdio_base
Pointer to the base of the USART module instance to use for stdio.
Serial Mode management.
Usart hardware registers.
static int usart_serial_putchar(usart_if p_usart, const uint8_t c)
Sends a character with the USART.
static void usart_serial_init(usart_if p_usart, usart_serial_options_t *opt)
Initializes the Usart in master mode.
Definition uart_serial.h:87
static void usart_serial_getchar(usart_if p_usart, uint8_t *data)
Waits until a character is received, and returns it.
usart_rs232_options_t usart_serial_options_t
Definition uart_serial.h:76