summaryrefslogtreecommitdiff
path: root/CHANGELOG
blob: d526672ce2c5ef5c3975be46da86abfdecc43ffb (plain)
1
debian/changelog
href='#n159'>159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
/* flash.c */
/*  {{{
 *
 * Copyright (C) 2008 NĂ©lio Laranjeiro
 *
 * 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.
 *
 * }}} */
#include "flash.h"
#include "modules/proto/proto.h"
#include "modules/spi/spi.h"
#include "modules/utils/utils.h"

/** Flash access.
  * The flash contains an address of 21 bits in a range from 0x0-0x1fffff.
  * This function shall access the memory directly by the SPI.
  * \param  addr  the address to provide to the flash memory.
  */
void
flash_address (uint32_t addr)
{
    /* The address must be sent */
    spi_send ((addr >> 16) & 0x1f);
    spi_send (addr >> 8);
    spi_send (addr);
}

/** Erase the memory.
  * \param  erase_type  the erase type..
  * \param  start_addr  the start address.
  */
void
flash_erase (uint8_t cmd, uint32_t start_addr)
{
    flash_send_command (FLASH_WREN);

    AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS);
    /* send the command. */
    spi_send (cmd);

    /* verify if the cmd is the full erase. */
    if (cmd != FLASH_ERASE_FULL)
      {
	/* Send the start address */
	flash_address (start_addr);
      }
    AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS);

    while (flash_is_busy());
}

/* Send a flash command to the flash memory (only a command).
 * \param  cmd  the command to send.
 */
void
flash_send_command (uint8_t cmd)
{
    AC_FLASH_PORT &= ~_BV(AC_FLASH_BIT_SS);
    spi_send (cmd);
    AC_FLASH_PORT |= _BV(AC_FLASH_BIT_SS);
}


/** Poll the busy bit in the Software Status Register of the flash memory.
  * \return  the status register.
  */
uint8_t