Skip to content

Commit

Permalink
[peripherals] ms5611: read prom while not yet initialized
Browse files Browse the repository at this point in the history
  • Loading branch information
flixr committed Aug 23, 2013
1 parent 4a20e7f commit 112638e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
46 changes: 23 additions & 23 deletions sw/airborne/peripherals/ms5611_i2c.c
Expand Up @@ -115,35 +115,13 @@ void ms5611_i2c_periodic_check(struct Ms5611_I2c *ms)
void ms5611_i2c_event(struct Ms5611_I2c *ms) {
if (ms->initialized) {
if (ms->i2c_trans.status == I2CTransFailed) {
ms->status = MS5611_STATUS_IDLE;
ms->i2c_trans.status = I2CTransDone;
}
else if (ms->i2c_trans.status == I2CTransSuccess) {
// Successfull reading
switch (ms->status) {

case MS5611_STATUS_PROM:
/* read prom data */
ms->data.c[ms->prom_cnt++] = (ms->i2c_trans.buf[0] << 8) |
ms->i2c_trans.buf[1];
if (ms->prom_cnt < PROM_NB) {
/* get next prom data */
ms->i2c_trans.buf[0] = MS5611_PROM_READ | (ms->prom_cnt << 1);
i2c_transceive(ms->i2c_p, &(ms->i2c_trans), ms->i2c_trans.slave_addr, 1, 2);
}
else {
/* done reading prom, check prom crc */
if (ms5611_prom_crc_ok(ms->data.c)) {
ms->initialized = TRUE;
ms->status = MS5611_STATUS_IDLE;
}
else {
/* checksum error, try again */
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
}
}
break;

case MS5611_STATUS_ADC_D1:
/* read D1 (pressure) */
ms->data.d1 = (ms->i2c_trans.buf[0] << 16) |
Expand Down Expand Up @@ -179,6 +157,28 @@ void ms5611_i2c_event(struct Ms5611_I2c *ms) {
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
case I2CTransSuccess:
if (ms->status == MS5611_STATUS_PROM) {
/* read prom data */
ms->data.c[ms->prom_cnt++] = (ms->i2c_trans.buf[0] << 8) |
ms->i2c_trans.buf[1];
if (ms->prom_cnt < PROM_NB) {
/* get next prom data */
ms->i2c_trans.buf[0] = MS5611_PROM_READ | (ms->prom_cnt << 1);
i2c_transceive(ms->i2c_p, &(ms->i2c_trans), ms->i2c_trans.slave_addr, 1, 2);
}
else {
/* done reading prom, check prom crc */
if (ms5611_prom_crc_ok(ms->data.c)) {
ms->initialized = TRUE;
ms->status = MS5611_STATUS_IDLE;
}
else {
/* checksum error, try again */
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
}
}
}
case I2CTransDone:
ms->i2c_trans.status = I2CTransDone;
break;
Expand Down
46 changes: 23 additions & 23 deletions sw/airborne/peripherals/ms5611_spi.c
Expand Up @@ -129,35 +129,13 @@ void ms5611_spi_periodic_check(struct Ms5611_Spi *ms)
void ms5611_spi_event(struct Ms5611_Spi *ms) {
if (ms->initialized) {
if (ms->spi_trans.status == SPITransFailed) {
ms->status = MS5611_STATUS_IDLE;
ms->spi_trans.status = SPITransDone;
}
else if (ms->spi_trans.status == SPITransSuccess) {
// Successfull reading
switch (ms->status) {

case MS5611_STATUS_PROM:
/* read prom data */
ms->data.c[ms->prom_cnt++] = (ms->rx_buf[1] << 8) |
ms->rx_buf[2];
if (ms->prom_cnt < PROM_NB) {
/* get next prom data */
ms->tx_buf[0] = MS5611_PROM_READ | (ms->prom_cnt << 1);
spi_submit(ms->spi_p, &(ms->spi_trans));
}
else {
/* done reading prom, check prom crc */
if (ms5611_prom_crc_ok(ms->data.c)) {
ms->initialized = TRUE;
ms->status = MS5611_STATUS_IDLE;
}
else {
/* checksum error, try again */
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
}
}
break;

case MS5611_STATUS_ADC_D1:
/* read D1 (pressure) */
ms->data.d1 = (ms->rx_buf[1] << 16) |
Expand Down Expand Up @@ -193,6 +171,28 @@ void ms5611_spi_event(struct Ms5611_Spi *ms) {
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
case SPITransSuccess:
if (ms->status == MS5611_STATUS_PROM) {
/* read prom data */
ms->data.c[ms->prom_cnt++] = (ms->rx_buf[1] << 8) |
ms->rx_buf[2];
if (ms->prom_cnt < PROM_NB) {
/* get next prom data */
ms->tx_buf[0] = MS5611_PROM_READ | (ms->prom_cnt << 1);
spi_submit(ms->spi_p, &(ms->spi_trans));
}
else {
/* done reading prom, check prom crc */
if (ms5611_prom_crc_ok(ms->data.c)) {
ms->initialized = TRUE;
ms->status = MS5611_STATUS_IDLE;
}
else {
/* checksum error, try again */
ms->prom_cnt = 0;
ms->status = MS5611_STATUS_UNINIT;
}
}
}
case SPITransDone:
ms->spi_trans.status = SPITransDone;
break;
Expand Down

0 comments on commit 112638e

Please sign in to comment.