*
* 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
*
* 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
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
-static uint8_t ao_m25_size[M25_MAX_CHIPS]; /* number of sectors in each chip */
-static uint8_t ao_m25_pin[M25_MAX_CHIPS]; /* chip select pin for each chip */
+static uint32_t ao_m25_size[M25_MAX_CHIPS]; /* number of sectors in each chip */
+static ao_port_t ao_m25_pin[M25_MAX_CHIPS]; /* chip select pin for each chip */
-static uint8_t ao_m25_total; /* total sectors available */
-static uint8_t ao_m25_wip; /* write in progress */
+static uint32_t ao_m25_total; /* total sectors available */
+static ao_port_t ao_m25_wip; /* write in progress */
-#define M25_SELECT(cs) ao_spi_get_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS, AO_SPI_SPEED_FAST)
+#define AO_M25_SPI_SPEED ao_spi_speed(10000000) /* this seems like a reasonable minimum speed to require */
+
+#define M25_SELECT(cs) ao_spi_get_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS,AO_M25_SPI_SPEED)
#define M25_DESELECT(cs) ao_spi_put_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS)
#define M25_BLOCK_SHIFT 16
#define M25_BLOCK 65536L
#define M25_DESELECT(cs) ao_spi_put_mask(AO_M25_SPI_CS_PORT,cs,AO_M25_SPI_BUS)
#define M25_BLOCK_SHIFT 16
#define M25_BLOCK 65536L
#define M25_SECTOR_TO_POS(sector) (((uint32_t) (sector)) << M25_BLOCK_SHIFT)
/*
* Block until the specified chip is done writing
*/
static void
#define M25_SECTOR_TO_POS(sector) (((uint32_t) (sector)) << M25_BLOCK_SHIFT)
/*
* Block until the specified chip is done writing
*/
static void
ao_spi_recv(ao_m25_instruction, 1, AO_M25_SPI_BUS);
} while (ao_m25_instruction[0] & M25_STATUS_WIP);
M25_DESELECT(cs);
ao_spi_recv(ao_m25_instruction, 1, AO_M25_SPI_BUS);
} while (ao_m25_instruction[0] & M25_STATUS_WIP);
M25_DESELECT(cs);
- ao_m25_instruction[1] = pos >> 16;
- ao_m25_instruction[2] = pos >> 8;
- ao_m25_instruction[3] = pos;
- return chip;
+ ao_m25_instruction[1] = (uint8_t) (pos >> 16);
+ ao_m25_instruction[2] = (uint8_t) (pos >> 8);
+ ao_m25_instruction[3] = (uint8_t) (pos);
+ return mask;
for (chip = 0; chip < ao_m25_numchips; chip++)
printf ("Flash chip %d select %02x size %d\n",
chip, ao_m25_pin[chip], ao_m25_size[chip]);
#else
for (chip = 0; chip < ao_m25_numchips; chip++)
printf ("Flash chip %d select %02x size %d\n",
chip, ao_m25_pin[chip], ao_m25_size[chip]);
#else
printf ("Available chips:\n");
for (cs = 1; cs != 0; cs <<= 1) {
if ((AO_M25_SPI_CS_MASK & cs) == 0)
printf ("Available chips:\n");
for (cs = 1; cs != 0; cs <<= 1) {
if ((AO_M25_SPI_CS_MASK & cs) == 0)