The following example uses the IfxScuCcu_init
function which allow us to set up to some pre-determine values the internal PLLs and peripheral divisor. We can also override the macro IFXSCU_CFG_CLK_DISTRIBUTION
which in turn is a structure to set our own peripheral divisor values if we desire different frequencies. There are a set of functions belong to iLLD library allowing us to know which frequencies were set.
#include "Ifx_Types.h"
#include "IfxCpu.h"
#include "IfxScuWdt.h"
#include "Port/Io/IfxPort_Io.h"
#include "Scu/Std/IfxScuCcu.h"
#include "Bsp.h"
#include <stdio.h>
IFX_ALIGN(4) IfxCpu_syncEvent g_cpuSyncEvent = 0;
/*Array with default with preset values for PLL steps */
static IfxScuCcu_PllStepConfig IfxScuCcu_defaultPllConfigSteps[] = { IFXSCU_CFG_PLL_STEPS };
/*presets wait state to configure the Flash memory*/
static const IfxScuCcu_FlashWaitstateConfig IfxScuCcu_defaultFlashWaitstateConfig = IFXSCU_CFG_FLASH_WAITSTATE;
/*Structure to configure the three internal PLL with the following frequencies
* PLL0 = 300MHz, PLL1 = 320MHz and PLL2 = 160MHz */
IfxScuCcu_Config IfxScuCcu_testClockConfig = {
IFXSCU_CFG_PLL_INITIAL_STEP,
{
sizeof(IfxScuCcu_defaultPllConfigSteps) / sizeof(IfxScuCcu_PllStepConfig),
IfxScuCcu_defaultPllConfigSteps
},
IFXSCU_CFG_CLK_DISTRIBUTION,
&IfxScuCcu_defaultFlashWaitstateConfig,
&IfxScuCcu_defaultModConfig
};
void core0_main( void )
{
volatile float32 AdcFreq;
volatile float32 GtmFreq;
volatile float32 CanFreq;
volatile float32 SpiFreq;
volatile float32 SysPllFrec, Per1PllFrec, Per2PllFrec, Cpu0Frec;
IfxCpu_enableInterrupts();
/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required */
IfxScuWdt_disableCpuWatchdog( IfxScuWdt_getCpuWatchdogPassword() );
IfxScuWdt_disableSafetyWatchdog( IfxScuWdt_getSafetyWatchdogPassword() );
/* Wait for CPU sync event */
IfxCpu_emitEvent( &g_cpuSyncEvent );
IfxCpu_waitEvent( &g_cpuSyncEvent, 1u );
/* standard PLL & clock initialisation */
IfxScuCcu_init( &IfxScuCcu_testClockConfig );
/*REad some of the system and peripheral frequencies*/
SysPllFrec = IfxScuCcu_getPllFrequency();
Per1PllFrec = IfxScuCcu_getPerPllFrequency1();
Per2PllFrec = IfxScuCcu_getPerPllFrequency2();
Cpu0Frec = IfxScuCcu_getCpuFrequency( IfxCpu_ResourceCpu_0 );
AdcFreq = IfxScuCcu_getAdcFrequency();
GtmFreq = IfxScuCcu_getGtmFrequency();
CanFreq = IfxScuCcu_getMcanFrequency();
SpiFreq = IfxScuCcu_getQspiFrequency();
while(1)
{
/*insert a break point right here and read the variables with the debugger*/
waitTime( IfxStm_getTicksFromMilliseconds( BSP_DEFAULT_TIMER, 1000u ) );
}
}