/*
 * init_perif.c
 *
 *  Created on: 21 авг. 2023 г.
 *      Author: seklyuts
 */
#include "f28x_project.h"
#include "ipc_init.h"
#include "internal_flash.h"

#ifdef CPU1
#include "gpio_init.h"
#include "spi_init.h"
#include "i2c_init.h"
#include "frm_uart.h"
#include "GD25Q16ETIGR.h"
#include <ZD24C02A_Control_Module.h>
#include "BL25CM1A.h"
#include "pwm_init.h"
#include "emif_init.h"
#endif

#define I2C_OWN_ADDRESS 0x30U

void InitPerif(void)
{
    InitSysCtrl();
#ifdef CPU1
    SpiGpioInit();
    I2CMasterGpioInit();
#endif

// Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts

    DINT;

//
// Initialize the PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the f2838x_piectrl.c file.
//
    InitPieCtrl();

//
// Disable CPU interrupts and clear all CPU interrupt flags:
//
    IER = 0x0000;
    IFR = 0x0000;

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in f2838x_defaultisr.c.
// This function is found in f2838x_pievect.c.
//
    InitPieVectTable();

//
#ifdef CPU1
    GpioInit();
    Gpio_SPI_CS_BL25CM1A(1);
    SpiInit();
    I2CMasterInit(I2C_OWN_ADDRESS,I2C_CONTROL_MODULE_SLAVE_ADDRESS);
#endif
//
// Enable global Interrupts and higher priority real-time debug events:
//
    EINT;  // Enable Global interrupt INTM
    ERTM;  // Enable Global realtime interrupt DBGM
#ifdef CPU1
    FRMUartInit();
    GD25Q16ETIGR_en();
    PWMInitEnable();
    PWMInitInterruptEn();
    PWMAllInit();
    emif_init();
#endif
    ipc_init();
    Internal_flash_Init();

}
