Compare commits
No commits in common. "b4bc651445a4807002e9f237708f56d14904c1c9" and "35268c53ae39d9e15013d19c2d051a0b86179fa9" have entirely different histories.
b4bc651445
...
35268c53ae
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
||||
# Directories
|
||||
doc
|
||||
|
||||
# AVR temp files
|
||||
*.srec
|
||||
*.s
|
||||
|
11
doc/ioc.md
11
doc/ioc.md
@ -1,11 +0,0 @@
|
||||
# IOC
|
||||
|
||||
## Firmware
|
||||
### General
|
||||
* All serial links run at 19200 baud
|
||||
|
||||
### Bootloader
|
||||
* The bootloader is a standard Arduino bootloader with the following additions
|
||||
* Use ASCII command 'X' to enable loop-through mode. Everything received on UART RX will be forwarded to UART TX until the next reset.
|
||||
* Use ASCII command 'Z' to immediately launch into the user firmware
|
||||
* Use the following avrdude command to program: `avrdude -p m8 -P /dev/ttyUSBx -c arduino -b 19200 -U flash:w:$(TARGET).hex`
|
@ -7,7 +7,6 @@
|
||||
/* */
|
||||
/* Hacked by DojoCorp - ZGZ - MMX - IVR */
|
||||
/* Hacked by David A. Mellis */
|
||||
/* Hacked by Markus Koch */
|
||||
/* */
|
||||
/* This program is free software; you can redistribute it */
|
||||
/* and/or modify it under the terms of the GNU General */
|
||||
@ -39,7 +38,19 @@
|
||||
#include <avr/interrupt.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
//#define F_CPU 16000000
|
||||
|
||||
/* We, Malmoitians, like slow interaction
|
||||
* therefore the slow baud rate ;-)
|
||||
*/
|
||||
//#define BAUD_RATE 9600
|
||||
|
||||
/* 6.000.000 is more or less 8 seconds at the
|
||||
* speed configured here
|
||||
*/
|
||||
//#define MAX_TIME_COUNT 6000000
|
||||
#define MAX_TIME_COUNT (F_CPU>>1)
|
||||
///#define MAX_TIME_COUNT_MORATORY 1600000
|
||||
|
||||
/* SW_MAJOR and MINOR needs to be updated from time to time to avoid warning message from AVR Studio */
|
||||
#define HW_VER 0x02
|
||||
@ -69,6 +80,12 @@
|
||||
#define eeprom_rw(addr) eeprom_read_word ((uint16_t *)(addr))
|
||||
#define eeprom_wb(addr, val) eeprom_write_byte ((uint8_t *)(addr), (uint8_t)(val))
|
||||
|
||||
/* Onboard LED is connected to pin PB5 */
|
||||
#define LED_DDR DDRB
|
||||
#define LED_PORT PORTB
|
||||
#define LED_PIN PINB
|
||||
#define LED PINB5
|
||||
|
||||
|
||||
#define SIG1 0x1E // Yep, Atmel is the only manufacturer of AVR micros. Single source :(
|
||||
#define SIG2 0x93
|
||||
@ -113,19 +130,18 @@ int main(void)
|
||||
uint8_t ch,ch2;
|
||||
uint16_t w;
|
||||
|
||||
/* Disable interrupts */
|
||||
cli();
|
||||
|
||||
/* Pre-init I/O */
|
||||
DDRB = 0;
|
||||
DDRC = 0;
|
||||
DDRD = 0;
|
||||
PORTB = 0;
|
||||
PORTC = 0;
|
||||
PORTD = 0;
|
||||
//cbi(BL_DDR,BL);
|
||||
//sbi(BL_PORT,BL);
|
||||
|
||||
asm volatile("nop\n\t");
|
||||
|
||||
/* check if flash is programmed already, if not start bootloader anyway */
|
||||
//if(pgm_read_byte_near(0x0000) != 0xFF) {
|
||||
|
||||
/* check if bootloader pin is set low */
|
||||
//if(bit_is_set(BL_PIN,BL)) app_start();
|
||||
//}
|
||||
|
||||
/* initialize UART(s) depending on CPU defined */
|
||||
/* m8 */
|
||||
UBRRH = (((F_CPU/BAUD_RATE)/16)-1)>>8; // set baud rate
|
||||
@ -133,10 +149,42 @@ int main(void)
|
||||
UCSRB = (1<<RXEN)|(1<<TXEN); // enable Rx & Tx
|
||||
UCSRC = (1<<URSEL)|(1<<UCSZ1)|(1<<UCSZ0); // config USART; 8N1
|
||||
|
||||
//UBRRL = (uint8_t)(F_CPU/(BAUD_RATE*16L)-1);
|
||||
//UBRRH = (F_CPU/(BAUD_RATE*16L)-1) >> 8;
|
||||
//UCSRA = 0x00;
|
||||
//UCSRC = 0x86;
|
||||
//UCSRB = _BV(TXEN)|_BV(RXEN);
|
||||
|
||||
|
||||
/* this was giving uisp problems, so I removed it; without it, the boot
|
||||
works on with uisp and avrdude on the mac (at least). */
|
||||
//putch('\0');
|
||||
|
||||
//uint32_t l;
|
||||
//uint32_t time_count;
|
||||
//time_count=0;
|
||||
|
||||
/* set LED pin as output */
|
||||
sbi(LED_DDR,LED);
|
||||
for (i = 0; i < 16; i++) {
|
||||
outb(LED_PORT, inb(LED_PORT) ^ _BV(LED));
|
||||
_delay_loop_2(0);
|
||||
}
|
||||
|
||||
//for (l=0; l<40000000; l++)
|
||||
//outb(LED_PORT, inb(LED_PORT) ^= _BV(LED));
|
||||
|
||||
/* flash onboard LED three times to signal entering of bootloader */
|
||||
//for(i=0; i<3; ++i) {
|
||||
//for(l=0; l<40000000; ++l);
|
||||
//sbi(LED_PORT,LED);
|
||||
//for(l=0; l<40000000; ++l);
|
||||
//cbi(LED_PORT,LED);
|
||||
//}
|
||||
|
||||
/* see comment at previous call to putch() */
|
||||
//putch('\0'); // this line is needed for the synchronization of the programmer
|
||||
|
||||
/* forever */
|
||||
for (;;) {
|
||||
//if((inb(UCSRA) & _BV(RXC))){
|
||||
@ -213,20 +261,6 @@ int main(void)
|
||||
// and give the programmer 1 sec to react
|
||||
}
|
||||
|
||||
/* Loop UART until reset */
|
||||
else if (ch == 'X') {
|
||||
while (1) {
|
||||
if (UCSRA & (1 << RXC)) {
|
||||
UDR = UDR;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Start user code NOW */
|
||||
else if (ch == 'Z') {
|
||||
app_start();
|
||||
}
|
||||
|
||||
/* Erase device, don't care as we will erase one page at a time anyway. */
|
||||
else if(ch=='R') {
|
||||
nothing_response();
|
||||
@ -263,6 +297,11 @@ int main(void)
|
||||
address.word++;
|
||||
}
|
||||
} else { //Write to FLASH one page at a time
|
||||
//if (address.byte[1]>127) address_high = 0x01; //Only possible with m128, m256 will need 3rd address byte. FIXME
|
||||
//else address_high = 0x00;
|
||||
|
||||
//address.word = address.word << 1; //address * 2 -> byte location
|
||||
//if ((length.byte[0] & 0x01)) length.word++; //Even up an odd number of bytes
|
||||
cli(); //Disable interrupts, just to be sure
|
||||
while(bit_is_set(EECR,EEWE)); //Wait for previous EEPROM writes to complete
|
||||
asm volatile(
|
||||
@ -282,12 +321,20 @@ int main(void)
|
||||
"cpi r17,0x00 \n\t" //If page_word_count=0 then erase page
|
||||
"brne no_page_erase \n\t"
|
||||
"rcall wait_spm \n\t"
|
||||
|
||||
// "wait_spm1: \n\t"
|
||||
// "lds r16,%0 \n\t" //Wait for previous spm to complete
|
||||
// "andi r16,1 \n\t"
|
||||
// "cpi r16,1 \n\t"
|
||||
// "breq wait_spm1 \n\t"
|
||||
"ldi r16,0x03 \n\t" //Erase page pointed to by Z
|
||||
"sts %0,r16 \n\t"
|
||||
"spm \n\t"
|
||||
"rcall wait_spm \n\t"
|
||||
|
||||
// "wait_spm2: \n\t"
|
||||
// "lds r16,%0 \n\t" //Wait for previous spm to complete
|
||||
// "andi r16,1 \n\t"
|
||||
// "cpi r16,1 \n\t"
|
||||
// "breq wait_spm2 \n\t"
|
||||
"ldi r16,0x11 \n\t" //Re-enable RWW section
|
||||
"sts %0,r16 \n\t"
|
||||
"spm \n\t"
|
||||
@ -296,7 +343,11 @@ int main(void)
|
||||
"ld r1,Y+ \n\t"
|
||||
|
||||
"rcall wait_spm \n\t"
|
||||
|
||||
// "wait_spm3: \n\t"
|
||||
// "lds r16,%0 \n\t" //Wait for previous spm to complete
|
||||
// "andi r16,1 \n\t"
|
||||
// "cpi r16,1 \n\t"
|
||||
// "breq wait_spm3 \n\t"
|
||||
"ldi r16,0x01 \n\t" //Load r0,r1 into FLASH page buffer
|
||||
"sts %0,r16 \n\t"
|
||||
"spm \n\t"
|
||||
@ -307,12 +358,20 @@ int main(void)
|
||||
"write_page: \n\t"
|
||||
"clr r17 \n\t" //New page, write current one first
|
||||
"rcall wait_spm \n\t"
|
||||
|
||||
// "wait_spm4: \n\t"
|
||||
// "lds r16,%0 \n\t" //Wait for previous spm to complete
|
||||
// "andi r16,1 \n\t"
|
||||
// "cpi r16,1 \n\t"
|
||||
// "breq wait_spm4 \n\t"
|
||||
"ldi r16,0x05 \n\t" //Write page pointed to by Z
|
||||
"sts %0,r16 \n\t"
|
||||
"spm \n\t"
|
||||
"rcall wait_spm \n\t"
|
||||
|
||||
// "wait_spm5: \n\t"
|
||||
// "lds r16,%0 \n\t" //Wait for previous spm to complete
|
||||
// "andi r16,1 \n\t"
|
||||
// "cpi r16,1 \n\t"
|
||||
// "breq wait_spm5 \n\t"
|
||||
"ldi r16,0x11 \n\t" //Re-enable RWW section
|
||||
"sts %0,r16 \n\t"
|
||||
"spm \n\t"
|
||||
@ -385,6 +444,12 @@ int main(void)
|
||||
else if(ch=='v') {
|
||||
byte_response(0x00);
|
||||
}
|
||||
// } else {
|
||||
// time_count++;
|
||||
// if (time_count>=MAX_TIME_COUNT) {
|
||||
// app_start();
|
||||
// }
|
||||
// }
|
||||
} /* end of forever loop */
|
||||
}
|
||||
|
||||
@ -412,6 +477,9 @@ void getNch(uint8_t count)
|
||||
{
|
||||
uint8_t i;
|
||||
for(i=0;i<count;i++) {
|
||||
/* m8 */
|
||||
//while(!(inb(UCSRA) & _BV(RXC)));
|
||||
//inb(UDR);
|
||||
getch(); // need to handle time out
|
||||
}
|
||||
}
|
||||
@ -432,3 +500,8 @@ void nothing_response(void)
|
||||
putch(0x10);
|
||||
}
|
||||
}
|
||||
|
||||
/* end of file ATmegaBOOT.c */
|
||||
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
|
||||
#define DELAY_ROW_SWITCH() _delay_ms(1) //_delay_us(1)
|
||||
|
||||
#define BAUDRATE 19200
|
||||
#define BAUDRATE 9600
|
||||
|
||||
/* Keycode from include/linux/input.h */
|
||||
#define KEY_RESERVED 0
|
||||
|
@ -4,7 +4,7 @@
|
||||
#include <stdio.h>
|
||||
#include <avr/pgmspace.h>
|
||||
|
||||
#define BAUDRATE 19200
|
||||
#define BAUDRATE 9600
|
||||
|
||||
inline void spi_process_data();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user