Redefining a Declared (undefined?) Struct as Another Struct
From this Question: "Accessing a member of a pointer (variable) struct
within a struct". We could use an (undefined?) struct to accept some
(unknown type?) parameters: The 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. After discussion in the previous
question, We finally arrived to this struct declaration:
typedef unsigned int u32_t;
typedef unsigned char u8_t;
typedef struct _interface_t{
struct PERIPH_BASE * BASE;
u8_t ID;
u32_t MODE;
} interface_t;
interface_t USART0_DEV = {(struct PERIPH_BASE *)AT91C_BASE_US0,
AT91C_ID_US0, 0}; // <-- AT91C_BASE_US0 struct as *BASE
interface_t TC0_DEV = {(struct PERIPH_BASE *)AT91C_BASE_TC0,
AT91C_ID_TC0, 0}; // <-- AT91C_BASE_TC0 struct as *BASE
interface_t TWI_DEV = {(struct PERIPH_BASE *)AT91C_BASE_TWI,
AT91C_ID_TWI, 0}; // <-- AT91C_BASE_TWI struct as *BASE
...
unsigned char ConfigureDevice(Interface_t *Interface, u32_t config, u32_t
Speed, u32_t IRQ_Trigger,...){
...
USART_Configure(Interface, config, Speed, PERIPHERALS_CLOCK);
//ERROR1
if (*Interface_irq_handler != NULL){
((AT91S_USART)Interface->BASE)->US_IER = IRQ_Trigger;
//ERROR2
}
USART_SetTransmitterEnabled(Interface->BASE, 1);
//ERROR2
USART_SetReceiverEnabled(Interface->BASE, 1);
//ERROR2
}
In this way Eclipse Code Editor Did not throw any warning or error, but
the I Builded all project and Compiler Complained:
incompatible type for argument 1 of 'USART_Configure' (ERROR1)
invalid type argument of '->' (have 'Interface_t') (ERROR2)
Before I was recieving the following error: "cast to union type from type
not present in union";
So, I think that Maybe ater I know the Type of BASE Struct I'm "Recieving"
(AT91S_PWMC, AT91S_USART, AT91S_AIC,... :Please Read Accessing a member of
a pointer (variable) struct within a struct) I can (re)define the
PERIPH_BASE Struct as been just as the Recieved Struct. Please Correct me
if I'm Wrong...
Best Regards!, Thanks in advance for you answers!
No comments:
Post a Comment