Skip to content

Instantly share code, notes, and snippets.

@ketul93
Last active August 29, 2015 14:19
Show Gist options
  • Save ketul93/2e0d2c4b8b586be62e1d to your computer and use it in GitHub Desktop.
Save ketul93/2e0d2c4b8b586be62e1d to your computer and use it in GitHub Desktop.
GPIO Driver development on BeagleBone Black with RTEMS
/**
* @file
*
* @ingroup arm_beagle
*
* @brief Global BSP definitions.
*/
/*
* Copyright (c) 2015 Ketul Shah <ketulshah1993 at gmail.com>
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifndef LIBBSP_ARM_BEAGLE_H
#define LIBBSP_ARM_BEAGLE_H
#include <stdint.h>
#include <bsp/utility.h>
/* GPIO Memory Registers */
#if IS_AM335X
#define AM335X_GPIO0_BASE (0x44E07000)
#define AM335X_GPIO1_BASE (0x4804C000)
#define AM335X_GPIO2_BASE (0x481AC000)
#define AM335X_GPIO3_BASE (0x481AE000)
#define AM335X_GPIO_OE (0x134)
#define AM335X_GPIO_DATAOUT (0x13C)
#define AM335X_GPIO_DATAIN (0x138)
#define AM335X_GPIO_CLEARDATAOUT (0x190)
#define AM335X_GPIO_SETDATAOUT (0x194)
#endif
#if IS_DM3730
#define DM37XX_GPIO1_BASE (0x48310000)
#define DM37XX_GPIO2_BASE (0x49050000)
#define DM37XX_GPIO3_BASE (0x49052000)
#define DM37XX_GPIO4_BASE (0x49054000)
#define DM37XX_GPIO5_BASE (0x49056000)
#define DM37XX_GPIO6_BASE (0x49058000)
#define DM37XX_GPIO_OE (0x34)
#define DM37XX_GPIO_DATAOUT (0x3c)
#define DM37XX_GPIO_DATAIN (0x38)
#define DM37XX_GPIO_CLEARDATAOUT (0x90)
#define DM37XX_GPIO_SETDATAOUT (0x94)
#endif
/**
* @file
*
* @ingroup arm_beagle
*
* @brief Global BSP definitions.
*/
/*
* Copyright (c) 2015 Ketul Shah <ketulshah1993 at gmail.com>
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#include <bsp/beagleboard.h>
#include <bsp/irq.h>
#include <bsp/gpio.h>
#include <bsp.h>
#include <stdlib.h>
#include <stdint.h>
bool is_initialized = flase;
void gpio_initialize(void)
{
if ( is_initialized )
return;
is_initialized = true;
/*Enabling GPIO1 pins as OUTPUT PINs*/
write32(AM335X_GPIO1_BASE +GPIO_OE,0x00000000);
}
void gpio_set_value(unsigned gpio, int value)
{
if (value)
{
uint8_t tmp = readb(AM335X_GPIO1_BASE + gpio/8+GPIO_SETDATAOUT);
tmp |= (1 << gpio%8);
writeb(tmp, AM335X_GPIO1_BASE + gpio/8+GPIO_SETDATAOUT);
}
else
{
uint8_t tmp = readb(AM335X_GPIO1_BASE + gpio/8+GPIO_CLEARDATAOUT);
tmp |= (1 << gpio%8);
writeb(tmp, AM335X_GPIO1_BASE + gpio/8+GPIO_CLEARDATAOUT);
}
}
void allgpioset(void)
{
printf("Setting all gpio1\n");
write32(AM335X_GPIO1_BASE +GPIO_SETDATAOUT,0xFFFFFFFF);
}
void allgpioclr(void)
{
printf("Clearing all gpio1\n");
write32(AM335X_GPIO1_BASE+GPIO_CLEARDATAOUT,0xFFFFFFFF);
}
/**
* @file
*
* @ingroup arm_beagle
*
* @brief Global BSP definitions.
*/
/*
* Copyright (c) 2015 Ketul Shah <ketulshah1993 at gmail.com>
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifndef LIBBSP_ARM_BEAGLE_GPIO_H
#define LIBBSP_ARM_BEAGLE_GPIO_H
#include <rtems.h>
#include "beagleboard.h"
#include <rtems.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
extern void gpio_initialize(void);
extern void allgpioset(void);
extern void allgpioclr(void);
extern void gpio_set_value(unsigned gpio, int value);
#endif /* LIBBSP_ARM_BEAGLE_GPIO_H */
/**
* @file
*
* @ingroup arm_beagle
*
* @brief Global BSP definitions.
*/
/*
* Copyright (c) 2015 Ketul Shah <ketulshah1993 at gmail.com>
* The license and distribution terms for this file may be
* found in the file LICENSE in this distribution or at
* http://www.rtems.org/license/LICENSE.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <rtems.h>
#include <rtems/test.h>
#include <bsp/gpio.h> /* Calls the BSP gpio library */
#include <rtems/status-checks.h>
#include <stdio.h>
#include <stdlib.h>
void inline delaysec(float sec)
{
rtems_task_wake_after(sec*rtems_clock_get_ticks_per_second());
}
/*Function for USR LEDs demo.*/
void inline gpio_auto()
{
/*Generating some patterns*/
allgpioset();
delaysec(1);
allgpioclr();
gpio_set_value(22,1);gpio_set_value(24,1);
delaysec(0.4);
gpio_set_value(22,1);gpio_set_value(24,0);
delaysec(0.3);
gpio_set_value(21,1);gpio_set_value(23,1);
delaysec(0.5);
gpio_set_value(22,0);gpio_set_value(24,0);
delaysec(0.2);
gpio_set_value(22,1);
delaysec(0.2);
allgpioclr();
delaysec(0.1);
}
rtems_task Init(rtems_task_argument argument);
const char rtems_test_name[] = "GPIO TEST";
rtems_task Init(
rtems_task_argument ignored
)
{
rtems_test_begin();
printf("GPIO Testing started\n");
gpio_initialize();
allgpioclr();
gpio_auto();
printf( "GPIO TEST by Ketul\n" );
rtems_test_end();
exit( 0 );
}
/* Clock driver module is enabled*/
#define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
#define CONFIGURE_MAXIMUM_TASKS 1
#define CONFIGURE_USE_DEVFS_AS_BASE_FILESYSTEM
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
#define CONFIGURE_INIT
#include <rtems/confdefs.h>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment