1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-02-18 08:54:15 +01:00

Fix bug in flash driver where it could assert CS line after failing to claim

the bus.  Also added a "claimed" flag to the device structure.
This commit is contained in:
James Cotton 2012-01-21 09:57:12 -06:00
parent 5dbbfec8a9
commit f6db859e4f

View File

@ -61,6 +61,7 @@ enum pios_w25x_dev_magic {
struct w25x_flash_dev { struct w25x_flash_dev {
uint32_t spi_id; uint32_t spi_id;
uint32_t slave_num; uint32_t slave_num;
bool claimed;
enum pios_w25x_dev_magic magic; enum pios_w25x_dev_magic magic;
}; };
@ -86,6 +87,7 @@ static struct w25x_flash_dev * PIOS_Flash_W25X_alloc(void)
w25x_dev = (struct w25x_flash_dev *)pvPortMalloc(sizeof(*w25x_dev)); w25x_dev = (struct w25x_flash_dev *)pvPortMalloc(sizeof(*w25x_dev));
if (!w25x_dev) return (NULL); if (!w25x_dev) return (NULL);
w25x_dev->claimed = false;
w25x_dev->magic = PIOS_W25X_DEV_MAGIC; w25x_dev->magic = PIOS_W25X_DEV_MAGIC;
return(w25x_dev); return(w25x_dev);
} }
@ -112,9 +114,13 @@ static int32_t PIOS_Flash_W25X_ClaimBus()
if(PIOS_Flash_W25X_Validate(flash_dev) != 0) if(PIOS_Flash_W25X_Validate(flash_dev) != 0)
return -1; return -1;
int8_t ret = PIOS_SPI_ClaimBus(flash_dev->spi_id); if(PIOS_SPI_ClaimBus(flash_dev->spi_id) < 0)
return -1;
PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 0); PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 0);
return (ret == 0) ? 0 : -1; flash_dev->claimed = true;
return 0;
} }
/** /**
@ -126,6 +132,8 @@ static int32_t PIOS_Flash_W25X_ReleaseBus()
return -1; return -1;
PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 1); PIOS_SPI_RC_PinSet(flash_dev->spi_id, flash_dev->slave_num, 1);
PIOS_SPI_ReleaseBus(flash_dev->spi_id); PIOS_SPI_ReleaseBus(flash_dev->spi_id);
flash_dev->claimed = false;
return 0;
} }
/** /**