MISRA-related fixes.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13422 27425a3e-05d8-49a3-a47f-9c15f0e5edd8
This commit is contained in:
Giovanni Di Sirio 2020-03-15 13:10:33 +00:00
parent 2beac71d4f
commit 1d36c33e5e
10 changed files with 288 additions and 25 deletions

View File

@ -1,19 +1,25 @@
--- Module: ..\..\..\os\hal\src\hal.c (C)
--- Module: ..\..\..\os\hal\src\hal_st.c (C)
--- Module: ..\..\..\os\hal\src\hal_buffers.c (C)
--- Module: ..\..\..\os\hal\src\hal_queues.c (C)
--- Module: ..\..\..\os\hal\src\hal_flash.c (C)
--- Module: ..\..\..\os\hal\src\hal_mmcsd.c (C)
--- Module: ..\..\..\os\hal\src\hal_adc.c (C)
--- Module: ..\..\..\os\hal\src\hal_can.c (C)
--- Module: ..\..\..\os\hal\src\hal_crypto.c (C)
--- Module: ..\..\..\os\hal\src\hal_dac.c (C)
--- Module: ..\..\..\os\hal\src\hal_ext.c (C)
--- Module: ..\..\..\os\hal\src\hal_efl.c (C)
--- Module: ..\..\..\os\hal\src\hal_gpt.c (C)
@ -31,8 +37,6 @@
--- Module: ..\..\..\os\hal\src\hal_pwm.c (C)
--- Module: ..\..\..\os\hal\src\hal_qspi.c (C)
--- Module: ..\..\..\os\hal\src\hal_rtc.c (C)
--- Module: ..\..\..\os\hal\src\hal_sdc.c (C)
@ -41,9 +45,11 @@
--- Module: ..\..\..\os\hal\src\hal_serial_usb.c (C)
--- Module: ..\..\..\os\hal\src\hal_sio.c (C)
--- Module: ..\..\..\os\hal\src\hal_spi.c (C)
--- Module: ..\..\..\os\hal\src\hal_st.c (C)
--- Module: ..\..\..\os\hal\src\hal_trng.c (C)
--- Module: ..\..\..\os\hal\src\hal_uart.c (C)
@ -51,6 +57,8 @@
--- Module: ..\..\..\os\hal\src\hal_wdg.c (C)
--- Module: ..\..\..\os\hal\src\hal_wspi.c (C)
--- Module: ..\..\..\os\hal\templates\osal\osal.c (C)
--- Module: ..\..\..\os\hal\templates\hal_lld.c (C)
@ -59,9 +67,11 @@
--- Module: ..\..\..\os\hal\templates\hal_can_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_crypto_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_dac_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_ext_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_efl_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_gpt_lld.c (C)
@ -77,20 +87,24 @@
--- Module: ..\..\..\os\hal\templates\hal_pwm_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_qspi_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_rtc_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_sdc_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_serial_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_sio_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_spi_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_st_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_trng_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_uart_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_usb_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_wdg_lld.c (C)
--- Module: ..\..\..\os\hal\templates\hal_wspi_lld.c (C)

View File

@ -120,7 +120,7 @@ extern "C" {
flash_error_t efl_lld_start_erase_all(void *instance);
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec);
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector);
#ifdef __cplusplus
}

View File

@ -131,7 +131,7 @@ extern "C" {
flash_error_t efl_lld_start_erase_all(void *instance);
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec);
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector);
#ifdef __cplusplus
}

View File

@ -146,7 +146,7 @@ extern "C" {
flash_error_t efl_lld_start_erase_all(void *instance);
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec);
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector);
#ifdef __cplusplus
}

View File

@ -103,7 +103,7 @@ extern "C" {
flash_error_t efl_lld_start_erase_all(void *instance);
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *wait_time);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec);
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector);
#ifdef __cplusplus
}

View File

@ -222,7 +222,7 @@ void rtcConvertDateTimeToStructTm(const RTCDateTime *timespec,
uint32_t *tv_msec) {
int sec;
timp->tm_year = (int)timespec->year + (RTC_BASE_YEAR - 1900);
timp->tm_year = (int)timespec->year + (int)(RTC_BASE_YEAR - 1900U);
timp->tm_mon = (int)timespec->month - 1;
timp->tm_mday = (int)timespec->day;
timp->tm_isdst = (int)timespec->dstflag;

View File

@ -684,11 +684,6 @@ bool sdcConnect(SDCDriver *sdcp) {
if (_mmcsd_get_slice(sdcp->csd, MMCSD_CSD_MMC_CSD_STRUCTURE_SLICE) > 1U) {
uint8_t *ext_csd = sdcp->buf;
/* Size detection requires the buffer.*/
if (NULL == ext_csd) {
goto failed;
}
if (sdc_lld_read_special(sdcp, ext_csd, 512, MMCSD_CMD_SEND_EXT_CSD, 0)) {
goto failed;
}

View File

@ -45,6 +45,19 @@ EFlashDriver EFLD1;
/* Driver local variables and types. */
/*===========================================================================*/
static const flash_descriptor_t efl_lld_descriptor = {
.attributes = FLASH_ATTR_ERASED_IS_ONE |
FLASH_ATTR_MEMORY_MAPPED |
FLASH_ATTR_ECC_CAPABLE |
FLASH_ATTR_ECC_ZERO_LINE_CAPABLE,
.page_size = 0,
.sectors_count = 0,
.sectors = NULL,
.sectors_size = 0,
.address = (uint8_t *)0,
.size = 0
};
/*===========================================================================*/
/* Driver local functions. */
/*===========================================================================*/
@ -112,6 +125,241 @@ void efl_lld_stop(EFlashDriver *eflp) {
}
}
/**
* @brief Gets the flash descriptor structure.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @return A flash device descriptor.
*
* @notapi
*/
const flash_descriptor_t *efl_lld_get_descriptor(void *instance) {
(void)instance;
return &efl_lld_descriptor;
}
/**
* @brief Read operation.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @param[in] offset flash offset
* @param[in] n number of bytes to be read
* @param[out] rp pointer to the data buffer
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_READ if the read operation failed.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @notapi
*/
flash_error_t efl_lld_read(void *instance, flash_offset_t offset,
size_t n, uint8_t *rp) {
EFlashDriver *devp = (EFlashDriver *)instance;
flash_error_t err = FLASH_NO_ERROR;
osalDbgCheck((instance != NULL) && (rp != NULL) && (n > 0U));
osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size);
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
"invalid state");
/* No reading while erasing.*/
if (devp->state == FLASH_ERASE) {
return FLASH_BUSY_ERASING;
}
/* FLASH_READY state while the operation is performed.*/
devp->state = FLASH_READ;
/* IMPLEMENT */
/* Ready state again.*/
devp->state = FLASH_READY;
return err;
}
/**
* @brief Program operation.
* @note The device supports ECC, it is only possible to write erased
* pages once except when writing all zeroes.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @param[in] offset flash offset
* @param[in] n number of bytes to be programmed
* @param[in] pp pointer to the data buffer
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_PROGRAM if the program operation failed.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @notapi
*/
flash_error_t efl_lld_program(void *instance, flash_offset_t offset,
size_t n, const uint8_t *pp) {
EFlashDriver *devp = (EFlashDriver *)instance;
flash_error_t err = FLASH_NO_ERROR;
osalDbgCheck((instance != NULL) && (pp != NULL) && (n > 0U));
osalDbgCheck(((size_t)offset + n) <= (size_t)efl_lld_descriptor.size);
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
"invalid state");
/* No programming while erasing.*/
if (devp->state == FLASH_ERASE) {
return FLASH_BUSY_ERASING;
}
/* FLASH_PGM state while the operation is performed.*/
devp->state = FLASH_PGM;
/* IMPLEMENT */
/* Ready state again.*/
devp->state = FLASH_READY;
return err;
}
/**
* @brief Starts a whole-device erase operation.
* @note This function only erases bank 2 if it is present. Bank 1 is not
* touched because it is where the program is running on.
* Pages on bank 1 can be individually erased.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @notapi
*/
flash_error_t efl_lld_start_erase_all(void *instance) {
EFlashDriver *devp = (EFlashDriver *)instance;
osalDbgCheck(instance != NULL);
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
"invalid state");
/* No erasing while erasing.*/
if (devp->state == FLASH_ERASE) {
return FLASH_BUSY_ERASING;
}
/* FLASH_PGM state while the operation is performed.*/
devp->state = FLASH_ERASE;
/* IMPLEMENT */
return FLASH_NO_ERROR;
}
/**
* @brief Starts an sector erase operation.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @param[in] sector sector to be erased
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @notapi
*/
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector) {
EFlashDriver *devp = (EFlashDriver *)instance;
osalDbgCheck(instance != NULL);
osalDbgCheck(sector < efl_lld_descriptor.sectors_count);
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
"invalid state");
/* No erasing while erasing.*/
if (devp->state == FLASH_ERASE) {
return FLASH_BUSY_ERASING;
}
/* FLASH_PGM state while the operation is performed.*/
devp->state = FLASH_ERASE;
/* IMPLEMENT */
return FLASH_NO_ERROR;
}
/**
* @brief Queries the driver for erase operation progress.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @param[out] msec recommended time, in milliseconds, that
* should be spent before calling this
* function again, can be @p NULL
* @return An error code.
* @retval FLASH_NO_ERROR if there is no erase operation in progress.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_ERASE if the erase operation failed.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @api
*/
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec) {
EFlashDriver *devp = (EFlashDriver *)instance;
flash_error_t err = FLASH_NO_ERROR;
(void)msec;
/* If there is an erase in progress then the device must be checked.*/
if (devp->state == FLASH_ERASE) {
/* IMPLEMENT */
}
return err;
}
/**
* @brief Returns the erase state of a sector.
*
* @param[in] ip pointer to a @p EFlashDriver instance
* @param[in] sector sector to be verified
* @return An error code.
* @retval FLASH_NO_ERROR if the sector is erased.
* @retval FLASH_BUSY_ERASING if there is an erase operation in progress.
* @retval FLASH_ERROR_VERIFY if the verify operation failed.
* @retval FLASH_ERROR_HW_FAILURE if access to the memory failed.
*
* @notapi
*/
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector) {
EFlashDriver *devp = (EFlashDriver *)instance;
flash_error_t err = FLASH_NO_ERROR;
osalDbgCheck(instance != NULL);
osalDbgCheck(sector < efl_lld_descriptor.sectors_count);
osalDbgAssert((devp->state == FLASH_READY) || (devp->state == FLASH_ERASE),
"invalid state");
/* No verifying while erasing.*/
if (devp->state == FLASH_ERASE) {
return FLASH_BUSY_ERASING;
}
/* IMPLEMENT */
/* Ready state again.*/
devp->state = FLASH_READY;
return err;
}
#endif /* HAL_USE_EFL == TRUE */
/** @} */

View File

@ -89,6 +89,16 @@ extern "C" {
void efl_lld_init(void);
void efl_lld_start(EFlashDriver *eflp);
void efl_lld_stop(EFlashDriver *eflp);
const flash_descriptor_t *efl_lld_get_descriptor(void *instance);
flash_error_t efl_lld_read(void *instance, flash_offset_t offset,
size_t n, uint8_t *rp);
flash_error_t efl_lld_program(void *instance, flash_offset_t offset,
size_t n, const uint8_t *pp);
flash_error_t efl_lld_start_erase_all(void *instance);
flash_error_t efl_lld_start_erase_sector(void *instance,
flash_sector_t sector);
flash_error_t efl_lld_query_erase(void *instance, uint32_t *msec);
flash_error_t efl_lld_verify_erase(void *instance, flash_sector_t sector);
#ifdef __cplusplus
}
#endif

View File

@ -77,14 +77,6 @@ typedef struct SDCDriver SDCDriver;
* @note It could be empty on some architectures.
*/
typedef struct {
/**
* @brief Working area for memory consuming operations.
* @note It is mandatory for detecting MMC cards bigger than 2GB else it
* can be @p NULL.
* @note Memory pointed by this buffer is only used by @p sdcConnect(),
* afterward it can be reused for other purposes.
*/
uint8_t *scratchpad;
/**
* @brief Bus width.
*/
@ -132,6 +124,10 @@ struct SDCDriver {
* @brief Card RCA.
*/
uint32_t rca;
/**
* @brief Buffer for internal operations.
*/
uint8_t buf[MMCSD_BLOCK_SIZE];
/* End of the mandatory fields.*/
};