aboutsummaryrefslogtreecommitdiff
path: root/stm-fmc.c
diff options
context:
space:
mode:
authorPaul Selkirk <paul@psgd.org>2017-10-15 21:34:00 -0400
committerPaul Selkirk <paul@psgd.org>2017-10-15 21:34:00 -0400
commit5af4a915edf3e77705fa2625081200b61f8dda26 (patch)
tree46d8e3cc6e27627e9f3e78c5a0b4a3573d1b1de3 /stm-fmc.c
parentb159bf0bb24a99c7d3ff1b3855f840add63198e5 (diff)
Cleanup: All drivers return HAL_StatusTypeDef rather than magic values.
Note: This affects libhal/ks_token.c, which uses the keystore driver directly.
Diffstat (limited to 'stm-fmc.c')
-rw-r--r--stm-fmc.c32
1 files changed, 18 insertions, 14 deletions
diff --git a/stm-fmc.c b/stm-fmc.c
index b202353..1302564 100644
--- a/stm-fmc.c
+++ b/stm-fmc.c
@@ -166,7 +166,7 @@ void fmc_init(void)
}
-static int _fmc_nwait_idle(void)
+static HAL_StatusTypeDef _fmc_nwait_idle(void)
{
int cnt;
@@ -175,41 +175,44 @@ static int _fmc_nwait_idle(void)
{
// read pin state
if (HAL_GPIO_ReadPin(FMC_GPIO_PORT_NWAIT, FMC_GPIO_PIN_NWAIT) == FMC_NWAIT_IDLE)
- return 0;
+ return HAL_OK;
}
- return -1;
+ return HAL_ERROR;
}
-int fmc_write_32(uint32_t addr, uint32_t *data)
+HAL_StatusTypeDef fmc_write_32(uint32_t addr, uint32_t *data)
{
// calculate target fpga address
uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK);
__disable_irq();
- int status =
+ HAL_StatusTypeDef status =
// write data to fpga
- (HAL_SRAM_Write_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1) != HAL_OK) ||
+ HAL_SRAM_Write_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1);
+ if (status == HAL_OK)
// wait for transaction to complete
- _fmc_nwait_idle();
+ status = _fmc_nwait_idle();
__enable_irq();
return status;
}
-static inline int _fmc_read_32(uint32_t *ptr, uint32_t *data)
+static inline HAL_StatusTypeDef _fmc_read_32(uint32_t *ptr, uint32_t *data)
{
- return
+ HAL_StatusTypeDef status =
// read data from fpga
- (HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1) != HAL_OK) ||
+ HAL_SRAM_Read_32b(&_fmc_fpga_inst, (uint32_t *)ptr, data, 1);
+ if (status == HAL_OK)
// wait for transaction to complete
- _fmc_nwait_idle();
+ status = _fmc_nwait_idle();
+ return status;
}
-int fmc_read_32(uint32_t addr, uint32_t *data)
+HAL_StatusTypeDef fmc_read_32(uint32_t addr, uint32_t *data)
{
// calculate target fpga address
uint32_t ptr = FMC_FPGA_BASE_ADDR + (addr & FMC_FPGA_ADDR_MASK);
@@ -232,9 +235,10 @@ int fmc_read_32(uint32_t addr, uint32_t *data)
*/
__disable_irq();
- int status =
- _fmc_read_32((uint32_t *)ptr, data) ||
+ HAL_StatusTypeDef status =
_fmc_read_32((uint32_t *)ptr, data);
+ if (status == HAL_OK)
+ status = _fmc_read_32((uint32_t *)ptr, data);
__enable_irq();