Skip to content

Commit dccc647

Browse files
authored
Merge pull request #24 from AlexLanzano/void-pointer
[spi, flash, rng, eth, block] Change data buffer parameters from uint8_t* to void*
2 parents eb63ca6 + 6b4786e commit dccc647

37 files changed

Lines changed: 191 additions & 137 deletions

src/block/block.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ inline whal_Error whal_Block_Deinit(whal_Block *blockDev)
2121
}
2222

2323
inline whal_Error whal_Block_Read(whal_Block *blockDev, uint32_t block,
24-
uint8_t *data, uint32_t blockCount)
24+
void *data, uint32_t blockCount)
2525
{
2626
if (!blockDev || !blockDev->driver || !blockDev->driver->Read || !data) {
2727
return WHAL_EINVAL;
@@ -31,7 +31,7 @@ inline whal_Error whal_Block_Read(whal_Block *blockDev, uint32_t block,
3131
}
3232

3333
inline whal_Error whal_Block_Write(whal_Block *blockDev, uint32_t block,
34-
const uint8_t *data, uint32_t blockCount)
34+
const void *data, uint32_t blockCount)
3535
{
3636
if (!blockDev || !blockDev->driver || !blockDev->driver->Write || !data) {
3737
return WHAL_EINVAL;

src/block/sdhc_spi.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,9 @@ whal_Error whal_SdhcSpi_Deinit(whal_Block *blockDev)
266266
}
267267

268268
whal_Error whal_SdhcSpi_Read(whal_Block *blockDev, uint32_t block,
269-
uint8_t *data, uint32_t blockCount)
269+
void *data, uint32_t blockCount)
270270
{
271+
uint8_t *dataBuf = (uint8_t *)data;
271272
whal_SdhcSpi_Cfg *cfg;
272273
whal_Error err;
273274
uint8_t r1;
@@ -309,7 +310,7 @@ whal_Error whal_SdhcSpi_Read(whal_Block *blockDev, uint32_t block,
309310
}
310311

311312
err = whal_Spi_SendRecv(cfg->spiDev, NULL, 0,
312-
data + (i * WHAL_SDHC_SPI_BLOCK_SZ),
313+
dataBuf + (i * WHAL_SDHC_SPI_BLOCK_SZ),
313314
WHAL_SDHC_SPI_BLOCK_SZ);
314315
if (err)
315316
break;
@@ -334,8 +335,9 @@ whal_Error whal_SdhcSpi_Read(whal_Block *blockDev, uint32_t block,
334335
}
335336

336337
whal_Error whal_SdhcSpi_Write(whal_Block *blockDev, uint32_t block,
337-
const uint8_t *data, uint32_t blockCount)
338+
const void *data, uint32_t blockCount)
338339
{
340+
const uint8_t *dataBuf = (const uint8_t *)data;
339341
whal_SdhcSpi_Cfg *cfg;
340342
whal_Error err;
341343
uint8_t r1;
@@ -379,7 +381,7 @@ whal_Error whal_SdhcSpi_Write(whal_Block *blockDev, uint32_t block,
379381
if (err)
380382
break;
381383
err = whal_Spi_SendRecv(cfg->spiDev,
382-
data + (i * WHAL_SDHC_SPI_BLOCK_SZ),
384+
dataBuf + (i * WHAL_SDHC_SPI_BLOCK_SZ),
383385
WHAL_SDHC_SPI_BLOCK_SZ, NULL, 0);
384386
if (err)
385387
break;

src/eth/eth.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ whal_Error whal_Eth_Stop(whal_Eth *ethDev)
3030
return ethDev->driver->Stop(ethDev);
3131
}
3232

33-
whal_Error whal_Eth_Send(whal_Eth *ethDev, const uint8_t *frame,
33+
whal_Error whal_Eth_Send(whal_Eth *ethDev, const void *frame,
3434
size_t len)
3535
{
3636
if (!ethDev || !ethDev->driver || !ethDev->driver->Send || !frame)
3737
return WHAL_EINVAL;
3838
return ethDev->driver->Send(ethDev, frame, len);
3939
}
4040

41-
whal_Error whal_Eth_Recv(whal_Eth *ethDev, uint8_t *frame, size_t *len)
41+
whal_Error whal_Eth_Recv(whal_Eth *ethDev, void *frame, size_t *len)
4242
{
4343
if (!ethDev || !ethDev->driver || !ethDev->driver->Recv || !frame || !len)
4444
return WHAL_EINVAL;

src/eth/stm32h5_eth.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,10 @@ whal_Error whal_Stm32h5Eth_Stop(whal_Eth *ethDev)
292292
return WHAL_SUCCESS;
293293
}
294294

295-
whal_Error whal_Stm32h5Eth_Send(whal_Eth *ethDev, const uint8_t *frame,
295+
whal_Error whal_Stm32h5Eth_Send(whal_Eth *ethDev, const void *frame,
296296
size_t len)
297297
{
298+
const uint8_t *frameBuf = (const uint8_t *)frame;
298299
whal_Stm32h5Eth_Cfg *cfg;
299300
whal_Stm32h5Eth_TxDesc *desc;
300301
size_t base;
@@ -318,7 +319,7 @@ whal_Error whal_Stm32h5Eth_Send(whal_Eth *ethDev, const uint8_t *frame,
318319
/* Copy frame into TX buffer */
319320
uint8_t *txBuf = cfg->txBufs + idx * cfg->txBufSize;
320321
for (size_t i = 0; i < len; i++)
321-
txBuf[i] = frame[i];
322+
txBuf[i] = frameBuf[i];
322323

323324
/* Set up descriptor */
324325
desc->des[0] = (uintptr_t)txBuf;
@@ -336,9 +337,10 @@ whal_Error whal_Stm32h5Eth_Send(whal_Eth *ethDev, const uint8_t *frame,
336337
return WHAL_SUCCESS;
337338
}
338339

339-
whal_Error whal_Stm32h5Eth_Recv(whal_Eth *ethDev, uint8_t *frame,
340+
whal_Error whal_Stm32h5Eth_Recv(whal_Eth *ethDev, void *frame,
340341
size_t *len)
341342
{
343+
uint8_t *frameBuf = (uint8_t *)frame;
342344
whal_Stm32h5Eth_Cfg *cfg;
343345
whal_Stm32h5Eth_RxDesc *desc;
344346
size_t base;
@@ -378,7 +380,7 @@ whal_Error whal_Stm32h5Eth_Recv(whal_Eth *ethDev, uint8_t *frame,
378380
/* Copy frame data */
379381
uint8_t *rxBuf = (uint8_t *)(cfg->rxBufs + idx * cfg->rxBufSize);
380382
for (size_t i = 0; i < pktLen; i++)
381-
frame[i] = rxBuf[i];
383+
frameBuf[i] = rxBuf[i];
382384
*len = pktLen;
383385

384386
/* Re-arm descriptor for DMA */

src/flash/flash.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ inline whal_Error whal_Flash_Unlock(whal_Flash *flashDev, size_t addr, size_t le
3838
return flashDev->driver->Unlock(flashDev, addr, len);
3939
}
4040

41-
inline whal_Error whal_Flash_Read(whal_Flash *flashDev, size_t addr, uint8_t *data,
41+
inline whal_Error whal_Flash_Read(whal_Flash *flashDev, size_t addr, void *data,
4242
size_t dataSz)
4343
{
4444
if (!flashDev || !flashDev->driver || !flashDev->driver->Read || !data) {
@@ -48,7 +48,7 @@ inline whal_Error whal_Flash_Read(whal_Flash *flashDev, size_t addr, uint8_t *da
4848
return flashDev->driver->Read(flashDev, addr, data, dataSz);
4949
}
5050

51-
inline whal_Error whal_Flash_Write(whal_Flash *flashDev, size_t addr, const uint8_t *data,
51+
inline whal_Error whal_Flash_Write(whal_Flash *flashDev, size_t addr, const void *data,
5252
size_t dataSz)
5353
{
5454
if (!flashDev || !flashDev->driver || !flashDev->driver->Write || !data) {

src/flash/pic32cz_flash.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -242,9 +242,10 @@ whal_Error whal_Pic32czFlash_Unlock(whal_Flash *flashDev, size_t addr, size_t le
242242
return WHAL_SUCCESS;
243243
}
244244

245-
whal_Error whal_Pic32czFlash_Read(whal_Flash *flashDev, size_t addr, uint8_t *data,
245+
whal_Error whal_Pic32czFlash_Read(whal_Flash *flashDev, size_t addr, void *data,
246246
size_t dataSz)
247247
{
248+
uint8_t *dataBuf = (uint8_t *)data;
248249
const whal_Regmap *reg;
249250
whal_Pic32czFlash_Cfg *cfg;
250251
uint8_t *flashAddr = (uint8_t *)addr;
@@ -265,17 +266,18 @@ whal_Error whal_Pic32czFlash_Read(whal_Flash *flashDev, size_t addr, uint8_t *da
265266

266267
/* Flash is memory-mapped; read directly */
267268
for (i = 0; i < dataSz; i++) {
268-
data[i] = flashAddr[i];
269+
dataBuf[i] = flashAddr[i];
269270
}
270271

271272
whal_Pic32czFlash_MutexUnlock(reg);
272273

273274
return WHAL_SUCCESS;
274275
}
275276

276-
whal_Error whal_Pic32czFlash_Write(whal_Flash *flashDev, size_t addr, const uint8_t *data,
277+
whal_Error whal_Pic32czFlash_Write(whal_Flash *flashDev, size_t addr, const void *data,
277278
size_t dataSz)
278279
{
280+
const uint8_t *dataBuf = (const uint8_t *)data;
279281
const whal_Regmap *reg;
280282
whal_Pic32czFlash_Cfg *cfg;
281283
const uint32_t *src;
@@ -294,7 +296,7 @@ whal_Error whal_Pic32czFlash_Write(whal_Flash *flashDev, size_t addr, const uint
294296
}
295297

296298
reg = &flashDev->regmap;
297-
src = (const uint32_t *)data;
299+
src = (const uint32_t *)dataBuf;
298300

299301

300302
err = whal_Pic32czFlash_MutexLock(reg, cfg->timeout);

0 commit comments

Comments
 (0)