1
0
mirror of https://github.com/Optiboot/optiboot.git synced 2025-08-17 21:41:03 +03:00

Modifications for ATtiny4x2, at least as far as compilation.

Eliminate RTC-based LED flashing code in favor of busy loop, which is significantly shorter now that peripherals are not in range of quick IO instructions.
Minor formatting changes while the code is young (notably spaces after the function name at the spot where they're actually defined, which makes them easier to search for.  Ancient corporate coding style guideline...)
This commit is contained in:
WestfW
2019-09-04 01:21:27 -07:00
parent bb9ae67aee
commit 58a71b130f
2 changed files with 55 additions and 27 deletions

View File

@@ -340,20 +340,12 @@ int main(void) {
}
}
#if LED_START_FLASHES > 0
// Set up RTC counting at about 1/8s (input is 32kHz)
while (RTC.STATUS & RTC_CTRLABUSY_bm)
; // RTC is used by startup logic (!) and might be busy.
RTC.CTRLA= RTC_PRESCALER_DIV4096_gc | RTC_RTCEN_bm;
RTC.DBGCTRL = 1; // enable during debug
#endif
_PROTECTED_WRITE(CLKCTRL.MCLKCTRLB, 0); // full speed clock
MYUART_TXPORT.DIR |= MYUART_TXPIN; // set TX pin to output
MYUART_TXPORT.OUT |= MYUART_TXPIN; // and "1" as per datasheet
#if defined (MYUART_PMUX)
PORTMUX.USARTROUTEA |= MYUART_PMUX; // alternate pinout to use
MYPMUX |= MYUART_PMUX; // alternate pinout to use
#endif
MYUART.BAUD = BAUD_SETTING;
MYUART.DBGCTRL = 1; // run during debug
@@ -361,8 +353,8 @@ int main(void) {
MYUART.CTRLA = 0; // Interrupts: all off
MYUART.CTRLB = USART_RXEN_bm | USART_TXEN_bm;
// Set up watchdog to trigger after 1s
// watchdogConfig(WDT_PERIOD_1KCLK_gc);
// Set up watchdog to trigger after 8s
watchdogConfig(WDT_PERIOD_8KCLK_gc);
#if (LED_START_FLASHES > 0) || defined(LED_DATA_FLASH) || defined(LED_START_ON)
/* Set LED pin as output */
@@ -431,7 +423,7 @@ int main(void) {
}
/* Write memory, length is big endian and is in bytes */
else if(ch == STK_PROG_PAGE) {
// PROGRAM PAGE - we support flash programming only, not EEPROM
// PROGRAM PAGE - any kind of page!
uint8_t desttype;
GETLENGTH(length);
@@ -442,6 +434,7 @@ int main(void) {
} else {
address.word += MAPPED_EEPROM_START;
}
// TODO: user row?
do {
*(address.bptr++) = getch();
@@ -469,6 +462,8 @@ int main(void) {
} else {
address.word += MAPPED_EEPROM_START;
}
// TODO: user row?
do {
putch(*(address.bptr++));
} while (--length);
@@ -532,11 +527,15 @@ void verifySpace() {
#if LED_START_FLASHES > 0
void flash_led (uint8_t count) {
uint8_t last;
#ifdef __INT24_MAX__
__uint24 delay;
#else
uint32_t delay;
# warning no uin24
#endif
while (count--) {
LED_PORT.IN |= LED;
last = RTC.CNTL & 1;
while ((RTC.CNTL & 1) == last) {
for (delay = (F_CPU/200); delay; delay--) {
watchdogReset();
if (MYUART.STATUS & USART_RXCIF_bm)
return;
@@ -550,8 +549,6 @@ void watchdogConfig(uint8_t x) {
}
#ifndef APP_NOSPM
/*

View File

@@ -670,6 +670,7 @@
#define USART_ALTPMUX 1
#if defined(__AVR_ATmega4809__)
#define MYPMUX PORTMUX.USARTROUTEA
# if (UARTTX == A0)
# ifndef USART0
# error Pin on USART0, but no USART0 exists
@@ -733,6 +734,36 @@
# endif
#endif // ATmega4809
/*
* 8pin Tiny0 and Tiny1
*/
#if defined(__AVR_ATtiny402__) || defined(__AVR_ATtiny202__) || \
defined(__AVR_ATtiny412__) || defined(__AVR_ATtiny212__)
#define MYPMUX PORTMUX.CTRLB
# if (UARTTX == A6)
# ifndef USART0
# error Pin on USART0, but no USART0 exists
# endif
# define MYUART USART0
# define MYUART_TXPORT VPORTA
# define MYUART_TXPIN (1<<PORT0)
# elif (UARTTX == A1)
# ifndef USART0
# error Pin on USART0, but no USART0 exists
# endif
# define MYUART USART0
# define MYUART_TXPORT VPORTA
# define MYUART_TXPIN (1<<PORT4)
# define MYUART_PMUX (USART_ALTPMUX)
# endif
#endif // Tiny402/etc
#if defined(__ATtiny3216__) || defined(__ATtiny1606__)
#endif
#if defined(__ATtiny1614__) || defined(__ATtiny1604__)
#endif
#ifndef MYUART
# warning No UARTTX pin specified.
#endif