/*
 * Copyright (c) 2020 Texas Instruments Incorporated - http://www.ti.com
 * 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 Texas Instruments Incorporated 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 OWNER 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 BOARD_H
#define BOARD_H

//*****************************************************************************
//
// If building with a C++ compiler, make all of the definitions in this header
// have a C binding.
//
//*****************************************************************************
#ifdef __cplusplus
extern "C"
{
#endif

//
// Included Files
//

#include "driverlib.h"
#include "device.h"

//*****************************************************************************
//
// PinMux Configurations
//
//*****************************************************************************

//
// ANALOG -> myANALOGPinMux0 Pinmux
//

//
// EPWM2 -> EPWM2_20MHz_SDFM_CLK Pinmux
//
//
// EPWM2_A - GPIO Settings
//
#define GPIO_PIN_EPWM2_A 2
#define EPWM2_20MHz_SDFM_CLK_EPWMA_GPIO 2
#define EPWM2_20MHz_SDFM_CLK_EPWMA_PIN_CONFIG GPIO_2_EPWM2_A
//
// EPWM2_B - GPIO Settings
//
#define GPIO_PIN_EPWM2_B 3
#define EPWM2_20MHz_SDFM_CLK_EPWMB_GPIO 3
#define EPWM2_20MHz_SDFM_CLK_EPWMB_PIN_CONFIG GPIO_3_EPWM2_B

//
// EPWM1 -> EPWM1_20KHz Pinmux
//
//
// EPWM1_A - GPIO Settings
//
#define GPIO_PIN_EPWM1_A 0
#define EPWM1_20KHz_EPWMA_GPIO 0
#define EPWM1_20KHz_EPWMA_PIN_CONFIG GPIO_0_EPWM1_A
//
// EPWM1_B - GPIO Settings
//
#define GPIO_PIN_EPWM1_B 1
#define EPWM1_20KHz_EPWMB_GPIO 1
#define EPWM1_20KHz_EPWMB_PIN_CONFIG GPIO_1_EPWM1_B
//
// GPIO36 - GPIO Settings
//
#define ISR_ADC_GPIO_PIN_CONFIG GPIO_36_GPIO36
//
// GPIO99 - GPIO Settings
//
#define CLA_TASK_GPIO_GPIO_PIN_CONFIG GPIO_99_GPIO99

//
// OUTPUTXBAR4 -> myOUTPUTXBAR4 Pinmux
//
//
// OUTPUTXBAR4 - GPIO Settings
//
#define GPIO_PIN_OUTPUTXBAR4 6
#define myOUTPUTXBAR4_OUTPUTXBAR_GPIO 6
#define myOUTPUTXBAR4_OUTPUTXBAR_PIN_CONFIG GPIO_6_OUTPUTXBAR4

//
// OUTPUTXBAR5 -> myOUTPUTXBAR5 Pinmux
//
//
// OUTPUTXBAR5 - GPIO Settings
//
#define GPIO_PIN_OUTPUTXBAR5 7
#define myOUTPUTXBAR5_OUTPUTXBAR_GPIO 7
#define myOUTPUTXBAR5_OUTPUTXBAR_PIN_CONFIG GPIO_7_OUTPUTXBAR5

//
// SD4 -> mySDFM4 Pinmux
//
//
// SD4_C1 - GPIO Settings
//
#define GPIO_PIN_SD4_C1 10
#define mySDFM4_SDC1_GPIO 10
#define mySDFM4_SDC1_PIN_CONFIG GPIO_10_SD4_C1
//
// SD4_D1 - GPIO Settings
//
#define GPIO_PIN_SD4_D1 11
#define mySDFM4_SDD1_GPIO 11
#define mySDFM4_SDD1_PIN_CONFIG GPIO_11_SD4_D1
//
// SD4_C2 - GPIO Settings
//
#define GPIO_PIN_SD4_C2 12
#define mySDFM4_SDC2_GPIO 12
#define mySDFM4_SDC2_PIN_CONFIG GPIO_12_SD4_C2
//
// SD4_D2 - GPIO Settings
//
#define GPIO_PIN_SD4_D2 13
#define mySDFM4_SDD2_GPIO 13
#define mySDFM4_SDD2_PIN_CONFIG GPIO_13_SD4_D2
//
// SD4_C3 - GPIO Settings
//
#define GPIO_PIN_SD4_C3 94
#define mySDFM4_SDC3_GPIO 94
#define mySDFM4_SDC3_PIN_CONFIG GPIO_94_SD4_C3
//
// SD4_D3 - GPIO Settings
//
#define GPIO_PIN_SD4_D3 41
#define mySDFM4_SDD3_GPIO 41
#define mySDFM4_SDD3_PIN_CONFIG GPIO_41_SD4_D3
//
// SD4_C4 - GPIO Settings
//
#define GPIO_PIN_SD4_C4 100
#define mySDFM4_SDC4_GPIO 100
#define mySDFM4_SDC4_PIN_CONFIG GPIO_100_SD4_C4
//
// SD4_D4 - GPIO Settings
//
#define GPIO_PIN_SD4_D4 43
#define mySDFM4_SDD4_GPIO 43
#define mySDFM4_SDD4_PIN_CONFIG GPIO_43_SD4_D4

//*****************************************************************************
//
// ADC Configurations
//
//*****************************************************************************
#define myADC_A0_BASE ADCA_BASE
#define myADC_A0_RESULT_BASE ADCARESULT_BASE
#define myADC_A0_SOC0 ADC_SOC_NUMBER0
#define myADC_A0_FORCE_SOC0 ADC_FORCE_SOC0
#define myADC_A0_SAMPLE_WINDOW_SOC0 80
#define myADC_A0_TRIGGER_SOURCE_SOC0 ADC_TRIGGER_EPWM1_SOCA
#define myADC_A0_CHANNEL_SOC0 ADC_CH_ADCIN0
void myADC_A0_init();


//*****************************************************************************
//
// ASYSCTL Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// CLA Configurations
//
//*****************************************************************************
#define myCLA1_BASE CLA1_BASE

//
// The following are symbols defined in the CLA assembly code
// Including them in the shared header file makes them global
// and the main CPU can make use of them.
//
__attribute__((interrupt)) void Cla1Task1();
__attribute__((interrupt)) void Cla1Task2();
__attribute__((interrupt)) void Cla1Task3();
__attribute__((interrupt)) void Cla1Task4();
__attribute__((interrupt)) void Cla1Task5();
__attribute__((interrupt)) void Cla1Task6();
__attribute__((interrupt)) void Cla1Task7();
__attribute__((interrupt)) void Cla1Task8();
void myCLA1_init();


//*****************************************************************************
//
// EPWM Configurations
//
//*****************************************************************************
#define EPWM2_20MHz_SDFM_CLK_BASE EPWM2_BASE
#define EPWM2_20MHz_SDFM_CLK_TBPRD 9
#define EPWM2_20MHz_SDFM_CLK_COUNTER_MODE EPWM_COUNTER_MODE_UP
#define EPWM2_20MHz_SDFM_CLK_TBPHS 0
#define EPWM2_20MHz_SDFM_CLK_CMPA 5
#define EPWM2_20MHz_SDFM_CLK_CMPB 0
#define EPWM2_20MHz_SDFM_CLK_CMPC 0
#define EPWM2_20MHz_SDFM_CLK_CMPD 0
#define EPWM2_20MHz_SDFM_CLK_DBRED 0
#define EPWM2_20MHz_SDFM_CLK_DBFED 0
#define EPWM2_20MHz_SDFM_CLK_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define EPWM2_20MHz_SDFM_CLK_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define EPWM2_20MHz_SDFM_CLK_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED
#define EPWM1_20KHz_BASE EPWM1_BASE
#define EPWM1_20KHz_TBPRD 4999
#define EPWM1_20KHz_COUNTER_MODE EPWM_COUNTER_MODE_UP_DOWN
#define EPWM1_20KHz_TBPHS 0
#define EPWM1_20KHz_CMPA 2500
#define EPWM1_20KHz_CMPB 2500
#define EPWM1_20KHz_CMPC 1000
#define EPWM1_20KHz_CMPD 2000
#define EPWM1_20KHz_DBRED 10
#define EPWM1_20KHz_DBFED 10
#define EPWM1_20KHz_TZA_ACTION EPWM_TZ_ACTION_HIGH_Z
#define EPWM1_20KHz_TZB_ACTION EPWM_TZ_ACTION_HIGH_Z
#define EPWM1_20KHz_INTERRUPT_SOURCE EPWM_INT_TBCTR_DISABLED

//*****************************************************************************
//
// GPIO Configurations
//
//*****************************************************************************
#define ISR_ADC 36
void ISR_ADC_init();
#define CLA_TASK_GPIO 99
void CLA_TASK_GPIO_init();

//*****************************************************************************
//
// INTERRUPT Configurations
//
//*****************************************************************************

// Interrupt Settings for INT_myADC_A0_1
// ISR need to be defined for the registered interrupts
#define INT_myADC_A0_1 INT_ADCA1
#define INT_myADC_A0_1_INTERRUPT_ACK_GROUP INTERRUPT_ACK_GROUP1
extern __interrupt void INT_myADC_A0_1_ISR(void);

//*****************************************************************************
//
// MEMCFG Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// OUTPUTXBAR Configurations
//
//*****************************************************************************
void myOUTPUTXBAR4_init();
#define myOUTPUTXBAR4 XBAR_OUTPUT4
#define myOUTPUTXBAR4_ENABLED_MUXES (XBAR_MUX13)
void myOUTPUTXBAR5_init();
#define myOUTPUTXBAR5 XBAR_OUTPUT5
#define myOUTPUTXBAR5_ENABLED_MUXES (XBAR_MUX15)

//*****************************************************************************
//
// SDFM Configurations
//
//*****************************************************************************
#define SDFM_HTLZ_ENABLE  0x8000 //High Threshold (Z) enabled
#define SDFM_HTLZ_DISABLE 0x0000 //High Threshold (Z) disabled
 
#define mySDFM4_BASE SDFM4_BASE
void    mySDFM4_init(void);

//*****************************************************************************
//
// SYNC Scheme Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// SYSCTL Configurations
//
//*****************************************************************************

//*****************************************************************************
//
// Board Configurations
//
//*****************************************************************************
void	Board_init();
void	ADC_init();
void	ASYSCTL_init();
void	CLA_init();
void	EPWM_init();
void	GPIO_init();
void	INTERRUPT_init();
void	MEMCFG_init();
void	OUTPUTXBAR_init();
void	SD_init();
void	SYNC_init();
void	SYSCTL_init();
void	PinMux_init();

//*****************************************************************************
//
// Mark the end of the C bindings section for C++ compilers.
//
//*****************************************************************************
#ifdef __cplusplus
}
#endif

#endif  // end of BOARD_H definition
