1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-29 14:52:12 +01:00

flash: use uintptr_t to hold opaque pointers

When storing an opaque pointer value in a uint, the
appropriate type is uintptr_t which is guaranteed to
be wide enough to hold a pointer.

This is particularly important when the code can be
compiled in a sim or unit test environment which is
intended to run on a 64-bit machine.

Conflicts:
	flight/PiOS/Common/pios_flash_jedec.c
	flight/targets/DiscoveryF4/System/pios_board.c
	flight/targets/FlyingF4/System/pios_board.c
	flight/targets/Freedom/System/pios_board.c
	flight/targets/Quanton/System/pios_board.c
This commit is contained in:
Stacey Sheldon 2012-12-14 23:13:33 -05:00 committed by Alessio Morale
parent dd5f4b949c
commit 17b8696261
12 changed files with 104 additions and 104 deletions

View File

@ -114,7 +114,7 @@ static int32_t PIOS_Flash_Jedec_Validate(struct jedec_flash_dev * flash_dev) {
/**
* @brief Initialize the flash device and enable write access
*/
int32_t PIOS_Flash_Jedec_Init(uint32_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg)
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg)
{
struct jedec_flash_dev * flash_dev = PIOS_Flash_Jedec_alloc();
if (flash_dev == NULL)
@ -129,7 +129,7 @@ int32_t PIOS_Flash_Jedec_Init(uint32_t * flash_id, uint32_t spi_id, uint32_t sla
return -1;
/* Give back a handle to this flash device */
*flash_id = (uint32_t) flash_dev;
*flash_id = (uintptr_t) flash_dev;
return 0;
}
@ -246,7 +246,7 @@ static int32_t PIOS_Flash_Jedec_ReadID(struct jedec_flash_dev * flash_dev)
* @brief Grab the semaphore to perform a transaction
* @return 0 for success, -1 for timeout
*/
static int32_t PIOS_Flash_Jedec_StartTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Jedec_StartTransaction(uintptr_t flash_id)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -265,7 +265,7 @@ static int32_t PIOS_Flash_Jedec_StartTransaction(uint32_t flash_id)
* @brief Release the semaphore to perform a transaction
* @return 0 for success, -1 for timeout
*/
static int32_t PIOS_Flash_Jedec_EndTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Jedec_EndTransaction(uintptr_t flash_id)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -282,12 +282,12 @@ static int32_t PIOS_Flash_Jedec_EndTransaction(uint32_t flash_id)
#else /* FLASH_USE_FREERTOS_LOCKS */
static int32_t PIOS_Flash_Jedec_StartTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Jedec_StartTransaction(uintptr_t flash_id)
{
return 0;
}
static int32_t PIOS_Flash_Jedec_EndTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Jedec_EndTransaction(uintptr_t flash_id)
{
return 0;
}
@ -301,7 +301,7 @@ static int32_t PIOS_Flash_Jedec_EndTransaction(uint32_t flash_id)
* @retval -1 if unable to claim bus
* @retval
*/
static int32_t PIOS_Flash_Jedec_EraseSector(uint32_t flash_id, uint32_t addr)
static int32_t PIOS_Flash_Jedec_EraseSector(uintptr_t flash_id, uint32_t addr)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -338,7 +338,7 @@ static int32_t PIOS_Flash_Jedec_EraseSector(uint32_t flash_id, uint32_t addr)
* @brief Execute the whole chip
* @returns 0 if successful, -1 if unable to claim bus
*/
static int32_t PIOS_Flash_Jedec_EraseChip(uint32_t flash_id)
static int32_t PIOS_Flash_Jedec_EraseChip(uintptr_t flash_id)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -389,7 +389,7 @@ static int32_t PIOS_Flash_Jedec_EraseChip(uint32_t flash_id)
* @retval -2 Size exceeds 256 bytes
* @retval -3 Length to write would wrap around page boundary
*/
static int32_t PIOS_Flash_Jedec_WriteData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_Jedec_WriteData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -457,7 +457,7 @@ static int32_t PIOS_Flash_Jedec_WriteData(uint32_t flash_id, uint32_t addr, uint
* @retval -2 Size exceeds 256 bytes
* @retval -3 Length to write would wrap around page boundary
*/
static int32_t PIOS_Flash_Jedec_WriteChunks(uint32_t flash_id, uint32_t addr, struct pios_flash_chunk chunks[], uint32_t num)
static int32_t PIOS_Flash_Jedec_WriteChunks(uintptr_t flash_id, uint32_t addr, struct pios_flash_chunk chunks[], uint32_t num)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;
@ -516,7 +516,7 @@ static int32_t PIOS_Flash_Jedec_WriteChunks(uint32_t flash_id, uint32_t addr, st
* @return Zero if success or error code
* @retval -1 Unable to claim SPI bus
*/
static int32_t PIOS_Flash_Jedec_ReadData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_Jedec_ReadData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
struct jedec_flash_dev * flash_dev = (struct jedec_flash_dev *)flash_id;

View File

@ -50,7 +50,7 @@ struct logfs_state {
/* Underlying flash driver glue */
const struct pios_flash_driver * driver;
uint32_t flash_id;
uintptr_t flash_id;
};
static struct logfs_state logfs;
@ -461,7 +461,7 @@ static int32_t logfs_mount_log(uint8_t arena_id)
* @brief Initialize the flash object setting FS
* @return 0 if success, -1 if failure
*/
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t * fs_id, const struct flashfs_logfs_cfg * cfg, const struct pios_flash_driver * driver, uint32_t flash_id)
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t * fs_id, const struct flashfs_logfs_cfg * cfg, const struct pios_flash_driver * driver, uintptr_t flash_id)
{
PIOS_Assert(cfg);
PIOS_Assert(fs_id);

View File

@ -166,7 +166,7 @@ static struct pios_internal_flash_dev * PIOS_Flash_Internal_alloc(void)
#endif /* defined(PIOS_INCLUDE_FREERTOS) */
int32_t PIOS_Flash_Internal_Init(uint32_t * flash_id, const struct pios_flash_internal_cfg * cfg)
int32_t PIOS_Flash_Internal_Init(uintptr_t * flash_id, const struct pios_flash_internal_cfg * cfg)
{
struct pios_internal_flash_dev * flash_dev;
@ -178,7 +178,7 @@ int32_t PIOS_Flash_Internal_Init(uint32_t * flash_id, const struct pios_flash_in
flash_dev->transaction_lock = xSemaphoreCreateMutex();
#endif /* defined(PIOS_INCLUDE_FREERTOS) */
*flash_id = (uint32_t) flash_dev;
*flash_id = (uintptr_t) flash_dev;
return 0;
}
@ -190,7 +190,7 @@ int32_t PIOS_Flash_Internal_Init(uint32_t * flash_id, const struct pios_flash_in
*********************************/
#include "pios_flash.h"
static int32_t PIOS_Flash_Internal_StartTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Internal_StartTransaction(uintptr_t flash_id)
{
struct pios_internal_flash_dev * flash_dev = (struct pios_internal_flash_dev *)flash_id;
@ -207,7 +207,7 @@ static int32_t PIOS_Flash_Internal_StartTransaction(uint32_t flash_id)
return 0;
}
static int32_t PIOS_Flash_Internal_EndTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_Internal_EndTransaction(uintptr_t flash_id)
{
struct pios_internal_flash_dev * flash_dev = (struct pios_internal_flash_dev *)flash_id;
@ -225,7 +225,7 @@ static int32_t PIOS_Flash_Internal_EndTransaction(uint32_t flash_id)
return 0;
}
static int32_t PIOS_Flash_Internal_EraseSector(uint32_t flash_id, uint32_t addr)
static int32_t PIOS_Flash_Internal_EraseSector(uintptr_t flash_id, uint32_t addr)
{
struct pios_internal_flash_dev * flash_dev = (struct pios_internal_flash_dev *)flash_id;
@ -249,7 +249,7 @@ static int32_t PIOS_Flash_Internal_EraseSector(uint32_t flash_id, uint32_t addr)
return 0;
}
static int32_t PIOS_Flash_Internal_WriteData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_Internal_WriteData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
PIOS_Assert(data);
@ -291,7 +291,7 @@ static int32_t PIOS_Flash_Internal_WriteData(uint32_t flash_id, uint32_t addr, u
return 0;
}
static int32_t PIOS_Flash_Internal_ReadData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_Internal_ReadData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
PIOS_Assert(data);

View File

@ -35,13 +35,13 @@ struct pios_flash_chunk {
};
struct pios_flash_driver {
int32_t (*start_transaction)(uint32_t flash_id);
int32_t (*end_transaction)(uint32_t flash_id);
int32_t (*erase_chip)(uint32_t flash_id);
int32_t (*erase_sector)(uint32_t flash_id, uint32_t addr);
int32_t (*write_data)(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len);
int32_t (*write_chunks)(uint32_t flash_id, uint32_t addr, struct pios_flash_chunk chunks[], uint32_t num_chunks);
int32_t (*read_data)(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len);
int32_t (*start_transaction)(uintptr_t flash_id);
int32_t (*end_transaction)(uintptr_t flash_id);
int32_t (*erase_chip)(uintptr_t flash_id);
int32_t (*erase_sector)(uintptr_t flash_id, uint32_t addr);
int32_t (*write_data)(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len);
int32_t (*write_chunks)(uintptr_t flash_id, uint32_t addr, struct pios_flash_chunk chunks[], uint32_t num_chunks);
int32_t (*read_data)(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len);
};
#endif /* PIOS_FLASH_H_ */

View File

@ -35,6 +35,6 @@ struct pios_flash_internal_cfg {
;
};
extern int32_t PIOS_Flash_Internal_Init(uint32_t * flash_id, const struct pios_flash_internal_cfg * cfg);
extern int32_t PIOS_Flash_Internal_Init(uintptr_t * flash_id, const struct pios_flash_internal_cfg * cfg);
#endif /* PIOS_FLASH_INTERNAL_H_ */

View File

@ -40,6 +40,6 @@ struct pios_flash_jedec_cfg {
uint32_t chip_erase;
};
int32_t PIOS_Flash_Jedec_Init(uint32_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg);
int32_t PIOS_Flash_Jedec_Init(uintptr_t * flash_id, uint32_t spi_id, uint32_t slave_num, const struct pios_flash_jedec_cfg * cfg);
#endif /* PIOS_FLASH_JEDEC_H_ */

View File

@ -41,6 +41,6 @@ struct flashfs_logfs_cfg {
uint32_t page_size; /* Maximum flash burst write size */
};
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t * fs_id, const struct flashfs_logfs_cfg * cfg, const struct pios_flash_driver * driver, uint32_t flash_id);
int32_t PIOS_FLASHFS_Logfs_Init(uintptr_t * fs_id, const struct flashfs_logfs_cfg * cfg, const struct pios_flash_driver * driver, uintptr_t flash_id);
#endif /* PIOS_FLASHFS_LOGFS_PRIV_H_ */

View File

@ -162,7 +162,7 @@ void PIOS_Board_Init(void) {
#endif
uint32_t flash_id;
uintptr_t flash_id;
uintptr_t fs_id;
switch(bdinfo->board_rev) {
case BOARD_REVISION_CC:

View File

@ -300,8 +300,8 @@ void PIOS_Board_Init(void) {
}
#if defined(PIOS_INCLUDE_FLASH)
/* Connect flash to the approrpiate interface and configure it */
uint32_t flash_id;
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_telem_flash_id, 1, &flash_m25p_cfg);
uintptr_t fs_id;
PIOS_FLASHFS_Logfs_Init(&fs_id, &flashfs_m25p_cfg, &pios_jedec_flash_driver, flash_id);

View File

@ -381,12 +381,12 @@ void PIOS_Board_Init(void) {
if (PIOS_SPI_Init(&pios_spi_flash_id, &pios_spi_flash_cfg)) {
PIOS_DEBUG_Assert(0);
}
/* Connect flash to the approrpiate interface and configure it */
uint32_t flash_id;
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_flash_id, 0, &flash_m25p_cfg);
#else
/* Connect flash to the approrpiate interface and configure it */
uint32_t flash_id;
/* Connect flash to the appropriate interface and configure it */
uintptr_t flash_id;
PIOS_Flash_Jedec_Init(&flash_id, pios_spi_accel_id, 1, &flash_m25p_cfg);
#endif
uintptr_t fs_id;

View File

@ -31,7 +31,7 @@ int main (int argc, char * argv[])
/* dd if=/dev/zero bs=1 count=2MiB | tr '\000' '\377' > theflash.bin */
uint32_t flash_id;
uintptr_t flash_id;
rc = PIOS_Flash_UT_Init(&flash_id, &flash_config);
if (rc != 0) {
printf ("flash init failed (%d)\n", rc);

View File

@ -26,7 +26,7 @@ static struct flash_ut_dev * PIOS_Flash_UT_Alloc(void)
return flash_dev;
}
int32_t PIOS_Flash_UT_Init(uint32_t * flash_id, const struct pios_flash_ut_cfg * cfg)
int32_t PIOS_Flash_UT_Init(uintptr_t * flash_id, const struct pios_flash_ut_cfg * cfg)
{
/* Check inputs */
assert(flash_id);
@ -50,7 +50,7 @@ int32_t PIOS_Flash_UT_Init(uint32_t * flash_id, const struct pios_flash_ut_cfg *
return -2;
}
*flash_id = (uint32_t)flash_dev;
*flash_id = (uintptr_t)flash_dev;
return 0;
}
@ -62,7 +62,7 @@ int32_t PIOS_Flash_UT_Init(uint32_t * flash_id, const struct pios_flash_ut_cfg *
*********************************/
#include "pios_flash.h"
static int32_t PIOS_Flash_UT_StartTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_UT_StartTransaction(uintptr_t flash_id)
{
struct flash_ut_dev * flash_dev = (struct flash_ut_dev *)flash_id;
@ -73,7 +73,7 @@ static int32_t PIOS_Flash_UT_StartTransaction(uint32_t flash_id)
return 0;
}
static int32_t PIOS_Flash_UT_EndTransaction(uint32_t flash_id)
static int32_t PIOS_Flash_UT_EndTransaction(uintptr_t flash_id)
{
struct flash_ut_dev * flash_dev = (struct flash_ut_dev *)flash_id;
@ -84,7 +84,7 @@ static int32_t PIOS_Flash_UT_EndTransaction(uint32_t flash_id)
return 0;
}
static int32_t PIOS_Flash_UT_EraseSector(uint32_t flash_id, uint32_t addr)
static int32_t PIOS_Flash_UT_EraseSector(uintptr_t flash_id, uint32_t addr)
{
struct flash_ut_dev * flash_dev = (struct flash_ut_dev *)flash_id;
@ -106,7 +106,7 @@ static int32_t PIOS_Flash_UT_EraseSector(uint32_t flash_id, uint32_t addr)
return 0;
}
static int32_t PIOS_Flash_UT_WriteData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_UT_WriteData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
/* Check inputs */
assert(data);
@ -127,7 +127,7 @@ static int32_t PIOS_Flash_UT_WriteData(uint32_t flash_id, uint32_t addr, uint8_t
return 0;
}
static int32_t PIOS_Flash_UT_ReadData(uint32_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
static int32_t PIOS_Flash_UT_ReadData(uintptr_t flash_id, uint32_t addr, uint8_t * data, uint16_t len)
{
/* Check inputs */
assert(data);