2 * Copyright © 2008 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
59 #define nop() _asm nop _endasm;
62 delay (unsigned char n)
91 out_byte(uint8_t byte)
95 for (s = 0; s < 8; s++) {
96 uint8_t b = (byte & 0x80) ? 1 : 0;
121 for (s = 0; s < 8; s++) {
158 write(uint32_t addr, uint8_t *bytes, uint16_t len)
163 out_byte(addr >> 16);
170 uint8_t status = rdsr();
171 if ((status & (1 << 0)) == 0)
177 read(uint32_t addr, uint8_t *bytes, uint16_t len)
181 out_byte(addr >> 16);
185 *bytes++ = in_byte();
190 debug_byte(uint8_t byte)
194 for (s = 0; s < 8; s++) {
221 * Turn off both block-protect bits
223 status &= ~((1 << 3) | (1 << 2));
225 * Turn off write protect enable
229 write(0x0, STRING, LENGTH);
231 read(0x0, buf, LENGTH);
232 for (i = 0; i < LENGTH; i++)