OpenOCD
bcm2835gpio.c File Reference
Include dependency graph for bcm2835gpio.c:

Go to the source code of this file.

Data Structures

struct  initial_gpio_state
 

Macros

#define BCM2835_GPIO_BASE   (bcm2835_peri_base + 0x200000) /* GPIO controller */
 
#define BCM2835_GPIO_MODE_INPUT   0
 
#define BCM2835_GPIO_MODE_OUTPUT   1
 
#define BCM2835_PADS_GPIO_0_27   (bcm2835_peri_base + 0x100000)
 
#define BCM2835_PADS_GPIO_0_27_OFFSET   (0x2c / 4)
 
#define GPIO_CLR   (*(pio_base+10)) /* clears bits which are 1, ignores bits which are 0 */
 
#define GPIO_LEV   (*(pio_base+13)) /* current level of the pin */
 
#define GPIO_SET   (*(pio_base+7)) /* sets bits which are 1, ignores bits which are 0 */
 
#define INP_GPIO(g)   do { *(pio_base+((g)/10)) &= ~(7<<(((g)%10)*3)); } while (0)
 
#define MODE_GPIO(g)   (*(pio_base+((g)/10))>>(((g)%10)*3) & 7)
 
#define OUT_GPIO(g)   SET_MODE_GPIO(g, BCM2835_GPIO_MODE_OUTPUT)
 
#define SET_MODE_GPIO(g, m)
 

Functions

static void bcm2835_delay (void)
 
static const char * bcm2835_get_mem_dev (void)
 
static void bcm2835_gpio_synchronize (void)
 
static void bcm2835_swdio_drive (bool is_output)
 
static int bcm2835_swdio_read (void)
 
static int bcm2835gpio_blink (int on)
 
static int bcm2835gpio_init (void)
 
static bool bcm2835gpio_jtag_mode_possible (void)
 
static int bcm2835gpio_khz (int khz, int *jtag_speed)
 
static void bcm2835gpio_munmap (void)
 
static int bcm2835gpio_quit (void)
 
static bb_value_t bcm2835gpio_read (void)
 
static int bcm2835gpio_reset (int trst, int srst)
 
static int bcm2835gpio_speed (int speed)
 
static int bcm2835gpio_speed_div (int speed, int *khz)
 
static bool bcm2835gpio_swd_mode_possible (void)
 
static int bcm2835gpio_swd_write_fast (int swclk, int swdio)
 
static int bcm2835gpio_swd_write_generic (int swclk, int swdio)
 
static int bcm2835gpio_write (int tck, int tms, int tdi)
 
 COMMAND_HANDLER (bcm2835gpio_handle_peripheral_base)
 
 COMMAND_HANDLER (bcm2835gpio_handle_peripheral_mem_dev)
 
 COMMAND_HANDLER (bcm2835gpio_handle_speed_coeffs)
 
static void initialize_gpio (enum adapter_gpio_config_index idx)
 
static bool is_gpio_config_valid (enum adapter_gpio_config_index idx)
 
static void restore_gpio (enum adapter_gpio_config_index idx)
 
static void set_gpio_value (const struct adapter_gpio_config *gpio_config, int value)
 

Variables

static const struct adapter_gpio_configadapter_gpio_config
 
static off_t bcm2835_peri_base = 0x20000000
 
static char * bcm2835_peri_mem_dev
 
static const char *const bcm2835_transports [] = { "jtag", "swd", NULL }
 
struct adapter_driver bcm2835gpio_adapter_driver
 
static struct bitbang_interface bcm2835gpio_bitbang
 
static const struct command_registration bcm2835gpio_command_handlers []
 
static struct jtag_interface bcm2835gpio_interface
 
static const struct command_registration bcm2835gpio_subcommand_handlers []
 
static int dev_mem_fd
 
static uint32_t initial_drive_strength_etc
 
static struct initial_gpio_state initial_gpio_state [ADAPTER_GPIO_IDX_NUM]
 
static unsigned int jtag_delay
 
static volatile uint32_t * pads_base = MAP_FAILED
 
static volatile uint32_t * pio_base = MAP_FAILED
 
static int speed_coeff = 113714
 
static int speed_offset = 28
 

Macro Definition Documentation

◆ BCM2835_GPIO_BASE

#define BCM2835_GPIO_BASE   (bcm2835_peri_base + 0x200000) /* GPIO controller */

Definition at line 24 of file bcm2835gpio.c.

◆ BCM2835_GPIO_MODE_INPUT

#define BCM2835_GPIO_MODE_INPUT   0

Definition at line 30 of file bcm2835gpio.c.

◆ BCM2835_GPIO_MODE_OUTPUT

#define BCM2835_GPIO_MODE_OUTPUT   1

Definition at line 31 of file bcm2835gpio.c.

◆ BCM2835_PADS_GPIO_0_27

#define BCM2835_PADS_GPIO_0_27   (bcm2835_peri_base + 0x100000)

Definition at line 26 of file bcm2835gpio.c.

◆ BCM2835_PADS_GPIO_0_27_OFFSET

#define BCM2835_PADS_GPIO_0_27_OFFSET   (0x2c / 4)

Definition at line 27 of file bcm2835gpio.c.

◆ GPIO_CLR

#define GPIO_CLR   (*(pio_base+10)) /* clears bits which are 1, ignores bits which are 0 */

Definition at line 42 of file bcm2835gpio.c.

◆ GPIO_LEV

#define GPIO_LEV   (*(pio_base+13)) /* current level of the pin */

Definition at line 43 of file bcm2835gpio.c.

◆ GPIO_SET

#define GPIO_SET   (*(pio_base+7)) /* sets bits which are 1, ignores bits which are 0 */

Definition at line 41 of file bcm2835gpio.c.

◆ INP_GPIO

#define INP_GPIO (   g)    do { *(pio_base+((g)/10)) &= ~(7<<(((g)%10)*3)); } while (0)

Definition at line 35 of file bcm2835gpio.c.

◆ MODE_GPIO

#define MODE_GPIO (   g)    (*(pio_base+((g)/10))>>(((g)%10)*3) & 7)

Definition at line 34 of file bcm2835gpio.c.

◆ OUT_GPIO

#define OUT_GPIO (   g)    SET_MODE_GPIO(g, BCM2835_GPIO_MODE_OUTPUT)

Definition at line 39 of file bcm2835gpio.c.

◆ SET_MODE_GPIO

#define SET_MODE_GPIO (   g,
 
)
Value:
do { /* clear the mode bits first, then set as necessary */ \
INP_GPIO(g); \
*(pio_base+((g)/10)) |= ((m)<<(((g)%10)*3)); } while (0)
static volatile uint32_t * pio_base
Definition: bcm2835gpio.c:46

Definition at line 36 of file bcm2835gpio.c.

Function Documentation

◆ bcm2835_delay()

static void bcm2835_delay ( void  )
inlinestatic

◆ bcm2835_get_mem_dev()

static const char* bcm2835_get_mem_dev ( void  )
inlinestatic

Definition at line 61 of file bcm2835gpio.c.

References bcm2835_peri_mem_dev.

Referenced by bcm2835gpio_init(), and COMMAND_HANDLER().

◆ bcm2835_gpio_synchronize()

static void bcm2835_gpio_synchronize ( void  )
inlinestatic

◆ bcm2835_swdio_drive()

static void bcm2835_swdio_drive ( bool  is_output)
static

◆ bcm2835_swdio_read()

static int bcm2835_swdio_read ( void  )
static

◆ bcm2835gpio_blink()

static int bcm2835gpio_blink ( int  on)
static

Definition at line 411 of file bcm2835gpio.c.

◆ bcm2835gpio_init()

◆ bcm2835gpio_jtag_mode_possible()

static bool bcm2835gpio_jtag_mode_possible ( void  )
static

◆ bcm2835gpio_khz()

static int bcm2835gpio_khz ( int  khz,
int *  jtag_speed 
)
static

Definition at line 274 of file bcm2835gpio.c.

References DIV_ROUND_UP, ERROR_FAIL, ERROR_OK, LOG_DEBUG, speed_coeff, and speed_offset.

◆ bcm2835gpio_munmap()

static void bcm2835gpio_munmap ( void  )
static

Definition at line 398 of file bcm2835gpio.c.

References pads_base, and pio_base.

Referenced by bcm2835gpio_quit().

◆ bcm2835gpio_quit()

◆ bcm2835gpio_read()

static bb_value_t bcm2835gpio_read ( void  )
static

◆ bcm2835gpio_reset()

static int bcm2835gpio_reset ( int  trst,
int  srst 
)
static

◆ bcm2835gpio_speed()

static int bcm2835gpio_speed ( int  speed)
static

Definition at line 295 of file bcm2835gpio.c.

References ERROR_OK, and jtag_delay.

◆ bcm2835gpio_speed_div()

static int bcm2835gpio_speed_div ( int  speed,
int *  khz 
)
static

Definition at line 287 of file bcm2835gpio.c.

References ERROR_OK, speed_coeff, and speed_offset.

◆ bcm2835gpio_swd_mode_possible()

static bool bcm2835gpio_swd_mode_possible ( void  )
static

Definition at line 389 of file bcm2835gpio.c.

References ADAPTER_GPIO_IDX_SWCLK, ADAPTER_GPIO_IDX_SWDIO, and is_gpio_config_valid().

Referenced by bcm2835gpio_init().

◆ bcm2835gpio_swd_write_fast()

static int bcm2835gpio_swd_write_fast ( int  swclk,
int  swdio 
)
static

◆ bcm2835gpio_swd_write_generic()

static int bcm2835gpio_swd_write_generic ( int  swclk,
int  swdio 
)
static

◆ bcm2835gpio_write()

static int bcm2835gpio_write ( int  tck,
int  tms,
int  tdi 
)
static

◆ COMMAND_HANDLER() [1/3]

COMMAND_HANDLER ( bcm2835gpio_handle_peripheral_base  )

Definition at line 325 of file bcm2835gpio.c.

◆ COMMAND_HANDLER() [2/3]

COMMAND_HANDLER ( bcm2835gpio_handle_peripheral_mem_dev  )

◆ COMMAND_HANDLER() [3/3]

COMMAND_HANDLER ( bcm2835gpio_handle_speed_coeffs  )

◆ initialize_gpio()

◆ is_gpio_config_valid()

◆ restore_gpio()

◆ set_gpio_value()

Variable Documentation

◆ adapter_gpio_config

Definition at line 54 of file bcm2835gpio.c.

◆ bcm2835_peri_base

off_t bcm2835_peri_base = 0x20000000
static

Definition at line 23 of file bcm2835gpio.c.

◆ bcm2835_peri_mem_dev

char* bcm2835_peri_mem_dev
static

Definition at line 22 of file bcm2835gpio.c.

Referenced by bcm2835_get_mem_dev(), bcm2835gpio_quit(), and COMMAND_HANDLER().

◆ bcm2835_transports

const char* const bcm2835_transports[] = { "jtag", "swd", NULL }
static

Definition at line 570 of file bcm2835gpio.c.

◆ bcm2835gpio_adapter_driver

struct adapter_driver bcm2835gpio_adapter_driver
Initial value:
= {
.name = "bcm2835gpio",
.transports = bcm2835_transports,
.speed_div = bcm2835gpio_speed_div,
.jtag_ops = &bcm2835gpio_interface,
.swd_ops = &bitbang_swd,
}
static const struct command_registration bcm2835gpio_command_handlers[]
Definition: bcm2835gpio.c:365
static int bcm2835gpio_init(void)
Definition: bcm2835gpio.c:428
static const char *const bcm2835_transports[]
Definition: bcm2835gpio.c:570
static int bcm2835gpio_khz(int khz, int *jtag_speed)
Definition: bcm2835gpio.c:274
static int bcm2835gpio_reset(int trst, int srst)
Definition: bcm2835gpio.c:231
static struct jtag_interface bcm2835gpio_interface
Definition: bcm2835gpio.c:572
static int bcm2835gpio_quit(void)
Definition: bcm2835gpio.c:534
static int bcm2835gpio_speed_div(int speed, int *khz)
Definition: bcm2835gpio.c:287
static int bcm2835gpio_speed(int speed)
Definition: bcm2835gpio.c:295
const struct swd_driver bitbang_swd
Definition: bitbang.c:617

Definition at line 570 of file bcm2835gpio.c.

◆ bcm2835gpio_bitbang

struct bitbang_interface bcm2835gpio_bitbang
static
Initial value:
= {
.swdio_read = bcm2835_swdio_read,
.swdio_drive = bcm2835_swdio_drive,
}
static int bcm2835gpio_swd_write_generic(int swclk, int swdio)
Definition: bcm2835gpio.c:220
static void bcm2835_swdio_drive(bool is_output)
Definition: bcm2835gpio.c:253
static int bcm2835gpio_blink(int on)
Definition: bcm2835gpio.c:411
static bb_value_t bcm2835gpio_read(void)
Definition: bcm2835gpio.c:173
static int bcm2835gpio_write(int tck, int tms, int tdi)
Definition: bcm2835gpio.c:181
static int bcm2835_swdio_read(void)
Definition: bcm2835gpio.c:267

Definition at line 411 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init().

◆ bcm2835gpio_command_handlers

const struct command_registration bcm2835gpio_command_handlers[]
static
Initial value:
= {
{
.name = "bcm2835gpio",
.mode = COMMAND_ANY,
.help = "perform bcm2835gpio management",
.usage = "",
},
}
static const struct command_registration bcm2835gpio_subcommand_handlers[]
Definition: bcm2835gpio.c:339
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:253
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:241

Definition at line 325 of file bcm2835gpio.c.

◆ bcm2835gpio_interface

struct jtag_interface bcm2835gpio_interface
static
Initial value:
= {
.supported = DEBUG_CAP_TMS_SEQ,
.execute_queue = bitbang_execute_queue,
}
int bitbang_execute_queue(struct jtag_command *cmd_queue)
Definition: bitbang.c:296
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:187

Definition at line 570 of file bcm2835gpio.c.

◆ bcm2835gpio_subcommand_handlers

const struct command_registration bcm2835gpio_subcommand_handlers[]
static
Initial value:
= {
{
.name = "speed_coeffs",
.handler = &bcm2835gpio_handle_speed_coeffs,
.mode = COMMAND_CONFIG,
.help = "SPEED_COEFF and SPEED_OFFSET for delay calculations.",
.usage = "[SPEED_COEFF SPEED_OFFSET]",
},
{
.name = "peripheral_mem_dev",
.handler = &bcm2835gpio_handle_peripheral_mem_dev,
.mode = COMMAND_CONFIG,
.help = "device to map memory mapped GPIOs from.",
.usage = "[device]",
},
{
.name = "peripheral_base",
.handler = &bcm2835gpio_handle_peripheral_base,
.mode = COMMAND_CONFIG,
.help = "peripheral base to access GPIOs, not needed with /dev/gpiomem.",
.usage = "[base]",
},
}
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 325 of file bcm2835gpio.c.

◆ dev_mem_fd

int dev_mem_fd
static

Definition at line 45 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init().

◆ initial_drive_strength_etc

uint32_t initial_drive_strength_etc
static

Definition at line 59 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init(), and bcm2835gpio_quit().

◆ initial_gpio_state

◆ jtag_delay

unsigned int jtag_delay
static

Definition at line 52 of file bcm2835gpio.c.

Referenced by bcm2835_delay(), and bcm2835gpio_speed().

◆ pads_base

volatile uint32_t* pads_base = MAP_FAILED
static

Definition at line 47 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init(), bcm2835gpio_munmap(), and bcm2835gpio_quit().

◆ pio_base

volatile uint32_t* pio_base = MAP_FAILED
static

Definition at line 46 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init(), and bcm2835gpio_munmap().

◆ speed_coeff

int speed_coeff = 113714
static

Definition at line 50 of file bcm2835gpio.c.

Referenced by bcm2835gpio_khz(), bcm2835gpio_speed_div(), and COMMAND_HANDLER().

◆ speed_offset

int speed_offset = 28
static

Definition at line 51 of file bcm2835gpio.c.

Referenced by bcm2835gpio_khz(), bcm2835gpio_speed_div(), and COMMAND_HANDLER().