Explorar el Código

PulseIn on LC issue

PulseIn may fail on LC as it is using *reg to test the value for on or
off, but on LC register is a bitmask associated with several IO pins.
So split off for LC to use the MASK value for the pin to test high and
low.

Warning did not update timings for this,  which may be necessary as adds
an & in the loop.  However when I tried TLC for 5000us timeout, it timed
out with 5138us, if I decremented the PULSEIN_LOOPS_PER_USEC by one,
then it timed out at 4398... This was at 49mhz.
main
Kurt Eckhardt hace 8 años
padre
commit
eb97df1ffe
Se han modificado 1 ficheros con 53 adiciones y 27 borrados
  1. +53
    -27
      teensy3/pins_teensy.c

+ 53
- 27
teensy3/pins_teensy.c Ver fichero

@@ -1179,12 +1179,12 @@ void delay(uint32_t ms)
#define PULSEIN_LOOPS_PER_USEC 1
#endif

#if defined(KINETISK)
uint32_t pulseIn_high(volatile uint8_t *reg, uint32_t timeout)
{
uint32_t timeout_count = timeout * PULSEIN_LOOPS_PER_USEC;
uint32_t usec_start, usec_stop;
// wait for any previous pulse to end
while (*reg) {
if (--timeout_count == 0) return 0;
@@ -1232,30 +1232,56 @@ uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout)
return pulseIn_low(portInputRegister(pin), timeout);;
}

#elif defined(KINETISL)
// For TeencyLC need to use mask on the input register as the register is shared by several IO pins
uint32_t pulseIn_high(volatile uint8_t *reg, uint8_t mask, uint32_t timeout)
{
uint32_t timeout_count = timeout * PULSEIN_LOOPS_PER_USEC;
uint32_t usec_start, usec_stop;
// wait for any previous pulse to end
while (*reg & mask) {
if (--timeout_count == 0) return -1;
}
// wait for the pulse to start
while (!(*reg & mask)) {
if (--timeout_count == 0) return 0;
}
usec_start = micros();
// wait for the pulse to stop
while (*reg & mask) {
if (--timeout_count == 0) return 0;
}
usec_stop = micros();
return usec_stop - usec_start;
}

uint32_t pulseIn_low(volatile uint8_t *reg, uint8_t mask, uint32_t timeout)
{
uint32_t timeout_count = timeout * PULSEIN_LOOPS_PER_USEC;
uint32_t usec_start, usec_stop;
// wait for any previous pulse to end
while (!(*reg & mask)) {
if (--timeout_count == 0) return 0;
}
// wait for the pulse to start
while (*reg & mask) {
if (--timeout_count == 0) return 0;
}
usec_start = micros();
// wait for the pulse to stop
while (!(*reg & mask)) {
if (--timeout_count == 0) return 0;
}
usec_stop = micros();
return usec_stop - usec_start;
}


























// TODO: an inline version should handle the common case where state is const
uint32_t pulseIn(uint8_t pin, uint8_t state, uint32_t timeout)
{
if (pin >= CORE_NUM_DIGITAL) return 0;
if (state) return pulseIn_high(portInputRegister(pin), digitalPinToBitMask(pin), timeout);
return pulseIn_low(portInputRegister(pin), digitalPinToBitMask(pin), timeout);;
}
#endif

Cargando…
Cancelar
Guardar