}CXA_XMEGA_ISR_END CXA_XMEGA_ISR_START(USARTE0_RXC_vect) { rxIsr(&USARTE0); }CXA_XMEGA_ISR_END
}CXA_XMEGA_ISR_END #ifdef USARTF1 CXA_XMEGA_ISR_START(USARTF1_RXC_vect) { rxIsr(&USARTF1); }CXA_XMEGA_ISR_END
}CXA_XMEGA_ISR_END #endif CXA_XMEGA_ISR_START(USARTF0_RXC_vect) { rxIsr(&USARTF0); }CXA_XMEGA_ISR_END
// Holds a GPIO pin to its old value until the needed time has past. // Then sets the gpio to a new value and updates the lastBitTime value. // Also takes inverting logic into account void holdAndSetTx(GpioUart* uart, bool value, struct timespec* lastBitTime, long nanosecondsNeeded) { // Save last time and value TESTING struct timespec startTime = *lastBitTime; bool oldValue = uart->rxPinValue; addTimeAndBusyWait(lastBitTime, nanosecondsNeeded); // Check on quality of timing! TESTING /*struct timespec endTime; get_monotonic_boottime(&endTime); printk(KERN_INFO "Time Quality Offset %ld", timeDifference(&endTime, lastBitTime)); */ // REMOVED FOR TESTING // gpio_set_value(uart->txPin, uart->invertingLogic ? !value : value); // ADDED FOR TESTING // Normalize to one and zero value = value ? 1 : 0; uart->rxPinValue = uart->invertingLogic ? !value : value; // TESTING ADD // Get current time /*struct timespec currentTime; get_monotonic_boottime(¤tTime); long bitTime = timeDifference(¤tTime, &startTime); long sinceLast = timeDifference(¤tTime, &uart->rxLastInterruptTime); printk(KERN_INFO "HCurrent time: %ld last int.: %ld", currentTime.tv_nsec, uart->rxLastInterruptTime.tv_nsec); get_monotonic_boottime(¤tTime); printk(KERN_INFO "ICurrent time: %ld", currentTime.tv_nsec);*/ uart->rxBitTimeA = startTime; uart->rxBitTimeB = *lastBitTime; // To be realistic to ourselves, only trigger an "interrupt" if we are actually changing the value if (oldValue != uart->rxPinValue) { rxIsr(uart->rxPin, uart, NULL); } // TESTING //printk(KERN_INFO "Held value %d for %ld (%ld desired), %ld last interrupt", oldValue, bitTime, nanosecondsNeeded, sinceLast); /*static int iterations = 0; static long bitTimeAverage = 0; static long sinceLastAverage = 0; bitTimeAverage = (bitTimeAverage * iterations + bitTime) / (iterations + 1); sinceLastAverage = (sinceLastAverage * iterations + sinceLast) / (iterations + 1); iterations++; // Report every once in a while! if (iterations >= 25) { printk(KERN_INFO "Average hold time %ld (%ld desired), %ld last interrupt", bitTimeAverage, nanosecondsNeeded, sinceLastAverage); iterations = 0; bitTimeAverage = 0; sinceLastAverage = 0; }*/ }
/************************************************************************************************** * @fn URXx/UTXx_VECTOR * * @brief Intercept the USART0 ISR's here and consume locally if in boot loader, or forward * to a valid run-code image. * * input parameters * * None. * * output parameters * * None. * * @return None. ************************************************************************************************** */ HAL_ISR_FUNCTION( halUart0RxIsr, URX0_VECTOR ) { if (magicByte == SB_STACK_VALUE) { void (*rxIsr)(void); rxIsr = (void (*)(void))0x2013; rxIsr(); } else if (magicByte == SB_MAGIC_VALUE) { halUartRxIsr(); } else { asm("NOP"); // Not expected. } }