Exemplo n.º 1
0
/*-----------------------------------------------------------------------------
| Function    :S32 gpio_pin_init(U16 pin_num, U8 in_out)
+------------------------------------------------------------------------------
| Description :This function is to initialize the gpio pin as input or output.
|
| Parameters  :pin_num
|                 - gpio pin that needs to be configured.
|
|              in_out
|                 - specifies whether the pin is to be configured as an
|                   input or output.
|
| Returns     : DAL_SUCCESS, if the initialization is successful.
|				else DAL_ERROR.
+-----------------------------------------------------------------------------*/
S32 gpio_pin_init(U16 pin_num, U8 in_out)
{

    U8 module_num = pin_num/NUM_OF_BITS_IN_REG + 1;
    /* GPIO module to which the GPIO number belongs to */
    U32 snum = (module_num-1)*NUM_OF_BITS_IN_REG;
    U32 offset = pin_num - snum;
    U32 pinmask;
    S32 ret_val = OMAPFLASH_SUCCESS;

    /* check whether the gpio number is valid */
    /* if yes continue else return*/
    ret_val = check_gpio_pin_num(pin_num);
    if(ret_val != OMAPFLASH_SUCCESS)
    {
        dbg_print(DBG_LEVEL_CRITICAL, "wrong gpio-pin number \n");
        return(ret_val);
    }

    /* this variable will have the position of the pin in the corresponding
    gpio module */

    pinmask = GPIO_PIN<<offset;

    /* call this function to configure the pin as input or output */

    set_gpio_in_out(module_num, pinmask, in_out<<offset);

    /*return from this function*/
    dbg_print(DBG_LEVEL_INFO, "gpio pin %d initialized \n",pin_num);

    return (ret_val);

}
Exemplo n.º 2
0
/*-----------------------------------------------------------------------------
| Function    : S32 set_gpio_output(U16 pin_num, U8 set)
+------------------------------------------------------------------------------
| Description : for writing data to the GPIO pins
|
| Parameters  : pin_num -
|                 gpio pin number
|               set -
|                 set/clear information
| Returns     : DAL_ERROR is returned if failure else the value returned
|               by the lower layer function is passed on.
+-----------------------------------------------------------------------------*/
S32 set_gpio_output(U16 pin_num, U8 set)
{
    S32                      ret_val = OMAPFLASH_DAL_ERROR;
    U8                       module_num = pin_num/NUM_OF_BITS_IN_REG + 1;
    /* GPIO module to which the GPIO pin number belongs to */
    U32                      snum = (module_num-1)*NUM_OF_BITS_IN_REG;
    U32                      offset = pin_num - snum;
    /* position of the GPIO pin in respective module register*/

    /* check whether the gpio number is valid */
    /* if yes continue else return*/
    ret_val = check_gpio_pin_num(pin_num);
    if(ret_val != OMAPFLASH_SUCCESS)
    {
        dbg_print(DBG_LEVEL_INFO, "wrong gpio-pin number \n");
        return(ret_val);
    }

    /* if the output pin value has to be made 1,then the data to be
    written will be - the bit corresponding to that pin is set
    else that bit is cleared and that function is called  */
    if (set)
    {
        gpio_write_output_pin(module_num, (1<<offset), (1<<offset));
    }
    else
    {
        gpio_write_output_pin(module_num, (1<<offset), (0<<offset));
    }
    /* return from this function*/
    // Commented out in order for CPLD flashing to be speeded up
    //    dbg_print(DBG_LEVEL_INFO,
    //              "wrote the data to gpio pin %d \n",pin_num);
    return(ret_val);
}
Exemplo n.º 3
0
/*-----------------------------------------------------------------------------
| Function    :S32 gpio_remove_int_handler(U16 pin_num)
+------------------------------------------------------------------------------
| Description :	This function adds the gpio interrupt handler
| Parameters  : pin_num
|                       -   gpio pin number
|
| Returns     : DAL_SUCCESS, if the initialization is successful.
|				else DAL_ERROR.
+-----------------------------------------------------------------------------*/
S32 gpio_remove_int_handler(U16 pin_num)
{
    U8 module_num = pin_num/NUM_OF_BITS_IN_REG + 1;
    /* GPIO module to which the GPIO pin number belongs to */
    U32 snum = (module_num-1)*NUM_OF_BITS_IN_REG;
    U32 pin_offset = pin_num - snum; /* position of the pin in the respective
                                     gpio module */
    S32 ret_val = OMAPFLASH_DAL_ERROR;

    /* check whether the gpio number is valid */
    /* if yes continue else return*/
    ret_val = check_gpio_pin_num(pin_num);
    if(ret_val != OMAPFLASH_SUCCESS)
    {
        dbg_print(DBG_LEVEL_CRITICAL,"wrong gpio-pin number \n");
        return(ret_val);
    }

    /* remove the call back function added to the gpio pin */
    gpio_remove_callback_handler(module_num, pin_offset);

    /* return from this function*/
    dbg_print(DBG_LEVEL_INFO,
              "removed callback function for gpio pin %d \n",pin_num);
    return(ret_val);
}
Exemplo n.º 4
0
S32 get_gpio_input(U32 pin_num)
{
    U32 module_num = pin_num/NUM_OF_BITS_IN_REG + 1;
    /* GPIO module to which the GPIO pin number belongs to */
    U32 snum = (module_num-1)*NUM_OF_BITS_IN_REG;
    U32 offset = pin_num - snum;
    /* position of the pin in the respective gpio module */
    U32 data = 0;
    S32 ret_val = OMAPFLASH_DAL_ERROR;

    /* check whether the gpio number is valid */
    /* if yes continue else return*/
    ret_val = check_gpio_pin_num(pin_num);
    if(ret_val != OMAPFLASH_SUCCESS)
    {
        dbg_print(DBG_LEVEL_INFO, "wrong gpio-pin number \r\n");
        return(ret_val);
    }

    /* call this function to read the value at the particular pin
    of the corresponding module */
    gpio_read_input_pin(module_num,(1<<offset), &data);
    data = data >> offset;
    /* return from this function*/
    // Commented out in order for CPLD flashing to be speeded up
    //    dbg_print(DBG_LEVEL_INFO,
    //              "read the data at gpio pin %d \n",pin_num);
    return(data);
}
Exemplo n.º 5
0
/* This function is to initialize the gpio pin as input or output. */
S32 gpio_pin_init(U16 pin_num, U8 in_out)
{
	/* GPIO module to which the GPIO number belongs to. */
	U8 module_num = (pin_num / NUM_OF_BITS_IN_REG + 1);
	U32 snum = ((module_num - 1) * NUM_OF_BITS_IN_REG);
	U32 offset = (pin_num - snum);
	U32 pinmask;
	S32 ret_val = SUCCESS;

	/* 
	 ** Check whether the gpio number is valid. 
	 ** If yes continue else return. 
	 */
	ret_val = check_gpio_pin_num(pin_num);
	if (SUCCESS != ret_val) {
#ifdef OMAP3530_DEBUG
		DEBUG("%s:%d - Wrong gpio-pin number.\r\n", __FILE__, __LINE__);
#endif
		return (ret_val);
	}

	/*
	 ** This variable will have the position of the pin in 
	 ** the corresponding gpio module.
	 */
	pinmask = (GPIO_PIN << offset);

	/* Call this function to configure the pin as input or output. */
	set_gpio_in_out(module_num, pinmask, (in_out << offset));

#ifdef OMAP3530_DEBUG
	DEBUG("gpio pin %d initialized.\r\n", pin_num);
#endif
	return (ret_val);
}
Exemplo n.º 6
0
S32 get_gpio_input(U32 pin_num)
{
	U8 module_num = pin_num / NUM_OF_BITS_IN_REG + 1;
	/* GPIO module to which the GPIO pin number belongs to */
	U32 snum = (module_num - 1) * NUM_OF_BITS_IN_REG;
	U32 offset = pin_num - snum;
	/* position of the pin in the respective gpio module */
	U32 data = 0;
	S32 ret_val = FAILURE;

	/* check whether the gpio number is valid */
	/* if yes continue else return */
	ret_val = check_gpio_pin_num(pin_num);
	if (ret_val != SUCCESS) {
		fprintf(stdout, "wrong gpio-pin number \r\n");
		return (ret_val);
	}

	/* call this function to read the value at the particular pin
	   of the corresponding module */
	gpio_read_input_pin(module_num, (1 << offset), &data);
	data = data >> offset;
	/* return from this function */
#ifdef OMAP3530_DEBUG
	DEBUG("read the data at gpio pin %d \n", pin_num);
#endif
	return (data);
}
Exemplo n.º 7
0
/*-----------------------------------------------------------------------------
| Function    :S32 gpio_add_int_handler(U16 pin_num, S32(*gpio_callback)(U8),
|                                         T_GPIO_INTR_TYPE intr_type)
+------------------------------------------------------------------------------
| Description :	This function adds the gpio interrupt handler
| Parameters  : pin_num
|                       -   gpio pin number
|
|                intr_type
|                       -   specifies the interrupt type
|
|               S32 (* gpio_callback)(U8)
|                       -   callback function specified by the application
|                           program.
|
| Returns     : DAL_SUCCESS, if the initialization is successful.
|				else DAL_ERROR.
+-----------------------------------------------------------------------------*/
S32 gpio_add_int_handler(U16 pin_num, S32(*gpio_callback)(U8),U8 data,
                         T_GPIO_INTR_TYPE intr_type)
{
    U8 module_num = pin_num/NUM_OF_BITS_IN_REG + 1;
    /* GPIO module to which the GPIO pin number belongs to */
    U32 snum = (module_num-1)*NUM_OF_BITS_IN_REG;
    U32 offset = pin_num - snum; /* position of the pin in the respective
                                 gpio module */
    U32 pinmask;
    S32 ret_val = OMAPFLASH_DAL_ERROR;

    /* check whether the gpio number is valid */
    /* if yes continue else return*/
    ret_val = check_gpio_pin_num(pin_num);
    if(ret_val != OMAPFLASH_SUCCESS)
    {
        dbg_print(DBG_LEVEL_CRITICAL,"wrong gpio-pin number \n");
        return(ret_val);
    }

    /* this variable will have the position of the pin in the corresponding
    gpio module */

    pinmask = GPIO_PIN<<offset;

    /* add gpio interrupt handler */
    /* first check whether there is a callback function that can be hooked to
    the interrupt */
    /* if unable to add gpio callback function return from this function */
    if(gpio_callback != NULL)
    {
        if(gpio_add_callback_handler(module_num, pinmask, gpio_callback, data)
           != OMAPFLASH_SUCCESS)
        {
            dbg_print(DBG_LEVEL_INFO, "could not add a callback handler \n");
            return OMAPFLASH_DAL_ERROR;
        }
        /* call this function to set the interrupt type */
        gpio_set_interrupt_type(module_num, intr_type, pinmask);
        ret_val = OMAPFLASH_SUCCESS;
    }
    /* return fromt this function*/
    dbg_print(DBG_LEVEL_INFO, "hooked a ISR for gpio pin %d \n",pin_num);
    return(ret_val);

}
Exemplo n.º 8
0
/* Writing data to the GPIO pins. */
S32 set_gpio_output(U16 pin_num, U8 set)
{
	S32 ret_val = FAILURE;
	/* GPIO module to which the GPIO pin number belongs to. */
	U8 module_num = (pin_num / NUM_OF_BITS_IN_REG + 1);
	U32 snum = ((module_num - 1) * NUM_OF_BITS_IN_REG);
	/* Position of the GPIO pin in respective module register. */
	U32 offset = (pin_num - snum);

	/* 
	 ** Check whether the gpio number is valid. 
	 ** if yes continue else return.
	 */
	ret_val = check_gpio_pin_num(pin_num);
	if (SUCCESS != ret_val) {
#ifdef OMAP3530_DEBUG
		DEBUG("%s:%d - Wrong gpio-pin number.\r\n", __FILE__, __LINE__);
#endif
		return (ret_val);
	}

	/* 
	 ** If the output pin value has to be made 1, then the data to be
	 ** written will be - the bit corresponding to that pin is set
	 ** else that bit is cleared and that function is called. 
	 */
	if (set) {
		gpio_write_output_pin(module_num, (1 << offset), (1 << offset));
	} else {
		gpio_write_output_pin(module_num, (1 << offset), (0 << offset));
	}

#ifdef OMAP3530_DEBUG
	DEBUG("Wrote the data to gpio pin - %d.\r\n", pin_num);
#endif
	return (ret_val);
}