#include "CH59x_common.h"
#define InitSysTickCnt() { SysTick->CTLR = 5; } // one tick = SYSCLK
#define GetSysTickCnt() ((uint32_t)SysTick->CNT) // one tick = SYSCLK
__HIGH_CODE
__attribute__((noinline))
void Main_CirculationRAM(void)
{
uint32_t cnt, tt, tt1, tt2;
cnt = 0x10000;
tt = GetSysTickCnt();
while(cnt--)
{
__nop();
__nop();
__nop();
__nop();
__nop();
}
tt1 = GetSysTickCnt() - tt;
cnt = 0x10000;
tt = GetSysTickCnt();
while(cnt--)
{
R32_PB_OUT ^= GPIO_Pin_4;
}
tt2 = GetSysTickCnt() - tt;
PRINT("RAM SysTick: %u %u\n", tt1, tt2);
}
__attribute__((noinline))
void Main_CirculationFlash(void)
{
uint32_t cnt, tt, tt1, tt2;
InitSysTickCnt();
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
cnt = 0x10000;
tt = GetSysTickCnt();
while(cnt--)
{
__nop();
__nop();
__nop();
__nop();
__nop();
}
tt1 = GetSysTickCnt() - tt;
cnt = 0x10000;
tt = GetSysTickCnt();
while(cnt--)
{
R32_PB_OUT ^= GPIO_Pin_4;
}
tt2 = GetSysTickCnt() - tt;
PRINT("FLASH SysTick: %u %u\n", tt1, tt2);
}
int main()
{
SetSysClock(CLK_SOURCE_PLL_60MHz);
PWR_DCDCCfg(ENABLE);
GPIOA_SetBits(GPIO_Pin_9);
GPIOA_ModeCfg(GPIO_Pin_9, GPIO_ModeOut_PP_5mA);
UART1_DefInit();
PRINT("Start @ChipID=%02x\n", R8_CHIP_ID);
PRINT("SysClock: %u kHz\n", GetSysClock()/1000);
DelayMs(200);
InitSysTickCnt();
GPIOB_ModeCfg(GPIO_Pin_4, GPIO_ModeOut_PP_5mA);
while(1) {
Main_CirculationRAM();
Main_CirculationFlash();
}
}