//
//
//  File:       serial.h
//  Author:     Eric J Martin
//  Copyright:  2016 MBARI
//  
//  Summary: This header file configures the single serial port wired on the PIC24FKA101
//      Ocean Imaging Sensor Board. 
//
//

#ifndef _SERIAL_H_
#define _SERIAL_H_

#include <xc.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdbool.h>

#include "buffer.h"
#include "system.h"
#include "misc.h"

#define S_1     1
#define S_2     2

// serInit(): init registers, software buffers, install IRQ
void serInit(void);

// setSerConfig( (0/1), ulong baud, int data_par, int stop) : sets up serial port 
//      do this before initialization? returns zero on success, <0 on failure
int serSetConfig( unsigned long baud, int data_par, int stop);

// serGetConfig( ulong * baud, int * data_par, int * stop) : retrieves settings
//
int serGetConfig( unsigned long* baud, int* data_par, int* stop);

// serGetByte: get a byte from the buffer
//
int serGetByte( unsigned char* b);

// serPutByte: put a byte on the fifo buffer
//
int serPutByte( unsigned char b);

// serPutString(): put a string on the buffer
//
int serPutString( char* buff);

void serRxFlush();
void serTxFlush();

void serSetBreak( int state);
int serGetBreak();

int serIsRxFull();
int serIsTxFull();

int serGetErrFlag();

void serClrXERR();
int serGetXERR();

void serClrOERR();
int serGetOERR();

void serClrFERR();
int serGetFERR();

void serClrPERR();
int serGetPERR();

#endif //_SERIAL_H_

