// CodeVisionAVR V2.0 C Compiler
// (C) 1998-2008 Pavel Haiduc, HP InfoTech S.R.L.

// Prototypes for standard I/O functions

#ifndef _STDIO_INCLUDED_
#define _STDIO_INCLUDED_

#include <stdarg.h>

#ifndef NULL
#define NULL 0
#endif

#ifndef EOF
#define EOF -1
#endif

#pragma used+

char getchar(void);
void putchar(char c);
void puts(char *str);
void putsf(char flash *str);

#ifdef _MODEL_TINY_
char *gets(char *str,unsigned char len);
#else
char *gets(char *str,unsigned int len);
#endif

void printf(char flash *fmtstr,...);
void sprintf(char *str, char flash *fmtstr,...);
#ifdef _MODEL_TINY_
void snprintf(char *str, unsigned char size, char flash *fmtstr,...);
#else
void snprintf(char *str, unsigned int size, char flash *fmtstr,...);
#endif
void vprintf (char flash * fmtstr, va_list argptr);
void vsprintf (char *str, char flash * fmtstr, va_list argptr);
#ifdef _MODEL_TINY_
void vsnprintf (char *str, unsigned char size, char flash * fmtstr, va_list argptr);
#else
void vsnprintf (char *str, unsigned int size, char flash * fmtstr, va_list argptr);
#endif
signed char scanf(char flash *fmtstr,...);
signed char sscanf(char *str, char flash *fmtstr,...);

// USARTC0 will be used as default USART for the ATxmega chips
#if defined _CHIP_ATXMEGA128A1_ | defined _CHIP_ATXMEGA128A4_ \
defined _CHIP_ATXMEGA16A4_ | defined _CHIP_ATXMEGA32A4_ \
defined _CHIP_ATXMEGA192A1_ | \
defined _CHIP_ATXMEGA256A1_ | defined _CHIP_ATXMEGA324A1_ | \
defined _CHIP_ATXMEGA64A1_ | defined _CHIP_ATXMEGA64A4_

#ifndef _ATXMEGA_USART_
#define _ATXMEGA_USART_ USARTC0
#endif

#endif

#ifdef _DEBUG_TERMINAL_IO_
// Used for AVR Studio V3.56 Terminal I/O
// DON'T CHANGE!

#ifndef _DEBUG_TERMINAL_IO_FN_DEFINED_
#define _DEBUG_TERMINAL_IO_FN_DEFINED_

#pragma warn-
void _c_getchar(void) {}

char getchar(void)
{
#asm
     push  r16
     push  r17
getchar0:
#endasm
_c_getchar();
#asm
     cpi   r17,0xff
     breq  getchar0
     mov   r30,r16
     pop   r17
     pop   r16
#endasm
}

void _c_putchar(void) {}

void putchar(char c)
{
#asm
    mov   r30,r16
    ld    r16,y
#endasm
_c_putchar();
#asm
    mov   r16,r30
#endasm
}

#ifdef _WARNINGS_ON_
#pragma warn+
#endif

#endif

#endif
#pragma used-

#pragma library stdio.lib

#endif

