/** Receives a byte via the hardware USART, blocking until data is received or timeout expired. * * \return Received byte from the USART */ uint8_t XPROGTarget_ReceiveByte(void) { /* Switch to Rx mode if currently in Tx mode */ if (IsSending) XPROGTarget_SetRxMode(); /* Wait until a byte has been received before reading */ while (!(UCSR1A & (1 << RXC1)) && !(TimeoutExpired)); return UDR1; }
/** Disables the target's PDI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetPDI(void) { /* Switch to Rx mode to ensure that all pending transmissions are complete */ XPROGTarget_SetRxMode(); /* Turn off receiver and transmitter of the USART, clear settings */ UCSR1A = ((1 << TXC1) | (1 << RXC1)); UCSR1B = 0; UCSR1C = 0; /* Tristate all pins */ DDRD &= ~((1 << 5) | (1 << 3)); PORTD &= ~((1 << 5) | (1 << 3) | (1 << 2)); }
/** Receives a byte via the software USART, blocking until data is received. * * \return Received byte from the USART */ uint8_t XPROGTarget_ReceiveByte(void) { /* Switch to Rx mode if currently in Tx mode */ if (IsSending) XPROGTarget_SetRxMode(); /* Wait until a byte has been received before reading */ while (!(UCSR1A & (1 << RXC1)) && TimeoutMSRemaining); if (TimeoutMSRemaining) TimeoutMSRemaining = COMMAND_TIMEOUT_MS; return UDR1; }
/** Receives a byte via the hardware USART, blocking until data is received or timeout expired. * * \return Received byte from the USART */ uint8_t XPROGTarget_ReceiveByte(void) { uint32_t dummy_read; /* Switch to Rx mode if currently in Tx mode */ if (IsSending) XPROGTarget_SetRxMode(); /* Wait until a byte has been received before reading */ //usart_getchar(USART_PDI, &dummy_read); while((usart_read(USART_PDI, &dummy_read) == 1) && (TimeoutTicksRemaining)); return dummy_read; }
/** Disables the target's TPI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetTPI(void) { /* Switch to Rx mode to ensure that all pending transmissions are complete */ XPROGTarget_SetRxMode(); /* Turn off receiver and transmitter of the USART, clear settings */ UCSR1A |= (1 << TXC1) | (1 << RXC1); UCSR1B = 0; UCSR1C = 0; /* Set all USART lines as input, tristate */ DDRD &= ~((1 << 5) | (1 << 3)); PORTD &= ~((1 << 5) | (1 << 3) | (1 << 2)); /* Tristate target /RESET line */ AUX_LINE_DDR &= ~AUX_LINE_MASK; AUX_LINE_PORT &= ~AUX_LINE_MASK; }
/** Disables the target's PDI interface, exits programming mode and starts the target's application. */ void XPROGTarget_DisableTargetPDI(void) { /* Switch to Rx mode to ensure that all pending transmissions are complete */ if (IsSending) XPROGTarget_SetRxMode(); /* Turn off receiver and transmitter of the USART, clear settings */ usart_disable_rx(USART_PDI); usart_disable_tx(USART_PDI); /* Tristate all pins */ gpio_configure_pin(PIN_PDIC_GPIO, PIN_PDIC_IN_FLAGS); gpio_configure_pin(PIN_PDIDRX_GPIO, PIN_PDIDRX_FLAGS); gpio_configure_pin(PIN_PDIDTX_GPIO, PIN_PDIDTX_IN_FLAGS); /* Turn off USART */ sysclk_disable_peripheral_clock(USART_PDI_ID); }