基本上,我正在从 RTOS 中的另一线索中获取数据。 此数据是板上的一个针。 所有 IO 端口都在iodefine.h 文件的结构/ 工会中。 请参见 micrium 是如何制造它的 :
struct st_portd {
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} DDR;
unsigned char wk0[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} DR;
unsigned char wk1[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} PORT;
unsigned char wk2[31];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} ICR;
unsigned char wk3[95];
union {
unsigned char BYTE;
struct {
unsigned char B0:1;
unsigned char B1:1;
unsigned char B2:1;
unsigned char B3:1;
unsigned char B4:1;
unsigned char B5:1;
unsigned char B6:1;
unsigned char B7:1;
} BIT;
} PCR;
};
Very clever way if you ask me. So I save this pin as 2 chars in a struct, called Port and Pin.
struct StepperMotor {
CPU_INT32U ID;
CPU_CHAR *EnablePort;
CPU_CHAR EnablePin;
CPU_CHAR *DirectionPort;
CPU_CHAR DirectionPin;
CPU_CHAR *PulsePort;
CPU_CHAR PulsePin;
};
我想这样用针子:
(struct st_portd)(steppermotor->PulsePort)->DR.BYTE ^= (1 << steppermotor->PulsePin);
steppermotor is the struct. Only with this way I get an error saying
在非结构或工会的某事中要求成员DR
How am I able to use the steppermotor->PulsePort->DR.BYTE without making a new variable for it? I hope anyone can help me!