This commit is contained in:
Olaf Rempel 2012-02-10 23:36:34 +01:00
parent f311af0fca
commit 3f11ccdc06

32
main.c
View File

@ -39,11 +39,11 @@
/* 25ms @8MHz */ /* 25ms @8MHz */
#define TIMER_RELOAD (0xFF - 195) #define TIMER_RELOAD (0xFF - 195)
/* 40 * 25ms */ /* 40 * 25ms = 1s */
#define TIMEOUT 40 #define TIMEOUT 40
#define EN_TX (1<<PORTD2) #define RXTX PORTD2
#define LED_GN (1<<PORTD3) #define LED PORTD3
#define BAUDRATE 115200 #define BAUDRATE 115200
#define MPM_ADDRESS 0x11 #define MPM_ADDRESS 0x11
@ -75,8 +75,7 @@
#define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1) #define UART_CALC_BAUDRATE(baudRate) (((uint32_t)F_CPU) / (((uint32_t)baudRate)*16) -1)
/* /*
* LED_GN blinks with 20Hz (while bootloader is running) * LED blinks with 20Hz (while bootloader is running)
* LED_RT blinks on activity
* *
* general protocol: * general protocol:
* ================= * =================
@ -147,8 +146,7 @@ const static uint8_t chipinfo[8] = {
(E2END +1) & 0xFF (E2END +1) & 0xFF
}; };
/* wait 40 * 25ms = 1s */ volatile static uint8_t boot_timeout = TIMEOUT;
static uint8_t boot_timeout = TIMEOUT;
volatile static uint8_t boot_wait = BOOTWAIT_RUNNING; volatile static uint8_t boot_wait = BOOTWAIT_RUNNING;
static uint8_t rx_addressed; static uint8_t rx_addressed;
@ -228,9 +226,15 @@ ISR(USART_RXC_vect)
if (rx_addressed == 0) { if (rx_addressed == 0) {
/* own address, disable MPM mode and receive following bytes */ /* own address, disable MPM mode and receive following bytes */
if (data == MPM_ADDRESS) { if (data == MPM_ADDRESS) {
#if 0
/* stay in bootloader */
boot_wait = BOOTWAIT_INTERRUPTED; boot_wait = BOOTWAIT_INTERRUPTED;
#else
/* restart timeout */
boot_timeout = TIMEOUT;
#endif
/* enable LED */ /* enable LED */
PORTD &= ~(LED_GN); PORTD &= ~(1<<LED);
UCSRA &= ~(1<<MPCM); UCSRA &= ~(1<<MPCM);
rx_addressed = 1; rx_addressed = 1;
@ -357,7 +361,7 @@ ISR(USART_UDRE_vect)
{ {
if (tx_bcnt == 0) { if (tx_bcnt == 0) {
/* enable RS485 transmitter */ /* enable RS485 transmitter */
PORTD |= EN_TX; PORTD |= (1<<RXTX);
UCSRB &= ~(1<<TXB8); UCSRB &= ~(1<<TXB8);
UDR = tx_cmd; UDR = tx_cmd;
@ -404,10 +408,10 @@ ISR(USART_UDRE_vect)
ISR(USART_TXC_vect) ISR(USART_TXC_vect)
{ {
/* disable LED */ /* disable LED */
PORTD |= LED_GN; PORTD |= (1<<LED);
/* disable RS485 transmitter */ /* disable RS485 transmitter */
PORTD &= ~(EN_TX); PORTD &= ~(1<<RXTX);
/* enable MP mode again */ /* enable MP mode again */
UCSRA |= (1<<MPCM); UCSRA |= (1<<MPCM);
@ -425,7 +429,7 @@ ISR(TIMER0_OVF_vect)
TCNT0 = TIMER_RELOAD; TCNT0 = TIMER_RELOAD;
if (boot_wait == BOOTWAIT_RUNNING) { if (boot_wait == BOOTWAIT_RUNNING) {
PORTD ^= LED_GN; PORTD ^= (1<<LED);
boot_timeout--; boot_timeout--;
if (boot_timeout == 0) { if (boot_timeout == 0) {
@ -450,7 +454,7 @@ int main(void) __attribute__ ((noreturn));
int main(void) int main(void)
{ {
/* LED and TXEN are outputs */ /* LED and TXEN are outputs */
DDRD |= LED_GN | EN_TX; DDRD |= (1<<LED) | (1<<RXTX);
#if defined(OSCCAL_VALUE) #if defined(OSCCAL_VALUE)
OSCCAL = OSCCAL_VALUE; OSCCAL = OSCCAL_VALUE;
@ -495,7 +499,7 @@ int main(void)
#endif #endif
/* disable LED */ /* disable LED */
PORTD |= LED_GN; PORTD |= (1<<LED);
uint16_t wait = 0x0000; uint16_t wait = 0x0000;
do { do {