git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9447 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
e8776f2fc5
commit
77ea39c0df
|
@ -62,15 +62,63 @@ static const struct N25Q128DriverVMT n25q128_vmt = {
|
||||||
/* Driver local variables and types. */
|
/* Driver local variables and types. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
static flash_descriptor_t descriptor = {
|
||||||
|
.attributes = FLASH_ATTR_ERASED_IS_ONE | FLASH_ATTR_REWRITABLE,
|
||||||
|
.page_size = 256,
|
||||||
|
.sectors_count = 4096,
|
||||||
|
.sectors = NULL,
|
||||||
|
.sectors_size = 4096,
|
||||||
|
.address = 0
|
||||||
|
};
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
/* Driver local functions. */
|
/* Driver local functions. */
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
|
||||||
|
static void spi_send_cmd_read(N25Q128Driver *devp, uint8_t cmd,
|
||||||
|
uint8_t *rp, size_t n) {
|
||||||
|
|
||||||
|
#if N25Q128_SHARED_SPI == TRUE
|
||||||
|
spiStart(devp->config->spip, devp->config->spicfg);
|
||||||
|
spiAcquireBus(devp->config->spip);
|
||||||
|
#endif
|
||||||
|
spiSelect(devp->config->spip);
|
||||||
|
spiSend(devp->config->spip, 1, &cmd);
|
||||||
|
spiReceive(devp->config->spip, n, rp);
|
||||||
|
spiUnselect(devp->config->spip);
|
||||||
|
#if N25Q128_SHARED_SPI == TRUE
|
||||||
|
spiReleaseBus(devp->config->spip);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
static void spi_send_cmd_addr_read(N25Q128Driver *devp,
|
||||||
|
uint8_t cmd,
|
||||||
|
flash_address_t addr,
|
||||||
|
uint8_t *rp, size_t n) {
|
||||||
|
uint8_t buf[4];
|
||||||
|
|
||||||
|
#if N25Q128_SHARED_SPI == TRUE
|
||||||
|
spiStart(devp->config->spip, devp->config->spicfg);
|
||||||
|
spiAcquireBus(devp->config->spip);
|
||||||
|
#endif
|
||||||
|
buf[0] = cmd;
|
||||||
|
buf[1] = (uint8_t)(addr >> 16);
|
||||||
|
buf[2] = (uint8_t)(addr >> 8);
|
||||||
|
buf[3] = (uint8_t)(addr >> 0);
|
||||||
|
spiSelect(devp->config->spip);
|
||||||
|
spiSend(devp->config->spip, 4, buf);
|
||||||
|
spiReceive(devp->config->spip, n, rp);
|
||||||
|
spiUnselect(devp->config->spip);
|
||||||
|
#if N25Q128_SHARED_SPI == TRUE
|
||||||
|
spiReleaseBus(devp->config->spip);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
static const flash_descriptor_t *get_attributes(void *instance) {
|
static const flash_descriptor_t *get_attributes(void *instance) {
|
||||||
|
|
||||||
(void)instance;
|
(void)instance;
|
||||||
|
|
||||||
return FLASH_NO_ERROR;
|
return &descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static flash_error_t erase_all(void *instance) {
|
static flash_error_t erase_all(void *instance) {
|
||||||
|
@ -116,10 +164,8 @@ static flash_error_t program(void *instance, flash_address_t addr,
|
||||||
static flash_error_t read(void *instance, flash_address_t addr,
|
static flash_error_t read(void *instance, flash_address_t addr,
|
||||||
uint8_t *rp, size_t n) {
|
uint8_t *rp, size_t n) {
|
||||||
|
|
||||||
(void)instance;
|
spi_send_cmd_addr_read((N25Q128Driver *)instance, N25Q128_CMD_READ,
|
||||||
(void)addr;
|
addr, rp, n);
|
||||||
(void)rp;
|
|
||||||
(void)n;
|
|
||||||
|
|
||||||
return FLASH_NO_ERROR;
|
return FLASH_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
* @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION
|
* @note The default is @p FALSE. Requires SPI_USE_MUTUAL_EXCLUSION
|
||||||
*/
|
*/
|
||||||
#if !defined(N25Q128_SHARED_SPI) || defined(__DOXYGEN__)
|
#if !defined(N25Q128_SHARED_SPI) || defined(__DOXYGEN__)
|
||||||
#define N25Q128_SHARED_SPI FALSE
|
#define N25Q128_SHARED_SPI TRUE
|
||||||
#endif
|
#endif
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#define FLASH_ATTR_ERASED_IS_ONE 0x00000001
|
#define FLASH_ATTR_ERASED_IS_ONE 0x00000001
|
||||||
#define FLASH_ATTR_MEMORY_MAPPED 0x00000002
|
#define FLASH_ATTR_MEMORY_MAPPED 0x00000002
|
||||||
#define FLASH_ATTR_REWRITABLE 0x00000004
|
#define FLASH_ATTR_REWRITABLE 0x00000004
|
||||||
|
#define FLASH_ATTR_READ_ECC_CAPABLE 0x00000008
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
/*===========================================================================*/
|
/*===========================================================================*/
|
||||||
|
@ -57,8 +58,9 @@ typedef enum {
|
||||||
FLASH_NO_ERROR = 0, /* No error. */
|
FLASH_NO_ERROR = 0, /* No error. */
|
||||||
FLASH_PARAMETER_ERROR = 1, /* Error in a function parameter. */
|
FLASH_PARAMETER_ERROR = 1, /* Error in a function parameter. */
|
||||||
FLASH_ADDRESS_ERROR = 2, /* Operation overlaps invalid addresses. */
|
FLASH_ADDRESS_ERROR = 2, /* Operation overlaps invalid addresses. */
|
||||||
FLASH_VERIFY_FAILURE = 3, /* Write or erase operation failed. */
|
FLASH_ECC_ERROR = 3, /* ECC error during read operation. */
|
||||||
FLASH_HW_FAILURE = 4 /* Controller or communication error. */
|
FLASH_VERIFY_FAILURE = 4, /* Write or erase operation failed. */
|
||||||
|
FLASH_HW_FAILURE = 5 /* Controller or communication error. */
|
||||||
} flash_error_t;
|
} flash_error_t;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue