Skip to content

Commit

Permalink
Initial LIN support
Browse files Browse the repository at this point in the history
  • Loading branch information
Baldanos committed Sep 20, 2018
1 parent a10093f commit 1b83986
Show file tree
Hide file tree
Showing 11 changed files with 385 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/common/exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ static struct cmd_map {
{ T_THREEWIRE, cmd_mode_init },
{ T_FLASH, cmd_mode_init },
{ T_WIEGAND, cmd_mode_init },
{ T_LIN, cmd_mode_init },
{ 0, NULL }
};

Expand Down
1 change: 1 addition & 0 deletions src/common/mode_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ typedef struct {
uint32_t dev_speed;
uint8_t dev_parity;
uint8_t dev_stop_bit;
uint8_t bus_mode;
} uart_config_t;

typedef struct {
Expand Down
24 changes: 23 additions & 1 deletion src/drv/stm32cube/bsp_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,14 +184,36 @@ bsp_status_t bsp_uart_init(bsp_dev_uart_t dev_num, mode_config_proto_t* mode_con
huart->Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart->Init.Mode = UART_MODE_TX_RX;

status = HAL_UART_Init(huart);
if(mode_conf->config.uart.bus_mode == BSP_UART_MODE_UART) {
status = HAL_UART_Init(huart);
} else {
status = HAL_LIN_Init(huart, UART_LINBREAKDETECTLENGTH_11B);
}

/* Dummy read to flush old character */
dummy_read = huart->Instance->DR;

return status;
}

/**
* @brief Sends a LIN break.
* @param dev_num: UART dev num.
* @retval status of the transfer.
*/
bsp_status_t bsp_lin_break(bsp_dev_uart_t dev_num)
{
UART_HandleTypeDef* huart;
huart = &uart_handle[dev_num];

bsp_status_t status;
status = HAL_LIN_SendBreak(huart);
if(status != BSP_OK) {
uart_error(dev_num);
}
return status;
}

/**
* @brief De-initialize the UART comunication bus
* @param dev_num: UART dev num.
Expand Down
5 changes: 5 additions & 0 deletions src/drv/stm32cube/bsp_uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ typedef enum {
BSP_DEV_UART_END = 2
} bsp_dev_uart_t;

#define BSP_UART_MODE_UART 0
#define BSP_UART_MODE_LIN 1

bsp_status_t bsp_uart_init(bsp_dev_uart_t dev_num, mode_config_proto_t* mode_conf);
bsp_status_t bsp_uart_deinit(bsp_dev_uart_t dev_num);

Expand All @@ -36,4 +39,6 @@ bsp_status_t bsp_uart_rxne(bsp_dev_uart_t dev_num);

uint32_t bsp_uart_get_final_baudrate(bsp_dev_uart_t dev_num);

bsp_status_t bsp_lin_break(bsp_dev_uart_t dev_num);

#endif /* _BSP_UART_H_ */
83 changes: 83 additions & 0 deletions src/hydrabus/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ t_token_dict tl_dict[] = {
{ T_TS2, "ts2" },
{ T_SJW, "sjw" },
{ T_WIEGAND, "wiegand" },
{ T_LIN, "lin" },
/* Developer warning add new command(s) here */

/* BP-compatible commands */
Expand Down Expand Up @@ -506,6 +507,82 @@ t_token tokens_uart[] = {
{ }
};

#define LIN_PARAMETERS \
{\
T_DEVICE,\
.arg_type = T_ARG_UINT,\
.help = "LIN device (1/2)"\
},\

t_token tokens_mode_lin[] = {
{
T_SHOW,
.subtokens = tokens_mode_show,
.help = "Show LIN parameters"
},
{
T_TRIGGER,
.subtokens = tokens_mode_trigger,
.help = "Setup LIN trigger"
},
LIN_PARAMETERS
/* LIN-specific commands */
{
T_READ,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Read byte (repeat with :<num>)"
},
{
T_HD,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Read byte (repeat with :<num>) and print hexdump"
},
{
T_WRITE,
.flags = T_FLAG_SUFFIX_TOKEN_DELIM_INT,
.help = "Write byte (repeat with :<num>)"
},
{
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_LEFT_SQ,
.help = "Send a LIN break"
},
{
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 LIN mode"
},
{ }
};

t_token tokens_lin[] = {
LIN_PARAMETERS
{ }
};

#define CAN_PARAMETERS \
{\
T_DEVICE,\
Expand Down Expand Up @@ -1775,6 +1852,12 @@ t_token tl_tokens[] = {
.subtokens = tokens_wiegand,
.help = "Wiegand mode"
},
{
T_LIN,
.subtokens = tokens_lin,
.help = "LIN mode",
.help_full = "Configuration: uart [device (1/2)>\r\nInteraction: <read/write (value:repeat)>"
},
{
T_DEBUG,
.subtokens = tokens_debug,
Expand Down
1 change: 1 addition & 0 deletions src/hydrabus/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ enum {
T_TS2,
T_SJW,
T_WIEGAND,
T_LIN,
/* Developer warning add new command(s) here */

/* BP-compatible commands */
Expand Down
1 change: 1 addition & 0 deletions src/hydrabus/hydrabus.mk
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ HYDRABUSSRC = hydrabus/hydrabus.c \
hydrabus/hydrabus_sd.c \
hydrabus/hydrabus_trigger.c \
hydrabus/hydrabus_mode_wiegand.c \
hydrabus/hydrabus_mode_lin.c

# Required include directories
HYDRABUSINC = ./hydrabus
3 changes: 3 additions & 0 deletions src/hydrabus/hydrabus_mode.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ extern const mode_exec_t mode_threewire_exec;
extern const mode_exec_t mode_can_exec;
extern const mode_exec_t mode_flash_exec;
extern const mode_exec_t mode_wiegand_exec;
extern const mode_exec_t mode_lin_exec;
extern t_token tokens_mode_spi[];
extern t_token tokens_mode_i2c[];
extern t_token tokens_mode_uart[];
Expand All @@ -62,6 +63,7 @@ extern t_token tokens_mode_threewire[];
extern t_token tokens_mode_can[];
extern t_token tokens_mode_flash[];
extern t_token tokens_mode_wiegand[];
extern t_token tokens_mode_lin[];

static struct {
int token;
Expand All @@ -81,6 +83,7 @@ static struct {
{ T_CAN, tokens_mode_can, &mode_can_exec },
{ T_FLASH, tokens_mode_flash, &mode_flash_exec },
{ T_WIEGAND, tokens_mode_wiegand, &mode_wiegand_exec },
{ T_LIN, tokens_mode_lin, &mode_lin_exec },
};

const char hydrabus_mode_str_cs_enabled[] = "/CS ENABLED\r\n";
Expand Down
Loading

0 comments on commit 1b83986

Please sign in to comment.