PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
POKITTO_HW/clock_11u6x.c@30:796f9611d2ac, 2018-01-30 (annotated)
- Committer:
- Pokitto
- Date:
- Tue Jan 30 10:41:12 2018 +0000
- Revision:
- 30:796f9611d2ac
Sound enhancements done
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 30:796f9611d2ac | 1 | #include "clock_11u6x.h" |
Pokitto | 30:796f9611d2ac | 2 | |
Pokitto | 30:796f9611d2ac | 3 | |
Pokitto | 30:796f9611d2ac | 4 | /* Inprecise clock rates for the watchdog oscillator */ |
Pokitto | 30:796f9611d2ac | 5 | STATIC const uint32_t wdtOSCRate[WDTLFO_OSC_4_60 + 1] = { |
Pokitto | 30:796f9611d2ac | 6 | 0, /* WDT_OSC_ILLEGAL */ |
Pokitto | 30:796f9611d2ac | 7 | 600000, /* WDT_OSC_0_60 */ |
Pokitto | 30:796f9611d2ac | 8 | 1050000, /* WDT_OSC_1_05 */ |
Pokitto | 30:796f9611d2ac | 9 | 1400000, /* WDT_OSC_1_40 */ |
Pokitto | 30:796f9611d2ac | 10 | 1750000, /* WDT_OSC_1_75 */ |
Pokitto | 30:796f9611d2ac | 11 | 2100000, /* WDT_OSC_2_10 */ |
Pokitto | 30:796f9611d2ac | 12 | 2400000, /* WDT_OSC_2_40 */ |
Pokitto | 30:796f9611d2ac | 13 | 2700000, /* WDT_OSC_2_70 */ |
Pokitto | 30:796f9611d2ac | 14 | 3000000, /* WDT_OSC_3_00 */ |
Pokitto | 30:796f9611d2ac | 15 | 3250000, /* WDT_OSC_3_25 */ |
Pokitto | 30:796f9611d2ac | 16 | 3500000, /* WDT_OSC_3_50 */ |
Pokitto | 30:796f9611d2ac | 17 | 3750000, /* WDT_OSC_3_75 */ |
Pokitto | 30:796f9611d2ac | 18 | 4000000, /* WDT_OSC_4_00 */ |
Pokitto | 30:796f9611d2ac | 19 | 4200000, /* WDT_OSC_4_20 */ |
Pokitto | 30:796f9611d2ac | 20 | 4400000, /* WDT_OSC_4_40 */ |
Pokitto | 30:796f9611d2ac | 21 | 4600000 /* WDT_OSC_4_60 */ |
Pokitto | 30:796f9611d2ac | 22 | }; |
Pokitto | 30:796f9611d2ac | 23 | |
Pokitto | 30:796f9611d2ac | 24 | /* Compute a PLL frequency */ |
Pokitto | 30:796f9611d2ac | 25 | STATIC uint32_t Chip_Clock_GetPLLFreq(uint32_t PLLReg, uint32_t inputRate) |
Pokitto | 30:796f9611d2ac | 26 | { |
Pokitto | 30:796f9611d2ac | 27 | uint32_t msel = ((PLLReg & 0x1F) + 1); |
Pokitto | 30:796f9611d2ac | 28 | |
Pokitto | 30:796f9611d2ac | 29 | return inputRate * msel; |
Pokitto | 30:796f9611d2ac | 30 | } |
Pokitto | 30:796f9611d2ac | 31 | |
Pokitto | 30:796f9611d2ac | 32 | /* Return System PLL output clock rate */ |
Pokitto | 30:796f9611d2ac | 33 | uint32_t Chip_Clock_GetSystemPLLOutClockRate(void) |
Pokitto | 30:796f9611d2ac | 34 | { |
Pokitto | 30:796f9611d2ac | 35 | return Chip_Clock_GetPLLFreq(LPC_SYSCTL->SYSPLLCTRL, |
Pokitto | 30:796f9611d2ac | 36 | Chip_Clock_GetSystemPLLInClockRate()); |
Pokitto | 30:796f9611d2ac | 37 | } |
Pokitto | 30:796f9611d2ac | 38 | |
Pokitto | 30:796f9611d2ac | 39 | |
Pokitto | 30:796f9611d2ac | 40 | /* Compute a WDT rate */ |
Pokitto | 30:796f9611d2ac | 41 | STATIC uint32_t Chip_Clock_GetWDTRate(uint32_t reg) |
Pokitto | 30:796f9611d2ac | 42 | { |
Pokitto | 30:796f9611d2ac | 43 | uint32_t div; |
Pokitto | 30:796f9611d2ac | 44 | CHIP_WDTLFO_OSC_T clk; |
Pokitto | 30:796f9611d2ac | 45 | |
Pokitto | 30:796f9611d2ac | 46 | /* Get WDT oscillator settings */ |
Pokitto | 30:796f9611d2ac | 47 | clk = (CHIP_WDTLFO_OSC_T) ((reg >> 5) & 0xF); |
Pokitto | 30:796f9611d2ac | 48 | div = reg & 0x1F; |
Pokitto | 30:796f9611d2ac | 49 | |
Pokitto | 30:796f9611d2ac | 50 | /* Compute clock rate and divided by divde value */ |
Pokitto | 30:796f9611d2ac | 51 | return wdtOSCRate[clk] / ((div + 1) << 1); |
Pokitto | 30:796f9611d2ac | 52 | } |
Pokitto | 30:796f9611d2ac | 53 | |
Pokitto | 30:796f9611d2ac | 54 | /* Return estimated watchdog oscillator rate */ |
Pokitto | 30:796f9611d2ac | 55 | uint32_t Chip_Clock_GetWDTOSCRate(void) |
Pokitto | 30:796f9611d2ac | 56 | { |
Pokitto | 30:796f9611d2ac | 57 | return Chip_Clock_GetWDTRate(LPC_SYSCTL->WDTOSCCTRL); |
Pokitto | 30:796f9611d2ac | 58 | } |
Pokitto | 30:796f9611d2ac | 59 | |
Pokitto | 30:796f9611d2ac | 60 | |
Pokitto | 30:796f9611d2ac | 61 | /* Return System PLL input clock rate */ |
Pokitto | 30:796f9611d2ac | 62 | uint32_t Chip_Clock_GetSystemPLLInClockRate(void) |
Pokitto | 30:796f9611d2ac | 63 | { |
Pokitto | 30:796f9611d2ac | 64 | uint32_t clkRate; |
Pokitto | 30:796f9611d2ac | 65 | |
Pokitto | 30:796f9611d2ac | 66 | switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->SYSPLLCLKSEL & 0x3)) { |
Pokitto | 30:796f9611d2ac | 67 | case SYSCTL_PLLCLKSRC_IRC: |
Pokitto | 30:796f9611d2ac | 68 | clkRate = Chip_Clock_GetIntOscRate(); |
Pokitto | 30:796f9611d2ac | 69 | break; |
Pokitto | 30:796f9611d2ac | 70 | |
Pokitto | 30:796f9611d2ac | 71 | case SYSCTL_PLLCLKSRC_MAINOSC: |
Pokitto | 30:796f9611d2ac | 72 | clkRate = Chip_Clock_GetMainOscRate(); |
Pokitto | 30:796f9611d2ac | 73 | break; |
Pokitto | 30:796f9611d2ac | 74 | |
Pokitto | 30:796f9611d2ac | 75 | case SYSCTL_PLLCLKSRC_RTC32K: |
Pokitto | 30:796f9611d2ac | 76 | clkRate = Chip_Clock_GetRTCOscRate(); |
Pokitto | 30:796f9611d2ac | 77 | break; |
Pokitto | 30:796f9611d2ac | 78 | |
Pokitto | 30:796f9611d2ac | 79 | default: |
Pokitto | 30:796f9611d2ac | 80 | clkRate = 0; |
Pokitto | 30:796f9611d2ac | 81 | } |
Pokitto | 30:796f9611d2ac | 82 | |
Pokitto | 30:796f9611d2ac | 83 | return clkRate; |
Pokitto | 30:796f9611d2ac | 84 | } |
Pokitto | 30:796f9611d2ac | 85 | |
Pokitto | 30:796f9611d2ac | 86 | |
Pokitto | 30:796f9611d2ac | 87 | /* Return main clock rate */ |
Pokitto | 30:796f9611d2ac | 88 | uint32_t Chip_Clock_GetMainClockRate(void) |
Pokitto | 30:796f9611d2ac | 89 | { |
Pokitto | 30:796f9611d2ac | 90 | uint32_t clkRate = 0; |
Pokitto | 30:796f9611d2ac | 91 | |
Pokitto | 30:796f9611d2ac | 92 | switch ((CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL & 0x3)) { |
Pokitto | 30:796f9611d2ac | 93 | case SYSCTL_MAINCLKSRC_IRC: |
Pokitto | 30:796f9611d2ac | 94 | clkRate = Chip_Clock_GetIntOscRate(); |
Pokitto | 30:796f9611d2ac | 95 | break; |
Pokitto | 30:796f9611d2ac | 96 | |
Pokitto | 30:796f9611d2ac | 97 | case SYSCTL_MAINCLKSRC_PLLIN: |
Pokitto | 30:796f9611d2ac | 98 | clkRate = Chip_Clock_GetSystemPLLInClockRate(); |
Pokitto | 30:796f9611d2ac | 99 | break; |
Pokitto | 30:796f9611d2ac | 100 | |
Pokitto | 30:796f9611d2ac | 101 | case SYSCTL_MAINCLKSRC_WDTOSC: |
Pokitto | 30:796f9611d2ac | 102 | clkRate = Chip_Clock_GetWDTOSCRate(); |
Pokitto | 30:796f9611d2ac | 103 | break; |
Pokitto | 30:796f9611d2ac | 104 | |
Pokitto | 30:796f9611d2ac | 105 | case SYSCTL_MAINCLKSRC_PLLOUT: |
Pokitto | 30:796f9611d2ac | 106 | clkRate = Chip_Clock_GetSystemPLLOutClockRate(); |
Pokitto | 30:796f9611d2ac | 107 | break; |
Pokitto | 30:796f9611d2ac | 108 | } |
Pokitto | 30:796f9611d2ac | 109 | |
Pokitto | 30:796f9611d2ac | 110 | return clkRate; |
Pokitto | 30:796f9611d2ac | 111 | } |
Pokitto | 30:796f9611d2ac | 112 | |
Pokitto | 30:796f9611d2ac | 113 | /* Return system clock rate */ |
Pokitto | 30:796f9611d2ac | 114 | uint32_t Chip_Clock_GetSystemClockRate(void) |
Pokitto | 30:796f9611d2ac | 115 | { |
Pokitto | 30:796f9611d2ac | 116 | /* No point in checking for divide by 0 */ |
Pokitto | 30:796f9611d2ac | 117 | return Chip_Clock_GetMainClockRate() / LPC_SYSCTL->SYSAHBCLKDIV; |
Pokitto | 30:796f9611d2ac | 118 | } |
Pokitto | 30:796f9611d2ac | 119 | |
Pokitto | 30:796f9611d2ac | 120 |