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:
@@ -254,7 +254,7 @@ static inline void flash_led(uint8_t);
|
||||
#endif
|
||||
|
||||
/* everything that needs to run VERY early */
|
||||
void pre_main(void) {
|
||||
void pre_main (void) {
|
||||
// Allow convenient way of calling do_spm function - jump table,
|
||||
// so entry to this function will always be here, indepedent of compilation,
|
||||
// features etc
|
||||
@@ -271,7 +271,7 @@ void pre_main(void) {
|
||||
|
||||
|
||||
/* main program starts here */
|
||||
int main(void) {
|
||||
int main (void) {
|
||||
uint8_t ch;
|
||||
|
||||
/*
|
||||
@@ -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);
|
||||
@@ -495,13 +490,13 @@ int main(void) {
|
||||
}
|
||||
}
|
||||
|
||||
void putch(char ch) {
|
||||
void putch (char ch) {
|
||||
while (0 == (MYUART.STATUS & USART_DREIF_bm))
|
||||
;
|
||||
MYUART.TXDATAL = ch;
|
||||
}
|
||||
|
||||
uint8_t getch(void) {
|
||||
uint8_t getch (void) {
|
||||
uint8_t ch, flags;
|
||||
while (!(MYUART.STATUS & USART_RXCIF_bm))
|
||||
;
|
||||
@@ -516,12 +511,12 @@ uint8_t getch(void) {
|
||||
return ch;
|
||||
}
|
||||
|
||||
void getNch(uint8_t count) {
|
||||
void getNch (uint8_t count) {
|
||||
do getch(); while (--count);
|
||||
verifySpace();
|
||||
}
|
||||
|
||||
void verifySpace() {
|
||||
void verifySpace () {
|
||||
if (getch() != CRC_EOP) {
|
||||
watchdogConfig(WDT_PERIOD_8CLK_gc); // shorten WD timeout
|
||||
while (1) // and busy-loop so that WD causes
|
||||
@@ -531,12 +526,16 @@ void verifySpace() {
|
||||
}
|
||||
|
||||
#if LED_START_FLASHES > 0
|
||||
void flash_led(uint8_t count) {
|
||||
uint8_t last;
|
||||
void flash_led (uint8_t count) {
|
||||
#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;
|
||||
@@ -545,13 +544,11 @@ void flash_led(uint8_t count) {
|
||||
}
|
||||
#endif
|
||||
|
||||
void watchdogConfig(uint8_t x) {
|
||||
void watchdogConfig (uint8_t x) {
|
||||
_PROTECTED_WRITE(WDT.CTRLA, x);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
#ifndef APP_NOSPM
|
||||
|
||||
/*
|
||||
@@ -572,7 +569,7 @@ void watchdogConfig(uint8_t x) {
|
||||
* data=0 in WRITE
|
||||
*/
|
||||
static void do_nvmctrl(uint16_t address, uint8_t command, uint16_t data) __attribute__ ((used));
|
||||
static void do_nvmctrl(uint16_t address, uint8_t command, uint16_t data) {
|
||||
static void do_nvmctrl (uint16_t address, uint8_t command, uint16_t data) {
|
||||
// Do spm stuff
|
||||
}
|
||||
#endif
|
||||
|
@@ -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
|
||||
@@ -731,7 +732,37 @@
|
||||
# define MYUART_TXPIN (1<<PORT4)
|
||||
# define MYUART_PMUX (USART_ALTPMUX<<PORTMUX_USART2_gp)
|
||||
# endif
|
||||
#endif // ATmega4809
|
||||
#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.
|
||||
|
Reference in New Issue
Block a user