/* 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.
 *
 *****************************************************************************/


/*
 * MUSBStack-S Keil/8051 C'99 definitions.
 * $Revision: #1 $
 */

#ifndef __C8051_STDINT_H__
#define __C8051_STDINT_H__

#include "x_lint.h"

LINT_EXT_HEADER_BEGIN

#ifdef MUSB_8226
    #include "usb_debug.h"
    #include "x_hal_5371.h"
    #include "x_hal_926.h"
#if !defined(CONFIG_ARCH_MT85XX)
    #include "bim_8225.h"
#endif
#else /* 53xx */
#if !defined(CONFIG_ARCH_MT85XX)
    #include "x_hal_5381.h"
    #include "x_hal_arm.h"
#else
    #include "x_hal_ic.h"
    #include "x_hal_1176.h"
#endif
    #include "x_os.h"
#endif /* #ifdef MUSB_8226 */
#include "x_typedef.h"
#include "x_assert.h"
#include "x_serial.h"
#include "x_bim.h"
#include "x_printf.h"

LINT_EXT_HEADER_END

#if defined(__KERNEL__) && defined(__MODEL_slt__)
typedef uint16_t		uint_fast16_t;
#endif

#if defined(CONFIG_ARCH_MT85XX)
#include <asm/system.h>

#ifndef _LINUX_TYPES_H
    /* 7.18.1.1 */

/* exact-width signed integer types */
#ifdef MUSB_8226
    typedef INT8			int8_t;
#else /* 53xx */
    typedef CHAR			int8_t;
#endif /* #ifdef MUSB_8226 */

typedef INT16			int16_t;
typedef INT32			int32_t;

/* exact-width unsigned integer types */
typedef UINT8		        uint8_t;
typedef UINT16		uint16_t;
typedef UINT32		uint32_t;
//  MTK Notice: Max Liao, 2006/11/20.
//  support disk size > 4 Gbytes.
typedef UINT64		uint64_t;
typedef INT64		        int64_t;

/* 7.18.1.2 */

/* smallest type of at least n bits */
/* minimum-width signed integer types */
typedef   int8_t		int_least8_t;
typedef   int16_t		int_least16_t;
typedef   int32_t		int_least32_t;

/* minimum-width unsigned integer types */
typedef uint8_t			uint_least8_t;
typedef uint16_t		uint_least16_t;
typedef uint32_t		uint_least32_t;

/* 7.18.1.4 integer types capable of holding object pointers */
typedef int32_t			intptr_t;
typedef uint32_t		uintptr_t;

#endif  //_LINUX_TYPES_H


/* 7.18.1.3 */

/* fastest minimum-width signed integer types */
typedef   int8_t		int_fast8_t;
typedef   int16_t		int_fast16_t;
typedef   int32_t		int_fast32_t;

    /* fastest minimum-width unsigned integer types */
typedef uint8_t			uint_fast8_t;
typedef uint16_t		uint_fast16_t;
typedef uint32_t		uint_fast32_t;


/* 7.18.1.5 greatest-width integer types */
typedef int32_t			intmax_t;
typedef uint32_t		uintmax_t;
#endif //#if defined(CONFIG_ARCH_MT85XX)

/* 7.18.2.1 */
#ifdef MUSB_8226

    typedef UINT32  HANDLE_T;
    typedef VOID (*x_os_timer_cb_fct) (HANDLE_T  pt_tm_handle,
                                       VOID*     pv_tag);

    typedef VOID (*x_os_isr_fct) (UINT16  ui2_vector_id);

    #define OSR_OK                    ((INT32)   0)

    typedef enum
    {
        X_TIMER_FLAG_ONCE   = 1,
        X_TIMER_FLAG_REPEAT
    }   TIMER_FLAG_T;

#endif /* #ifdef MUSB_8226 */

/* minimum values of exact-width signed integer types */
#ifdef INT8_MIN
#undef INT8_MIN
#define INT8_MIN                   -128
#endif

#ifdef INT16_MIN
#undef INT16_MIN
#define INT16_MIN                -32768
#endif

#ifdef INT32_MIN
#undef INT32_MIN
#define INT32_MIN          (~0x7fffffff)   /* -2147483648 is unsigned */
#endif

/* maximum values of exact-width signed integer types */
#ifdef INT8_MAX 
#undef INT8_MAX
#define INT8_MAX                    127
#endif

#ifdef INT16_MAX 
#undef INT16_MAX
#define INT16_MAX                 32767
#endif

#ifdef INT32_MAX
#undef INT32_MAX
#define INT32_MAX            2147483647
#endif

/* maximum values of exact-width unsigned integer types */
#ifdef UINT8_MAX
#undef UINT8_MAX
#define UINT8_MAX                   255
#endif

#ifdef UINT16_MAX
#undef UINT16_MAX
#define UINT16_MAX                65535
#endif

#ifdef UINT32_MAX
#undef UINT32_MAX
#define UINT32_MAX           4294967295u
#endif
/* 7.18.2.2 */

/* minimum values of minimum-width signed integer types */
#ifdef INT_LEAST8_MIN
#undef INT_LEAST8_MIN
#define INT_LEAST8_MIN                   -128
#endif

#ifdef INT_LEAST16_MIN
#undef INT_LEAST16_MIN
#define INT_LEAST16_MIN                -32768
#endif

#ifdef INT_LEAST32_MIN
#undef INT_LEAST32_MIN
#define INT_LEAST32_MIN          (~0x7fffffff)
#endif

/* maximum values of minimum-width signed integer types */
#ifdef INT_LEAST8_MAX
#undef INT_LEAST8_MAX
#define INT_LEAST8_MAX                    127
#endif

#ifdef INT_LEAST16_MAX
#undef INT_LEAST16_MAX
#define INT_LEAST16_MAX                 32767
#endif

#ifdef INT_LEAST32_MAX
#undef INT_LEAST32_MAX
#define INT_LEAST32_MAX            2147483647
#endif

/* maximum values of minimum-width unsigned integer types */
#ifdef UINT_LEAST8_MAX
#undef UINT_LEAST8_MAX
#define UINT_LEAST8_MAX                   255
#endif

#ifdef UINT_LEAST16_MAX
#undef UINT_LEAST16_MAX
#define UINT_LEAST16_MAX                65535
#endif

#ifdef UINT_LEAST32_MAX
#undef UINT_LEAST32_MAX
#define UINT_LEAST32_MAX           4294967295u
#endif

/* 7.18.2.3 */

/* minimum values of fastest minimum-width signed integer types */
#ifdef INT_FAST8_MIN
#undef INT_FAST8_MIN
#define INT_FAST8_MIN           (~0x7fffffff)
#endif

#ifdef INT_FAST16_MIN
#undef INT_FAST16_MIN
#define INT_FAST16_MIN          (~0x7fffffff)
#endif

#ifdef INT_FAST32_MIN
#undef INT_FAST32_MIN
#define INT_FAST32_MIN          (~0x7fffffff)
#endif

/* maximum values of fastest minimum-width signed integer types */
#ifdef INT_FAST8_MAX
#undef INT_FAST8_MAX
#define INT_FAST8_MAX             2147483647
#endif 

#ifdef INT_FAST16_MAX
#undef INT_FAST16_MAX
#define INT_FAST16_MAX            2147483647
#endif

#ifdef INT_FAST32_MAX
#undef INT_FAST32_MAX
#define INT_FAST32_MAX            2147483647
#endif

/* maximum values of fastest minimum-width unsigned integer types */
#ifdef UINT_FAST8_MAX
#undef UINT_FAST8_MAX
#define UINT_FAST8_MAX            4294967295u
#endif

#ifdef UINT_FAST16_MAX
#undef UINT_FAST16_MAX
#define UINT_FAST16_MAX           4294967295u
#endif

#ifdef UINT_FAST32_MAX
#undef UINT_FAST32_MAX
#define UINT_FAST32_MAX           4294967295u
#endif
/* 7.18.2.4 */

/* minimum value of pointer-holding signed integer type */
#ifdef INTPTR_MIN
#undef INTPTR_MIN
#define INTPTR_MIN (~0x7fffffff)
#endif

/* maximum value of pointer-holding signed integer type */
#ifdef INTPTR_MAX
#undef INTPTR_MAX
#define INTPTR_MAX   2147483647
#endif

/* maximum value of pointer-holding unsigned integer type */
#ifdef UINTPTR_MAX
#undef UINTPTR_MAX
#define UINTPTR_MAX  4294967295u
#endif
/* 7.18.2.5 */

/* minimum value of greatest-width signed integer type */
#ifdef INTMAX_MIN
#undef INTMAX_MIN
#define INTMAX_MIN  ((int64_t)~0x7fffffffffffffff)
#endif

/* maximum value of greatest-width signed integer type */
#ifdef INTMAX_MAX
#undef INTMAX_MAX
#define INTMAX_MAX   ((int64_t)9223372036854775807)
#endif
/* maximum value of greatest-width unsigned integer type */
#ifdef UINTMAX_MAX
#undef UINTMAX_MAX
#define UINTMAX_MAX ((uint64_t)18446744073709551615)
#endif

#endif	/* multiple inclusion protection */
