/// \file DeviceInit.h
/// \brief This file contains required global declarations for my project.
/*
=============================================================================
* Copyright (C) 2020
* PNC Technologies Co., Ltd.
* All Rights Reserved
*
* The content of this file is copyrighted by PNC Technologies Co., Ltd. or
* its affiliated, associated or related companies. All copyrights and other
* associated intellectual property rights related thereto are expressly
* reserved by PNC Technologies Co., Ltd.
=============================================================================
* File Revision History (top to bottom: first revision to last revision)
=============================================================================
*
* Date          user    (Description on following lines: changes, etc.)
* ----------- --------
* 26-Mar-2020   BT Jung
* + Created initial version
*
*
=============================================================================
*/


/*=========================================================================*/
/*                            COMPILER DIRECTIVES                          */
/*=========================================================================*/

#ifndef __DEVICEINIT_H
#define __DEVICEINIT_H


/*=========================================================================*/
/*                     MODULES USED  (#include statements)                 */
/*=========================================================================*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>

/*=========================================================================*/
/*                                 CONSTANTS                               */
/*=========================================================================*/
// OMAPL1x SYSCFG Specific
#define KICK0_KEY 0x83E70B13
#define KICK1_KEY 0x95A4F1E0
#define KICK_LOCK 0x00000000

#define PLLEN_MUX_SWITCH         (4U)
#define PLL_LOCK_TIME_CNT        (2400U)
#define PLL_STABILIZATION_TIME   (2000U)
#define PLL_RESET_TIME_CNT       (200U)

#define DEFS_PLL_INIT			0
#define DEFS_DDR2_INIT			0

#define DEFS_UART2_USED         0  // Interrupt ID [69], LCDK Default Port - ARM
#define DEFS_UART1_USED         1  // Interrupt ID [46]


// UART1,2 user PLL1_SYSCLK2
// UART STUDIO는 13 oversample임 (Register default는 16샘플임)
// JTAG - gel도 456MHz로 변경, oversample을 16로 변경
// divider = in_clock / (baurate * 16)

#define DSPDEFS_BAUDRATE_9600          0x05CC       /*   1484 ( 1484.38) */
#define DSPDEFS_BAUDRATE_19200         0x02E6       /*    742 (  742.19) */
#define DSPDEFS_BAUDRATE_57600         0x00C8       /*    247 (  247.40) */
#define DSPDEFS_BAUDRATE_115200        0x007c       /*    124 (  123.70) */
#define DSPDEFS_BAUDRATE_230400        0x003e       /*    62  (  123.70) */

#define CLK_PLL0_SYSCLK3                  (0xFFFFFFF8)

#define BOARD_PINMUX0_GPIO_ENABLE        (0x88888888u)  // GP0[8]-GP0[15]
#define BOARD_PINMUX1_GPIO_ENABLE        (0x08888808u)  // GP0[0]-GP0[7]
#define BOARD_PINMUX2_GPIO_ENABLE        (0x00000008u)  // GP8[7],GP1[9]-GP1[15]
#define BOARD_PINMUX5_GPIO_ENABLE        (0x00008000u)  // GP2[8]-GP2[15]
#define BOARD_PINMUX6_GPIO_ENABLE        (0x00008888u)  // GP2[0]-GP2[7]
#define BOARD_PINMUX7_GPIO_ENABLE        (0x08000000u)  // GP3[9]
#define BOARD_PINMUX13_GPIO_ENABLE       (0x88888880u)  // GP6[8]-GP6[15]
#define BOARD_PINMUX14_GPIO_ENABLE       (0x00000088u)  // GP6[6]-GP6[7]
#define BOARD_PINMUX16_GPIO_ENABLE       (0x00000080u)  // GP6[5]
#define BOARD_PINMUX18_GPIO_ENABLE       (0x80888800u)  // GP8[10], GP8[12]-GP8[15]
#define BOARD_PINMUX19_GPIO_ENABLE       (0x00888800u)  // GP6[1]-GP6[4]

#define BOARD_PINMUX5_EMIF_ENABLE        (0x11000000u)  // ba1,ba0
#define BOARD_PINMUX6_EMIF_ENABLE        (0x11110001u)  // cs0,wait1,we_dq1,we_dq0-ema_clk
#define BOARD_PINMUX7_EMIF_ENABLE        (0x10111111u)  // wait0,rw,oe,we,cs5,cs4,cs3,cs2
#define BOARD_PINMUX8_EMIF_ENABLE        (0x11111111u)  // d8-d15
#define BOARD_PINMUX9_EMIF_ENABLE        (0x11111111u)  // d0-d7
#define BOARD_PINMUX10_EMIF_ENABLE       (0x11100000u)  // a16-a18
#define BOARD_PINMUX11_EMIF_ENABLE       (0x11111111u)  // a8-a15
#define BOARD_PINMUX12_EMIF_ENABLE       (0x11111111u)  // a0-a7

#define BOARD_PINMUX16_LCD_ENABLE        (0x22222200u)
#define BOARD_PINMUX17_LCD_ENABLE        (0x22222222u)
#define BOARD_PINMUX18_LCD_ENABLE        (0x02000022u)
#define BOARD_PINMUX19_LCD_ENABLE        (0x02000022u)

#define BOARD_PINMUX2_EMAC_ENABLE        (0x88888880u)
#define BOARD_PINMUX3_EMAC_ENABLE        (0x88888888u)
#define BOARD_PINMUX4_EMAC_ENABLE        (0x00000088u)

#define BOARD_PINMUX5_EPWM_ENABLE         (0x00000002u)
#define BOARD_PINMUX4_UART_ENABLE        (0x22220000u)
#define BOARD_PINMUX4_I2C_ENABLE         (0x00002200u)
#define BOARD_PINMUX1_ECAP_ENABLE         (0x40000004u)

#define SPI_USE_CS      1
#define SPI_PORT_USE    1
#if SPI_USE_CS
#define BOARD_PINMUX5_SPI_ENABLE         (0x00110110u)
#else
#define BOARD_PINMUX5_SPI_ENABLE         (0x00110180u)
#endif



#define ARM       0xFAFA

#define CPU_RUN_LED_OFF             (gpioRegs->BANK_REGISTERS[3].CLR_DATA = 0x00001000u)    // GP6.12
#define CPU_RUN_LED_ON              (gpioRegs->BANK_REGISTERS[3].SET_DATA = 0x00001000u)

#define MPU_RUN_LED_OFF             (gpioRegs->BANK_REGISTERS[3].CLR_DATA = 0x00002000u)    // GP6.13
#define MPU_RUN_LED_ON              (gpioRegs->BANK_REGISTERS[3].SET_DATA = 0x00002000u)


/* LCD Contrast */
#define LCD_CONTRAST_PWM_APRD   (10000*LCD_CONTRAST_MUL)
/* LCD Contrast */
#define	LCD_CONTRAST_LOWER			9000
#define	LCD_CONTRAST_UPPER			10000
#define	LCD_CONTRAST_DEFAULT		9500
#define	LCD_CONTRAST_MUL			100
#define	LCD_CONTRAST_STEP			10
#define	LCD_CONTRAST_UNIT			UNIT_NULL

#define LCD_BACKLIGHT_OFF           LCDContrastSet(FRAMStPtr->LCDContrast/20)
#define LCD_BACKLIGHT_ON            LCDContrastSet(FRAMStPtr->LCDContrast)

#define WD_OUT_HIGH            (gpioRegs->BANK_REGISTERS[3].SET_DATA = 0x00004000u)     // GP6.14
#define WD_OUT_LOW             (gpioRegs->BANK_REGISTERS[3].CLR_DATA = 0x00004000u)     // GP6.14

/*=========================================================================*/
/*                       MACROS  (inline functions)                        */
/*=========================================================================*/


/*=========================================================================*/
/*                                  TYPEDEFS                               */
/*=========================================================================*/


/*=========================================================================*/
/*                               GLOBAL FUNCTIONS                          */
/*=========================================================================*/

void DeviceInit();

void Peripheral_Init();



#endif         // End of Program
