Question
Question 2: Memory-Mapped I/O and GPIO Ports You are given the following code that accesses GPIO Port A. Explain the port macro definition by explaining
Question 2: Memory-Mapped I/O and GPIO Ports
- You are given the following code that accesses GPIO Port A. Explain the port macro definition by explaining what each part of the definition means or does, i.e., each keyword and symbol used.
#define PA (*((volatile unsigned long *)0x400043FC)) data = PA;
}
void wait3(void){ volatile unsigned long *pt;
pt = ______________________;
while(_____________________){}; }
- Consider the following C code that uses a data structure to access memory-mapped GPIO ports.
struct theport{ unsigned char mask; // defines which bits are active volatile unsigned long *addr; // pointer to data reg volatile unsigned long *ddr;}; // pointer to direction reg
typedef struct theport port_t;
port_t PortB, PortF;
PortB.mask = 0xFF; // the TM4C123 has 8 bits on PORTB PortB.addr = (volatile unsigned long *)(0x400053FC); PortB.ddr = (volatile unsigned long *)(0x40005400); PortE.mask = 0x3F; // the TM4C123 has 6 bits on PORTE PortE.addr = (volatile unsigned long *)(0x400243FC); PortE.ddr = (volatile unsigned long *)(0x40024400); (*PortE.ddr) = 0; // specify PortE as inputs (*PortB.addr) = (*PortE.addr); // copy from PortE to PortB
- Given the above code, write a line of code to specify Port B pins as outputs using its direction register.
- Write a line of code in this function to write the 8-bit data to a ports data register, where the port struct variable is passed by reference in a function call (e.g., WriteData(&PortB,0xC4), which would write the value 0xC4 to the Port B data register).
void WriteData (port_t *ppt, unsigned char data){
} Will rate thanks!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started