//***************************************************************************** // //! Sets the interrupt type for the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! \param ui32IntType specifies the type of interrupt trigger mechanism. //! //! This function sets up the various interrupt trigger mechanisms for the //! specified pin(s) on the selected GPIO port. //! //! The parameter \e ui32IntType is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_FALLING_EDGE //! - \b GPIO_RISING_EDGE //! - \b GPIO_BOTH_EDGES //! - \b GPIO_LOW_LEVEL //! - \b GPIO_HIGH_LEVEL //! //! where the different values describe the interrupt detection mechanism //! (edge or level) and the particular triggering event (falling, rising, //! or both edges for edge detect, low or high for level detect). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note To avoid any spurious interrupts, the user must //! ensure that the GPIO inputs remain stable for the duration of //! this function. //! //! \return None // //***************************************************************************** void GPIOIntTypeSet(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32IntType) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT((ui32IntType == GPIO_FALLING_EDGE) || (ui32IntType == GPIO_RISING_EDGE) || (ui32IntType == GPIO_BOTH_EDGES) || (ui32IntType == GPIO_LOW_LEVEL) || (ui32IntType == GPIO_HIGH_LEVEL)); // // Set the pin interrupt type. // HWREG(ui32Port + GPIO_O_IBE) = ((ui32IntType & 1) ? (HWREG(ui32Port + GPIO_O_IBE) | ui8Pins) : (HWREG(ui32Port + GPIO_O_IBE) & ~(ui8Pins))); HWREG(ui32Port + GPIO_O_IS) = ((ui32IntType & 2) ? (HWREG(ui32Port + GPIO_O_IS) | ui8Pins) : (HWREG(ui32Port + GPIO_O_IS) & ~(ui8Pins))); HWREG(ui32Port + GPIO_O_IEV) = ((ui32IntType & 4) ? (HWREG(ui32Port + GPIO_O_IEV) | ui8Pins) : (HWREG(ui32Port + GPIO_O_IEV) & ~(ui8Pins))); }
//***************************************************************************** // //! Sets the interrupt type for the specified pin(s). //! //! \param ulPort is the base address of the GPIO port. //! \param ucPins is the bit-packed representation of the pin(s). //! \param ulIntType specifies the type of interrupt trigger mechanism. //! //! This function sets up the various interrupt trigger mechanisms for the //! specified pin(s) on the selected GPIO port. //! //! The parameter \e ulIntType is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_FALLING_EDGE //! - \b GPIO_RISING_EDGE //! - \b GPIO_BOTH_EDGES //! - \b GPIO_LOW_LEVEL //! - \b GPIO_HIGH_LEVEL //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note In order to avoid any spurious interrupts, the user must //! ensure that the GPIO inputs remain stable for the duration of //! this function. //! //! \return None. // //***************************************************************************** void GPIOIntTypeSet(unsigned long ulPort, unsigned char ucPins, unsigned long ulIntType) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); ASSERT((ulIntType == GPIO_FALLING_EDGE) || (ulIntType == GPIO_RISING_EDGE) || (ulIntType == GPIO_BOTH_EDGES) || (ulIntType == GPIO_LOW_LEVEL) || (ulIntType == GPIO_HIGH_LEVEL)); // // Set the pin interrupt type. // HWREG(ulPort + GPIO_O_GPIO_IBE) = ((ulIntType & 1) ? (HWREG(ulPort + GPIO_O_GPIO_IBE) | ucPins) : (HWREG(ulPort + GPIO_O_GPIO_IBE) & ~(ucPins))); HWREG(ulPort + GPIO_O_GPIO_IS) = ((ulIntType & 2) ? (HWREG(ulPort + GPIO_O_GPIO_IS) | ucPins) : (HWREG(ulPort + GPIO_O_GPIO_IS) & ~(ucPins))); HWREG(ulPort + GPIO_O_GPIO_IEV) = ((ulIntType & 4) ? (HWREG(ulPort + GPIO_O_GPIO_IEV) | ucPins) : (HWREG(ulPort + GPIO_O_GPIO_IEV) & ~(ucPins))); }
//***************************************************************************** // //! Gets the interrupt type for a pin //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pin is the pin number. //! //! This function gets the interrupt type for a specified pin on the selected //! GPIO port. The pin can be configured as a falling edge, rising edge, or //! both edge detected interrupt, or can be configured as a low level or //! high level detected interrupt. The type of interrupt detection mechanism //! is returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIOIntTypeSet(). // //***************************************************************************** uint32_t GPIOIntTypeGet(uint32_t ui32Port, uint8_t ui8Pin) { uint32_t ui32IBE, ui32IS, ui32IEV; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT(ui8Pin < 8); // // Convert from a pin number to a bit position. // ui8Pin = 1 << ui8Pin; // // Return the pin interrupt type. // ui32IBE = HWREG(ui32Port + GPIO_O_IBE); ui32IS = HWREG(ui32Port + GPIO_O_IS); ui32IEV = HWREG(ui32Port + GPIO_O_IEV); return(((ui32IBE & ui8Pin) ? 1 : 0) | ((ui32IS & ui8Pin) ? 2 : 0) | ((ui32IEV & ui8Pin) ? 4 : 0)); }
//***************************************************************************** // //! Gets the direction and mode of a pin //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pin is the pin number. //! //! This function gets the direction and control mode for a specified pin on //! the selected GPIO port. The pin can be configured as either an input or //! output under software control, or it can be under hardware control. The //! type of control and direction are returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIODirModeSet(). // //***************************************************************************** uint32_t GPIODirModeGet(uint32_t ui32Port, uint8_t ui8Pin) { uint32_t ui32Dir; uint32_t ui32AFSEL; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT(ui8Pin < 8); // // Convert from a pin number to a bit position. // ui8Pin = 1 << ui8Pin; // // Return the pin direction and mode. // ui32Dir = HWREG(ui32Port + GPIO_O_DIR); ui32AFSEL = HWREG(ui32Port + GPIO_O_AFSEL); return(((ui32Dir & ui8Pin) ? GPIO_DIR_MODE_OUT : GPIO_DIR_MODE_IN) | ((ui32AFSEL & ui8Pin) ? GPIO_DIR_MODE_HW : GPIO_DIR_MODE_IN)); }
//***************************************************************************** // //! Disables a GPIO port as a trigger to start a DMA transaction. //! //! \param ulPort is the base address of the GPIO port. //! //! This function disables a GPIO port to be used as a trigger to start a uDMA //! transaction. This function can be used to disable this feature if it was //! enabled via a call to GPIODMATriggerEnable(). //! //! \return None. // //***************************************************************************** void GPIODMATriggerDisable(unsigned long ulPort) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Set the pin as a DMA trigger. // if(ulPort == GPIOA0_BASE) { HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x1; } else if(ulPort == GPIOA1_BASE) { HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x2; } else if(ulPort == GPIOA2_BASE) { HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x4; } else if(ulPort == GPIOA3_BASE) { HWREG(COMMON_REG_BASE + COMMON_REG_O_APPS_GPIO_TRIG_EN) &= ~0x8; } }
//***************************************************************************** // //! \brief Sets the direction and mode of the specified pin(s). //! //! \param ulPort is the base address of the GPIO port //! \param ulPins is the bit-packed representation of the pin(s). //! \param ulPinIO is the pin direction and/or mode. //! //! This function will set the specified pin(s) on the selected GPIO port //! as either an input or output under software control, or it will set the //! pin to be under hardware control. //! //! The parameter \e ulPinIO is an enumerated data type that can be one of //! the following values: //! //! - \b xGPIO_DIR_MODE_IN //! - \b xGPIO_DIR_MODE_OUT //! - \b xGPIO_DIR_MODE_OD //! - \b xGPIO_DIR_MODE_HW //! //! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as //! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin //! will be programmed as a software controlled output, and //! \b GPIO_DIR_MODE_HW specifies that the pin will be placed under //! hardware control.\b GPIO_DIR_MODE_OD specifies that the pin will be //! programmed as a Open-Drain.\b GPIO_DIR_MODE_QB specifies that the pin //! will be programmed as Quasi-bidirectional //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None. // //***************************************************************************** void xGPIODirModeSet(unsigned long ulPort, unsigned long ulPins, unsigned long ulPinIO) { unsigned long ulBit; // // Check the arguments. // xASSERT(GPIOBaseValid(ulPort)); xASSERT((ulPinIO == xGPIO_DIR_MODE_IN) || (ulPinIO == xGPIO_DIR_MODE_OUT) || (ulPinIO == xGPIO_DIR_MODE_OD)); // // Set the pin direction and mode. // for(ulBit=0; ulBit<16; ulBit++) { if(ulPins & (1 << ulBit)) { GPIODirModeSet(ulPort, ulBit, ulPinIO & 0xC, ulPinIO & 0x3); } } }
//***************************************************************************** // //! Gets the interrupt type for a pin. //! //! \param ulPort is the base address of the GPIO port. //! \param ucPin is the pin number. //! //! This function gets the interrupt type for a specified pin on the selected //! GPIO port. The pin can be configured as a falling edge, rising edge, or //! both edge detected interrupt, or it can be configured as a low level or //! high level detected interrupt. The type of interrupt detection mechanism //! is returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIOIntTypeSet(). // //***************************************************************************** unsigned long GPIOIntTypeGet(unsigned long ulPort, unsigned char ucPin) { unsigned long ulIBE, ulIS, ulIEV; // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); ASSERT(ucPin < 8); // // Convert from a pin number to a bit position. // ucPin = 1 << ucPin; // // Return the pin interrupt type. // ulIBE = HWREG(ulPort + GPIO_O_GPIO_IBE); ulIS = HWREG(ulPort + GPIO_O_GPIO_IS); ulIEV = HWREG(ulPort + GPIO_O_GPIO_IEV); return(((ulIBE & ucPin) ? 1 : 0) | ((ulIS & ucPin) ? 2 : 0) | ((ulIEV & ucPin) ? 4 : 0)); }
//***************************************************************************** // //! Sets the power-up interrupt type for the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! \param ui32IntType specifies type of power-up interrupt trigger mechanism. //! //! This function sets up the various interrupt trigger mechanisms for the //! specified pin(s) on the selected GPIO port. //! //! The parameter \e ui32IntType is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_POW_FALLING_EDGE //! - \b GPIO_POW_RISING_EDGE //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note To avoid any spurious interrupts, the user must //! ensure that the GPIO inputs remain stable for the duration of //! this function. //! //! \return None // //***************************************************************************** void GPIOPowIntTypeSet(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32IntType) { uint32_t ui32PortOffset; uint32_t ui32IntPins; // // Initialize value // ui32PortOffset = 0; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT((ui32IntType == GPIO_POW_FALLING_EDGE) || (ui32IntType == GPIO_POW_RISING_EDGE)); // // Find bit mask for wanted pin(s) // if(ui32Port == GPIO_A_BASE) { ui32PortOffset = 0; } if(ui32Port == GPIO_B_BASE) { ui32PortOffset = 8; } if(ui32Port == GPIO_C_BASE) { ui32PortOffset = 16; } if(ui32Port == GPIO_D_BASE) { ui32PortOffset = 24; } ui32IntPins = ui8Pins << ui32PortOffset; // // Set the pin interrupt type. // if(ui32IntType == GPIO_POW_FALLING_EDGE) { HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) |= ui32IntPins; } else // GPIO_POW_RAISING_EDGE { HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) &= ~(ui32IntPins); } }
//***************************************************************************** // //! Writes a value to the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! \param ui8Val is the value to write to the pin(s). //! //! Writes the corresponding bit values to the output pin(s) specified by //! \e ui8Pins. Writing to a pin configured as an input pin has no effect. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None // //***************************************************************************** void GPIOPinWrite(uint32_t ui32Port, uint8_t ui8Pins, uint8_t ui8Val) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Write the pins. // HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2))) = ui8Val; }
//***************************************************************************** // //! Disables the specified GPIO interrupts. //! //! \param ulPort is the base address of the GPIO port. //! \param ulIntFlags is the bit mask of the interrupt sources to disable. //! //! This function disables the indicated GPIO interrupt sources. Only the //! sources that are enabled can be reflected to the processor interrupt; //! disabled sources have no effect on the processor. //! //! The \e ulIntFlags parameter is the logical OR of any of the following: //! //! - \b GPIO_INT_DMA - interrupt due to GPIO triggered DMA Done //! - \b GPIO_INT_PIN_0 - interrupt due to activity on Pin 0. //! - \b GPIO_INT_PIN_1 - interrupt due to activity on Pin 1. //! - \b GPIO_INT_PIN_2 - interrupt due to activity on Pin 2. //! - \b GPIO_INT_PIN_3 - interrupt due to activity on Pin 3. //! - \b GPIO_INT_PIN_4 - interrupt due to activity on Pin 4. //! - \b GPIO_INT_PIN_5 - interrupt due to activity on Pin 5. //! - \b GPIO_INT_PIN_6 - interrupt due to activity on Pin 6. //! - \b GPIO_INT_PIN_7 - interrupt due to activity on Pin 7. //! //! \return None. // //***************************************************************************** void GPIOIntDisable(unsigned long ulPort, unsigned long ulIntFlags) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Disable the interrupts. // HWREG(ulPort + GPIO_O_GPIO_IM) &= ~(ulIntFlags); }
//***************************************************************************** // //! Clears the interrupt for the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! Clears the interrupt for the specified pin(s). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note The write buffer in the Cortex-M3 processor can cause the interrupt //! source to take several clock cycles before clearing. //! Therefore, TI recommends clearing the interrupt source early in the //! interrupt handler (as opposed to the very last action) to avoid //! returning from the interrupt handler before the interrupt source is //! actually cleared. Failure to clear the interrupt source early can result in //! the interrupt handler being immediately reentered (because NVIC still sees //! the interrupt source asserted). //! //! \return None // //***************************************************************************** void GPIOPinIntClear(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Clear the interrupts. // HWREG(ui32Port + GPIO_O_IC) = ui8Pins; }
//***************************************************************************** // //! Writes a value to the specified pin(s). //! //! \param ulPort is the base address of the GPIO port. //! \param ucPins is the bit-packed representation of the pin(s). //! \param ucVal is the value to write to the pin(s). //! //! Writes the corresponding bit values to the output pin(s) specified by //! \e ucPins. Writing to a pin configured as an input pin has no effect. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None. // //***************************************************************************** void GPIOPinWrite(unsigned long ulPort, unsigned char ucPins, unsigned char ucVal) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Write the pins. // HWREG(ulPort + (GPIO_O_GPIO_DATA + (ucPins << 2))) = ucVal; }
//***************************************************************************** // //! Disables interrupts for the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! Masks the interrupt for the specified pin(s) //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None // //***************************************************************************** void GPIOPinIntDisable(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Disable the interrupts. // HWREG(ui32Port + GPIO_O_IE) &= ~(ui8Pins); }
//***************************************************************************** // //! Reads the values present of the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! The values at the specified pin(s) are read, as specified by \e ui8Pins. //! Values are returned for both input and output pin(s), and the value //! for pin(s) that are not specified by \e ui8Pins are set to 0. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return Returns a bit-packed byte providing the state of the specified //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents //! GPIO port pin 1, and so on. Any bit that is not specified by \e ui8Pins //! is returned as a 0. Bits 31:8 should be ignored. // //***************************************************************************** uint32_t GPIOPinRead(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Return the pin value(s). // return(HWREG(ui32Port + (GPIO_O_DATA + (ui8Pins << 2)))); }
//***************************************************************************** // //! Clears the interrupt for the specified pin(s). //! //! \param ulPort is the base address of the GPIO port. //! \param ulIntFlags is a bit mask of the interrupt sources to be cleared. //! //! Clears the interrupt for the specified pin(s). //! //! The \e ulIntFlags parameter has the same definition as the \e ulIntFlags //! parameter to GPIOIntEnable(). //! //! //! \return None. // //***************************************************************************** void GPIOIntClear(unsigned long ulPort, unsigned long ulIntFlags) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Clear the interrupts. // HWREG(ulPort + GPIO_O_GPIO_ICR) = ulIntFlags; }
//***************************************************************************** // //! Reads the values present of the specified pin(s). //! //! \param ulPort is the base address of the GPIO port. //! \param ucPins is the bit-packed representation of the pin(s). //! //! The values at the specified pin(s) are read, as specified by \e ucPins. //! Values are returned for both input and output pin(s), and the value //! for pin(s) that are not specified by \e ucPins are set to 0. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return Returns a bit-packed byte providing the state of the specified //! pin, where bit 0 of the byte represents GPIO port pin 0, bit 1 represents //! GPIO port pin 1, and so on. Any bit that is not specified by \e ucPins //! is returned as a 0. Bits 31:8 should be ignored. // //***************************************************************************** long GPIOPinRead(unsigned long ulPort, unsigned char ucPins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Return the pin value(s). // return(HWREG(ulPort + (GPIO_O_GPIO_DATA + (ucPins << 2)))); }
//***************************************************************************** // //! Gets the power-up interrupt type for a pin //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pin is the pin number. //! //! This function gets the interrupt type for a specified pin on the selected //! GPIO port. The pin can be configured as a falling edge, rising edge, or //! both edge detected interrupt, or it can be configured as a low level or //! high level detected interrupt. The type of interrupt detection mechanism //! is returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIOIntTypeSet(). // //***************************************************************************** uint32_t GPIOPowIntTypeGet(uint32_t ui32Port, uint8_t ui8Pin) { uint32_t ui32PortOffset; uint32_t ui32IntPin; // // Initialize value // ui32PortOffset = 0; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT(ui8Pin < 8); // // Convert from a port- pin number to a bit position. // if(ui32Port == GPIO_A_BASE) { ui32PortOffset = 0; } if(ui32Port == GPIO_B_BASE) { ui32PortOffset = 8; } if(ui32Port == GPIO_C_BASE) { ui32PortOffset = 16; } if(ui32Port == GPIO_D_BASE) { ui32PortOffset = 24; } ui32IntPin = 1 << (ui8Pin + ui32PortOffset); // // Return the pin interrupt type. // if(HWREG(ui32Port + GPIO_O_P_EDGE_CTRL) & ui32IntPin) { return(GPIO_POW_FALLING_EDGE); } else { return(GPIO_POW_RISING_EDGE); } }
//***************************************************************************** // //! \internal //! Gets the GPIO interrupt number //! //! \param ui32Port is the base address of the GPIO port. //! //! Given a GPIO base address, returns the corresponding interrupt number. //! //! \return Returns a GPIO interrupt number, or 0 if \e ui32Port is invalid. // //***************************************************************************** uint32_t GPIOGetIntNumber(uint32_t ui32Port) { uint32_t ui32Int; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Determine the GPIO interrupt number for the given module. // switch(ui32Port) { case GPIO_A_BASE: { ui32Int = INT_GPIOA; break; } case GPIO_B_BASE: { ui32Int = INT_GPIOB; break; } case GPIO_C_BASE: { ui32Int = INT_GPIOC; break; } case GPIO_D_BASE: { ui32Int = INT_GPIOD; break; } default: { return(0); } } // // Return GPIO interrupt number. // return(ui32Int); }
//***************************************************************************** // //! Sets the direction and mode of the specified pin(s). //! //! \param ulPort is the base address of the GPIO port //! \param ucPins is the bit-packed representation of the pin(s). //! \param ulPinIO is the pin direction and/or mode. //! //! This function will set the specified pin(s) on the selected GPIO port //! as either an input or output under software control, or it will set the //! pin to be under hardware control. //! //! The parameter \e ulPinIO is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_DIR_MODE_IN //! - \b GPIO_DIR_MODE_OUT //! //! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as //! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin //! will be programmed as a software controlled output. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note GPIOPadConfigSet() must also be used to configure the corresponding //! pad(s) in order for them to propagate the signal to/from the GPIO. //! //! \return None. // //***************************************************************************** void GPIODirModeSet(unsigned long ulPort, unsigned char ucPins, unsigned long ulPinIO) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); ASSERT((ulPinIO == GPIO_DIR_MODE_IN) || (ulPinIO == GPIO_DIR_MODE_OUT)); // // Set the pin direction and mode. // HWREG(ulPort + GPIO_O_GPIO_DIR) = ((ulPinIO & 1) ? (HWREG(ulPort + GPIO_O_GPIO_DIR) | ucPins) : (HWREG(ulPort + GPIO_O_GPIO_DIR) & ~(ucPins))); }
//***************************************************************************** // //! Configures pin(s) for use as GPIO outputs //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! The GPIO pins must be properly configured to function correctly as //! GPIO outputs. This function provides the proper configuration for those //! pin(s). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None // //***************************************************************************** void GPIOPinTypeGPIOOutput(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Make the pin(s) be outputs. // GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_OUT); // // Set the pad(s) no override of the drive type. // IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS); }
//***************************************************************************** // //! Configures pin(s) for use by the Timer peripheral //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! The CCP pins must be properly configured for the timer peripheral to //! function correctly. This function provides a typical configuration for //! those pin(s); other configurations might work as well depending upon the //! board setup (for example, using the on-chip pull-ups). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note This function cannot be used to turn any pin into a timer pin but only //! configures a timer pin for proper operation. //! //! \return None // //***************************************************************************** void GPIOPinTypeTimer(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Make the pin(s) be peripheral controlled. // GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW); // // Set the pad(s) to no drive type. // IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_DIS); }
//***************************************************************************** // //! Configures output pin(s) for use by the UART peripheral //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! The UART output pins must be properly configured for the UART peripheral to //! function correctly. This function provides a typical configuration for //! those pin(s); other configurations might work as well depending upon the //! board setup (for example, using the on-chip pull-ups). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \note This function cannot be used to turn any pin into a UART pin; but only //! configures a UART pin for proper operation. //! //! \return None // //***************************************************************************** void GPIOPinTypeUARTOutput(uint32_t ui32Port, uint8_t ui8Pins) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT(!((ui32Port == GPIO_C_BASE) && ((ui8Pins & 0xf) > 0))); // // Make the pin(s) be peripheral controlled. // GPIODirModeSet(ui32Port, ui8Pins, GPIO_DIR_MODE_HW); // // Set the pad(s) to output enable. // IOCPadConfigSet(ui32Port, ui8Pins, IOC_OVERRIDE_OE); }
//***************************************************************************** // //! Disables power-up interrupts for the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! //! Masks the interrupt for the specified pin(s). //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None // //***************************************************************************** void GPIOPowIntDisable(uint32_t ui32Port, uint8_t ui8Pins) { uint32_t ui32PortOffset; uint32_t ui32IntPins; // // Initialize value // ui32PortOffset = 0; // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Find bit mask for wanted pin(s) // if(ui32Port == GPIO_A_BASE) { ui32PortOffset = 0; } if(ui32Port == GPIO_B_BASE) { ui32PortOffset = 8; } if(ui32Port == GPIO_C_BASE) { ui32PortOffset = 16; } if(ui32Port == GPIO_D_BASE) { ui32PortOffset = 24; } ui32IntPins = ui8Pins << ui32PortOffset; // // Disable the interrupts. // HWREG(ui32Port + GPIO_O_PI_IEN) &= ~(ui32IntPins); }
//***************************************************************************** // //! Gets power-up interrupt status for the specified GPIO port //! //! \param ui32Port is the base address of the GPIO port. //! \param bMasked specifies whether masked or raw interrupt status is //! returned. //! //! If \e bMasked is set as \b true, then the masked interrupt status is //! returned; otherwise, the raw interrupt status is returned. //! //! \return Returns a bit-packed byte, where each bit that is set identifies //! an active masked or raw interrupt, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! Bits 31:8 should be ignored. // //***************************************************************************** uint32_t GPIOPowIntStatus(uint32_t ui32Port, bool bMasked) { uint32_t ui32PortOffset; // // Initialize value // ui32PortOffset = 0; // Check the arguments. ASSERT(GPIOBaseValid(ui32Port)); // // Find bit mask for wanted pin(s) // if(ui32Port == GPIO_A_BASE) { ui32PortOffset = 0; } if(ui32Port == GPIO_B_BASE) { ui32PortOffset = 8; } if(ui32Port == GPIO_C_BASE) { ui32PortOffset = 16; } if(ui32Port == GPIO_D_BASE) { ui32PortOffset = 24; } // Return the interrupt status. if(bMasked) { return((HWREG(ui32Port + GPIO_O_IRQ_DETECT_ACK) >> ui32PortOffset) & 0xFF); } else { return((HWREG(ui32Port + GPIO_O_IRQ_DETECT_UNMASK) >> ui32PortOffset) &
//***************************************************************************** // //! Gets the direction and mode of a pin. //! //! \param ulPort is the base address of the GPIO port. //! \param ulBit is the pin number. //! //! This function gets the direction and control mode for a specified pin on //! the selected GPIO port. The pin can be configured as either an input or //! output under software control, or it can be under hardware control. The //! type of control and direction are returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIODirModeSet(). // //***************************************************************************** unsigned long GPIODirModeGet(unsigned long ulPort, unsigned long ulBit) { // // Check the arguments. // xASSERT(GPIOBaseValid(ulPort)); xASSERT(ulBit < 16); // // Return the pin direction and mode. // if(ulBit < 8) { return((xHWREG(ulPort + GPIO_CRL) & (0xF << (ulBit * 4))) >> (ulBit * 4)); } else { return((xHWREG(ulPort + GPIO_CRH) &
//***************************************************************************** // //! Gets interrupt status for the specified GPIO port //! //! \param ui32Port is the base address of the GPIO port. //! \param bMasked specifies whether masked or raw interrupt status is //! returned. //! //! If \e bMasked is set as \b true, then the masked interrupt status is //! returned; otherwise, the raw interrupt status is returned. //! //! \return Returns a bit-packed byte, where each bit that is set identifies //! an active masked or raw interrupt, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! Bits 31:8 should be ignored. // //***************************************************************************** uint32_t GPIOPinIntStatus(uint32_t ui32Port, bool bMasked) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); // // Return the interrupt status. // if(bMasked) { return(HWREG(ui32Port + GPIO_O_MIS)); } else { return(HWREG(ui32Port + GPIO_O_RIS)); } }
//***************************************************************************** // //! Gets interrupt status for the specified GPIO port. //! //! \param ulPort is the base address of the GPIO port. //! \param bMasked specifies whether masked or raw interrupt status is //! returned. //! //! If \e bMasked is set as \b true, then the masked interrupt status is //! returned; otherwise, the raw interrupt status will be returned. //! //! \return Returns the current interrupt status, enumerated as a bit field of //! values described in GPIOIntEnable(). // //***************************************************************************** long GPIOIntStatus(unsigned long ulPort, tBoolean bMasked) { // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); // // Return the interrupt status. // if(bMasked) { return(HWREG(ulPort + GPIO_O_GPIO_MIS)); } else { return(HWREG(ulPort + GPIO_O_GPIO_RIS)); } }
//***************************************************************************** // //! \brief Sets the direction and pad configuration of the specified pin. //! //! \param ulPort is the base address of the GPIO port //! \param ulBit is the bit number of a port. //! \param ulPinType is the pin direction and/or pad configuration. //! \param ulPinSpeed is input or output speed of specified pin. //! //! This function will set the specified pin(Only 1 pin) on the selected GPIO //! port as either an input or output under software control, or it will set //! the pin to be under hardware control. //! //! The parameter \e ulPinType is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_TYPE_IN_ANALOG //! - \b GPIO_TYPE_IN_FLOATING //! - \b GPIO_TYPE_IN_WPU_WPD //! - \b GPIO_TYPE_OUT_STD //! - \b GPIO_TYPE_OUT_OD //! - \b GPIO_TYPE_AFOUT_STD //! - \b GPIO_TYPE_AFOUT_OD //! //! The parameter \e ulPinSpeed is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_IN_SPEED_FIXED //! - \b GPIO_OUT_SPEED_10M //! - \b GPIO_OUT_SPEED_2M //! - \b GPIO_OUT_SPEED_50M //! //! //! \return None. // //***************************************************************************** void GPIODirModeSet(unsigned long ulPort, unsigned long ulBit, unsigned long ulPinType, unsigned long ulPinSpeed) { // // Check the arguments. // xASSERT(GPIOBaseValid(ulPort)); xASSERT(ulBit < 16); xASSERT((ulPinType == GPIO_TYPE_IN_ANALOG) || (ulPinType == GPIO_TYPE_IN_FLOATING) || (ulPinType == GPIO_TYPE_IN_WPU_WPD) || (ulPinType == GPIO_TYPE_OUT_STD) || (ulPinType == GPIO_TYPE_OUT_OD) || (ulPinType == GPIO_TYPE_AFOUT_STD) || (ulPinType == GPIO_TYPE_AFOUT_OD)); xASSERT((ulPinSpeed == GPIO_IN_SPEED_FIXED) || (ulPinSpeed == GPIO_OUT_SPEED_10M) || (ulPinSpeed == GPIO_OUT_SPEED_2M) || (ulPinSpeed == GPIO_OUT_SPEED_50M)); // // Set the pin direction and mode. // if(ulBit < 8) { xHWREG(ulPort + GPIO_CRL) &= (~((GPIO_CRL_MODE0_M | GPIO_CRL_CNF0_M) << (ulBit * 4))); xHWREG(ulPort + GPIO_CRL) = (xHWREG(ulPort + GPIO_CRL) | \ (((ulPinSpeed | ulPinType)) << (ulBit * 4))); } else { xHWREG(ulPort + GPIO_CRH) &= (~((GPIO_CRH_MODE8_M | GPIO_CRH_CNF8_M) << ((ulBit -8) * 4))); xHWREG(ulPort + GPIO_CRH) = (xHWREG(ulPort + GPIO_CRH) | \ (((ulPinSpeed | ulPinType)) << ((ulBit -8) * 4))); } }
//***************************************************************************** // //! Sets the direction and mode of the specified pin(s) //! //! \param ui32Port is the base address of the GPIO port. //! \param ui8Pins is the bit-packed representation of the pin(s). //! \param ui32PinIO is the pin direction and/or mode. //! //! This function sets the specified pin(s) on the selected GPIO port //! as either an input or output under software control or sets the //! pin to be under hardware control. //! //! The parameter \e ui32PinIO is an enumerated data type that can be one of //! the following values: //! //! - \b GPIO_DIR_MODE_IN //! - \b GPIO_DIR_MODE_OUT //! - \b GPIO_DIR_MODE_HW //! //! where \b GPIO_DIR_MODE_IN specifies that the pin will be programmed as //! a software controlled input, \b GPIO_DIR_MODE_OUT specifies that the pin //! will be programmed as a software controlled output, and //! \b GPIO_DIR_MODE_HW specifies that the pin will be placed under //! hardware control. //! //! The pin(s) are specified using a bit-packed byte, where each bit that is //! set identifies the pin to be accessed, and where bit 0 of the byte //! represents GPIO port pin 0, bit 1 represents GPIO port pin 1, and so on. //! //! \return None // //***************************************************************************** void GPIODirModeSet(uint32_t ui32Port, uint8_t ui8Pins, uint32_t ui32PinIO) { // // Check the arguments. // ASSERT(GPIOBaseValid(ui32Port)); ASSERT((ui32PinIO == GPIO_DIR_MODE_IN) || (ui32PinIO == GPIO_DIR_MODE_OUT) || (ui32PinIO == GPIO_DIR_MODE_HW)); // // Set the pin direction and mode. // HWREG(ui32Port + GPIO_O_DIR) = ((ui32PinIO & GPIO_DIR_MODE_OUT) ? (HWREG(ui32Port + GPIO_O_DIR) | ui8Pins) : (HWREG(ui32Port + GPIO_O_DIR) & ~(ui8Pins))); HWREG(ui32Port + GPIO_O_AFSEL) = ((ui32PinIO & GPIO_DIR_MODE_HW) ? (HWREG(ui32Port + GPIO_O_AFSEL) | ui8Pins) : (HWREG(ui32Port + GPIO_O_AFSEL) & ~(ui8Pins))); }
//***************************************************************************** // //! Gets the direction and mode of a pin. //! //! \param ulPort is the base address of the GPIO port. //! \param ucPin is the pin number. //! //! This function gets the direction and control mode for a specified pin on //! the selected GPIO port. The pin can be configured as either an input or //! output under software control, or it can be under hardware control. The //! type of control and direction are returned as an enumerated data type. //! //! \return Returns one of the enumerated data types described for //! GPIODirModeSet(). // //***************************************************************************** unsigned long GPIODirModeGet(unsigned long ulPort, unsigned char ucPin) { unsigned long ulDir; // // Check the arguments. // ASSERT(GPIOBaseValid(ulPort)); ASSERT(ucPin < 8); // // Convert from a pin number to a bit position. // ucPin = 1 << ucPin; // // Return the pin direction and mode. // ulDir = HWREG(ulPort + GPIO_O_GPIO_DIR); return(((ulDir & ucPin) ? 1 : 0)); }