/********************************************************************************
 * @file    SYSTICK_Example.c
 * @author  SOC AE Team
 * @version V1.1
 * @date    2025-06-27
 * @brief   PA10循环输出50ms高电平和100ms低电平的方波信号
 *
 *******************************************************************************/

#include "sc32_conf.h"
#include "Function_Init.h"
#include "stdio.h"

volatile uint32_t TimingDelay;

void SYSTICK_Example_Function(void)
{
  GPIO_InitTypeDef GPIO_InitStruct; //定义GPIO初始化结构体变量
  GPIO_InitStruct.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT_PP;
  GPIO_Init(GPIOA, &GPIO_InitStruct);
  
  RCC_Unlock(0xFF);
  RCC_SYSCLKConfig(RCC_SYSCLKSource_HIRC); //滴答定时器时钟源为PLLR
  RCC_SystickCLKConfig(RCC_SysTickSource_HCLK);//HCLK=32/36M
#if defined(SC32f10xx)|| defined(SC32f12xx)
  RCC_SystickSetCounter(32000); //1ms中断一次

#endif
  
  NVIC_EnableIRQ(SysTick_IRQn);
  RCC_SystickCmd(ENABLE);	
  
  printf("\r\n SysTickTimer is initialized successfully! \r\n");
  
  while(1)
  {
    Delay(50);/* Insert 50 ms delay */
    printf("\r\n 50ms delay \r\n");
    
    Delay(100);/* Insert 100 ms delay */
    printf("\r\n 100ms delay \r\n");
    
  }
}

void Delay(uint32_t nTime)
{ 
  TimingDelay = nTime;
  PA_OT(10);   //PA10翻转
  while(TimingDelay != 0);
}

void SYSTICK_Example_SYSTICKHandler(void)
{
  if (TimingDelay != 0)
  { 
    TimingDelay--;
  }
}

