mirror of
https://github.com/Optiboot/optiboot.git
synced 2025-09-01 13:41:55 +03:00
Finish SINGLESPEED option support
This commit is contained in:
@@ -32,7 +32,11 @@ fcpu=${fcpu/U/}
|
|||||||
/*
|
/*
|
||||||
* Compute the divisor
|
* Compute the divisor
|
||||||
*/
|
*/
|
||||||
|
#ifdef SINGLESPEED
|
||||||
|
BAUD_SETTING=$(( ( ($fcpu + $bps * 8) / (($bps * 16))) - 1 ))
|
||||||
|
#else
|
||||||
BAUD_SETTING=$(( ( ($fcpu + $bps * 4) / (($bps * 8))) - 1 ))
|
BAUD_SETTING=$(( ( ($fcpu + $bps * 4) / (($bps * 8))) - 1 ))
|
||||||
|
#endif
|
||||||
// echo baud setting = $BAUD_SETTING
|
// echo baud setting = $BAUD_SETTING
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -40,7 +44,11 @@ BAUD_SETTING=$(( ( ($fcpu + $bps * 4) / (($bps * 8))) - 1 ))
|
|||||||
* And the error. Since we're all integers, we have to calculate
|
* And the error. Since we're all integers, we have to calculate
|
||||||
* the tenths part of the error separately.
|
* the tenths part of the error separately.
|
||||||
*/
|
*/
|
||||||
|
#ifdef SINGLESPEED
|
||||||
|
BAUD_ACTUAL=$(( ($fcpu/(16 * (($BAUD_SETTING)+1))) ))
|
||||||
|
#else
|
||||||
BAUD_ACTUAL=$(( ($fcpu/(8 * (($BAUD_SETTING)+1))) ))
|
BAUD_ACTUAL=$(( ($fcpu/(8 * (($BAUD_SETTING)+1))) ))
|
||||||
|
#endif
|
||||||
BAUD_ERROR=$(( (( 100*($BAUD_ACTUAL - $bps) ) / $bps) ))
|
BAUD_ERROR=$(( (( 100*($BAUD_ACTUAL - $bps) ) / $bps) ))
|
||||||
ERR_TS=$(( ((( 1000*($BAUD_ACTUAL - $bps) ) / $bps) - $BAUD_ERROR * 10) ))
|
ERR_TS=$(( ((( 1000*($BAUD_ACTUAL - $bps) ) / $bps) - $BAUD_ERROR * 10) ))
|
||||||
ERR_TENTHS=$(( ERR_TS > 0 ? ERR_TS: -ERR_TS ))
|
ERR_TENTHS=$(( ERR_TS > 0 ? ERR_TS: -ERR_TS ))
|
||||||
|
@@ -326,8 +326,15 @@ typedef union {
|
|||||||
#define UART 0
|
#define UART 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef SINGLESPEED
|
||||||
|
/* Single speed option */
|
||||||
|
#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 8L) / ((BAUD_RATE * 16L))) - 1 )
|
||||||
|
#define BAUD_ACTUAL (F_CPU/(16 * ((BAUD_SETTING)+1)))
|
||||||
|
#else
|
||||||
|
/* Normal U2X usage */
|
||||||
#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
|
#define BAUD_SETTING (( (F_CPU + BAUD_RATE * 4L) / ((BAUD_RATE * 8L))) - 1 )
|
||||||
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
|
#define BAUD_ACTUAL (F_CPU/(8 * ((BAUD_SETTING)+1)))
|
||||||
|
#endif
|
||||||
#if BAUD_ACTUAL <= BAUD_RATE
|
#if BAUD_ACTUAL <= BAUD_RATE
|
||||||
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)
|
#define BAUD_ERROR (( 100*(BAUD_RATE - BAUD_ACTUAL) ) / BAUD_RATE)
|
||||||
#if BAUD_ERROR >= 5
|
#if BAUD_ERROR >= 5
|
||||||
@@ -344,14 +351,14 @@ typedef union {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 > 250
|
#if BAUD_SETTING > 250
|
||||||
#error Unachievable baud rate (too slow) BAUD_RATE
|
#error Unachievable baud rate (too slow) BAUD_RATE
|
||||||
#endif // baud rate slow check
|
#endif // baud rate slow check
|
||||||
#if (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 < 3
|
#if (BAUD_SETTING - 1) < 3
|
||||||
#if BAUD_ERROR != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
|
#if BAUD_ERROR != 0 // permit high bitrates (ie 1Mbps@16MHz) if error is zero
|
||||||
#error Unachievable baud rate (too fast) BAUD_RATE
|
#error Unachievable baud rate (too fast) BAUD_RATE
|
||||||
#endif
|
#endif
|
||||||
#endif // baud rate fastn check
|
#endif // baud rate fast check
|
||||||
|
|
||||||
/* Watchdog settings */
|
/* Watchdog settings */
|
||||||
#define WATCHDOG_OFF (0)
|
#define WATCHDOG_OFF (0)
|
||||||
@@ -559,12 +566,16 @@ int main(void) {
|
|||||||
|
|
||||||
#ifndef SOFT_UART
|
#ifndef SOFT_UART
|
||||||
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega16__)
|
#if defined(__AVR_ATmega8__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega16__)
|
||||||
|
#ifndef SINGLESPEED
|
||||||
UCSRA = _BV(U2X); //Double speed mode USART
|
UCSRA = _BV(U2X); //Double speed mode USART
|
||||||
|
#endif
|
||||||
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
|
UCSRB = _BV(RXEN) | _BV(TXEN); // enable Rx & Tx
|
||||||
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
|
UCSRC = _BV(URSEL) | _BV(UCSZ1) | _BV(UCSZ0); // config USART; 8N1
|
||||||
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
UBRRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
||||||
#else
|
#else
|
||||||
|
#ifndef SINGLESPEED
|
||||||
UART_SRA = _BV(U2X0); //Double speed mode USART0
|
UART_SRA = _BV(U2X0); //Double speed mode USART0
|
||||||
|
#endif
|
||||||
UART_SRB = _BV(RXEN0) | _BV(TXEN0);
|
UART_SRB = _BV(RXEN0) | _BV(TXEN0);
|
||||||
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
|
UART_SRC = _BV(UCSZ00) | _BV(UCSZ01);
|
||||||
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
UART_SRL = (uint8_t)( (F_CPU + BAUD_RATE * 4L) / (BAUD_RATE * 8L) - 1 );
|
||||||
|
Reference in New Issue
Block a user