hello i look to some way for access Xtal value in my program . when i start new project in keil , in "Options for Target..." window i add Xtal Frequency in hertz . (it is 18.432 for at91sam usually ) can someone help me to access this value in program ? i need this value for this function :
while (!ok) { cldiv = ((mck / (2 * twck)) - 3) / power_2_ckdiv; if (cldiv <= 255) { ok = 1; } else { ckdiv++; } }
i calculation mck with this function and it need Xtal value (crystal) :
unsigned int GET_MASTER_CPU_CLOCK (void) { unsigned int reg = AT91C_BASE_PMC->PMC_MCKR; unsigned int prescaler = (1 << ((reg & AT91C_PMC_PRES) >> 2)); unsigned int pll_divider, pll_multiplier; switch (reg & AT91C_PMC_CSS) { case AT91C_PMC_CSS_SLOW_CLK: // Slow clock selected return 32000 / prescaler; case AT91C_PMC_CSS_MAIN_CLK: // Main clock is selected return crystal / prescaler; case AT91C_PMC_CSS_PLL_CLK: // PLLB clock is selected pll_divider = (AT91C_BASE_CKGR->CKGR_PLLR & AT91C_CKGR_DIV); pll_multiplier = ((AT91C_BASE_CKGR->CKGR_PLLR & AT91C_CKGR_MUL) >> 16) + 1; return (crystal / pll_divider * pll_multiplier / prescaler); } return 0; }
regards
The "options for target" is a dialog where _you_ tell the debugger/simulator what speed to pretend your virtual hardware should use. Knowing that value, the debugger can compute how long time a function call takes, and the simulator can compute what baudrate you get when you configure an UART.
But it is totally outside of your source code domain.
You should add some code line somewhere in your source code that allows your source code to know how to compute any divisors for baudrates etc.
So consider explicitly adding:
#define CRYSTAL=18432000
or maybe
enum { CRYSTAL = 18432000, };