This is the mail archive of the
ecos-discuss@sourceware.org
mailing list for the eCos project.
Re: How to create a GPIO driver
Great answer! Thanks! A question: can you tell me how the function
hal_LPC1XXX_gpio_set() (and other) appear in your source? In my source this
function is described in this way:
__externC void hal_LPC17XX_gpio_set( cyg_uint32 pin )
{
cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
cyg_uint32 cm = CYGHWR_HAL_LPC17XX_GPIO_CFG(pin);
cyg_uint32 cr;
if( pin == CYGHWR_HAL_LPC17XX_GPIO_NONE )
return;
if( bit > 7 ) port += 4, bit -= 8;
HAL_READ_UINT32( port, cr );
cr &= ~(0xF<<(bit*4));
cr |= cm<<(bit*4);
HAL_WRITE_UINT32( port, cr );
// If this is a pullup/down input, set the ODR bit to switch on
// the appropriate pullup/down resistor.
if( cm ==
(CYGHWR_HAL_LPC17XX_GPIO_MODE_IN|CYGHWR_HAL_LPC17XX_GPIO_CNF_PULL) )
{
cyg_uint32 odr;
port = CYGHWR_HAL_LPC17XX_GPIO_PORT( pin );
bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
HAL_READ_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_ODR, odr );
if( pin & CYGHWR_HAL_LPC17XX_GPIO_PULLUP )
odr |= (1<<bit);
else
odr &= ~(1<<bit);
HAL_WRITE_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_ODR, odr );
}
}
__externC void hal_LPC17XX_gpio_out( cyg_uint32 pin, int val )
{
cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
port += CYGHWR_HAL_LPC17XX_GPIO_BSRR;
if( (val&1) == 0 ) port += 4;
HAL_WRITE_UINT32( port, 1<<bit );
}
__externC void hal_LPC17XX_gpio_in ( cyg_uint32 pin, int *val )
{
cyg_uint32 port = CYGHWR_HAL_LPC17XX_GPIO_PORT(pin);
int bit = CYGHWR_HAL_LPC17XX_GPIO_BIT(pin);
cyg_uint32 pd;
HAL_READ_UINT32( port+CYGHWR_HAL_LPC17XX_GPIO_IDR, pd );
*val = (pd>>bit)&1;
}
--
View this message in context: http://sourceware-org.1504.n7.nabble.com/How-to-create-a-GPIO-driver-tp224910p225218.html
Sent from the Sourceware - ecos-discuss mailing list archive at Nabble.com.
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss