#ifndef __COMPORTDESCRIPTOR_H
#define __COMPORTDESCRIPTOR_H
#include "main.h"
#include <stdio.h>
#if _DLIB_FILE_DESCRIPTOR
//The three standard file pointers provided by the run time library.
#define STDIN_FILENO 0
#define STDOUT_FILENO 1
#define STDERR_FILENO 2
FILE* InitCOM0(unsigned long Speed);
FILE* InitCOM1(unsigned long Speed);
FILE* InitCOM2(unsigned long Speed);
int fputc(int ch, FILE *f);
#endif /* _DLIB_FILE_DESCRIPTOR */
#ifdef __COMPORTDESCRIPTOR_C
#define COM_PORT0 (0)
#define COM_PORT1 (1)
#define COM_PORT2 (2)
#define COM_PORT_NONE (-1)
#define STDOUT_COM_PORT COM_PORT_NONE //COM порт для stdout
#else
#endif
#endif
#define __COMPORTDESCRIPTOR_C
#include "ComPortDescriptor.h"
#if _DLIB_FILE_DESCRIPTOR
static FILE COM0;
static FILE COM1;
static FILE COM2;
static const unsigned char TextCom0[]="COM0";
static const unsigned char TextCom1[]="COM1";
static const unsigned char TextCom2[]="COM2";
#define COM0_FILENO (3) //дескриптор
#define COM1_FILENO (4) //дескриптор
#define COM2_FILENO (5) //дескриптор
FILE* InitCOM0(unsigned long Speed)
{
FifoInit0(Speed);//Инициализация UART FIFO
COM0._Mode=(stdin->_Mode)|(stdout->_Mode);
COM0._Lockno=COM0_FILENO;
COM0._Handle=COM0_FILENO;
COM0._Tmpnam=(char*)TextCom0;
return &COM0;
}
FILE* InitCOM1(unsigned long Speed)
{
FifoInit1(Speed);//Инициализация UART FIFO
COM1._Mode=(stdin->_Mode)|(stdout->_Mode);
COM1._Lockno=COM1_FILENO;
COM1._Handle=COM1_FILENO;
COM1._Tmpnam=(char*)TextCom1;
return &COM1;
}
FILE* InitCOM2(unsigned long Speed)
{
FifoInit2(Speed);//Инициализация UART FIFO
COM2._Mode=(stdin->_Mode)|(stdout->_Mode);
COM2._Lockno=COM2_FILENO;
COM2._Handle=COM2_FILENO;
COM2._Tmpnam=(char*)TextCom2;
return &COM2;
}
int fputc(int ch, FILE *f)
{
switch(f->_Handle)
{
case COM0_FILENO: {PutFifo0(ch); break;}
case COM1_FILENO: {PutFifo1(ch); break;}
case COM2_FILENO: {PutFifo2(ch); break;}
default: break;
}
return ch;
}
#endif /* _DLIB_FILE_DESCRIPTOR */
#if STDOUT_COM_PORT==COM_PORT0
int putchar(int a)
{
PutFifo0(a);
return a;
}
#endif
#if STDOUT_COM_PORT==COM_PORT1
int putchar(int a)
{
PutFifo1(a);
return a;
}
#endif
#if STDOUT_COM_PORT==COM_PORT2
int putchar(int a)
{
PutFifo2(a);
return a;
}
#endif