Skip to content

Commit fa260c0

Browse files
committed
[sw/lib] minor cleanups
1 parent 2effe9f commit fa260c0

17 files changed

+50
-147
lines changed

sw/lib/source/neorv32_aux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ uint64_t neorv32_aux_hexstr2uint64(char *buffer, unsigned int length) {
208208
}
209209

210210
res <<= 4;
211-
res |= (uint64_t)(d & 0xf);
211+
res += (uint64_t)d;
212212
}
213213

214214
return res;

sw/lib/source/neorv32_cfs.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// ================================================================================ //
22
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
33
// Copyright (c) NEORV32 contributors. //
4-
// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
4+
// Copyright (c) 2020 - 2026 Stephan Nolting. All rights reserved. //
55
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
66
// SPDX-License-Identifier: BSD-3-Clause //
77
// ================================================================================ //
@@ -13,8 +13,6 @@
1313
* @warning There are no "real" CFS driver functions available here, because these functions are defined by the actual hardware.
1414
* @warning Hence, the CFS designer has to provide the actual driver functions.
1515
*
16-
* @note These functions should only be used if the CFS was synthesized (IO_CFS_EN = true).
17-
*
1816
* @see https://stnolting.github.io/neorv32/sw/files.html
1917
*/
2018

@@ -24,15 +22,10 @@
2422
/**********************************************************************//**
2523
* Check if custom functions subsystem was synthesized.
2624
*
27-
* @return 0 if CFS was not synthesized, 1 if CFS is available.
25+
* @return 0 if CFS was not synthesized, non-zero if CFS is available.
2826
**************************************************************************/
2927
int neorv32_cfs_available(void) {
3028

31-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_CFS)) {
32-
return 1;
33-
}
34-
else {
35-
return 0;
36-
}
29+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_CFS));
3730
}
3831

sw/lib/source/neorv32_clint.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
/**********************************************************************//**
1818
* Check if CLINT module was synthesized.
1919
*
20-
* @return 0 if CLINT was not synthesized, 1 if CLINT is available.
20+
* @return 0 if CLINT was not synthesized, non-zero if CLINT is available.
2121
**************************************************************************/
2222
int neorv32_clint_available(void) {
2323

24-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_CLINT)) {
25-
return 1;
26-
}
27-
else {
28-
return 0;
29-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_CLINT));
3025
}
3126

3227

sw/lib/source/neorv32_cpu_cfu.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
// ================================================================================ //
22
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
33
// Copyright (c) NEORV32 contributors. //
4-
// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
4+
// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
55
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
66
// SPDX-License-Identifier: BSD-3-Clause //
77
// ================================================================================ //
88

99
/**
1010
* @file neorv32_cpu_cfu.c
1111
* @brief CPU Core custom functions unit HW driver source file.
12-
*
13-
* @see https://stnolting.github.io/neorv32/sw/files.html
1412
*/
1513

1614
#include <neorv32.h>
@@ -19,15 +17,10 @@
1917
/**********************************************************************//**
2018
* Check if custom functions unit was synthesized.
2119
*
22-
* @return 0 if CFU was not synthesized, 1 if CFU is available.
20+
* @return 0 if CFU was not synthesized, non-zero if CFU is available.
2321
**************************************************************************/
2422
int neorv32_cpu_cfu_available(void) {
2523

2624
// this is an ISA extension - not a SoC module
27-
if (neorv32_cpu_csr_read(CSR_MXISA) & (1 << CSR_MXISA_ZXCFU)) {
28-
return 1;
29-
}
30-
else {
31-
return 0;
32-
}
25+
return (int)(neorv32_cpu_csr_read(CSR_MXISA) & (1 << CSR_MXISA_ZXCFU));
3326
}

sw/lib/source/neorv32_dma.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
/**********************************************************************//**
1818
* Check if DMA controller was synthesized.
1919
*
20-
* @return 0 if DMA was not synthesized, 1 if DMA is available.
20+
* @return 0 if DMA was not synthesized, non-zero if DMA is available.
2121
**************************************************************************/
2222
int neorv32_dma_available(void) {
2323

24-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_DMA)) {
25-
return 1;
26-
}
27-
else {
28-
return 0;
29-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_DMA));
3025
}
3126

3227

sw/lib/source/neorv32_gpio.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
/**
1010
* @file neorv32_gpio.c
1111
* @brief General purpose input/output port unit (GPIO) HW driver source file.
12-
#include <neorv32.h>
1312
*/
1413

1514
#include <neorv32.h>
@@ -18,16 +17,11 @@
1817
/**********************************************************************//**
1918
* Check if GPIO unit was synthesized.
2019
*
21-
* @return 0 if GPIO was not synthesized, 1 if GPIO is available.
20+
* @return 0 if GPIO was not synthesized, non-zero if GPIO is available.
2221
**************************************************************************/
2322
int neorv32_gpio_available(void) {
2423

25-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_GPIO)) {
26-
return 1;
27-
}
28-
else {
29-
return 0;
30-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_GPIO));
3125
}
3226

3327

sw/lib/source/neorv32_gptmr.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,11 @@
1717
/**********************************************************************//**
1818
* Check if general purpose timer unit was synthesized.
1919
*
20-
* @return 0 if GPTMR was not synthesized, 1 if GPTMR is available.
20+
* @return 0 if GPTMR was not synthesized, non-zero if GPTMR is available.
2121
**************************************************************************/
2222
int neorv32_gptmr_available(void) {
2323

24-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_GPTMR)) {
25-
return 1;
26-
}
27-
else {
28-
return 0;
29-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_GPTMR));
3025
}
3126

3227

sw/lib/source/neorv32_neoled.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// ================================================================================ //
22
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
33
// Copyright (c) NEORV32 contributors. //
4-
// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
4+
// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
55
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
66
// SPDX-License-Identifier: BSD-3-Clause //
77
// ================================================================================ //
88

99
/**
1010
* @file neorv32_neoled.c
1111
* @brief Smart LED Interface (NEOLED) HW driver source file.
12-
*
13-
* @note These functions should only be used if the NEOLED unit was synthesized (IO_NEOLED_EN = true).
14-
*
15-
* @see https://stnolting.github.io/neorv32/sw/files.html
1612
*/
1713

1814
#include <neorv32.h>
@@ -21,16 +17,11 @@
2117
/**********************************************************************//**
2218
* Check if NEOLED unit was synthesized.
2319
*
24-
* @return 0 if NEOLED was not synthesized, 1 if NEOLED is available.
20+
* @return 0 if NEOLED was not synthesized, non-zero if NEOLED is available.
2521
**************************************************************************/
2622
int neorv32_neoled_available(void) {
2723

28-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_NEOLED)) {
29-
return 1;
30-
}
31-
else {
32-
return 0;
33-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_NEOLED));
3425
}
3526

3627

sw/lib/source/neorv32_onewire.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// ================================================================================ //
22
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
33
// Copyright (c) NEORV32 contributors. //
4-
// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
4+
// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
55
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
66
// SPDX-License-Identifier: BSD-3-Clause //
77
// ================================================================================ //
88

99
/**
1010
* @file neorv32_onewire.c
1111
* @brief 1-Wire Interface Controller (ONEWIRE) HW driver source file.
12-
*
13-
* @note These functions should only be used if the ONEWIRE unit was synthesized (IO_ONEWIRE_EN = true).
14-
*
15-
* @see https://stnolting.github.io/neorv32/sw/files.html
1612
*/
1713

1814
#include <neorv32.h>
@@ -21,16 +17,11 @@
2117
/**********************************************************************//**
2218
* Check if ONEWIRE controller was synthesized.
2319
*
24-
* @return 0 if ONEWIRE was not synthesized, 1 if ONEWIRE is available.
20+
* @return 0 if ONEWIRE was not synthesized, non-zero if ONEWIRE is available.
2521
**************************************************************************/
2622
int neorv32_onewire_available(void) {
2723

28-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_ONEWIRE)) {
29-
return 1;
30-
}
31-
else {
32-
return 0;
33-
}
24+
return (int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_ONEWIRE));
3425
}
3526

3627

sw/lib/source/neorv32_pwm.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
// ================================================================================ //
22
// The NEORV32 RISC-V Processor - https://github.com/stnolting/neorv32 //
33
// Copyright (c) NEORV32 contributors. //
4-
// Copyright (c) 2020 - 2024 Stephan Nolting. All rights reserved. //
4+
// Copyright (c) 2020 - 2025 Stephan Nolting. All rights reserved. //
55
// Licensed under the BSD-3-Clause license, see LICENSE for details. //
66
// SPDX-License-Identifier: BSD-3-Clause //
77
// ================================================================================ //
88

99
/**
1010
* @file neorv32_pwm.c
1111
* @brief Pulse-Width Modulation Controller (PWM) HW driver source file.
12-
*
13-
* @note These functions should only be used if the PWM unit was synthesized (IO_PWM_EN = true).
14-
*
15-
* @see https://stnolting.github.io/neorv32/sw/files.html
1612
*/
1713

1814
#include <neorv32.h>
@@ -21,16 +17,11 @@
2117
/**********************************************************************//**
2218
* Check if PWM unit was synthesized.
2319
*
24-
* @return 0 if PWM was not synthesized, 1 if PWM is available.
20+
* @return 0 if PWM was not synthesized, non-zero if PWM is available.
2521
**************************************************************************/
2622
int neorv32_pwm_available(void) {
2723

28-
if (NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_PWM)) {
29-
return 1;
30-
}
31-
else {
32-
return 0;
33-
}
24+
return(int)(NEORV32_SYSINFO->SOC & (1 << SYSINFO_SOC_IO_PWM));
3425
}
3526

3627

0 commit comments

Comments
 (0)