Skip to main content

Building a Spresense Powered Smart Security Device Part 4: GNSS and Storage

Main43_f064c441d1549657e6d85f47ee79b3766707d76b.jpg

This series of posts demonstrates how the advanced capabilities of the Sony Spresense can be put to use in creating a low power security device for asset monitoring and tracking.

In the first post, we introduced the project, the second covered SDK setup, and the previous explored the Sensor Control Unit (SCU) via SDK examples. In this post, we will now take a look at the Global Navigation Satellite System (GNSS) receiver and integrated SPI flash storage. When an event occurs these will allow us to identify the current position and log this along with event details.

GNSS

GNSSsubsystem_8f65a844595ad6c705ac40e654fad0130eacf5b6.jpg

GNSS is the generic term used for navigation systems such as GPS, GLONASS, Galileo and BeiDu, which along with positioning, provide a high accuracy time reference which is derived from the atomic clocks onboard the satellites delivering the service. The CXD5602’s embedded GNSS receiver supports all the aforementioned four systems, plus also satellite-based augmentation systems (SBAS) which are used to further improve accuracy and reliability.

Key features of the receiver include:

  • Asynchronous position processing and notification
  • Geofencing (detecting whether the receiver is leaving a specified area)
  • Ability to store up to 170 logs in the GNSS core

geofence_notification-1_e3a6d46e90a1ef22887592e475c56cabe1de6197.jpg

Geofencing transition notification

As with the SCU and sensor processing, such features free up the application processor to focus on the main task at hand, while significantly reducing energy consumption.

Spresense SDK GNSS features include:

  • /dev/gps interface plus ioctl commands
  • Library to convert output to standard NMEA format
  • Example data for development and testing indoors, plus a command emulator
  • LNA power control and GNSS sleep mode
  • Ability to backup data for faster positioning via hot start
  • Hardware-based position notification and geofencing support

The GNSS interface can be opened and read like a regular file and data structures are provided which give access to things such as the satellite status, position data and accuracy etc.

SPI flash

Flash_7fc5f6b787699c56cbcbbda66ece8c8924d09325.jpg

The Spresense module is equipped with 8MB (8M x 8) quad-SPI flash, which is used to store programs along with data, such as GNSS backup data for faster positioning start-up.

NuttX provides a Memory Technology Device (MTD) driver for accessing devices such as flash and EEPROM. The Spresense SDK uses this to access the flash storage and can configure support for NXFFS — the NuttX wear-leveling flash filesystem — or alternatively, the SMART flash filesystem from Ken Pettit.

PVTlog example

structcxd56__pvtlog__s__coll__graph_4aef195445d513e6773e8af17ad5c7e8976ec3bf.jpg

PVTlog is a function that logs position, velocity, and time information in the GNSS core. Up to 170 logs can be stored in the GNSS core and when the threshold is reached the application is notified. The cxd56_pvtlog_s structure is used for this and this can be seen in the above diagram.

The log store is started and stopped with CXD56_GNSS_IOCTL_PVTLOG_START and CXD56_GNSS_IOCTL_PVTLOG_STOP. The former takes a parameter pointing to the cxd56_pvtlog_setting_s structure, which configures the log interval and notification threshold.

The SDK includes a PVTlog example which allows us to:

  1. Start positioning, cache position in the GNSS core and then notify when the threshold is exceeded, following which write the log to a file
  2. Read the saved file and output this to the console
  3. Delete the saved file
  4. Execute all of 1-3 above

So let’s take a look at the key parts involved for positioning and writing the log. For complete details see the source file.

Once the GPS device file is opened and we have a file descriptor we can start the log function.

  pvtlog_setting.cycle     = TEST_RECORDING_CYCLE;
  pvtlog_setting.threshold = TEST_NOTIFY_THRESHOLD;
  ret = ioctl(fd, CXD56_GNSS_IOCTL_PVTLOG_START,
              (unsigned long)&pvtlog_setting);

Then start positioning.

ret = ioctl(fd, CXD56_GNSS_IOCTL_START, CXD56_GNSS_STMOD_HOT);

We now wait for signals that were configured to tell us when positioning data is available and when the pvtlog threshold has been reached. In the case of the former, we print this out, and with the latter we write this to a file.

  sig_id = sigwaitinfo(&mask, NULL);

  switch (sig_id)
    {
    case MY_GNSS_SIG0:
      /* Read and print POS data. */

      read_and_print(fd);
      timecount++;
      break;

    case MY_GNSS_SIG1:
      /* Receive pvtlog signal */

      get_pvtlog(fd);
      writefile(file_count);
      file_count++;
      break;

The writefile function constructs a filename and opens this write-only with:

fd_write = open(filename, O_WRONLY | O_CREAT | O_BINARY);

And then writes to it with:

write(fd_write, &pvtlogdat, sizeof(struct cxd56_pvtlog_s)

Following which it closes the file. Error handling is also included and once again, see the source for complete details.

We can configure the SDK example with:

$ tools/config.py examples/gnss_pvtlog

Following which we can build the example, flash it to the Spresense and run it by entering “gnss_pvtlog” at the NuttShell prompt.

$ make buildkernel

$ make

$ tools/flash.sh -c /dev/ttyUSB3 nuttx.spk

$ screen /dev/ttyUSB3 115200

After output from initial start-up, we will see “No Positioning...” messages until the receiver obtains a fix, following which the date and time plus lat/long will be output.

Note that the default if no argument is given to gnss_pvtlog is the write mode as described earlier. In this second run, we passed the “r” argument to retrieve the log file written in the first run.

Thereby also demonstrating reading from flash storage.

Prototype solution

Now that we have explored the SCU and GNSS domains, in the next post we will combine the use of these two capabilities with a program that configures the event detector, then reads sensor input and if this exceeds threshold, logs event details along with the current position to flash storage. Our prototype solution!

Andrew Back

Open source (hardware and software!) advocate, Treasurer and Director of the Free and Open Source Silicon Foundation, organiser of Wuthering Bytes technology festival and founder of the Open Source Hardware User Group.