Here's the deal: I am working on a C function that configures a struct that contains many members, as the *BASE (Pointer to a Struct),ID,MODE; but the BASE is a struct that might be defined as (say) "struct a", "struct b", "...", depending of the interface. This is the struct (and some examples) declaration:
typedef unsigned int u32_t;
typedef unsigned char u8_t;
typedef struct _interface_t{
u32_t *BASE;
u8_t ID;
u32_t MODE;
} interface_t;
interface_t USART0_DEV = {AT91C_BASE_US0, AT91C_ID_US0, 0}; // <-- Here we have a AT91C_BASE_US0 struct as *BASE
interface_t USART1_DEV = {AT91C_BASE_US1, AT91C_ID_US1, 0};
interface_t TC0_DEV = {AT91C_BASE_TC0, AT91C_ID_TC0, 0}; // <-- Here we have a AT91C_BASE_TC0 struct as *BASE
interface_t TC1_DEV = {AT91C_BASE_TC1, AT91C_ID_TC1, 0};
interface_t TC2_DEV = {AT91C_BASE_TC2, AT91C_ID_TC2, 0};
interface_t TWI_DEV = {AT91C_BASE_TWI, AT91C_ID_TWI, 0}; // <-- Here we have a AT91C_BASE_TWI struct as *BASE
As you see I used u32_t
instead of the struct because I'm declaring a pointer to that struct. Later I have my function defined as:
unsigned char ConfigureDevice(interface_t *Interface, u32_t config, u32_t Speed, u32_t IRQ_Trigger, void (*Interface_irq_handler)(void)){
...
Interface->BASE->US_IER = IRQ_Trigger; //Note: US_IER Must receive a vector to a function
...
}
But I get error 'US_IER could not be resolved'.
So I tried AT91S_USART InterfaceBASE = Interface->BASE; InterfaceBASE->US_IER = IRQ_Trigger;
instead of Interface->BASE->US_IER = IRQ_Trigger;
and got no error. But I can't use this, because I don't always know what kind of interface I'm handling (until I read ID member).
It gets even worst: When I try to compile I keep getting conflicting type qualifiers for 'u32_t'
error in the u32_t
typedef and initialization from incompatible pointer type
and near initialization for USART0_DEV.BASE
warnings in each of the interface_t
definitions.
I searched in the forums but I couldn't figure my error(s) out. These ones kinda helped:
- creating struct within struct
- Defining struct within typedef struct
What's wrong with my code?
What can I do to use something like Interface->BASE->US_IER
EDIT: Hi!, so now this is what I got:
typedef struct _Interface_t{
struct PERIPH_BASE * BASE;
u32_t ID;
u32_t MODE;
Interface_t;
Interface_t USART0_DEV = {(struct PERIPH_BASE *)AT91C_BASE_US0, AT91C_ID_US0, 0};
...
unsigned char ConfigureDevice(Interface_t *Interface, u32_t config, u32_t Speed, u32_t IRQ_Trigger,...
...
((AT91S_SYS)Interface->BASE)->AIC_IECR = IRQ_Trigger; //No problems marked by Eclipse Code Editor
....
}
Looks Fine, but when compiling I get cast to union type from type not present in union
Error...