|
|
/*------------------------------------------------------------------------------
|
|
|
-- This file is a part of the libuc, microcontroler library
|
|
|
-- Copyright (C) 2012, Alexis Jeandet
|
|
|
--
|
|
|
-- This program is free software; you can redistribute it and/or modify
|
|
|
-- it under the terms of the GNU General Public License as published by
|
|
|
-- the Free Software Foundation; either version 3 of the License, or
|
|
|
-- (at your option) any later version.
|
|
|
--
|
|
|
-- This program is distributed in the hope that it will be useful,
|
|
|
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
-- GNU General Public License for more details.
|
|
|
--
|
|
|
-- You should have received a copy of the GNU General Public License
|
|
|
-- along with this program; if not, write to the Free Software
|
|
|
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
-------------------------------------------------------------------------------
|
|
|
-- Author : Alexis Jeandet
|
|
|
-- Mail : alexis.jeandet@gmail.com
|
|
|
-------------------------------------------------------------------------------*/
|
|
|
#ifndef UART_H
|
|
|
#define UART_H
|
|
|
#include <stdint.h>
|
|
|
#include <uhandle.h>
|
|
|
#include <streamdevices.h>
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
extern "C" {
|
|
|
#endif
|
|
|
|
|
|
/*
|
|
|
typedef volatile struct uart_t
|
|
|
{
|
|
|
volatile void* _dev;
|
|
|
volatile int cfg;
|
|
|
volatile int speed;
|
|
|
}uart_t;
|
|
|
*/
|
|
|
|
|
|
typedef int uart_t;
|
|
|
#define uart1 0
|
|
|
#define uart2 1
|
|
|
#define uart3 2
|
|
|
#define uart4 3
|
|
|
#define uart5 4
|
|
|
#define uart6 5
|
|
|
#define uart7 6
|
|
|
#define uart8 7
|
|
|
#define uart9 8
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
{
|
|
|
uartparitynone = 0x1,
|
|
|
uartparityeven = 0x2,
|
|
|
uartparityodd = 0x3
|
|
|
}uartparity_t;
|
|
|
|
|
|
#define UARTPARITYMASK 0x3
|
|
|
|
|
|
typedef enum
|
|
|
{
|
|
|
uart7bits = 0x4,
|
|
|
uart8bits = 0x8,
|
|
|
uart9bits = 0xC
|
|
|
}uartbits_t;
|
|
|
|
|
|
#define UARTBITSMASK 0xC
|
|
|
|
|
|
|
|
|
typedef enum
|
|
|
{
|
|
|
uarthalfstop = 0x10,
|
|
|
uartonestop = 0x20,
|
|
|
uartonehalfstop = 0x30,
|
|
|
uarttwostop = 0x40
|
|
|
}uartstopbits_t;
|
|
|
|
|
|
#define UARTSTOPBITSMASK 0x70
|
|
|
|
|
|
extern uart_t uartopen(int count);
|
|
|
extern uart_t uartopenandconfig(int count ,uint32_t cfg,uint32_t speed,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin);
|
|
|
extern int uartclose(uart_t uart);
|
|
|
extern int uartsetpins(uart_t uart,uint32_t TXpin,uint32_t RXpin,uint32_t RTSpin,uint32_t CTSpin);
|
|
|
extern int uartenable(uart_t uart);
|
|
|
extern int uartdisable(uart_t uart);
|
|
|
extern int uartsetconfig(uart_t uart,uint32_t cfg,uint32_t speed);
|
|
|
extern int uartsetspeed(uart_t uart,uint32_t speed);
|
|
|
extern int uartsetparity(uart_t uart,uartparity_t parity);
|
|
|
extern int uartsetdatabits(uart_t uart,uartbits_t databits);
|
|
|
extern int uartsetstopbits(uart_t uart,uartstopbits_t stopbits);
|
|
|
extern int uartputc(uart_t uart,char c);
|
|
|
extern char uartgetc(uart_t uart);
|
|
|
extern int uartputs(uart_t uart,char* s);
|
|
|
extern int uartgets(uart_t uart,char* s);
|
|
|
extern int uartputnc(uart_t uart,char* c,int n);
|
|
|
extern int uartgetnc(uart_t uart,char* c,int n);
|
|
|
extern int uartavailiabledata(uart_t uart);
|
|
|
|
|
|
extern int uartmkstreamdev(uart_t uart,streamdevice* strdev);
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
}
|
|
|
#endif
|
|
|
#endif //SPI_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|