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_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_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
 
uint32_t bcm2835_peri_base = 0x20000000
 
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 23 of file bcm2835gpio.c.

◆ BCM2835_GPIO_MODE_INPUT

#define BCM2835_GPIO_MODE_INPUT   0

Definition at line 29 of file bcm2835gpio.c.

◆ BCM2835_GPIO_MODE_OUTPUT

#define BCM2835_GPIO_MODE_OUTPUT   1

Definition at line 30 of file bcm2835gpio.c.

◆ BCM2835_PADS_GPIO_0_27

#define BCM2835_PADS_GPIO_0_27   (bcm2835_peri_base + 0x100000)

Definition at line 25 of file bcm2835gpio.c.

◆ BCM2835_PADS_GPIO_0_27_OFFSET

#define BCM2835_PADS_GPIO_0_27_OFFSET   (0x2c / 4)

Definition at line 26 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 41 of file bcm2835gpio.c.

◆ GPIO_LEV

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

Definition at line 42 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 40 of file bcm2835gpio.c.

◆ INP_GPIO

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

Definition at line 34 of file bcm2835gpio.c.

◆ MODE_GPIO

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

Definition at line 33 of file bcm2835gpio.c.

◆ OUT_GPIO

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

Definition at line 38 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:45

Definition at line 35 of file bcm2835gpio.c.

Function Documentation

◆ 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 372 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 261 of file bcm2835gpio.c.

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

◆ bcm2835gpio_munmap()

static void bcm2835gpio_munmap ( void  )
static

Definition at line 359 of file bcm2835gpio.c.

References pads_base, and pio_base.

Referenced by bcm2835gpio_init(), and 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 279 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 273 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 350 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/2]

COMMAND_HANDLER ( bcm2835gpio_handle_peripheral_base  )

Definition at line 297 of file bcm2835gpio.c.

◆ COMMAND_HANDLER() [2/2]

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 53 of file bcm2835gpio.c.

◆ bcm2835_peri_base

uint32_t bcm2835_peri_base = 0x20000000

Definition at line 22 of file bcm2835gpio.c.

◆ bcm2835_transports

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

Definition at line 518 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:326
static int bcm2835gpio_init(void)
Definition: bcm2835gpio.c:389
static const char *const bcm2835_transports[]
Definition: bcm2835gpio.c:518
static int bcm2835gpio_khz(int khz, int *jtag_speed)
Definition: bcm2835gpio.c:261
static int bcm2835gpio_reset(int trst, int srst)
Definition: bcm2835gpio.c:221
static struct jtag_interface bcm2835gpio_interface
Definition: bcm2835gpio.c:520
static int bcm2835gpio_quit(void)
Definition: bcm2835gpio.c:485
static int bcm2835gpio_speed_div(int speed, int *khz)
Definition: bcm2835gpio.c:273
static int bcm2835gpio_speed(int speed)
Definition: bcm2835gpio.c:279
const struct swd_driver bitbang_swd
Definition: bitbang.c:569

Definition at line 518 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:209
static void bcm2835_swdio_drive(bool is_output)
Definition: bcm2835gpio.c:240
static int bcm2835gpio_blink(int on)
Definition: bcm2835gpio.c:372
static bb_value_t bcm2835gpio_read(void)
Definition: bcm2835gpio.c:160
static int bcm2835gpio_write(int tck, int tms, int tdi)
Definition: bcm2835gpio.c:168
static int bcm2835_swdio_read(void)
Definition: bcm2835gpio.c:254

Definition at line 372 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:307
#define COMMAND_REGISTRATION_DONE
Use this as the last entry in an array of command_registration records.
Definition: command.h:247
@ COMMAND_ANY
Definition: command.h:42
const char * usage
a string listing the options and arguments, required or optional
Definition: command.h:235

Definition at line 297 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(void)
Definition: bitbang.c:281
#define DEBUG_CAP_TMS_SEQ
Definition: interface.h:189

Definition at line 518 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_base",
.handler = &bcm2835gpio_handle_peripheral_base,
.mode = COMMAND_CONFIG,
.help = "peripheral base to access GPIOs (RPi1 0x20000000, RPi2 0x3F000000).",
.usage = "[base]",
},
}
@ COMMAND_CONFIG
Definition: command.h:41

Definition at line 297 of file bcm2835gpio.c.

◆ dev_mem_fd

int dev_mem_fd
static

Definition at line 44 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init().

◆ initial_drive_strength_etc

uint32_t initial_drive_strength_etc
static

Definition at line 58 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init(), and bcm2835gpio_quit().

◆ initial_gpio_state

◆ jtag_delay

unsigned int jtag_delay
static

◆ pads_base

volatile uint32_t* pads_base = MAP_FAILED
static

Definition at line 46 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 45 of file bcm2835gpio.c.

Referenced by bcm2835gpio_init(), and bcm2835gpio_munmap().

◆ speed_coeff

int speed_coeff = 113714
static

Definition at line 49 of file bcm2835gpio.c.

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

◆ speed_offset

int speed_offset = 28
static

Definition at line 50 of file bcm2835gpio.c.

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