8 static void (*PortA_Callbacks[32])(void);
9 static void (*PortD_Callbacks[32])(void);
15 memset(PortA_Callbacks, 0,
sizeof(PortA_Callbacks));
16 memset(PortD_Callbacks, 0,
sizeof(PortD_Callbacks));
30 PortA_Callbacks[pin] = f;
31 }
else if(port ==
PORTD) {
32 PortD_Callbacks[pin] = f;
34 printf(
"ERROR: Attempt to register interrupt on un-supported port.\n\r");
53 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
54 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
60 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
61 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
62 Port->
PCR[Pin] |= PORT_PCR_IRQC_ZERO;
68 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
69 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
70 Port->
PCR[Pin] |= PORT_PCR_IRQC_RISING;
76 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
77 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
78 Port->
PCR[Pin] |= PORT_PCR_IRQC_FALLING;
84 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
85 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
86 Port->
PCR[Pin] |= PORT_PCR_IRQC_EDGE;
92 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
93 Port->
PCR[Pin] = Port->
PCR[Pin] & ~(PORT_PCR_IRQC_MASK);
94 Port->
PCR[Pin] |= PORT_PCR_IRQC_ONE;
106 Port->
ISFR = Pin_Mask;
112 if(Port->
PCR[Pin] & PORT_PCR_ISF_MASK) {
122 Port->
PCR[Pin] |= PORT_PCR_ISF_MASK;
131 Port->
PDDR &= ~(Pin_Mask);
137 Port->
PDDR |= Pin_Mask;
143 Port->
PSOR |= Pin_Mask;
149 Port->
PCOR |= Pin_Mask;
155 Port->
PTOR |= Pin_Mask;
161 return (((Port->
PDOR & Port->
PDDR) | (Port->
PDIR & ~(Port->
PDDR))) & Pin_Mask);
168 void PORTA_IRQHandler(
void)
173 ENERGEST_ON(ENERGEST_TYPE_IRQ);
177 for(i = 0; i < 32; i++) {
179 if(PortA_Callbacks[i] !=
NULL) {
180 (*PortA_Callbacks[i])();
188 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
193 void PORTD_IRQHandler(
void)
198 ENERGEST_ON(ENERGEST_TYPE_IRQ);
202 for(i = 0; i < 32; i++) {
204 if(PortD_Callbacks[i] !=
NULL) {
205 (*PortD_Callbacks[i])();
213 ENERGEST_OFF(ENERGEST_TYPE_IRQ);
__O uint32_t PSOR
Port Set Output Register, offset: 0x4.
void gpio_init()
Initialise the GPIO module.
__O uint32_t PCOR
Port Clear Output Register, offset: 0x8.
__IO uint32_t PDDR
Port Data Direction Register, offset: 0x14.
void port_conf_pin_int_rise(PORT_Type *Port, uint8_t Pin)
Configure rising-edge interrupt on the specified Pin of the port with PORTx_BASE_PTR.
__IO uint32_t PDOR
Port Data Output Register, offset: 0x0.
void port_conf_pin_int_edge(PORT_Type *Port, uint8_t Pin)
Configure either-edge interrupt on the specified Pin of the port with PORTx_BASE_PTR.
__I uint32_t PDIR
Port Data Input Register, offset: 0x10.
void NVIC_Set_Priority(uint32_t IRQ, uint8_t priority)
Set the priority of the specified interrupt in the ARM NVIC.
void gpio_set_output(GPIO_Type *Port, uint32_t Pin_Mask)
Set pins with Pin_Mask of port with GPIOn_BASE_PTR to output.
uint32_t gpio_read_pin(GPIO_Type *Port, uint32_t Pin_Mask)
Read pins with Pin_Mask of port with GPIOn_BASE_PTR.
Header file for the energy estimation mechanism
void NVIC_CLEAR_PENDING(uint32_t IRQ)
Clear a pending interrupt for the specified interrupt in the ARM NVIC.
GPIO - Register Layout Typedef.
__IO uint32_t ISFR
Interrupt Status Flag Register, offset: 0xA0.
bool port_read_pin_isf(PORT_Type *Port, uint8_t Pin)
Return the Interrupt Status Flags of Pin in port with PORTx_BASE_PTR.
void port_conf_pin_int_one(PORT_Type *Port, uint8_t Pin)
Configure one-level interrupt on the specified Pin of the port with PORTx_BASE_PTR.
void port_conf_pin_int_zero(PORT_Type *Port, uint8_t Pin)
Configure zero-level interrupt on the specified Pin of the port with PORTx_BASE_PTR.
void port_clr_isf(PORT_Type *Port, uint32_t Pin_Mask)
Clear the Interrupt Status Flag of port with PORTx_BASE_PTR.
#define PORTD
Peripheral PORTD base pointer.
__IO uint32_t PCR[32]
Pin Control Register n, array offset: 0x0, array step: 0x4.
void port_conf_pin_int_fall(PORT_Type *Port, uint8_t Pin)
Configure falling-edge interrupt on the specified Pin of the port with PORTx_BASE_PTR.
#define PORTA
Peripheral PORTA base pointer.
#define NULL
The null pointer.
void port_register_callback(void *f, PORT_Type *port, uint8_t pin)
Register Port interrupt callback function.
uint32_t port_read_isf(PORT_Type *Port)
Return the Interrupt Status Flags of port with PORTx_BASE_PTR.
void gpio_clr_pin(GPIO_Type *Port, uint32_t Pin_Mask)
Clear pins with Pin_Mask of port with GPIOn_BASE_PTR low.
void port_conf_pin(PORT_Type *Port, uint8_t Pin, uint32_t PCR)
Configure the specified Pin of the port with PORTx_BASE_PTR with PCR.
PORT - Register Layout Typedef.
void gpio_tgl_pin(GPIO_Type *Port, uint32_t Pin_Mask)
Toggle pins with Pin_Mask of port with GPIOn_BASE_PTR low.
__O uint32_t PTOR
Port Toggle Output Register, offset: 0xC.
void gpio_set_input(GPIO_Type *Port, uint32_t Pin_Mask)
Set pins with Pin_Mask of port with GPIOn_BASE_PTR to input.
void port_conf_pin_int_disable(PORT_Type *Port, uint8_t Pin)
Disable interrupt on the specified Pin of the port with PORTx_BASE_PTR.
void NVIC_ENABLE_INT(uint32_t IRQ)
Enable specified interrupt in the ARM NVIC.
void port_pin_clr_isf(PORT_Type *Port, uint8_t Pin)
Clear the Interrupt Status Flag of Pin in port with PORTx_BASE_PTR.
void gpio_set_pin(GPIO_Type *Port, uint32_t Pin_Mask)
Set pins with Pin_Mask of port with GPIOn_BASE_PTR high.
uint32_t port_pin_to_mask(uint8_t pin)
Convert a pin number (0 to 31) to a pin mask.