Use more defines when using main clock or master clock

This commit is contained in:
Philippe Teuwen
2019-08-06 13:40:08 +02:00
parent 2cbe43f269
commit 8b3159c83d
6 changed files with 11 additions and 8 deletions

View File

@@ -102,7 +102,6 @@
#define MAX_BLOCKS 4
#define MAX_SECTORS 16
#define MCK 48000000
//#define FLASH_BAUD 24000000
#define FLASH_MINFAST 24000000 //33000000
#define FLASH_BAUD MCK/2

View File

@@ -13,7 +13,7 @@
// timer counts in 21.3uS increments (1024/48Mhz), rounding applies
// WARNING: timer can't measure more than 1.39s (21.3uS * 0xffff)
void SpinDelayUs(int us) {
int ticks = (48 * us + 512) >> 10;
int ticks = ((MCK / 1000000) * us + 512) >> 10;
// Borrow a PWM unit for my real-time clock
// This resets PWMC_CPRDR as well
@@ -59,7 +59,7 @@ void StartTickCount(void) {
while ((AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINRDY) == 0); // Wait for MAINF value to become available...
uint16_t mainf = AT91C_BASE_PMC->PMC_MCFR & AT91C_CKGR_MAINF; // Get # main clocks within 16 slow clocks
// set RealTimeCounter divider to count at 1kHz, should be 32 if RC is exactly at 32kHz:
AT91C_BASE_RTTC->RTTC_RTMR = AT91C_RTTC_RTTRST | ((((16000000 / 1000 * 16) + (mainf / 2)) / mainf) & AT91C_RTTC_RTPRES);
AT91C_BASE_RTTC->RTTC_RTMR = AT91C_RTTC_RTTRST | ((((MAINCK / 1000 * 16) + (mainf / 2)) / mainf) & AT91C_RTTC_RTPRES);
// note: worst case precision is approx 2.5%
}

View File

@@ -182,7 +182,7 @@ int BUTTON_CLICKED(int ms) {
Dbprintf(_RED_("Error, BUTTON_CLICKED called with %i > 1390"), ms);
ms = 1390;
}
int ticks = (48000 * (ms ? ms : 1000)) >> 10;
int ticks = ((MCK / 1000) * (ms ? ms : 1000)) >> 10;
// If we're not even pressed, forget about it!
if (!BUTTON_PRESS())
@@ -210,7 +210,7 @@ int BUTTON_CLICKED(int ms) {
// reset our timer for 500ms
start = AT91C_BASE_PWMC_CH0->PWMC_CCNTR;
ticks = (48000 * (500)) >> 10;
ticks = ((MCK / 1000) * (500)) >> 10;
}
// Still haven't let it off