/*品智科技S32K118开发板*/


/* bootloader实验-APP
 * 内存配置文件在工程文件夹内的Project Setting/Linker Files/S32K144_64_flash下
 * KEY1 PTC14
 * KEY2 PTC15
 * KEY3 PTC16
 * LED1 PTD16
 * LED2 PTD15
 * LED3 PTE9
 * LED4 PTE8
 * 开发板采用无外部晶振设计,时钟走FIRC 48mhz,配置时钟时需要注意
 */


#include "Cpu.h"
#include "delay.h"
#include "uart.h"
#include "oled.h"
#include "key.h"

  volatile int exit_code = 0;

/* User includes (#include below this line is not maintained by Processor Expert) */

#define LED1(x)  PINS_DRV_WritePin(PTD,16,!x);
#define LED2(x)  PINS_DRV_WritePin(PTD,15,!x);
#define LED3(x)  PINS_DRV_WritePin(PTE,9,!x);
#define LED4(x)  PINS_DRV_WritePin(PTE,8,!x);




int main(void)
{
  /* Write your local variable definition here */
	int MCU_Freq;
	uint8_t pinstate;
  /*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
  #ifdef PEX_RTOS_INIT
    PEX_RTOS_INIT();                   /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of Processor Expert internal initialization.                    ***/
    CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
                   g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
    CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
    MCU_Freq = delay_init();//初始化delay函数


    PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);

    I2C_MasterInit(&i2c1_instance, &i2c1_MasterConfig0);//初始化I2C外设,用于OLED通讯
	LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0); //初始化串口

	oled_init(); //OLED配置参数初始化
	OLED_TITLE((uint8_t*)"S32K118",(uint8_t*)"BOOT-APP");//OLED显示标题
	OLED_ShowString(0,2,(uint8_t*)"    BOOT-APP",16,0); //OLED显示字符串
	u1_printf("当前进入APP程序 内存起始地址为0x0008000,MCU运行频率为 %d Mhz \r\n",MCU_Freq);



    while(1)
    {
    	delay_ms(100);
    	PINS_DRV_TogglePins(PTD, 1 << 15);
    	PINS_DRV_TogglePins(PTD, 1 << 16);
    }




  /*** Don't write any code pass this line, or it will be deleted during code generation. ***/
  /*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
  #ifdef PEX_RTOS_START
    PEX_RTOS_START();                  /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
  #endif
  /*** End of RTOS startup code.  ***/
  /*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
  for(;;) {
    if(exit_code != 0) {
      break;
    }
  }
  return exit_code;
  /*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/

/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
**     This file was created by Processor Expert 10.1 [05.21]
**     for the NXP S32K series of microcontrollers.
**
** ###################################################################
*/
