From: Nathael Pajani Date: Thu, 23 Jan 2014 10:22:27 +0000 (+0100) Subject: SPI and eeprom chip select fixes. X-Git-Url: http://git.techno-innov.fr/?a=commitdiff_plain;h=d740063e9a2fda528f84f3ea7f15d8246a30abad;p=soft%2Flpc122x%2Fcore SPI and eeprom chip select fixes. --- diff --git a/drivers/eeprom.c b/drivers/eeprom.c index 6aa161f..a46b2e8 100644 --- a/drivers/eeprom.c +++ b/drivers/eeprom.c @@ -44,7 +44,7 @@ int I2C_CS_Default_Set(void) /* Configure SPI_CS as output and set it low. */ gpio0->data_dir |= (1 << I2C_CS_PIN); gpio0->clear = (1 << I2C_CS_PIN); - return 1; + return 0; } void I2C_CS_Default_Release(void) { @@ -138,7 +138,7 @@ int eeprom_read(uint32_t offset, void *buf, size_t count) char ctrl_buf[CMD_BUF_SIZE] = { I2C_CONT, I2C_CONT, I2C_DO_REPEATED_START, I2C_CONT, }; int eeprom_type = 0; - if (spi_device_cs_pull_low() == 0) { + if (spi_device_cs_pull_low() != 0) { return -EBUSY; } eeprom_type = get_eeprom_type(); @@ -193,7 +193,7 @@ int eeprom_write(uint32_t offset, const void *buf, size_t count) char full_buff[(EEPROM_ID_MAX_PAGE_SIZE + MAX_CMD_SIZE)]; int eeprom_type = 0; - if (spi_device_cs_pull_low() == 0) { + if (spi_device_cs_pull_low() != 0) { return -EBUSY; } eeprom_type = get_eeprom_type(); diff --git a/drivers/ssp.c b/drivers/ssp.c index 43331bc..fdf15fa 100644 --- a/drivers/ssp.c +++ b/drivers/ssp.c @@ -111,6 +111,10 @@ int spi_device_cs_pull_low(void) void spi_device_cs_release(void) { struct lpc_gpio* gpio0 = LPC_GPIO_0; + + /* Release mutex */ + sync_lock_release(&spi_cs_mutex); + /* Set pin high */ gpio0->set = (1 << SPI_CS_PIN); /* Configure pin as SPI again */