static int init(t_hydra_console *con, t_tokenline_parsed *p) { mode_config_proto_t* proto = &con->mode->proto; bsp_status_t bsp_status; int tokens_used; /* Defaults */ init_proto_default(con); /* Process cmdline arguments, skipping "can". */ tokens_used = 1 + exec(con, p, 1); bsp_status = bsp_can_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); } /* By default, get all packets */ if (proto->config.can.filter_id_low != 0 || proto->config.can.filter_id_high != 0) { bsp_status = bsp_can_set_filter(proto->dev_num, proto, proto->config.can.filter_id_low, proto->config.can.filter_id_high); } else { bsp_status = bsp_can_init_filter(proto->dev_num, proto); } if( bsp_status != BSP_OK) { cprintf(con, "bsp_can_init_filter() error %d\r\n", bsp_status); } show_params(con); return tokens_used; }
static int init(t_hydra_console *con, t_tokenline_parsed *p) { mode_config_proto_t* proto = &con->mode->proto; int tokens_used; init_proto_default(con); /* Process cmdline arguments, skipping "spi". */ tokens_used = 1 + exec(con, p, 1); bsp_spi_init(proto->dev_num, proto); show_params(con); return tokens_used; }
static int exec(t_hydra_console *con, t_tokenline_parsed *p, int token_pos) { mode_config_proto_t* proto = &con->mode->proto; float arg_float; int arg_int, t, i; bsp_status_t bsp_status; for (t = token_pos; p->tokens[t]; t++) { switch (p->tokens[t]) { case T_SHOW: t += show(con, p); break; case T_DEVICE: /* Integer parameter. */ t += 2; memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int)); if (arg_int < 1 || arg_int > 2) { cprintf(con, "SPI device must be 1 or 2.\r\n"); return t; } init_proto_default(con); proto->dev_num = arg_int - 1; bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } tl_set_prompt(con->tl, (char *)con->mode->exec->get_prompt(con)); cprintf(con, "Note: SPI parameters have been reset to default values.\r\n"); break; case T_PULL: switch (p->tokens[++t]) { case T_UP: proto->dev_gpio_pull = MODE_CONFIG_DEV_GPIO_PULLUP; break; case T_DOWN: proto->dev_gpio_pull = MODE_CONFIG_DEV_GPIO_PULLDOWN; break; case T_FLOATING: proto->dev_gpio_pull = MODE_CONFIG_DEV_GPIO_NOPULL; break; } bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; case T_MODE: if (p->tokens[++t] == T_MASTER) proto->dev_mode = DEV_SPI_MASTER; else proto->dev_mode = DEV_SPI_SLAVE; bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; case T_FREQUENCY: t += 2; memcpy(&arg_float, p->buf + p->tokens[t], sizeof(float)); for (i = 0; i < SPEED_NB; i++) { if (arg_float == speeds[proto->dev_num][i]) { proto->dev_speed = i; break; } } if (i == 8) { cprintf(con, "Invalid frequency.\r\n"); return t; } bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; case T_POLARITY: t += 2; memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int)); if (arg_int < 0 || arg_int > 1) { cprintf(con, "Polarity device must be 0 or 1.\r\n"); return t; } proto->dev_polarity = arg_int; bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; case T_PHASE: t += 2; memcpy(&arg_int, p->buf + p->tokens[t], sizeof(int)); if (arg_int < 0 || arg_int > 1) { cprintf(con, "Phase device must be 0 or 1.\r\n"); return t; } proto->dev_phase = arg_int; bsp_spi_init(proto->dev_num, proto); break; case T_MSB_FIRST: proto->dev_bit_lsb_msb = DEV_SPI_FIRSTBIT_MSB; bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; case T_LSB_FIRST: proto->dev_bit_lsb_msb = DEV_SPI_FIRSTBIT_LSB; bsp_status = bsp_spi_init(proto->dev_num, proto); if( bsp_status != BSP_OK) { cprintf(con, str_bsp_init_err, bsp_status); return t; } break; default: return t - token_pos; } } return t - token_pos; }