/* SPDX-License-Identifier: LGPL-2.1-only OR BSD-3-Clause */
/******************************************************************************
 *
 * This file is provided under a dual license.  When you use or
 * distribute this software, you may choose to be licensed under
 * version 2.1 of the GNU Lesser General Public License 
 * ("LGPLv2.1 License") or BSD License.
 *
 * LGPLv2.1 License
 *
 * Copyright(C) 2019 MediaTek Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of version 2.1 of the GNU Lesser General Public 
 * License as published by the Free Software Foundation.
 *
 * 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 https://www.gnu.org/licenses/old-licenses/lgpl-2.1.html for more
 * details.
 *
 * BSD LICENSE
 *
 * Copyright(C) 2019 MediaTek Inc.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *  * Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *  * Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in
 *    the documentation and/or other materials provided with the
 *    distribution.
 *  * Neither the name of the copyright holder nor the names of its
 *    contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 *****************************************************************************/

#ifndef X_SERIAL_H
#define X_SERIAL_H

#include "x_typedef.h"



#define ASCII_NULL						0x00
#define ASCII_ENTER						0x0D
#define ASCII_KEY_BS					0x08
#define ASCII_KEY_NL					0x0A
#define ASCII_KEY_CR					0x0D
#define ASCII_KEY_ESC					0x1B
#define ASCII_KEY_ARROW					0x5B
#define ASCII_KEY_UP					0x41
#define ASCII_KEY_DOWN					0x42
#define ASCII_KEY_RIGHT					0x43
#define ASCII_KEY_LEFT					0x44
#define ASCII_KEY_SPACE					0x20
#define ASCII_KEY_PRINTABLE_MIN			0x20
#define ASCII_KEY_PRINTABLE_MAX			0x7E

// for x-modem
#define ASCII_SOH  						0x01
#define ASCII_STX  						0x02
#define ASCII_EOT  						0x04
#define ASCII_ACK  						0x06
#define ASCII_NAK  						0x15
#define ASCII_CAN  						0x18

EXTERN void SerInit(void);
EXTERN void SerStart(void);
EXTERN void SerEnd(void);
EXTERN void SerTransparent(void);
EXTERN void SerNormalMode(void);
EXTERN void SerWaitTxBufClear(void);
EXTERN void SerEnableMergeMode(BOOL fgEnable);
EXTERN void SerPollPutChar(UINT8 cc);
EXTERN UINT32 SerGetRxDataCnt(void);
EXTERN UINT8 SerPollGetChar(void);
EXTERN UINT8 SerGetChar(void);
EXTERN UINT8 SerGetCharTimeout(UINT8* ucChar, UINT32 ui4Time);
EXTERN CHAR* SerGetS(CHAR* s);
EXTERN void outbyte(CHAR c);
EXTERN BOOL SerInByte(UCHAR* puc);

EXTERN void SerIsrEnable(void);
EXTERN void SerIsrDisable(void);
EXTERN void SerIsrReg(void);
EXTERN UINT8 SerGetDebugPortNum(void);
EXTERN void SerSetoutbyte(BOOL fgSet);

// comes from drv_dbg.h
typedef void (*PF_DBG_INPUT_T) (INT32 i4Ch);
extern INT32 DBG_SetCallback(BOOL fgEnable, PF_DBG_INPUT_T pfInputCb);

#endif	// X_SERIAL_H
