|
6 | 6 | // ============================================================================ |
7 | 7 | // Global bus instances |
8 | 8 | // ============================================================================ |
| 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 | + |
9 | 17 | I3CBus I3C; |
10 | 18 |
|
11 | 19 | // ============================================================================ |
@@ -78,14 +86,14 @@ extern "C" void HAL_I3C_NotifyCallback(I3C_HandleTypeDef *hi3c, uint32_t eventId |
78 | 86 | { |
79 | 87 | if ((hi3c != nullptr) && (hi3c->Instance != nullptr)) { |
80 | 88 | #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); |
83 | 91 | } |
84 | 92 | #endif |
85 | 93 |
|
86 | 94 | #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); |
89 | 97 | } |
90 | 98 | #endif |
91 | 99 | } |
@@ -1941,30 +1949,67 @@ bool I3CBus::buildTargetTiming(LL_I3C_TgtBusConfTypeDef &outTgt) const |
1941 | 1949 | // ============================================================================ |
1942 | 1950 | // IRQ handlers |
1943 | 1951 | // ============================================================================ |
| 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 | +} |
1944 | 1981 |
|
1945 | 1982 | extern "C" void I3C1_EV_IRQHandler(void) |
1946 | 1983 | { |
1947 | 1984 | #if defined(I3C1) |
1948 | | - HAL_I3C_EV_IRQHandler(I3C1Bus.halHandle()); |
| 1985 | + if (g_i3c1Owner != nullptr) { |
| 1986 | + HAL_I3C_EV_IRQHandler(g_i3c1Owner->halHandle()); |
| 1987 | + } |
1949 | 1988 | #endif |
1950 | 1989 | } |
1951 | 1990 |
|
1952 | 1991 | extern "C" void I3C1_ER_IRQHandler(void) |
1953 | 1992 | { |
1954 | 1993 | #if defined(I3C1) |
1955 | | - HAL_I3C_ER_IRQHandler(I3C1Bus.halHandle()); |
| 1994 | + if (g_i3c1Owner != nullptr) { |
| 1995 | + HAL_I3C_ER_IRQHandler(g_i3c1Owner->halHandle()); |
| 1996 | + } |
1956 | 1997 | #endif |
1957 | 1998 | } |
1958 | 1999 |
|
1959 | 2000 | #if defined(I3C2) |
1960 | 2001 | extern "C" void I3C2_EV_IRQHandler(void) |
1961 | 2002 | { |
1962 | | - HAL_I3C_EV_IRQHandler(I3C2Bus.halHandle()); |
| 2003 | + if (g_i3c2Owner != nullptr) { |
| 2004 | + HAL_I3C_EV_IRQHandler(g_i3c2Owner->halHandle()); |
| 2005 | + } |
1963 | 2006 | } |
1964 | 2007 |
|
1965 | 2008 | extern "C" void I3C2_ER_IRQHandler(void) |
1966 | 2009 | { |
1967 | | - HAL_I3C_ER_IRQHandler(I3C2Bus.halHandle()); |
| 2010 | + if (g_i3c2Owner != nullptr) { |
| 2011 | + HAL_I3C_ER_IRQHandler(g_i3c2Owner->halHandle()); |
| 2012 | + } |
1968 | 2013 | } |
1969 | 2014 | #endif |
1970 | 2015 |
|
|
0 commit comments