diff options
author | Rob Austein <sra@hactrn.net> | 2017-05-17 19:28:40 -0400 |
---|---|---|
committer | Rob Austein <sra@hactrn.net> | 2017-05-17 19:28:40 -0400 |
commit | b6017cf2295dfa16b2062794ac55e8553f64a1a6 (patch) | |
tree | 5e2b44fd03128d6779a1a2455baf7a21a7c6c5f2 | |
parent | 478b0c56bb2ea284eb502b03f1b0291bd966fd93 (diff) |
No, children, you can't || enum error codes. Again.
-rw-r--r-- | mkmif.c | 52 |
1 files changed, 28 insertions, 24 deletions
@@ -50,9 +50,11 @@ hal_error_t hal_mkmif_init(hal_core_t *core) cmd.word = htonl(MKMIF_CTRL_CMD_INIT); - err = hal_core_alloc(MKMIF_NAME, &core) || - hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4) || - hal_io_wait_ready(core); + if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK) + return err; + + if ((err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) == HAL_OK) + err = hal_io_wait_ready(core); hal_core_free(core); return err; @@ -65,8 +67,10 @@ hal_error_t hal_mkmif_set_clockspeed(hal_core_t *core, const uint32_t divisor) data.word = htonl(divisor); - err = hal_core_alloc(MKMIF_NAME, &core) || - hal_io_write(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4); + if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK) + return err; + + err = hal_io_write(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4); hal_core_free(core); return err; @@ -77,10 +81,10 @@ hal_error_t hal_mkmif_get_clockspeed(hal_core_t *core, uint32_t *divisor) byteword_t data; hal_error_t err; - err = hal_core_alloc(MKMIF_NAME, &core) || - hal_io_read(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4); + if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK) + return err; - if (err == HAL_OK) + if ((err = hal_io_read(core, MKMIF_ADDR_SCLK_DIV, data.byte, 4)) == HAL_OK) *divisor = htonl(data.word); hal_core_free(core); @@ -101,11 +105,11 @@ hal_error_t hal_mkmif_write(hal_core_t *core, uint32_t addr, const uint8_t *buf, for (; len > 0; addr += 4, buf += 4, len -= 4) { byteword_t write_addr; write_addr.word = htonl((uint32_t)addr); - if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, write_addr.byte, 4)) || - (err = hal_io_write(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) || - (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) || - (err = hal_io_wait_ready(core))) - return err; + if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, write_addr.byte, 4)) != HAL_OK || + (err = hal_io_write(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) != HAL_OK || + (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) != HAL_OK || + (err = hal_io_wait_ready(core)) != HAL_OK) + break; } } @@ -132,19 +136,19 @@ hal_error_t hal_mkmif_read(hal_core_t *core, uint32_t addr, uint8_t *buf, size_t cmd.word = htonl(MKMIF_CTRL_CMD_READ); - if ((err = hal_core_alloc(MKMIF_NAME, &core)) == HAL_OK) { - for (; len > 0; addr += 4, buf += 4, len -= 4) { - byteword_t read_addr; - read_addr.word = htonl((uint32_t)addr); - if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, read_addr.byte, 4)) || - (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) || - (err = hal_io_wait_valid(core)) || - (err = hal_io_read(core, MKMIF_ADDR_EMEM_DATA, buf, 4))) - goto out; - } + if ((err = hal_core_alloc(MKMIF_NAME, &core)) != HAL_OK) + return err; + + for (; len > 0; addr += 4, buf += 4, len -= 4) { + byteword_t read_addr; + read_addr.word = htonl((uint32_t)addr); + if ((err = hal_io_write(core, MKMIF_ADDR_EMEM_ADDR, read_addr.byte, 4)) != HAL_OK || + (err = hal_io_write(core, MKMIF_ADDR_CTRL, cmd.byte, 4)) != HAL_OK || + (err = hal_io_wait_valid(core)) != HAL_OK || + (err = hal_io_read(core, MKMIF_ADDR_EMEM_DATA, buf, 4)) != HAL_OK) + break; } -out: hal_core_free(core); return err; } |