1
0
mirror of git://projects.qi-hardware.com/antorcha.git synced 2024-11-01 11:28:26 +02:00
antorcha/fw/boot.c
Werner Almesberger 56476539cf fw/: addition of boot loader (WIP) and assorted cleanup and improvements
The boot loader currently uses the protocol switch intended for the
application. This makes it too big to fit in the very limiting
constraints the ATmega168 poses - and there's not even cryptographic
authentication yet. We'll have to dumb it down quite a bit.
2012-06-18 10:56:43 -03:00

82 lines
1.4 KiB
C

/*
* fw/boot.c - Antorcha boot loader
*
* Written 2012 by Werner Almesberger
* Copyright 2012 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <avr/io.h>
#include <avr/pgmspace.h>
#include "io.h"
#include "rf.h"
#include "proto.h"
#include "dispatch.h"
#include "fw.h"
#define MS_TO_LOOP(ms) ((uint32_t) (ms)*335)
static void wait_upload(void)
{
uint8_t buf[PAYLOAD+5];
uint32_t i;
uint8_t got;
restart:
for (i = 0; i != MS_TO_LOOP(2000); i++) {
got = rf_recv(buf, sizeof(buf));
if (got && dispatch(buf, got, fw_protos))
goto restart;
}
}
int main(void)
{
volatile int zero = 0;
/* Port B has two LEDs and the rest is SPI */
PORTB = MASK(B, RF_nSS) | MASK(B, RF_nRST);
DDRB = MASK(B, RF_SCLK) | MASK(B, RF_MOSI) | MASK(B, RF_nSS) |
MASK(B, RF_nRST) | 0xc0;
/* All port C pins drive LEDs */
PORTC = 0;
DDRC = 0x3f;
/* All port D pins drive LEDs */
PORTD = 0;
DDRD = 0xff;
/* disable pull-ups */
MCUCR |= 1 << PUD;
rf_init();
/*
* Switch the LED inside the loop so that we get a short pulse one can
* observe on a scope.
*/
do {
SET(LED_B8);
wait_upload();
CLR(LED_B8);
while (1);
} while (pgm_read_byte(zero) != 0xff);
((void (*)(void)) 0)();
/* not reached */
return 0;
}