gnss-can support : First implementation
This commit is contained in:
parent
bf667f5171
commit
424b41c40e
|
|
@ -10,4 +10,4 @@ ifeq ($(CONFIG_SKIP_LOWLEVEL_INIT),)
|
|||
obj-y := mux.o
|
||||
endif
|
||||
|
||||
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o shield.o shield_can.o shield_comio.o fileaccess.o
|
||||
obj-y += board.o ../common/bdparser.o ../common/board_descriptor.o shield.o shield_can.o shield_comio.o shield_gnss_can.o fileaccess.o
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@
|
|||
#include "shield.h"
|
||||
#include "shield_can.h"
|
||||
#include "shield_comio.h"
|
||||
#include "shield_gnss_can.h"
|
||||
#include "fileaccess.h"
|
||||
|
||||
DECLARE_GLOBAL_DATA_PTR;
|
||||
|
|
@ -82,6 +83,7 @@ static BD_Context bdctx[3]; /* The descriptor context */
|
|||
|
||||
#define SHIELD_COM_IO 0
|
||||
#define SHIELD_DUALCAN 1
|
||||
#define SHIELD_GNSS_CAN 2
|
||||
|
||||
static int _bd_init(void)
|
||||
{
|
||||
|
|
@ -591,6 +593,16 @@ static struct shield_command known_shield_commands[] = {
|
|||
"fdt set $can1 status okay;",
|
||||
can_shield_init
|
||||
},
|
||||
{
|
||||
SHIELD_GNSS_CAN,
|
||||
"gnss-can",
|
||||
"shield gnss-can gnss-mode uart can termination off",
|
||||
"fdt get value serial0 /aliases serial0;" \
|
||||
"fdt set $serial0 status okay;" \
|
||||
"fdt get value can1 /aliases d_can1;" \
|
||||
"fdt set $can1 status okay;",
|
||||
gnss_can_shield_init
|
||||
},
|
||||
};
|
||||
|
||||
static const struct shield_command* get_shield_command(int shield_id)
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ static int do_shieldmode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv
|
|||
}
|
||||
|
||||
U_BOOT_CMD(
|
||||
shield, 6, 1, do_shieldmode,
|
||||
shield, 7, 1, do_shieldmode,
|
||||
"Set the shield mode",
|
||||
"dualcan termination [on|off] [on|off]\n"
|
||||
"shield comio mode [rs232|rs485] termination [on|off]\n"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,222 @@
|
|||
#define DEBUG
|
||||
|
||||
#include <common.h>
|
||||
#include <asm/gpio.h>
|
||||
#include <asm/arch/mux.h>
|
||||
|
||||
#include "shield.h"
|
||||
#include "board.h"
|
||||
|
||||
#define NETBIRD_GPIO_RST_SHIELD_N GPIO_TO_PIN(0, 27)
|
||||
#define NETBIRD_GPIO_LATCH GPIO_TO_PIN(0, 7)
|
||||
#define NETBIRD_GPIO_MODE_1 GPIO_TO_PIN(1, 10)
|
||||
|
||||
static int shield_slot_initialized = 0;
|
||||
|
||||
|
||||
static struct module_pin_mux can_shield_netbird_pin_mux_config[] = {
|
||||
/* Leave UART0 unconfigured because we want to configure it as needed by linux (can/spi/uart/etc) */
|
||||
{OFFSET(uart0_ctsn), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* CAN1 tx */
|
||||
//{OFFSET(uart0_rxd), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* CAN0 tx */
|
||||
{OFFSET(ecap0_in_pwm0_out), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* Latch EN */
|
||||
{-1},
|
||||
};
|
||||
|
||||
static struct module_pin_mux can_shield_netbird_pin_mux_final[] = {
|
||||
/* Leave UART0 unconfigured because we want to configure it as needed by linux (can/spi/uart/etc) */
|
||||
{OFFSET(uart0_ctsn), (MODE(2) | PULLUDEN | PULLUP_EN)}, /* E18 CAN1 tx */
|
||||
{OFFSET(uart0_rtsn), (MODE(2) | PULLUDDIS | RXACTIVE)}, /* E17 CAN1 rx */
|
||||
{OFFSET(uart0_rxd), (MODE(7) | PULLUDDIS)}, /* (E15) UART0_RXD */
|
||||
{OFFSET(uart0_txd), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* (E16) UART0_TXD */
|
||||
//{OFFSET(uart0_txd), (MODE(2) | PULLUDDIS | RXACTIVE)}, /* CAN0 rx */
|
||||
//{OFFSET(uart0_rxd), (MODE(2) | PULLUDEN | PULLUP_EN)}, /* CAN0 tx */
|
||||
{-1},
|
||||
};
|
||||
|
||||
static struct module_pin_mux gnss_shield_netbird_pin_mux_uart[] = {
|
||||
/* Leave UART0 unconfigured because we want to configure it as needed by linux (can/spi/uart/etc) */
|
||||
{OFFSET(uart0_rxd), (MODE(7) | PULLUDDIS)}, /* (E15) UART0_RXD */
|
||||
{OFFSET(uart0_txd), (MODE(7) | PULLUDEN | PULLUP_EN)}, /* (E16) UART0_TXD */
|
||||
{-1},
|
||||
};
|
||||
|
||||
static struct module_pin_mux gnss_shield_netbird_pin_mux_i2c[] = {
|
||||
{OFFSET(uart0_rxd), (MODE(3) | PULLUDDIS)}, /* (E15) UART0_RXD - I2C2_SDA */
|
||||
{OFFSET(uart0_txd), (MODE(3) | PULLUDEN | PULLUP_EN)}, /* (E16) UART0_TXD - I2C_SCL */
|
||||
{-1},
|
||||
};
|
||||
|
||||
static int request_gpios(void)
|
||||
{
|
||||
int ret;
|
||||
|
||||
debug("Shield configure gpios\n");
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_RST_SHIELD_N, "shield-rst");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_LATCH, "shield-load");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
/*
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_MODE_0, "shield-mode0");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
*/
|
||||
ret = shield_gpio_request_as_input(NETBIRD_GPIO_MODE_1, "shield-mode1");
|
||||
if ((ret < 0))
|
||||
return -1;
|
||||
|
||||
shield_slot_initialized = 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int configure_can_termination(int termination)
|
||||
{
|
||||
int ret;
|
||||
|
||||
|
||||
debug ("Set can termination to %d\n", termination);
|
||||
|
||||
if (!shield_slot_initialized) {
|
||||
if (request_gpios()) {
|
||||
puts("Failed to request gpios\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
debug("Configure shield pin muxing for configuration\n");
|
||||
configure_module_pin_mux(can_shield_netbird_pin_mux_config);
|
||||
|
||||
debug("Make sure shield module is in reset\n");
|
||||
ret = gpio_direction_output(NETBIRD_GPIO_RST_SHIELD_N, 0);
|
||||
if (ret < 0) {
|
||||
puts("Can not set shield-rst as output\n");
|
||||
return -1;
|
||||
}
|
||||
udelay(10);
|
||||
|
||||
debug("Set latch to high\n");
|
||||
ret = gpio_direction_output(NETBIRD_GPIO_LATCH, 1);
|
||||
if (ret < 0) {
|
||||
puts("Can not set shield-load as output\n");
|
||||
return -1;
|
||||
}
|
||||
udelay(10);
|
||||
|
||||
debug("Write termination to GPIOs\n");
|
||||
/*
|
||||
ret = gpio_direction_output(NETBIRD_GPIO_MODE_0, mode & 0x01);
|
||||
if (ret < 0) {
|
||||
puts("Can not set shield-mode0 as output\n");
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
ret = gpio_direction_output(NETBIRD_GPIO_MODE_1, termination);
|
||||
if (ret < 0) {
|
||||
puts("Can not set shield-mode1 as output\n"); ///////////////// 1
|
||||
return -1;
|
||||
}
|
||||
udelay(10);
|
||||
|
||||
debug("Set latch to low\n");
|
||||
gpio_set_value(NETBIRD_GPIO_LATCH, 0);
|
||||
udelay(10);
|
||||
|
||||
debug("Set mode0 and mode1 to highz again\n");
|
||||
/* ret = gpio_direction_input(NETBIRD_GPIO_MODE_0);
|
||||
if ((ret < 0)) {
|
||||
puts("Could not configure shield slot mode0 gpio as input\n");
|
||||
return -1;
|
||||
}
|
||||
*/
|
||||
ret = gpio_direction_input(NETBIRD_GPIO_MODE_1);
|
||||
if ((ret < 0)) {
|
||||
puts("Could not configure shield slot mode1 gpio as input\n");
|
||||
return -1;
|
||||
}
|
||||
udelay(10);
|
||||
|
||||
debug("Take shield out of reset\n");
|
||||
gpio_set_value(NETBIRD_GPIO_RST_SHIELD_N, 1);
|
||||
udelay(10);
|
||||
|
||||
debug("Set final can shield muxing\n");
|
||||
configure_module_pin_mux(can_shield_netbird_pin_mux_final);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
static int get_termination(const char* termination)
|
||||
{
|
||||
if (strcmp("on", termination) == 0) {
|
||||
return 1;
|
||||
}
|
||||
else if (strcmp("off", termination) == 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
debug ("Invalid termination mode %s (falling back to off)", termination);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
static int get_termination_from_args(char * const argv[], int argc)
|
||||
{
|
||||
int termination;
|
||||
|
||||
if(argc != 2){
|
||||
debug("2 arguments are needed for can configuration\n");
|
||||
return -1;
|
||||
}
|
||||
if (strcmp ("termination", argv[0])) {
|
||||
debug("The only option for can is terminations\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
termination = get_termination(argv[1]);
|
||||
if (termination < 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Termination is inverse */
|
||||
return !termination;
|
||||
}
|
||||
|
||||
// shield gnss-can gnss-mode uart can termination off
|
||||
static int set_shieldmode(char * const argv[], int argc)
|
||||
{
|
||||
int ret = 0;
|
||||
if (argc != 5) {
|
||||
printf("Too few arguments for gnss-can\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (strcmp ("gnss-mode", argv[0])) {
|
||||
printf("gnss can module want a gnss-mode\n");
|
||||
return -1;
|
||||
}
|
||||
ret = 0;//configure_gnss_mode(argv[1]);
|
||||
if(ret != 0) return ret;
|
||||
|
||||
|
||||
if (strcmp ("can", argv[2])) {
|
||||
printf("gnss can module wants a gnss-mode\n");
|
||||
return -1;
|
||||
}
|
||||
printf("configure_can_termination");
|
||||
ret = configure_can_termination(get_termination_from_args(&argv[3], 2));
|
||||
if(ret != 0) return ret;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct shield_t gnss_can_shield = {
|
||||
"gnss-can", set_shieldmode
|
||||
};
|
||||
|
||||
void gnss_can_shield_init(void)
|
||||
{
|
||||
shield_register(&gnss_can_shield);
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,9 @@
|
|||
#ifndef SHIELD_GNSS_CAN_H
|
||||
#define SHIELD_GNSS_CAN_H
|
||||
|
||||
int shield_gnss_can_init(void);
|
||||
int shield_gnss_can_setmode(int mode);
|
||||
|
||||
void gnss_can_shield_init(void);
|
||||
|
||||
#endif // SHIELD_GNSS_CAN_H
|
||||
Loading…
Reference in New Issue