X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=teensy3%2Fpins_teensy.c;h=52df77794b83eb129713406b3d196a8bdb787b29;hb=HEAD;hp=a45fc84e794dbfa26e62e60a6e70be99617fb723;hpb=a773ac06cdc55be51ebc0bc61aa6066b54746c7d;p=teensytas.git diff --git a/teensy3/pins_teensy.c b/teensy3/pins_teensy.c index a45fc84..52df777 100644 --- a/teensy3/pins_teensy.c +++ b/teensy3/pins_teensy.c @@ -611,7 +611,7 @@ void pinMode(uint8_t pin, uint8_t mode) if (mode == OUTPUT) { *portModeRegister(pin) = 1; - *config = PORT_PCR_SRE | PORT_PCR_DSE | PORT_PCR_MUX(1); + *config = /*PORT_PCR_SRE |*/ PORT_PCR_DSE | PORT_PCR_MUX(1); } else { *portModeRegister(pin) = 0; if (mode == INPUT) { @@ -690,7 +690,7 @@ volatile uint32_t systick_millis_count = 0; //uint32_t systick_current, systick_count, systick_istatus; // testing only -uint32_t micros(void) +static uint32_t micros_mask(void) { uint32_t count, current, istatus; @@ -707,6 +707,24 @@ uint32_t micros(void) return count * 1000 + current / (F_CPU / 1000000); } +uint32_t micros(void) +{ + uint32_t count, current, istatus; + + if (nvic_execution_priority() <= (SCB_SHPR3 >> 24)) + return micros_mask(); + + do { + current = SYST_CVR; + count = systick_millis_count; + istatus = SCB_ICSR; // bit 26 indicates if systick exception pending + } + while (istatus & SCB_ICSR_PENDSTSET); + + current = ((F_CPU / 1000) - 1) - current; + return count * 1000 + current / (F_CPU / 1000000); +} + void delay(uint32_t ms) { uint32_t start = micros();