1 #ifndef _TERMIOS_H_ 2 #include <termios.h> 3 #endif 4 5 #define PIC_CMD_MAX 255 6 #define PIC_RESPONSE_MAX 255 7 #define PIC_HEX_LINE_MAX 1024 8 9 #define PIC_WRITE_BLOCK_SIZE 8 10 #define PIC_ERASE_BLOCK_SIZE 64 11 /* 12 * The protocol supports 16-bit block counts according to shtylman.com, but if 13 * the len_low byte is 0 (e.g. 256 erase-blocks), the controller just goes to 14 * the IFI> prompt when you send the erase command packet. Curiously, it seems 15 * to work fine for erase_blocks > 256. The problem only occurs when erase_blocks 16 * is exactly 256. 17 * Hence, we erase flash in chunks of 128 or smaller, so that len_low is always 18 * > 0 and len_high is always 0. 19 */ 20 #define PIC_MAX_ERASE_BLOCKS 128 21 22 /* PIC special characters */ 23 #define CHAR_SI 0x0F /* Start transmission */ 24 #define CHAR_EOT 0x04 /* End transmission */ 25 #define CHAR_ESC 0x05 /* Escape next character (must precede CHAR_SI, 26 CHAR_EOT and CHAR_ESC in payload */ 27 28 #define PIC_BAUD_RATE B115200 29 30 #ifndef MIN 31 #define MIN(x,y) ((x) < (y) ? (x) : (y)) 32 #endif 33 34 #ifndef MAX 35 #define MAX(x,y) ((x) > (y) ? (x) : (y)) 36 #endif 37 38 typedef enum 39 { 40 PIC_GET_BOOTLOADER_VERSION= 0x00, 41 PIC_READ_PROGRAM_MEM= 0x01, 42 PIC_WRITE_PROGRAM_MEM= 0x02, 43 PIC_RETURN_TO_USER_CODE= 0x08, 44 PIC_ERASE_PROGRAM_MEM= 0x09 45 } pic_cmd_t; 46 47 typedef struct 48 { 49 unsigned long address; 50 int len; 51 char code[PIC_HEX_LINE_MAX+1]; 52 } pic_line_t; 53 54 typedef struct 55 { 56 int fd; 57 int bootloader_major; 58 int bootloader_minor; 59 char *device; 60 char response[PIC_RESPONSE_MAX+1]; 61 struct termios current_port_settings; 62 struct termios original_port_settings; 63 } rct_pic_t; 64 65 #define PIC_IS_OPEN(p) ((p)->fd != -1) 66 67