summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/isp/isp.h
blob: dc3a9f54cb9bd02dc9c17ad6242e451bb9c82991 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#ifndef isp_h
#define isp_h
/* isp.h - ISP AVR programming. */
/* avr.isp - Serial programming AVR module. {{{
 *
 * Copyright (C) 2009 Nicolas Schodet
 *
 * APBTeam:
 *        Web: http://apbteam.org/
 *      Email: team AT apbteam DOT org
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * }}} */

/** Results returned by ISP functions. */
enum isp_result_t
{
    /** Operation success. */
    ISP_OK,
    /** Operation failed. */
    ISP_FAILED,
    /** Operation failed on a timeout. */
    ISP_TIMEOUT,
};

/** ISP Programming mode. */
enum isp_mode_t
{
    /** Use page programming. */
    ISP_MODE_PAGE = 1,
    /** Use simple delay for word programming. */
    ISP_MODE_WORD_DELAY = 2,
    /** Use value polling if possible for word programming, fall back to delay
     * if not possible. */
    ISP_MODE_WORD_VALUE = 4,
    /** Use RDY/BSY polling for word programming. */
    ISP_MODE_WORD_RDY_BSY = 8,
    /** Use simple delay for page programming. */
    ISP_MODE_PAGE_DELAY = 16,
    /** Use value polling if possible for page programming, fall back to delay
     * if not possible. */
    ISP_MODE_PAGE_VALUE = 32,
    /** Use RDY/BSY polling for page programming. */
    ISP_MODE_PAGE_RDY_BSY = 64,
    /** Write page at end of transfer.  Used for big pages which must be
     * transfered in several packets. */
    ISP_MODE_PAGE_WRITE = 128,
};

uint8_t
isp_enter_progmode (uint8_t timeout_ms, uint8_t stab_delay_ms,
		    uint8_t cmd_exe_delay_ms, uint8_t synch_loops,
		    uint8_t byte_delay_ms, uint8_t poll_value,
		    uint8_t poll_index, uint8_t cmd[4]);

void
isp_leave_progmode (uint8_t pre_delay_ms, uint8_t post_delay_ms);

void
isp_load_address (uint32_t addr);

uint8_t
isp_chip_erase (uint8_t erase_delay_ms, uint8_t poll_method, uint8_t cmd[4]);

uint8_t
isp_program_flash_begin (uint16_t num_bytes, uint8_t mode, uint8_t delay_ms,
			 uint8_t cmd_write_mem, uint8_t cmd_write_page,
			 uint8_t cmd_read_mem, uint8_t poll[2]);

uint8_t
isp_program_eeprom_begin (uint16_t num_bytes, uint8_t mode, uint8_t delay_ms,
			  uint8_t cmd_write_mem, uint8_t cmd_write_page,
			  uint8_t cmd_read_mem, uint8_t poll[2]);

uint8_t
isp_program_continue (uint8_t *data, uint16_t size);

uint8_t
isp_program_end (void);

uint8_t
isp_read_flash_begin (uint16_t num_bytes, uint8_t cmd_read_mem);

uint8_t
isp_read_eeprom_begin (uint16_t num_bytes, uint8_t cmd_read_mem);

uint8_t
isp_read_continue (uint8_t *data, uint16_t size);

uint8_t
isp_read_end (void);

void
isp_program_misc (uint8_t cmd[4]);

uint8_t
isp_read_misc (uint8_t ret_addr, uint8_t cmd[4]);

void
isp_multi (uint8_t num_tx, uint8_t num_rx, uint8_t rx_start, uint8_t *data);

#endif /* isp_h */