summaryrefslogtreecommitdiffhomepage
path: root/digital/avr/modules/isp/isp.h
blob: 88b35c28d9aac9b7b8d387c83c8a60338d023108 (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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#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, const 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,
		const uint8_t cmd[4]);

uint8_t
isp_program_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, const uint8_t poll[2],
		   uint8_t flash);

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, const 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, const uint8_t poll[2]);

uint8_t
isp_program_continue (const uint8_t *data, uint16_t size);

uint8_t
isp_program_end (void);

uint8_t
isp_read_begin (uint16_t num_bytes, uint8_t cmd_read_mem, uint8_t flash);

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 (const uint8_t cmd[4]);

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

void
isp_multi (uint8_t num_tx, uint8_t num_rx, uint8_t rx_start,
	   const uint8_t *dout, uint8_t *din);

void
AC_ISP_SPI_ENABLE (void);

void
AC_ISP_SPI_DISABLE (void);

void
AC_ISP_SPI_SCK_PULSE (void);

uint8_t
AC_ISP_SPI_TX (uint8_t data);

#endif /* isp_h */