Skip to content

Commit 8fbf20d

Browse files
committed
Additional slight adaptions
1 parent b7b45bf commit 8fbf20d

File tree

9 files changed

+127
-78
lines changed

9 files changed

+127
-78
lines changed

ref_app/ref_app.vcxproj

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3233,6 +3233,10 @@
32333233
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
32343234
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
32353235
</ClInclude>
3236+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_reg.h">
3237+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
3238+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
3239+
</ClInclude>
32363240
<ClInclude Include="src\mcal\xtensa_esp32_s3\mcal_benchmark.h">
32373241
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
32383242
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
@@ -3733,9 +3737,6 @@
37333737
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
37343738
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
37353739
</Text>
3736-
<Text Include="src\mcal\xtensa_esp32_p4\xtensa_esp32_p4.txt">
3737-
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
3738-
</Text>
37393740
<Text Include="tools\Util\msys64\usr\bin\README.md" />
37403741
<Text Include="tools\Util\msys64\usr\local\gcc-13.2.0-x86_64-w64-mingw32\README_STL.txt" />
37413742
</ItemGroup>

ref_app/ref_app.vcxproj.filters

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3123,6 +3123,9 @@
31233123
<ClInclude Include="src\mcal\r7fa4m1ab\mcal_benchmark.h">
31243124
<Filter>src\mcal\r7fa4m1ab</Filter>
31253125
</ClInclude>
3126+
<ClInclude Include="src\mcal\xtensa_esp32_p4\mcal_reg.h">
3127+
<Filter>src\mcal\xtensa_esp32_p4</Filter>
3128+
</ClInclude>
31263129
</ItemGroup>
31273130
<ItemGroup>
31283131
<None Include="src\util\STL\algorithm">
@@ -3368,8 +3371,5 @@
33683371
<Text Include="tools\Util\msys64\usr\bin\README.md">
33693372
<Filter>tools\Util\msys64\usr\bin</Filter>
33703373
</Text>
3371-
<Text Include="src\mcal\xtensa_esp32_p4\xtensa_esp32_p4.txt">
3372-
<Filter>src\mcal\xtensa_esp32_p4</Filter>
3373-
</Text>
33743374
</ItemGroup>
33753375
</Project>

ref_app/src/mcal/riscvfe310/mcal_gpt.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,18 +87,18 @@ void mcal::gpt::init(const config_type*)
8787
using clint_mtimecmp_reg_address_type = std::uint32_t;
8888
using clint_mtimecmp_reg_value_type = std::uint64_t;
8989

90-
using clint_mtimecmp_reg_access_type =
90+
using clint_mtimecmp_reg_set_type =
9191
mcal::reg::reg_access_static<clint_mtimecmp_reg_address_type,
9292
clint_mtimecmp_reg_value_type,
9393
mcal::reg::clint_mtimecmp,
9494
(std::numeric_limits<clint_mtimecmp_reg_value_type>::max)()>;
9595

96-
static_assert(std::is_same<typename clint_mtimecmp_reg_access_type::register_value_type, clint_mtimecmp_reg_value_type>::value,
96+
static_assert(std::is_same<typename clint_mtimecmp_reg_set_type::register_value_type, clint_mtimecmp_reg_value_type>::value,
9797
"Error: Unexpected clint_mtimecmp register value type");
9898

9999
// Set the 64-bit mtimer compare register to its maximum value.
100100
// This results in an essentially infinite timeout.
101-
clint_mtimecmp_reg_access_type::reg_set();
101+
clint_mtimecmp_reg_set_type::reg_set();
102102

103103
gpt_is_initialized() = true;
104104
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
///////////////////////////////////////////////////////////////////////////////
2+
// Copyright Christopher Kormanyos 2026.
3+
// Distributed under the Boost Software License,
4+
// Version 1.0. (See accompanying file LICENSE_1_0.txt
5+
// or copy at http://www.boost.org/LICENSE_1_0.txt)
6+
//
7+
8+
#ifndef MCAL_REG_2026_02_11_H
9+
#define MCAL_REG_2026_02_11_H
10+
11+
#include <cstdint>
12+
13+
namespace mcal
14+
{
15+
namespace reg
16+
{
17+
constexpr std::uint32_t clint_base { UINT32_C(0x02000000) };
18+
constexpr std::uint32_t clint_mtime { clint_base + static_cast<std::uint32_t>(UINT32_C(0x0000BFF8)) };
19+
constexpr std::uint32_t clint_mtimeh { clint_base + static_cast<std::uint32_t>(UINT32_C(0x0000BFFC)) };
20+
constexpr std::uint32_t clint_mtimecmp { clint_base + static_cast<std::uint32_t>(UINT32_C(0x00004000)) };
21+
constexpr std::uint32_t clint_mtimecmph { clint_base + static_cast<std::uint32_t>(UINT32_C(0x00004004)) };
22+
23+
constexpr std::uint32_t clic_base { UINT32_C(0x20800000) };
24+
}
25+
}
26+
27+
#include <mcal/mcal_reg_access_dynamic.h>
28+
#include <mcal/mcal_reg_access_static.h>
29+
30+
#endif // MCAL_REG_2026_02_11_H

ref_app/src/mcal/xtensa_esp32_p4/xtensa_esp32_p4.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

ref_app/target/micros/xtensa_esp32_p4/startup/Code/Appli/main.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,13 @@
2020
#include <interrupt.h>
2121
#include <gpio.h>
2222

23-
#include <cstdio>
2423
#include <cstdint>
2524

2625
constexpr unsigned TIMEOUT_500MS { 160000000u };
2726
constexpr unsigned TIMEOUT_1S { 320000000u };
2827

2928
extern "C"
3029
{
31-
uint32_t sync_lock;
32-
33-
void osHwAcquireSpinLock(uint32_t* lock);
34-
void osHwReleaseSpinLock(uint32_t* lock);
3530
uint32_t osGetActiveCore(void);
3631
void __attribute__((interrupt)) Isr_TIMER_Interrupt(void);
3732
}
@@ -40,11 +35,6 @@ auto main(void) -> int __attribute__((used,noinline));
4035

4136
auto main(void) -> int
4237
{
43-
osHwAcquireSpinLock(&sync_lock);
44-
/* output a text message on the uart console */
45-
printf("BareMetal ESP32-P4 SW is Alive on HP core%ld!\n\r", osGetActiveCore());
46-
osHwReleaseSpinLock(&sync_lock);
47-
4838
if(0 == osGetActiveCore())
4939
{
5040
gpio_cfg_output(7);
@@ -71,19 +61,19 @@ auto main(void) -> int
7161
gpio_cfg_output(21);
7262
}
7363

74-
/* set the timer interrupt as hardware vectored in the CLIC */
64+
// Set the timer interrupt as hardware vectored in the CLIC.
7565
CLIC->interrupt[INT_TIMER_ID].clicintattr = 1;
7666

77-
/* enable timer machine interrupt in the CLIC */
67+
// Enable the timer machine interrupt in the CLIC.
7868
CLIC->interrupt[INT_TIMER_ID].clicintie = 1;
7969

80-
/* configure the sampling mode of MTIME */
70+
// Configure the sampling mode of MTIME.
8171
CLINT_MTIMECTL |= (3ul << 4);
8272

83-
/* set MTIME timeout to 500ms */
73+
// Set the MTIME timeout.
8474
CLINT_MTIMECMP = (uint64_t)(CLINT_MTIME + TIMEOUT_1S);
8575

86-
/* endless loop */
76+
// Endless loop: Never return or break.
8777
while(1)
8878
{
8979
asm volatile("nop");
@@ -95,11 +85,13 @@ void Isr_TIMER_Interrupt(void)
9585
{
9686
CLINT_MTIMECMP = (uint64_t)(CLINT_MTIME + TIMEOUT_1S);
9787

98-
if(0 == osGetActiveCore())
88+
const std::uint32_t core_id { osGetActiveCore() };
89+
90+
if(std::uint32_t { UINT8_C(0) } == core_id)
9991
{
10092
gpio_toggle_output_level(54);
10193
}
102-
else
94+
else if(std::uint32_t { UINT8_C(1) } == core_id)
10395
{
10496
gpio_toggle_output_level(19);
10597
}

ref_app/target/micros/xtensa_esp32_p4/startup/Code/Mcal/gpio.c

Lines changed: 51 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,19 @@
1818
//-----------------------------------------------------------------------------------------
1919
// Includes
2020
//-----------------------------------------------------------------------------------------
21-
#include "gpio.h"
21+
#include <gpio.h>
2222

2323

2424
//-----------------------------------------------------------------------------------------
2525
// Types
2626
//-----------------------------------------------------------------------------------------
2727

28-
typedef union {
28+
typedef union
29+
{
2930
volatile uint32_t reg;
30-
31-
struct {
31+
32+
struct
33+
{
3234
volatile uint32_t MCU_OE : 1;
3335
volatile uint32_t SLP_SEL : 1;
3436
volatile uint32_t MCU_WPD : 1;
@@ -42,25 +44,33 @@ typedef union {
4244
volatile uint32_t MCU_SEL : 3;
4345
volatile uint32_t FILTER_EN : 1;
4446
uint32_t : 16;
45-
} bit;
46-
} IO_MUX_GPIO;
47+
}
48+
bit;
49+
}
50+
IO_MUX_GPIO;
4751

48-
typedef union {
52+
typedef union
53+
{
4954
__IOM uint32_t reg;
50-
51-
struct {
55+
56+
struct
57+
{
5258
__IOM uint32_t OUT_SEL : 9;
5359
__IOM uint32_t INV_SEL : 1;
5460
__IOM uint32_t OEN_SEL : 1;
5561
__IOM uint32_t OEN_INV_SEL : 1;
5662
uint32_t : 20;
57-
} bit;
58-
} GPIO_FUNC_OUT_SEL_CFG;
63+
}
64+
bit;
65+
}
66+
GPIO_FUNC_OUT_SEL_CFG;
5967

60-
typedef union {
68+
typedef union
69+
{
6170
__IOM uint32_t reg;
62-
63-
struct {
71+
72+
struct
73+
{
6474
__IOM uint32_t REG_PAD_DRV : 2;
6575
__IOM uint32_t REG_PAD_RDE : 1;
6676
__IOM uint32_t REG_PAD_RUE : 1;
@@ -72,8 +82,10 @@ typedef union {
7282
__IOM uint32_t REG_PAD_FUN_IE : 1;
7383
__IOM uint32_t REG_PAD_FILTER_EN : 1;
7484
uint32_t : 20;
75-
} bit;
76-
} LP_IO_MUX_GPIO;
85+
}
86+
bit;
87+
}
88+
LP_IO_MUX_GPIO;
7789

7890
//-----------------------------------------------------------------------------------------
7991
/// \brief
@@ -84,14 +96,16 @@ typedef union {
8496
//-----------------------------------------------------------------------------------------
8597
void gpio_cfg_output(uint8_t pin)
8698
{
87-
if(pin > 54)
88-
return;
89-
90-
volatile IO_MUX_GPIO* pIO_MUX_GPIO = (volatile IO_MUX_GPIO*)(IO_MUX_BASE + 4ul + 4ul*pin);
91-
volatile GPIO_FUNC_OUT_SEL_CFG* pGPIO_FUNC_OUT_SEL_CFG = (volatile GPIO_FUNC_OUT_SEL_CFG*)(GPIO_BASE + 0x558ul + 4ul*pin);
92-
volatile LP_IO_MUX_GPIO* pLP_IO_MUX_GPIO = (volatile LP_IO_MUX_GPIO*)(LP_IO_MUX_BASE + 8ul + 4ul*pin);
93-
volatile uint32_t* pGPIO_OUTx_W1TC = (volatile uint32_t*)(GPIO_BASE + ((pin < 32u) ? (0x0Cul) : (0x18ul)));
94-
volatile uint32_t* pGPIO_ENABLE1x_W1TS = (volatile uint32_t*)(GPIO_BASE + ((pin < 32u) ? (0x24ul) : (0x30ul)));
99+
if((unsigned) pin > 54u)
100+
{
101+
return;
102+
}
103+
104+
volatile IO_MUX_GPIO* pIO_MUX_GPIO = (volatile IO_MUX_GPIO*)(IO_MUX_BASE + 4u + 4u * (unsigned) pin);
105+
volatile GPIO_FUNC_OUT_SEL_CFG* pGPIO_FUNC_OUT_SEL_CFG = (volatile GPIO_FUNC_OUT_SEL_CFG*)(GPIO_BASE + 0x558ul + 4u * (unsigned) pin);
106+
volatile LP_IO_MUX_GPIO* pLP_IO_MUX_GPIO = (volatile LP_IO_MUX_GPIO*)(LP_IO_MUX_BASE + 8u + 4u * (unsigned) pin);
107+
volatile uint32_t* pGPIO_OUTx_W1TC = (volatile uint32_t*)(GPIO_BASE + (((unsigned) pin < 32u) ? 0x0Cu : 0x18u));
108+
volatile uint32_t* pGPIO_ENABLE1x_W1TS = (volatile uint32_t*)(GPIO_BASE + (((unsigned) pin < 32u) ? 0x24u : 0x30u));
95109

96110
/* configure the pinmux */
97111
pIO_MUX_GPIO->bit.FUN_DRV = 2;
@@ -109,8 +123,8 @@ void gpio_cfg_output(uint8_t pin)
109123
}
110124

111125
/* drive the IO output low */
112-
*pGPIO_OUTx_W1TC = (uint32_t)(1ul << ((pin < 32ul) ? (pin) : (pin - 32ul)));
113-
*pGPIO_ENABLE1x_W1TS = (uint32_t)(1ul << ((pin < 32ul) ? (pin) : (pin - 32ul)));
126+
*pGPIO_OUTx_W1TC = (uint32_t)(1u << (((unsigned) pin < 32u) ? (unsigned) pin : ((unsigned) pin - 32u)));
127+
*pGPIO_ENABLE1x_W1TS = (uint32_t)(1u << (((unsigned) pin < 32u) ? (unsigned) pin : ((unsigned) pin - 32u)));
114128
}
115129

116130
//-----------------------------------------------------------------------------------------
@@ -122,12 +136,14 @@ void gpio_cfg_output(uint8_t pin)
122136
//-----------------------------------------------------------------------------------------
123137
void gpio_set_output_level(uint8_t pin, uint8_t level)
124138
{
125-
volatile uint32_t* pGPIO_OUT_W1Tx = (volatile uint32_t*)(GPIO_BASE + ((pin < 32u) ? (8ul) : (0x14ul)) + ((level == 1u) ? (0ul) : (4ul)));
139+
volatile uint32_t* pGPIO_OUT_W1Tx = (volatile uint32_t*)(GPIO_BASE + (((unsigned) pin < 32u) ? 8u : 0x14u) + (((unsigned) level == 1u) ? (0u) : (4u)));
126140

127-
if((pin > 54) && (level > 1))
141+
if(((unsigned) pin > 54u) || ((unsigned) level > 1u))
142+
{
128143
return;
144+
}
129145

130-
*pGPIO_OUT_W1Tx = (uint32_t)(1ul << ((pin < 32ul) ? (pin) : (pin - 32ul)));
146+
*pGPIO_OUT_W1Tx = (uint32_t)(1u << (((unsigned) pin < 32u) ? (unsigned) pin : ((unsigned) pin - 32u)));
131147
}
132148

133149
//-----------------------------------------------------------------------------------------
@@ -139,10 +155,12 @@ void gpio_set_output_level(uint8_t pin, uint8_t level)
139155
//-----------------------------------------------------------------------------------------
140156
void gpio_toggle_output_level(uint8_t pin)
141157
{
142-
volatile uint32_t* pGPIO_OUT = (volatile uint32_t*)(GPIO_BASE + 4ul + ((pin < 32u) ? 0ul : 0xcul));
158+
volatile uint32_t* pGPIO_OUT = (volatile uint32_t*)(GPIO_BASE + 4u + (((unsigned) pin < 32u) ? 0u : 0xCu));
143159

144-
if(pin > 54)
160+
if((unsigned) pin > 54u)
161+
{
145162
return;
163+
}
146164

147-
*pGPIO_OUT ^= (uint32_t)(1ul << ((pin < 32u) ? (pin) : (pin - 32u)));
148-
}
165+
*pGPIO_OUT ^= (uint32_t)(1u << (((unsigned) pin < 32u) ? (unsigned) pin : ((unsigned) pin - 32u)));
166+
}

ref_app/target/micros/xtensa_esp32_p4/startup/Code/Mcal/interrupt.h

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,24 @@ extern "C"
2525
{
2626
#endif
2727

28-
typedef struct {
28+
typedef struct
29+
{
2930

3031
uint8_t clicintip; /* Interrupt pending register */
3132
uint8_t clicintie; /* Interrupt enable register */
3233
uint8_t clicintattr; /* Interrupt attribute register */
3334
uint8_t clicintct; /* Interrupt level control register*/
34-
}clicint_t;
35-
36-
typedef struct {
35+
}
36+
clicint_t;
3737

38+
typedef struct
39+
{
3840
uint32_t mcliccfg; /* CLIC machine mode global configuration register */
3941
uint32_t clicinfo; /* CLIC information register */
4042
uint32_t mintthresh; /* CLIC machine mode interrupt threshold register */
4143
clicint_t interrupt[48] __attribute__((aligned(0x1000))); /* CLIC interrupt configuration registers */
42-
}clic_t;
44+
}
45+
clic_t;
4346

4447
#define CLIC_BASE 0x20800000ul
4548
#define CLIC ((volatile clic_t*)(CLIC_BASE))

0 commit comments

Comments
 (0)