/******************************************************************************/
/* Williams Advanced Engineering Limited                     Copyright(C) 2021*/
/* Grove                                                  All rights reserved */
/*                                                                            */
/******************************************************************************/


#ifndef __IOS_TERMINAL
#define __IOS_TERMINAL

#include "hal_stdtypes.h"
#include "sci.h"
#include "Ios_Shared.h"
#include <string.h>


/*----------------------------------------------------------------------------*/
/* CONSTANT DEFINITIONS                                                       */
/*----------------------------------------------------------------------------*/

#define TX_BUFFER_LEN           512             /* Transmitter buffer length */
#define RX_BUFFER_LEN           256             /* Transmitter buffer length */

#define CTRL_C                0x0003             /* Soft reset                */
#define CTRL_L                0x000c             /* Pull last command         */ 
#define ESCAPE_CHAR1          '\33'              /* Escape character          */
#define ESCAPE_CHAR2          '['                /* Escape character          */
#define UP_CHAR               'A'                /* Up arrow - after escape   */
#define LEFT_CHAR             'D'                /* Left arrow - after escape */
#define RIGHT_CHAR            'C'                /* Right arrow - after escape*/
#define START_ASCII           0x0020             /* First printable char      */
#define END_ASCII             0x007e             /* Last printable char       */
   
#define LINE_LEN      128                      /* Length of input line    */
#define ERROR_LEN     32              /* length of err message              */
#define MAX_LINES     20
#define COMMAND_LEN   12
#define IDENT_LEN     16

#define NUM_RECALLS           5    //* 5 Recall buffers
#define MAX_LINE_LENGTH       80   //* Maximum number of characters on 1 line

#define HOME          "\033[H"
#define CLEAR_SCREEN  "\033[H\033[J"

/*----------------------------------------------------------------------------*/
/* TYPE DEFINITIONS                                                           */
/*----------------------------------------------------------------------------*/
typedef struct
{
    uint16  wTxOldestEntry;
    uint16  wTxNewestEntry;
    uint8   bTxQueue[TX_BUFFER_LEN];
    uint16  wRxOldestEntry;
    uint16  wRxNewestEntry;
    uint8   bRxQueue[RX_BUFFER_LEN];

} TerminalQueueType;

/*----------------------------------------------------------------------------*/
/* GLOBAL VARIABLES                                                           */
/*----------------------------------------------------------------------------*/


/*----------------------------------------------------------------------------*/
/* FUNCTION PROTOTYPES                                                        */
/*----------------------------------------------------------------------------*/

extern   void   fnIosTerminalInitialise     (void);

extern   uint8    fnIosTerminalGetChar      (long port_number );
extern   char  *fnIosTerminalGetStr         (void);
extern   void   fnIosTerminalTx             (void);
extern   void   fnIosFlushTxQueue           (void);
extern   void   fnIosTerminalRx             (void);
extern   void   fnIosTerminalPoll           (void);

extern   void   fnIosTerminalPutChar        (long port_number, uint8 character);
extern   void   fnIosTerminalPutStr         (const char *str_ptr);

extern   uint8   fnIosTerminalCharToTxQueue  (char cInChar);

extern   uint8 fnIosTerminalTxComplete    (void);


/*----------------------------------------------------------------------------*/
#endif
