Hi,
I'm using SDK 2.10.1 for LPC5526. While struggling with code for USART (managed by Peripherals Tools), I checked the code flow when characters are received in an IRQ based configuration.
On receive, the IRQ handler FLEXCOMM0_DriverIRQHandler is called
fsl_flexcomm.c:
void FLEXCOMM0_DriverIRQHandler(void)
{
uint32_t instance;
/* Look up instance number */
instance = FLEXCOMM_GetInstance(FLEXCOMM0);
assert(s_flexcommIrqHandler[instance] != NULL);
s_flexcommIrqHandler[instance]((uint32_t *)s_flexcommBaseAddrs[instance], s_flexcommHandle[instance]);
SDK_ISR_EXIT_BARRIER;
}
FLEXCOMM_GetInstance() iterates over a static array
fsl_flexcomm.c:
static const uint32_t s_flexcommBaseAddrs[] = FLEXCOMM_BASE_ADDRS;
that contains all base addresses in natural order
LPC5526.h:
#define FLEXCOMM_BASE_ADDRS {
FLEXCOMM0_BASE,
FLEXCOMM1_BASE,
FLEXCOMM2_BASE,
FLEXCOMM3_BASE,
FLEXCOMM4_BASE,
FLEXCOMM5_BASE,
FLEXCOMM6_BASE,
FLEXCOMM7_BASE,
FLEXCOMM8_BASE }
As you can see, the handler contains the base address of flexcom instance 0 hard coded and iterates over all possible base addresses to figure out the instance of this handler.
I think this violates the guideline to keep handler code short and concise.
Most of all, as the instance number should be well known at compile time. For example, there could be a define #define FLEXCOMM0_INSTANCE 0 to avoid the iteration.
I wonder why the code is so odd?