static ssize_t sirf_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[256]; int flag, ret; char buffer[7]; if (len > 256) len = 256; if (copy_from_user(messages, buff, len)) return -EFAULT; if (strncmp(messages, "off", 3) == 0) { strcpy(sirf_status, "off"); gps_power_off(); } else if (strncmp(messages, "on", 2) == 0) { strcpy(sirf_status, "on"); gps_power_on(); } else if (strncmp(messages, "reset", 5) == 0) { strcpy(sirf_status, messages); ret = sscanf(messages, "%s %d", buffer, &flag); if (ret == 2) gps_reset(flag); } else if (strncmp(messages, "sirfon", 5) == 0) { strcpy(sirf_status, messages); ret = sscanf(messages, "%s %d", buffer, &flag); if (ret == 2) gps_on_off(flag); } else { printk("usage: echo {on/off} > /proc/driver/sirf\n"); } return len; }
static long gpsctl_ioctl(struct file *file,unsigned int cmd, unsigned long arg) { void __user *pa = (void __user *)arg; short is_poweron; short is_clkon; short is_reset; short is_on; switch (cmd) { case GPSCTL_IOC_SET_POWER: if (copy_from_user(&is_poweron, pa, sizeof(is_poweron))) return -EFAULT; gps_power_ctl(is_poweron); break; case GPSCTL_IOC_SET_CLK: if (copy_from_user(&is_clkon, pa, sizeof(is_clkon))) return -EFAULT; clk_32k_config(is_clkon); break; case GPSCTL_IOC_RESET: if (copy_from_user(&is_reset, pa, sizeof(is_reset))) return -EFAULT; gps_reset(is_reset); break; case GPSCTL_IOC_ONOFF: if (copy_from_user(&is_on, pa, sizeof(is_on))) return -EFAULT; gps_onoff(is_on); break; default: break; } return 0; }
static int tomtom_gps_probe(struct platform_device *pdev) { struct gps_device *gpsd; tomtom_gps_data_t *gps_drv_data = NULL; int ret = 0; BUG_ON(!pdev); BUG_ON(!(&pdev->dev)); printk(KERN_INFO PFX "Probed.\n"); gps_drv_data = tomtom_gps_init_drv_data(pdev); if (IS_ERR (gps_drv_data)) return PTR_ERR(gps_drv_data); gpsd = gps_device_register(gps_drv_data->name, &pdev->dev, NULL, &tomtom_gps_ops); if (IS_ERR (gpsd)) { kfree(gps_drv_data); return PTR_ERR(gpsd); } dev_set_drvdata(&gpsd->dev, gps_drv_data); platform_set_drvdata(pdev, gpsd); gpsd->props.power = GPS_OFF; memset(&gpsd->props.tv, 0x00, sizeof(struct timeval)); if (gps_drv_data->machinfo->gps_reset) gps_drv_data->machinfo->gps_reset(); gps_set_power(gpsd); gps_reset(gpsd); if (0 != (ret = tomtom_gps_request_resource(pdev))) { gps_device_unregister(gpsd); kfree(gps_drv_data); return ret; } printk(KERN_INFO PFX "Initialized.\n"); return 0; }
static ssize_t sirf_write_proc(struct file *filp, const char *buff, size_t len, loff_t *off) { char messages[256]; int flag, ret; char buffer[7]; if (len > 255) len = 255; memset(messages, 0, sizeof(messages)); if (!buff || copy_from_user(messages, buff, len)) return -EFAULT; if (strlen(messages) > (SIRF_STATUS_LEN - 1)) { pr_warning("[ERROR] messages too long! (%d) %s\n", strlen(messages), messages); return -EFAULT; } if (strncmp(messages, "off", 3) == 0) { strcpy(sirf_status, "off"); gps_power_off(); } else if (strncmp(messages, "on", 2) == 0) { strcpy(sirf_status, "on"); gps_power_on(); } else if (strncmp(messages, "reset", 5) == 0) { strcpy(sirf_status, messages); ret = sscanf(messages, "%s %d", buffer, &flag); if (ret == 2){ gps_reset(flag); } } else if (strncmp(messages, "sirfon", 6) == 0) { strcpy(sirf_status, messages); ret = sscanf(messages, "%s %d", buffer, &flag); if (ret == 2){ gps_on_off(flag); } } else pr_info("usage: echo {on/off} > /proc/driver/sirf\n"); return len; }
static ssize_t gps_ctrl(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { static char msg[256]; int flag, ret; struct mmp_gps_info *info = dev_get_drvdata(dev); count = (count > 255) ? 255 : count; memset(msg, 0, count); sscanf(buf, "%s", info->chip_status); if (!strncmp(buf, "off", 3)) { strncpy(info->chip_status, "off", 4); gps_power_off(info); } else if (!strncmp(buf, "on", 2)) { strncpy(info->chip_status, "on", 3); gps_power_on(info); } else if (!strncmp(buf, "reset", 5)) { strncpy(info->chip_status, "reset", 6); ret = sscanf(buf, "%s %d", msg, &flag); if (ret == 2) gps_reset(info, flag); } else if (!strncmp(buf, "wakeup", 6)) { strncpy(info->chip_status, "wakeup", 7); ret = sscanf(buf, "%s %d", msg, &flag); if (ret == 2) gps_on_off(info, flag); } else if (!strncmp(buf, "eclk", 4)) { strncpy(info->chip_status, "eclk", 5); ret = sscanf(buf, "%s %d", msg, &flag); if (ret == 2) gps_eclk_ctrl(info, flag); } else dev_info(info->dev, "usage wrong\n"); return count; }
static msg_t GPSThread(void *arg) { (void)arg; chRegSetThreadName("gps_thread"); if (gps_data != NULL) { chHeapFree(gps_data); } gps_data = chHeapAlloc(NULL, GPS_CMD_BUF); size_t gps_bytes_read; uint16_t i; if (gps_data == NULL) { while (TRUE) { palTogglePad(GPIO_LED_1_PORT, GPIO_LED_1_PIN); chThdSleepMilliseconds(50); } } sdStart(&GPS_SERIAL, &SD3_Config); palSetPadMode(GPS_USART_PORT, GPS_USART_TX_PIN, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPS_USART_PORT, GPS_USART_RX_PIN, PAL_MODE_ALTERNATE(7)); gps_reset(); while (TRUE) { size_t readed_msg_len = 0; uint8_t res = gps_read_msg(&readed_msg_len); if (res == E_OK) { if (check_checksum() != E_OK) { sdWrite(&SD1, "GPS CHK ERR\r\n", 13); } else { if (gps_message_type() == GPS_MESSAGE_GPRMC) { gps_rmc_state_t state; //sdWrite(&SD1, gps_data, readed_msg_len); if (parse_gps_rmc(&state) == E_OK) { sdWrite(&SD1, "GPS PARSE OK\r\n", 14); } } else if (gps_message_type() == GPS_MESSAGE_UNKNOWN) { sdWrite(&SD1, "GPS MSG UNKNOWN\r\n", 17); } } } else { gps_data[0] = '0' + res; sdWrite(&SD1, "GPS ERROR:", 10); sdWrite(&SD1, gps_data, 1); gps_reset(); } sdWrite(&SD1, "\r\n", 2); //sdWrite(&SD1, "GPS: ", 5); //while ((gps_bytes_read = sdReadTimeout(&GPS_SERIAL, gps_data, GPS_CMD_BUF, 100)) > 0) // sdWrite(&SD1, gps_data, gps_bytes_read); //sdWrite(&SD1, "|||\r\n", 5); //chThdSleepMilliseconds(500); } chHeapFree(gps_data); }