summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulK <contact@paulk.fr>2012-03-18 16:39:18 (GMT)
committerPaulK <contact@paulk.fr>2012-03-18 16:39:18 (GMT)
commite4f94e901b9b4c5fef5642ad9580863fc2bfe336 (patch)
treee76ac49be65b47c654c953a4c30bf67577a91453
parent576f7826e43786d6293bae8887f1b6551247a092 (diff)
downloadbcm4751-e4f94e901b9b4c5fef5642ad9580863fc2bfe336.zip
bcm4751-e4f94e901b9b4c5fef5642ad9580863fc2bfe336.tar.gz
bcm4751-e4f94e901b9b4c5fef5642ad9580863fc2bfe336.tar.bz2
Added daemon, hal and lib modules and solved serial setup for bcm4751_test
-rw-r--r--Android.mk57
-rw-r--r--MODULE_LICENSE_GPL0
-rw-r--r--bcm4751_daemon.c60
-rw-r--r--bcm4751_hal.c150
-rw-r--r--bcm4751_lib.c65
-rw-r--r--bcm4751_test.c112
6 files changed, 393 insertions, 51 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..5a305a3
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,57 @@
+LOCAL_PATH := $(call my-dir)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := bcm4751_test.c
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := bcm4751_test
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := bcm4751_hal.c
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+LOCAL_C_INCLUDES += hardware/libhardware/include/
+
+LOCAL_SHARED_LIBRARIES := liblog libcutils libhardware libhardware_legacy
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := bcm4751_hal
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := bcm4751_daemon.c
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := bcm4751_daemon
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := bcm4751_lib.c
+
+LOCAL_C_INCLUDES += $(LOCAL_PATH)/include
+
+LOCAL_SHARED_LIBRARIES := liblog libcutils
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_MODULE := bcm4751_lib
+LOCAL_MODULE_TAGS := optional
+
+include $(BUILD_EXECUTABLE)
diff --git a/MODULE_LICENSE_GPL b/MODULE_LICENSE_GPL
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/MODULE_LICENSE_GPL
diff --git a/bcm4751_daemon.c b/bcm4751_daemon.c
new file mode 100644
index 0000000..3cc3190
--- /dev/null
+++ b/bcm4751_daemon.c
@@ -0,0 +1,60 @@
+// Copyright (C) 2012 Paul Kocialkowski, contact@paulk.fr, GNU GPLv3+
+// BCM4751 daemon code
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/select.h>
+#include <fcntl.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <cutils/sockets.h>
+
+int main(void)
+{
+ int fd;
+ int cfd;
+ int rc;
+
+ int clen;
+ char buf[50];
+ char status[] = {
+ 0x08, 0x00, 0x00, 0x00, 0x18, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ struct sockaddr_un caddr;
+
+ fd = socket_local_server("gps", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
+ listen(fd, 1);
+ printf("socket_local_server passed: %d\n", fd);
+
+ cfd = accept(fd, 0, &clen);
+ printf("accept passed: %d\n", cfd);
+
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(cfd, &fds);
+
+ while(1)
+ {
+ memset(buf, 0, sizeof(buf));
+ select(cfd+1, &fds, NULL, NULL, NULL);
+ rc = read(cfd, buf, 50);
+
+ printf("read %d bytes!\n", rc);
+
+ if(rc == 50) {
+ write(cfd, status, sizeof(status));
+ printf("wrote %d bytes!\n", sizeof(status));
+ }
+ }
+
+ return 0;
+}
diff --git a/bcm4751_hal.c b/bcm4751_hal.c
new file mode 100644
index 0000000..d60bb9e
--- /dev/null
+++ b/bcm4751_hal.c
@@ -0,0 +1,150 @@
+// Copyright (C) 2012 Paul Kocialkowski, contact@paulk.fr, GNU GPLv3+
+// BCM4751 HAL code
+// This code will open the gps lib only: we can trace it that way
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include <hardware/hardware.h>
+#include <hardware/gps.h>
+#include <hardware_legacy/power.h>
+
+#define WAKE_LOCK_NAME "GPS"
+
+hw_module_t* module;
+hw_device_t* device;
+
+static const GpsInterface* sGpsInterface = NULL;
+static const GpsXtraInterface* sGpsXtraInterface = NULL;
+static const AGpsInterface* sAGpsInterface = NULL;
+static const GpsNiInterface* sGpsNiInterface = NULL;
+static const GpsDebugInterface* sGpsDebugInterface = NULL;
+static const AGpsRilInterface* sAGpsRilInterface = NULL;
+
+static void location_callback(GpsLocation* location)
+{
+ printf("got a location callback!\n");
+}
+
+static void status_callback(GpsStatus* status)
+{
+ printf("got a status callback!\n");
+}
+
+static void sv_status_callback(GpsSvStatus* sv_status)
+{
+ printf("got a svstatus callback!\n");
+}
+
+static void nmea_callback(GpsUtcTime timestamp, const char* nmea, int length)
+{
+ printf("got a nmea callback: %s!\n", nmea);
+}
+
+static void set_capabilities_callback(uint32_t capabilities)
+{
+ printf("set_capabilities_callback: %ld\n", capabilities);
+}
+
+
+static void acquire_wakelock_callback()
+{
+ acquire_wake_lock(PARTIAL_WAKE_LOCK, WAKE_LOCK_NAME);
+}
+
+static void release_wakelock_callback()
+{
+ release_wake_lock(WAKE_LOCK_NAME);
+}
+
+static pthread_t create_thread_callback(const char* name, void (*start)(void *), void* arg)
+{
+ printf("doing a thread!\n");
+
+ pthread_t thread;
+ pthread_create(&thread, NULL, start, arg);
+ return thread;
+}
+
+GpsCallbacks sGpsCallbacks = {
+ sizeof(GpsCallbacks),
+ location_callback,
+ status_callback,
+ sv_status_callback,
+ nmea_callback,
+ set_capabilities_callback,
+ acquire_wakelock_callback,
+ release_wakelock_callback,
+ create_thread_callback,
+};
+
+void hal_init(void)
+{
+ int rc;
+ rc = hw_get_module("gps", (hw_module_t const**)&module);
+ printf("hw_get_module: %d\n", rc);
+
+ if(rc < 0)
+ return;
+
+ rc = module->methods->open(module, GPS_HARDWARE_MODULE_ID, &device);
+ printf("module->methods->open: %d\n", rc);
+
+ if(rc < 0)
+ return;
+
+ struct gps_device_t* gps_device = (struct gps_device_t *)device;
+ sGpsInterface = gps_device->get_gps_interface(gps_device);
+
+ if (sGpsInterface) {
+ printf("GPS interface ready\n");
+ sGpsXtraInterface =
+ (const GpsXtraInterface*)sGpsInterface->get_extension(GPS_XTRA_INTERFACE);
+ sAGpsInterface =
+ (const AGpsInterface*)sGpsInterface->get_extension(AGPS_INTERFACE);
+ sGpsNiInterface =
+ (const GpsNiInterface*)sGpsInterface->get_extension(GPS_NI_INTERFACE);
+ sGpsDebugInterface =
+ (const GpsDebugInterface*)sGpsInterface->get_extension(GPS_DEBUG_INTERFACE);
+ sAGpsRilInterface =
+ (const AGpsRilInterface*)sGpsInterface->get_extension(AGPS_RIL_INTERFACE);
+ }
+}
+
+void gps_init(void)
+{
+ int rc;
+ rc = sGpsInterface->init(&sGpsCallbacks);
+ printf("sGpsInterface->init: %d\n", rc);
+
+/*
+ // if XTRA initialization fails we will disable it by sGpsXtraInterface to null,
+ // but continue to allow the rest of the GPS interface to work.
+ if (sGpsXtraInterface && sGpsXtraInterface->init(&sGpsXtraCallbacks) != 0)
+ sGpsXtraInterface = NULL;
+ if (sAGpsInterface)
+ sAGpsInterface->init(&sAGpsCallbacks);
+ if (sGpsNiInterface)
+ sGpsNiInterface->init(&sGpsNiCallbacks);
+ if (sAGpsRilInterface)
+ sAGpsRilInterface->init(&sAGpsRilCallbacks);
+*/
+}
+
+int main(void)
+{
+ hal_init();
+ gps_init();
+
+ sleep(1);
+
+ printf("Starting GPS!\n");
+ sGpsInterface->start();
+ sleep(60);
+ printf("Stopping GPS!\n");
+ sGpsInterface->stop();
+
+ sleep(60);
+
+ return 0;
+}
diff --git a/bcm4751_lib.c b/bcm4751_lib.c
new file mode 100644
index 0000000..3dd9e6d
--- /dev/null
+++ b/bcm4751_lib.c
@@ -0,0 +1,65 @@
+// Copyright (C) 2012 Paul Kocialkowski, contact@paulk.fr, GNU GPLv3+
+// BCM4751 lib code
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <arpa/inet.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/select.h>
+#include <fcntl.h>
+
+#include <arpa/inet.h>
+#include <netinet/in.h>
+
+#include <cutils/sockets.h>
+
+/*
+535 socket(PF_UNIX, SOCK_SEQPACKET, 0) = 3
+535 connect(3, {sa_family=AF_UNIX, path="/dev/socket/gps"}, 110) = 0
+
+535 write(3, "\x08\x00\x00\x00\x6b\x00\x00\x00\x20\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x14\x00\x00\x00\x03\x00\x00\x00\xff\xff\xff\xff"..., 44) = 44
+535 write(3, "\x08\x00\x00\x00\x6c\x00\x00\x00\x0c\x00\x00\x00\x06\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 24) = 24
+535 write(3, "\x08\x00\x00\x00\x17\x00\x00\x00\x0c\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00", 24) = 24
+535 write(3, "\x08\x00\x00\x00\x08\x00\x00\x00\x30\x00\x00\x00\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x05\x00\x00\x00\x01\x00\x00\x00"..., 60) = 60
+*/
+int main(void)
+{
+ int fd = socket_local_client("gps", ANDROID_SOCKET_NAMESPACE_RESERVED, SOCK_SEQPACKET);
+ if(fd < 0) {
+ printf("Socket is dead!\n");
+ return 1;
+ }
+
+ char data1[] = {
+ 0x08, 0x00, 0x00, 0x00, 0x6b, 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x05, 0x93, 0xd2, 0xaf, 0x14, 0xcc, 0xc0, 0xbe
+ };
+ char data2[] = {
+ 0x08, 0x00, 0x00, 0x00, 0x6c, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ char data3[] = {
+ 0x08, 0x00, 0x00, 0x00, 0x17, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
+ };
+ char data4[] = {
+ 0x08, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00
+ };
+/*
+ write(fd, data1, sizeof(data1));
+ usleep(500000);
+ write(fd, data2, sizeof(data2));
+ usleep(500000);
+ write(fd, data3, sizeof(data3));
+ usleep(500000);
+*/
+ // Ask GPSD to start obtaining data from the chip
+ write(fd, data4, sizeof(data4));
+ usleep(500000);
+
+ sleep(60);
+
+ return 0;
+}
diff --git a/bcm4751_test.c b/bcm4751_test.c
index da04bbb..bf4159b 100644
--- a/bcm4751_test.c
+++ b/bcm4751_test.c
@@ -1,31 +1,19 @@
-/*
- * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
+// Copyright (C) 2012 Paul Kocialkowski, contact@paulk.fr, GNU GPLv3+
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <unistd.h>
-#include <termio.h>
+#include <termios.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
+#include <sys/syscall.h>
+#include <sys/linux-syscalls.h>
+
void hex_dump(void *data, int size)
{
/* dumps size bytes of *data to stdout. Looks like:
@@ -145,6 +133,8 @@ int main(int argc, char *argv[])
}
}
+ sleep(1);
+
printf("Wake lock on gpsd-interface\n");
wake_lock("gpsd-interface", 14);
@@ -155,7 +145,7 @@ int main(int argc, char *argv[])
usleep(250000);
printf("Opening /dev/s3c2410_serial1\n");
- serial_fd = open("/dev/s3c2410_serial1", O_RDWR|O_NOCTTY);
+ serial_fd = open("/dev/s3c2410_serial1", O_RDWR|O_NOCTTY|O_NONBLOCK);
if(serial_fd < 0) {
printf("Serial fd is wrong, aborting\n");
@@ -163,69 +153,82 @@ int main(int argc, char *argv[])
}
tcgetattr(serial_fd, &termios);
-// ioctl(serial_fd, TIOCMGET, &serial);
- ioctl(serial_fd, TCFLSH, 0x2);
+ ioctl(serial_fd, TCFLSH, 0x2);
cfmakeraw(&termios);
cfsetispeed(&termios, B115200);
cfsetospeed(&termios, B115200);
- tcsetattr(serial_fd, TCSANOW, &termios);
-// ioctl(serial_fd, TIOCMSET, &serial);
- ioctl(serial_fd, TCFLSH, 0x2);
+ // This is the magic to contact the chip
+ termios.c_cflag = 0x800018b2;
+// termios.c_cc[5]=0x01;
+// termios.c_cc[6]=0x00;
- //ioctl(serial_fd, TIOCMGET, &serial);
+ tcsetattr(serial_fd, TCSANOW, &termios);
+ ioctl(serial_fd, TCFLSH, 0x2);
tcgetattr(serial_fd, &termios);
-// usleep(250000);
-
FD_ZERO(&fds);
FD_SET(serial_fd, &fds);
memset(init_val, 0x80, 21);
data = malloc(512);
- timeout.tv_sec = 1;
- timeout.tv_usec = 0;
+ timeout.tv_sec = 1;
+ timeout.tv_usec = 0;
printf("Writing init bits\n");
- rc = write(serial_fd, init_val, 20);
- printf("Written %d bytes!\n",rc);
+
+ rc = select(serial_fd + 1, NULL, &fds, NULL, &timeout);
+ if(rc > 0) {
+ write(serial_fd, init_val, 20);
+ printf("Written\n");
+ } else {
+ printf("Timeout!\n");
+ return 0;
+ }
for(i=0 ; i < 3 ; i++) {
timeout.tv_sec = 1;
timeout.tv_usec = 0;
- rc = read(serial_fd, data, 512);
- printf("read %d bytes!\n", rc);
+ rc = select(serial_fd + 1, &fds, NULL, NULL, &timeout);
- if(rc < 0) {
- wake_unlock("gpsd-interface", 14);
- gpio_write_ascii(gpio_standby_path, "0\n");
- return 0;
- }
- hex_dump(data, rc);
- break;
- write(serial_fd, init_val, 20);
- }
+ printf("select rc is %d\n", rc);
- for(i=0 ; i < 3 ; i++) {
+ if(rc > 0) {
rc = read(serial_fd, data, 512);
printf("read %d bytes!\n", rc);
if(rc < 0) {
- perror("Here comes the error");
+ wake_unlock("gpsd-interface", 14);
+ gpio_write_ascii(gpio_standby_path, "0\n");
+ return 0;
+ }
- } else
- hex_dump(data, rc);
+ hex_dump(data, rc);
+ break;
+ }
- usleep(250000);
- }
+ write(serial_fd, init_val, 20);
+ }
+
+ for(i=0 ; i < 3 ; i++) {
+ rc = read(serial_fd, data, 512);
+ printf("read %d bytes!\n", rc);
+
+ if(rc < 0) {
+ perror("Here comes the error");
+ } else
+ hex_dump(data, rc);
+
+ usleep(250000);
+ }
wake_unlock("gpsd-interface", 14);
gpio_write_ascii(gpio_standby_path, "0\n");
- return 0;
+ return 0;
printf("Writing MEIF init bits\n");
@@ -243,10 +246,17 @@ int main(int argc, char *argv[])
timeout.tv_sec = 1;
timeout.tv_usec = 499000;
- rc = read(serial_fd, data, 512);
- printf("read %d bytes!\n");
- hex_dump(data, rc);
+ rc = select(serial_fd + 1, &fds, NULL, NULL, &timeout);
+ printf("select rc is %d\n", rc);
+
+ if(rc > 0) {
+ rc = read(serial_fd, data, 512);
+ printf("read %d bytes!\n");
+ hex_dump(data, rc);
+
+ // usleep(30000);
+ }
}
free(data);