Skip to content

Commit ff34982

Browse files
committed
fix(i3c): route IRQ and HAL notify callbacks to the active bus instance
Signed-off-by: Aymane Bahssain <aymane.bahssain@st.com>
1 parent 673c32a commit ff34982

2 files changed

Lines changed: 59 additions & 8 deletions

File tree

‎libraries/I3C/src/I3C.cpp‎

Lines changed: 53 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
// ============================================================================
77
// Global bus instances
88
// ============================================================================
9+
#if defined(I3C1)
10+
static I3CBus *g_i3c1Owner = nullptr;
11+
#endif
12+
13+
#if defined(I3C2)
14+
static I3CBus *g_i3c2Owner = nullptr;
15+
#endif
16+
917
I3CBus I3C;
1018

1119
// ============================================================================
@@ -78,14 +86,14 @@ extern "C" void HAL_I3C_NotifyCallback(I3C_HandleTypeDef *hi3c, uint32_t eventId
7886
{
7987
if ((hi3c != nullptr) && (hi3c->Instance != nullptr)) {
8088
#if defined(I3C1)
81-
if (hi3c->Instance == I3C1) {
82-
I3C1Bus.handleHalNotify(eventId);
89+
if ((hi3c->Instance == I3C1) && (g_i3c1Owner != nullptr)) {
90+
g_i3c1Owner->handleHalNotify(eventId);
8391
}
8492
#endif
8593

8694
#if defined(I3C2)
87-
if (hi3c->Instance == I3C2) {
88-
I3C2Bus.handleHalNotify(eventId);
95+
if ((hi3c->Instance == I3C2) && (g_i3c2Owner != nullptr)) {
96+
g_i3c2Owner->handleHalNotify(eventId);
8997
}
9098
#endif
9199
}
@@ -1941,30 +1949,67 @@ bool I3CBus::buildTargetTiming(LL_I3C_TgtBusConfTypeDef &outTgt) const
19411949
// ============================================================================
19421950
// IRQ handlers
19431951
// ============================================================================
1952+
void I3CBus::registerInstanceOwner()
1953+
{
1954+
#if defined(I3C1)
1955+
if (_instance == I3C1) {
1956+
g_i3c1Owner = this;
1957+
}
1958+
#endif
1959+
1960+
#if defined(I3C2)
1961+
if (_instance == I3C2) {
1962+
g_i3c2Owner = this;
1963+
}
1964+
#endif
1965+
}
1966+
1967+
void I3CBus::unregisterInstanceOwner()
1968+
{
1969+
#if defined(I3C1)
1970+
if ((g_i3c1Owner == this) && (_instance == I3C1)) {
1971+
g_i3c1Owner = nullptr;
1972+
}
1973+
#endif
1974+
1975+
#if defined(I3C2)
1976+
if ((g_i3c2Owner == this) && (_instance == I3C2)) {
1977+
g_i3c2Owner = nullptr;
1978+
}
1979+
#endif
1980+
}
19441981

19451982
extern "C" void I3C1_EV_IRQHandler(void)
19461983
{
19471984
#if defined(I3C1)
1948-
HAL_I3C_EV_IRQHandler(I3C1Bus.halHandle());
1985+
if (g_i3c1Owner != nullptr) {
1986+
HAL_I3C_EV_IRQHandler(g_i3c1Owner->halHandle());
1987+
}
19491988
#endif
19501989
}
19511990

19521991
extern "C" void I3C1_ER_IRQHandler(void)
19531992
{
19541993
#if defined(I3C1)
1955-
HAL_I3C_ER_IRQHandler(I3C1Bus.halHandle());
1994+
if (g_i3c1Owner != nullptr) {
1995+
HAL_I3C_ER_IRQHandler(g_i3c1Owner->halHandle());
1996+
}
19561997
#endif
19571998
}
19581999

19592000
#if defined(I3C2)
19602001
extern "C" void I3C2_EV_IRQHandler(void)
19612002
{
1962-
HAL_I3C_EV_IRQHandler(I3C2Bus.halHandle());
2003+
if (g_i3c2Owner != nullptr) {
2004+
HAL_I3C_EV_IRQHandler(g_i3c2Owner->halHandle());
2005+
}
19632006
}
19642007

19652008
extern "C" void I3C2_ER_IRQHandler(void)
19662009
{
1967-
HAL_I3C_ER_IRQHandler(I3C2Bus.halHandle());
2010+
if (g_i3c2Owner != nullptr) {
2011+
HAL_I3C_ER_IRQHandler(g_i3c2Owner->halHandle());
2012+
}
19682013
}
19692014
#endif
19702015

‎libraries/I3C/src/I3C.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,12 @@ class I3CBus {
532532
bool buildControllerTiming(uint32_t freq, LL_I3C_CtrlBusConfTypeDef &outCtrl) const;
533533
bool buildTargetTiming(LL_I3C_TgtBusConfTypeDef &outTgt) const;
534534

535+
// ------------------------------------------------------------------------
536+
// Irq helpers
537+
// ------------------------------------------------------------------------
538+
void registerInstanceOwner();
539+
void unregisterInstanceOwner();
540+
535541
// ------------------------------------------------------------------------
536542
// Internal state
537543
// ------------------------------------------------------------------------

0 commit comments

Comments
 (0)