Exemple #1
0
/**
 * \brief   This function writes a logic 1 or a logic 0 to the specified pin.
 *
 * \param   baseAdd    The memory address of the GPIO instance being used.
 * \param   pinNumber  The serial number of the GPIO pin.
 *                     The 144 GPIO pins have serial numbers from 1 to 144. 
 *
 * \param   bitValue   This signifies whether to write a logic 0 or logic 1 
 *                     to the specified pin.This variable can take any of the 
 *                     following two values:
 *                     1> GPIO_PIN_LOW, which indicates to clear(logic 0) the bit.
 *                     2> GPIO_PIN_HIGH, which indicates to set(logic 1) the bit.
 *
 * \return  None.
 *
 * \note    The pre-requisite to write to any pin is that the pin has to
 *          be configured as an output pin.
 */
void GPIOPinWrite(unsigned int baseAdd, unsigned int pinNumber, 
                  unsigned int bitValue)
{
    unsigned int regNumber = 0;
    unsigned int pinOffset = 0;
    
    /*
    ** Each register contains settings for each pin of two banks. The 32 bits
    ** represent 16 pins each from the banks. Thus the register number must be
    ** calculated based on 32 pins boundary.
    */
 
    regNumber = (pinNumber - 1)/32;

    /*
    ** In every register the least significant bits starts with a GPIO number on
    ** a boundary of 32. Thus the pin offset must be calculated based on 32
    ** pins boundary. Ex: 'pinNumber' of 1 corresponds to bit 0 in 
    ** 'register_name01'.
    */
   
    pinOffset = (pinNumber - 1) % 32;

    if(GPIO_PIN_LOW == bitValue)
    {
        HWREG(baseAdd + GPIO_CLR_DATA(regNumber)) = (1 << pinOffset);
    }
    else if(GPIO_PIN_HIGH == bitValue)
    {
        HWREG(baseAdd + GPIO_SET_DATA(regNumber)) = (1 << pinOffset);
    }
}
Exemple #2
0
void GPIOBankPinsWrite(unsigned int baseAdd, unsigned int bankNumber,
                       unsigned int setPins, unsigned int clrPins)
{
    unsigned int regNumber;

    regNumber = bankNumber/2;

    if (1 == (bankNumber % 2))
    {
        HWREG(baseAdd + GPIO_SET_DATA(regNumber)) = ((setPins & 0xFFFF) << 16);
        HWREG(baseAdd + GPIO_CLR_DATA(regNumber)) = ((clrPins & 0xFFFF) << 16);
    }
    else
    {
        HWREG(baseAdd + GPIO_SET_DATA(regNumber)) = (setPins & 0xFFFF);
        HWREG(baseAdd + GPIO_CLR_DATA(regNumber)) = (clrPins & 0xFFFF);
    }

}
/**
 * \brief   This function writes a logic 1 or a logic 0 to the specified pin.
 *
 * \param   baseAdd    The memory address of the GPIO instance being used.
 * \param   pinNumber  The serial number of the GPIO pin.
 *                     The 144 GPIO pins have serial numbers from 1 to 144. 
 *
 * \param   bitValue   This signifies whether to write a logic 0 or logic 1 
 *                     to the specified pin.This variable can take any of the 
 *                     following two values:
 *                     1> GPIO_PIN_LOW, which indicates to clear(logic 0) the bit.
 *                     2> GPIO_PIN_HIGH, which indicates to set(logic 1) the bit.
 *
 * \return  None.
 *
 * \note    The pre-requisite to write to any pin is that the pin has to
 *          be configured as an output pin.
 */
void GPIOPinWrite(unsigned int baseAdd, unsigned int pinNumber, 
                  unsigned int bitValue)
{
    unsigned int regNumber = 0;
    unsigned int pinOffset = 0;
    
    /*
    ** Each register contains settings for each pin of two banks. The 32 bits
    ** represent 16 pins each from the banks. Thus the register number must be
    ** calculated based on 32 pins boundary.
    */
 
    regNumber = (pinNumber - 1)/32;
	/*
		-> 108 / 32 = 3.375 = 3	
	*/

    /*
    ** In every register the least significant bits starts with a GPIO number on
    ** a boundary of 32. Thus the pin offset must be calculated based on 32
    ** pins boundary. Ex: 'pinNumber' of 1 corresponds to bit 0 in 
    ** 'register_name01'.
    */
   
    pinOffset = (pinNumber - 1) % 32;
	/*
		108 % 32 = 12
	*/

    if(GPIO_PIN_LOW == bitValue)
    {
        HWREG(baseAdd + GPIO_CLR_DATA(regNumber)) = (1 << pinOffset);
		/*
			baseAdd = 0x01E26000
			
			GPIO_CLR_DATA(n) -> (0x1C + (0x28 * n)) -> 0x94
			
			0x01E26000 + 0x94 -> 0x01E2 6094 -> CLR_DATA67 
			 ->GPIO Banks 6 and 7 Clear Data Register
			 
			CLR_DATA67 = (1<<12) 
			 -> GP6P12 is set to output logic low
		*/
    }
    else if(GPIO_PIN_HIGH == bitValue)
    {
        HWREG(baseAdd + GPIO_SET_DATA(regNumber)) = (1 << pinOffset);
    }
}