static int __init gps_get_config(struct gps_config_info *gps_info) { script_item_value_type_e type; script_item_u val; struct gpio_config *gpio_p = NULL; memset(gps_info,0,sizeof(struct gps_config_info)); type = script_get_item("gps_para", "gps_used", &val); if (SCIRPT_ITEM_VALUE_TYPE_INT != type) { GPS_ERR("failed to fetch gps configuration!\n"); return -1; } if (!val.val) { GPS_ERR("gsp not used in configuration\n"); return -1; } gps_info->gps_used = val.val; type = script_get_item("gps_para", "gps_standby_n", &val); if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) GPS_DBG("mod has no gps_standby_n gpio\n"); else { gpio_p = &val.gpio; gps_info->standby = gpio_p->gpio; sunxi_gpio_req(gpio_p); } type = script_get_item("gps_para", "gps_rst_n", &val); if (SCIRPT_ITEM_VALUE_TYPE_PIO != type) GPS_DBG("mod has no gps_rst_n gpio\n"); else { gpio_p = &val.gpio; gps_info->reset = gpio_p->gpio; sunxi_gpio_req(gpio_p); } type = script_get_item("gps_para", "gps_clk", &val); if (SCIRPT_ITEM_VALUE_TYPE_STR != type) GPS_DBG("failed to fetch gps_clk\n"); else { strcpy(gps_info->gps_clk, val.str); } return 0; }
static void enable_gps_32k(int enable) { int ret = 0; if (enable){ ret = clk_prepare_enable(gps_32k); if (ret){ GPS_ERR("enable ap 32k failed!\n"); } } else { clk_disable_unprepare(gps_32k); } }
static int create_sysfs_interfaces(struct device *dev) { int i; for (i = 0; i < ARRAY_SIZE(attributes); i++) if (device_create_file(dev, attributes + i)) goto error; return 0; error: for (; i >= 0; i--) device_remove_file(dev, attributes + i); GPS_ERR("%s:Unable to create interface\n", __func__); return -1; }
static int gps_probe(struct platform_device *pdev) { int err = 0; struct gps_dev *dev = _gps_dev; struct gps_config_info *gps_info = &dev->gps_info; if(gps_info->gps_clk && strcmp(gps_info->gps_clk, "")){ gps_32k = clk_get(NULL, gps_info->gps_clk); if (IS_ERR(gps_32k)){ GPS_ERR("Get ap 32k clk out failed!\n"); return -1; } enable_gps_32k(1); } GPS_DBG("set %s 32k out\n", gps_info->gps_clk); gps_power_init(); create_sysfs_interfaces(&pdev->dev); return err; }
int GPS::setBaudrate(unsigned baud) { #if __PX4_QURT // TODO: currently QURT does not support configuration with termios. dspal_serial_ioctl_data_rate data_rate; switch (baud) { case 9600: data_rate.bit_rate = DSPAL_SIO_BITRATE_9600; break; case 19200: data_rate.bit_rate = DSPAL_SIO_BITRATE_19200; break; case 38400: data_rate.bit_rate = DSPAL_SIO_BITRATE_38400; break; case 57600: data_rate.bit_rate = DSPAL_SIO_BITRATE_57600; break; case 115200: data_rate.bit_rate = DSPAL_SIO_BITRATE_115200; break; default: PX4_ERR("ERR: unknown baudrate: %d", baud); return -EINVAL; } int ret = ::ioctl(_serial_fd, SERIAL_IOCTL_SET_DATA_RATE, (void *)&data_rate); if (ret != 0) { return ret; } #else /* process baud rate */ int speed; switch (baud) { case 9600: speed = B9600; break; case 19200: speed = B19200; break; case 38400: speed = B38400; break; case 57600: speed = B57600; break; case 115200: speed = B115200; break; case 230400: speed = B230400; break; default: PX4_ERR("ERR: unknown baudrate: %d", baud); return -EINVAL; } struct termios uart_config; int termios_state; /* fill the struct for the new configuration */ tcgetattr(_serial_fd, &uart_config); /* properly configure the terminal (see also https://en.wikibooks.org/wiki/Serial_Programming/termios ) */ // // Input flags - Turn off input processing // // convert break to null byte, no CR to NL translation, // no NL to CR translation, don't mark parity errors or breaks // no input parity check, don't strip high bit off, // no XON/XOFF software flow control // uart_config.c_iflag &= ~(IGNBRK | BRKINT | ICRNL | INLCR | PARMRK | INPCK | ISTRIP | IXON); // // Output flags - Turn off output processing // // no CR to NL translation, no NL to CR-NL translation, // no NL to CR translation, no column 0 CR suppression, // no Ctrl-D suppression, no fill characters, no case mapping, // no local output processing // // config.c_oflag &= ~(OCRNL | ONLCR | ONLRET | // ONOCR | ONOEOT| OFILL | OLCUC | OPOST); uart_config.c_oflag = 0; // // No line processing // // echo off, echo newline off, canonical mode off, // extended input processing off, signal chars off // uart_config.c_lflag &= ~(ECHO | ECHONL | ICANON | IEXTEN | ISIG); /* no parity, one stop bit */ uart_config.c_cflag &= ~(CSTOPB | PARENB); /* set baud rate */ if ((termios_state = cfsetispeed(&uart_config, speed)) < 0) { GPS_ERR("ERR: %d (cfsetispeed)", termios_state); return -1; } if ((termios_state = cfsetospeed(&uart_config, speed)) < 0) { GPS_ERR("ERR: %d (cfsetospeed)", termios_state); return -1; } if ((termios_state = tcsetattr(_serial_fd, TCSANOW, &uart_config)) < 0) { GPS_ERR("ERR: %d (tcsetattr)", termios_state); return -1; } #endif return 0; }