Skip to content

Commit

Permalink
Raw 3-wire support (#52)
Browse files Browse the repository at this point in the history
* Initial 3-wire support

* 3-wire BBIO support

* BBIO timer cleanup
  • Loading branch information
Baldanos authored and bvernoux committed May 12, 2016
1 parent 5a5751b commit a9681c5
Show file tree
Hide file tree
Showing 15 changed files with 823 additions and 198 deletions.
1 change: 1 addition & 0 deletions common/exec.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ static struct cmd_map {
{ T_JTAG, cmd_mode_init }, { T_JTAG, cmd_mode_init },
{ T_RNG, cmd_rng }, { T_RNG, cmd_rng },
{ T_TWOWIRE, cmd_mode_init }, { T_TWOWIRE, cmd_mode_init },
{ T_THREEWIRE, cmd_mode_init },
{ 0, NULL } { 0, NULL }
}; };


Expand Down
107 changes: 107 additions & 0 deletions hydrabus/commands.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ t_token_dict tl_dict[] = {
{ T_FILTER, "filter" }, { T_FILTER, "filter" },
{ T_LOW, "low" }, { T_LOW, "low" },
{ T_HIGH, "high" }, { T_HIGH, "high" },
{ T_THREEWIRE, "3-wire" },


{ T_LEFT_SQ, "[" }, { T_LEFT_SQ, "[" },
{ T_RIGHT_SQ, "]" }, { T_RIGHT_SQ, "]" },
Expand Down Expand Up @@ -911,6 +912,107 @@ t_token tokens_twowire[] = {
{ } { }
}; };


#define THREEWIRE_PARAMETERS \
{ T_DEVICE, \
.arg_type = T_ARG_UINT, \
.help = "3-wire device (1)" }, \
{ T_PULL, \
.arg_type = T_ARG_TOKEN, \
.subtokens = tokens_gpio_pull, \
.help = "GPIO pull (up/down/floating)" }, \
{ T_MSB_FIRST, \
.help = "Send/receive MSB first" }, \
{ T_LSB_FIRST, \
.help = "Send/receive LSB first" },

t_token tokens_mode_threewire[] = {
{
T_SHOW,
.subtokens = tokens_mode_show,
.help = "Show 3-wire parameters"
},
THREEWIRE_PARAMETERS
/* 3-wire-specific commands */
{
T_READ,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Read byte (repeat with :<num>)"
},
{
T_WRITE,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Write byte (repeat with :<num>)"
},
{
T_FREQUENCY,
.arg_type = T_ARG_FLOAT,
.help = "Bus frequency"
},
{
T_ARG_UINT,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Write byte (repeat with :<num>)"
},
{
T_ARG_STRING,
.help = "Write string"
},
/* BP commands */
{
T_CARET,
.help = "Send one clock tick"
},
{
T_SLASH,
.help = "Toggle clock level high"
},
{
T_BACKSLASH,
.help = "Toggle clock level low"
},
{
T_MINUS,
.help = "Toggle SDO high"
},
{
T_UNDERSCORE,
.help = "Toggle SDO low"
},
{
T_EXCLAMATION,
.help = "Read bit with clock"
},
{
T_DOT,
.help = "Read bit without clock"
},
{
T_AMPERSAND,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Delay 1 usec (repeat with :<num>)"
},
{
T_PERCENT,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Delay 1 msec (repeat with :<num>)"
},
{
T_TILDE,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Write a random byte (repeat with :<num>)"
},
{
T_EXIT,
.help = "Exit 3-wire mode"
},
{ }
};

t_token tokens_threewire[] = {
THREEWIRE_PARAMETERS
{ }
};

t_token tokens_gpio_mode[] = { t_token tokens_gpio_mode[] = {
{ {
T_IN, T_IN,
Expand Down Expand Up @@ -1247,6 +1349,11 @@ t_token tl_tokens[] = {
.subtokens = tokens_twowire, .subtokens = tokens_twowire,
.help = "2-wire mode" .help = "2-wire mode"
}, },
{
T_THREEWIRE,
.subtokens = tokens_threewire,
.help = "3-wire mode"
},
{ {
T_UART, T_UART,
.subtokens = tokens_uart, .subtokens = tokens_uart,
Expand Down
1 change: 1 addition & 0 deletions hydrabus/commands.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ enum {
T_FILTER, T_FILTER,
T_LOW, T_LOW,
T_HIGH, T_HIGH,
T_THREEWIRE,


/* BP-compatible commands */ /* BP-compatible commands */
T_LEFT_SQ, T_LEFT_SQ,
Expand Down
3 changes: 2 additions & 1 deletion hydrabus/hydrabus.mk
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ HYDRABUSSRC = hydrabus/hydrabus.c \
hydrabus/hydrabus_mode_jtag.c \ hydrabus/hydrabus_mode_jtag.c \
hydrabus/hydrabus_rng.c \ hydrabus/hydrabus_rng.c \
hydrabus/hydrabus_mode_twowire.c \ hydrabus/hydrabus_mode_twowire.c \
hydrabus/hydrabus_mode_threewire.c \
hydrabus/hydrabus_mode_can.c \ hydrabus/hydrabus_mode_can.c \
hydrabus/hydrabus_bbio.c \ hydrabus/hydrabus_bbio.c \
hydrabus/hydrabus_bbio_spi.c \ hydrabus/hydrabus_bbio_spi.c \
hydrabus/hydrabus_bbio_pin.c \ hydrabus/hydrabus_bbio_pin.c \
hydrabus/hydrabus_bbio_can.c \ hydrabus/hydrabus_bbio_can.c \
hydrabus/hydrabus_bbio_uart.c \ hydrabus/hydrabus_bbio_uart.c \
hydrabus/hydrabus_bbio_i2c.c \ hydrabus/hydrabus_bbio_i2c.c \
hydrabus/hydrabus_bbio_twowire.c hydrabus/hydrabus_bbio_rawwire.c


# Required include directories # Required include directories
HYDRABUSINC = ./hydrabus HYDRABUSINC = ./hydrabus
4 changes: 2 additions & 2 deletions hydrabus/hydrabus_bbio.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#include "hydrabus_bbio_can.h" #include "hydrabus_bbio_can.h"
#include "hydrabus_bbio_uart.h" #include "hydrabus_bbio_uart.h"
#include "hydrabus_bbio_i2c.h" #include "hydrabus_bbio_i2c.h"
#include "hydrabus_bbio_twowire.h" #include "hydrabus_bbio_rawwire.h"


int cmd_bbio(t_hydra_console *con) int cmd_bbio(t_hydra_console *con)
{ {
Expand Down Expand Up @@ -59,7 +59,7 @@ int cmd_bbio(t_hydra_console *con)
break; break;
case BBIO_RAWWIRE: case BBIO_RAWWIRE:
cprint(con, "RAW1", 4); cprint(con, "RAW1", 4);
bbio_mode_twowire(con); bbio_mode_rawwire(con);
break; break;
case BBIO_JTAG: case BBIO_JTAG:
cprint(con, "OCD1", 4); cprint(con, "OCD1", 4);
Expand Down
36 changes: 18 additions & 18 deletions hydrabus/hydrabus_bbio.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -105,23 +105,23 @@
/* /*
* 2-Wire-specific commands * 2-Wire-specific commands
*/ */
#define BBIO_2WIRE_I2C_START 0b00000010 #define BBIO_RAWWIRE_I2C_START 0b00000010
#define BBIO_2WIRE_I2C_STOP 0b00000011 #define BBIO_RAWWIRE_I2C_STOP 0b00000011
#define BBIO_2WIRE_CS_LOW 0b00000100 #define BBIO_RAWWIRE_CS_LOW 0b00000100
#define BBIO_2WIRE_CS_HIGH 0b00000101 #define BBIO_RAWWIRE_CS_HIGH 0b00000101
#define BBIO_2WIRE_READ_BYTE 0b00000110 #define BBIO_RAWWIRE_READ_BYTE 0b00000110
#define BBIO_2WIRE_READ_BIT 0b00000111 #define BBIO_RAWWIRE_READ_BIT 0b00000111
#define BBIO_2WIRE_PEEK_INPUT 0b00001000 #define BBIO_RAWWIRE_PEEK_INPUT 0b00001000
#define BBIO_2WIRE_CLK_TICK 0b00001001 #define BBIO_RAWWIRE_CLK_TICK 0b00001001
#define BBIO_2WIRE_CLK_LOW 0b00001010 #define BBIO_RAWWIRE_CLK_LOW 0b00001010
#define BBIO_2WIRE_CLK_HIGH 0b00001011 #define BBIO_RAWWIRE_CLK_HIGH 0b00001011
#define BBIO_2WIRE_DATA_LOW 0b00001100 #define BBIO_RAWWIRE_DATA_LOW 0b00001100
#define BBIO_2WIRE_DATA_HIGH 0b00001101 #define BBIO_RAWWIRE_DATA_HIGH 0b00001101
#define BBIO_2WIRE_BULK_TRANSFER 0b00010000 #define BBIO_RAWWIRE_BULK_TRANSFER 0b00010000
#define BBIO_2WIRE_BULK_CLK 0b00100000 #define BBIO_RAWWIRE_BULK_CLK 0b00100000
#define BBIO_2WIRE_BULK_BIT 0b00110000 #define BBIO_RAWWIRE_BULK_BIT 0b00110000
#define BBIO_2WIRE_CONFIG_PERIPH 0b01000000 #define BBIO_RAWWIRE_CONFIG_PERIPH 0b01000000
#define BBIO_2WIRE_SET_SPEED 0b01100000 #define BBIO_RAWWIRE_SET_SPEED 0b01100000
#define BBIO_2WIRE_CONFIG 0b10000000 #define BBIO_RAWWIRE_CONFIG 0b10000000


int cmd_bbio(t_hydra_console *con); int cmd_bbio(t_hydra_console *con);
Loading

0 comments on commit a9681c5

Please sign in to comment.