Revision 183
Began moving parts of the code into the common directoty. Began setting up the jump table
trunk/common/tooltron.h | ||
---|---|---|
13 | 13 |
* You should have received a copy of the Lesser GNU General Public License |
14 | 14 |
* along with Tooltron. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 |
* |
16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com> |
|
16 |
* Copyright 2009 Kevin Woo <kwoo@2ndt.com>, Brad Neuman <bneuman@andrew.cmu.edu>
|
|
17 | 17 |
* |
18 | 18 |
********/ |
19 | 19 |
#ifndef _TOOLTRON_H_ |
20 | 20 |
#define _TOOLTRON_H_ |
21 | 21 |
|
22 |
#include <stdint.h> |
|
23 |
|
|
24 |
/****** Message Dictionary ******/ |
|
25 |
// Commonly used message bytes |
|
22 | 26 |
#define DELIM '^' |
23 | 27 |
#define SERVER 1 |
24 | 28 |
#define ACK_CRC ADDR ^ SERVER |
25 | 29 |
|
26 |
#define TT_GET_KEY 'k' |
|
27 |
#define TT_ACK 'a' |
|
28 |
#define TT_NACK 'n' |
|
29 |
#define TT_TO 'f' |
|
30 |
#define TT_TIMEOUT 't' |
|
31 |
#define TT_RESET 'r' |
|
32 |
#define TT_BOOT 'b' |
|
33 |
#define TT_PROGM 'p' |
|
34 |
#define TT_PROGD 'd' |
|
35 |
#define TT_BAD 0 |
|
30 |
// These are the bytes used in the messaage types |
|
31 |
#define TT_GET_KEY 'k' // Get a key from the keyboard |
|
32 |
#define TT_ACK 'a' // Ack |
|
33 |
#define TT_NACK 'n' // Nack |
|
34 |
#define TT_TO 'f' // State timeout |
|
35 |
#define TT_TIMEOUT 't' // Packet timeout |
|
36 |
#define TT_RESET 'r' // Tool reset request |
|
37 |
#define TT_BOOT 'b' // Tool boot message |
|
38 |
#define TT_PROGM 'p' // Program mode request |
|
39 |
#define TT_PROGD 'd' // Program data |
|
40 |
#define TT_BAD 0 // If there was a packet parsing error |
|
36 | 41 |
|
42 |
// Number of bytes that the PROGx packets have in the payload |
|
37 | 43 |
#define PROGM_PACKET_SIZE 2 |
38 | 44 |
#define PROGD_PACKET_SIZE 32 |
39 | 45 |
|
40 |
#define PAGE_SIZE 32 |
|
46 |
// Packet handler states |
|
47 |
typedef enum { |
|
48 |
sd, // Looking for start delimiter |
|
49 |
src, // Looking for source |
|
50 |
dest, // Looking for destination |
|
51 |
comd, // Looking for command |
|
52 |
read, // Reading payload |
|
53 |
cs // Calculate checksum |
|
54 |
} state_t; |
|
41 | 55 |
|
56 |
// Tool timeout? |
|
42 | 57 |
#define TIMEOUT_SECONDS 10 |
43 | 58 |
|
59 |
// Memory locations |
|
60 |
#define MAIN_ADDR 0x0 // User code starts here |
|
61 |
#define BOOT_START 0x400 // Bootloader code starts here |
|
62 |
|
|
63 |
/****** Utility Definitions ******/ |
|
64 |
#define TRUE 0 |
|
65 |
#define FALSE 1 |
|
66 |
|
|
67 |
/****** Jump Table ******/ |
|
68 |
// Jump table addresses |
|
69 |
// If the bootloader changes, you must change the jump table addresses! |
|
70 |
#define JT_INIT_UART 0x0 |
|
71 |
#define JT_UART_GET_BYTE 0x0 |
|
72 |
#define JT_UART_SEND_BYTE 0x0 |
|
73 |
#define JT_PARSE_PACKET 0x0 |
|
74 |
#define JT_SEND_PACKET 0x0 |
|
75 |
|
|
76 |
|
|
77 |
// Jump table functions for locations that are in the bootloader |
|
78 |
#ifdef TOOLBOX |
|
79 |
void (*init_uart)(uint16_t baud) = JT_INIT_UART; |
|
80 |
int8_t (*uart_get_byte)(uint8_t *output_byte) = JT_UART_GET_BYTE; |
|
81 |
void (*uart_send_byte)(uint8_t data) = JT_UART_SEND_BYTE; |
|
82 |
void (*uart_toggle_transmit)(uint8_t state) = JT_UART_TOGGLE_TRANSMIT; |
|
83 |
char (*parse_packet)(uint8_t *mbuf) = JT_PARSE_PACKET; |
|
84 |
void (*send_packet)(uint8_t cmd) = JT_SEND_PACKET; |
|
44 | 85 |
#endif |
86 |
|
|
87 |
|
|
88 |
#endif |
trunk/bootloader/bootloader.c | ||
---|---|---|
1 | 1 |
#include <avr/io.h> |
2 | 2 |
#include <avr/boot.h> |
3 |
#include <avr/pgmspace.h> |
|
4 | 3 |
#include <avr/wdt.h> |
5 |
|
|
6 | 4 |
#include <tooltron.h> |
7 | 5 |
#include "uart.h" |
8 | 6 |
|
9 |
#define TRUE 0 |
|
10 |
#define FALSE 1 |
|
11 |
|
|
12 | 7 |
#define ADDR 18 |
13 | 8 |
|
14 |
|
|
15 | 9 |
// Error thresholds |
16 | 10 |
#define MAX_TIMEOUT 60000 // Seconds to wait before exiting bootloader mode |
17 | 11 |
#define MAX_RETRIES 5 // Number of times to retry before giving up |
18 | 12 |
|
19 |
// Memory locations |
|
20 |
#define MAIN_ADDR 0x000 // Where the user code starts |
|
21 |
#define BOOT_START 0x400 // Where the bootloader starts |
|
22 |
|
|
23 | 13 |
//Status LED |
24 | 14 |
#define LED_DDR DDRB |
25 | 15 |
#define LED_PORT PORTB |
... | ... | |
28 | 18 |
//Function prototypes |
29 | 19 |
void (*main_start)(void) = BOOT_START/2 - 1; |
30 | 20 |
|
31 |
// Packet handler states |
|
32 |
typedef enum { |
|
33 |
sd, |
|
34 |
src, |
|
35 |
dest, |
|
36 |
comd, |
|
37 |
read, |
|
38 |
cs, |
|
39 |
ack |
|
40 |
} state_t; |
|
41 |
|
|
42 | 21 |
typedef union { |
43 | 22 |
uint8_t bytes[2]; |
44 | 23 |
int16_t sword; |
Also available in: Unified diff