Reputation: 109
I have a problem about "stroage size of a isn't known". I checked the stackoverflow and i found some answers. But, these solutions did not work or i could not use these answers very well.
Please help me to solve my problem. Thanks for your help and have a nice day.
main.c file
#include <avr/io.h>
#include <PORT.h>
int main(void)
{
// Insert code
PORT a;
while(1)
;
return 0;
}
PORT.h file
#ifndef PORT_H_INCLUDED
#define PORT_H_INCLUDED
#include <config.h>
typedef enum PORT_TYPE{
// All port in ATmega328P
PORT_B,
PORT_C,
PORT_D
}PORT_TYPE;
typedef enum PORT_PIN{
// All pins in ATmega328P
PIN_0,
PIN_1,
PIN_2,
PIN_3,
PIN_4,
PIN_5,
PIN_6,
PIN_7
}PORT_PIN;
typedef struct PORT PORT;
void PORT_init(PORT * const me,
void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPortFunction)(PORT * const me));
void PORT_setDirection(PORT * const me, PORT_PIN pinNumber);
void PORT_setStatus(PORT * const me, PORT_PIN pinNumber);
void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber);
void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber);
void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber);
unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber);
unsigned char PORT_readPort(PORT * const me);
PORT * PORT_create(PORT_TYPE whichPort);
void PORT_destroy(PORT * const me);
#endif // PORT_H_INCLUDED
PORT.c file
#include <avr/io.h>
#include <PORT.h>
#define ADDR_PORTB (0x0023)
#define ADDR_PORTC (0x0026)
#define ADDR_PORTD (0x0029)
typedef volatile struct{
// it is used for manipulating registers.
unsigned char pin;
unsigned char ddr;
unsigned char port;
}PORT_hw;
struct PORT{
unsigned char changePIN;
PORT_hw volatile *p_hw;
void (* setDirection)(PORT * const me, PORT_PIN pinNumber);
void (* setStatus)(PORT * const me, PORT_PIN pinNumber);
void (* enablePullResistor)(PORT * const me, PORT_PIN pinNumber);
void (* disablePullResistor)(PORT * const me, PORT_PIN pinNumber);
void (* notifyPinChange)(PORT * const me, PORT_PIN pinNumber);
unsigned char (*readPIN)(PORT * const me, PORT_PIN pinNumber);
unsigned char (*readPort)(PORT * const me);
};
static PORT g_PORT[3];
g_PORT[0].p_hw = (PORT_hw volatile *)ADDR_PORTB;
g_PORT[1].p_hw = (PORT_hw volatile *)ADDR_PORTC;
g_PORT[2].p_hw = (PORT_hw volatile *)ADDR_PORTD;
void PORT_init(PORT * const me,
void (* setDirectionFunction)(PORT * const me, PORT_PIN pinNumber),
void (* setStatusFunction)(PORT * const me, PORT_PIN pinNumber),
void (* enablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* disablePullResistorFunction)(PORT * const me, PORT_PIN pinNumber),
void (* notifyPinChangeFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPINFunction)(PORT * const me, PORT_PIN pinNumber),
unsigned char (*readPortFunction)(PORT * const me)){
me->changePIN = 0x00;
me->pinStatus = 0x00;
me->setDirection = setDirectionFunction;
me->setStatus = setStatusFunction;
me->enablePullResistor = enablePullResistorFunction;
me->disablePullResistor = disablePullResistorFunction;
me->notifyPinChange = notifyPinChangeFunction;
me->readPIN = readPINFunction;
me->readPort = readPortFunction;
}
void PORT_setDirection(PORT * const me, PORT_PIN pinNumber){}
void PORT_setStatus(PORT * const me, PORT_PIN pinNumber){}
void PORT_enablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_disablePullResistor(PORT * const me, PORT_PIN pinNumber){}
void PORT_notifyPinChange(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPIN(PORT * const me, PORT_PIN pinNumber){}
unsigned char PORT_readPort(PORT * const me){}
PORT * PORT_create(PORT_TYPE whichPort){
PORT *p_PORT = &(g_PORT[whichPort]);
PORT_init(p_PORT, PORT_setDirection, PORT_setStatus, PORT_enablePullResistor, PORT_disablePullResistor, PORT_notifyPinChange, PORT_readPIN, PORT_readPort);
return p_PORT;
}
void PORT_destroy(PORT * const me){}
Upvotes: 1
Views: 63
Reputation: 223897
The PORT.h header file declares that struct PORT
exists, but doesn't define it:
typedef struct PORT PORT;
The actual definition is in PORT.c, which is not visible in main.c.
As a result, you can't create a variable of type PORT
. You can however create one of type PORT *
. Because the definition is not known, this is referred to as an opaque pointer.
Judging by the functions defined in PORT.h, you would use the PORT_create function to return a PORT *
that can be subsequently passed to other functions.
Upvotes: 2