Skip to content

Commit

Permalink
arch/risc-v/src/mpfs/mpfs_dsn: Correct serial number reading routine
Browse files Browse the repository at this point in the history
- Fix retry counter handling and increase the maximum number of retries.
- Add some parenthesis for clarity.
- Change return type to signed int, as it may return -ETIMEDOUT
- Correct comment for returned value

Signed-off-by: Jukka Laitinen <[email protected]>
  • Loading branch information
jlaitine committed Jun 16, 2023
1 parent 0831ee2 commit c5abe96
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions arch/risc-v/src/mpfs/mpfs_dsn.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@

/* Retry count */

#define RETRIES 100
#define RETRIES 500

/****************************************************************************
* Public Functions
Expand All @@ -70,11 +70,11 @@
* len - Number of bytes to read
*
* Returned Value:
* Number of bytes read, -1 on error
* Number of bytes read, -ETIMEDOUT on error
*
****************************************************************************/

size_t mpfs_read_dsn(uint8_t *dsn, size_t len)
int mpfs_read_dsn(uint8_t *dsn, size_t len)
{
uint32_t reg;
uint8_t *p = (uint8_t *)MSS_SCBMAILBOX;
Expand All @@ -86,7 +86,7 @@ size_t mpfs_read_dsn(uint8_t *dsn, size_t len)
* using the system controller services
*/

while (getreg32(SERVICES_SR) & SCBCTRL_SERVICESSR_BUSY && retries-- > 0)
while ((getreg32(SERVICES_SR) & SCBCTRL_SERVICESSR_BUSY) && --retries > 0)
{
leave_critical_section(flags);
usleep(1000);
Expand Down Expand Up @@ -118,7 +118,7 @@ size_t mpfs_read_dsn(uint8_t *dsn, size_t len)
{
reg = getreg32(SERVICES_CR);
}
while (reg & SCBCTRL_SERVICESCR_REQ && retries-- > 0);
while ((reg & SCBCTRL_SERVICESCR_REQ) && --retries);

if (retries == 0)
{
Expand All @@ -132,7 +132,7 @@ size_t mpfs_read_dsn(uint8_t *dsn, size_t len)
{
reg = getreg32(SERVICES_SR);
}
while (reg & SCBCTRL_SERVICESSR_BUSY && retries-- > 0);
while ((reg & SCBCTRL_SERVICESSR_BUSY) && --retries);

if (retries == 0)
{
Expand Down
2 changes: 1 addition & 1 deletion arch/risc-v/src/mpfs/mpfs_dsn.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ extern "C"
*
****************************************************************************/

size_t mpfs_read_dsn(uint8_t *dsn, size_t len);
int mpfs_read_dsn(uint8_t *dsn, size_t len);

#ifdef __cplusplus
}
Expand Down

0 comments on commit c5abe96

Please sign in to comment.