Permalink
Browse files

Initial LIN support

  • Loading branch information...
Baldanos committed Apr 7, 2017
1 parent a10093f commit 1b8398660c11c9a295ef0ea7c3be1aa6f3ec5b03
View
@@ -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 }
};
View
@@ -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 {
@@ -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.
@@ -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);
@@ -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_ */
View
@@ -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 */
@@ -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,\
@@ -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,
View
@@ -145,6 +145,7 @@ enum {
T_TS2,
T_SJW,
T_WIEGAND,
T_LIN,
/* Developer warning add new command(s) here */
/* BP-compatible commands */
View
@@ -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
@@ -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[];
@@ -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;
@@ -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";
Oops, something went wrong.

0 comments on commit 1b83986

Please sign in to comment.