Skip to content
This repository has been archived by the owner on Apr 13, 2021. It is now read-only.

Commit

Permalink
Merge pull request #648 from gsmcmullin/v3_track
Browse files Browse the repository at this point in the history
Tracking on Piksi v3
  • Loading branch information
jacobmcnamee committed Apr 29, 2016
2 parents 5f54374 + 6fac885 commit 8f8dcc4
Show file tree
Hide file tree
Showing 26 changed files with 796 additions and 463 deletions.
42 changes: 2 additions & 40 deletions src/board/nap/nap_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,6 @@
/** \addtogroup nap
* \{ */

/* NAP Register Addresses. */
#define NAP_REG_IRQ 0x00
#define NAP_REG_ERROR 0x01
#define NAP_REG_PPS_WIDTH 0xF4
#define NAP_REG_PPS_COMPARE 0xF5
#define NAP_REG_EXT_EVENT_TIME 0xF6
#define NAP_REG_TIMING_COMPARE 0xF8
#define NAP_REG_TIMING_COUNT 0xF9
#define NAP_REG_TIMING_COUNT_LATCH 0xFA
#define NAP_REG_HASH_STATUS 0xFB
#define NAP_REG_DNA 0xFD
#define NAP_REG_RDWR 0xFE
#define NAP_REG_DECEASED_COW 0xFF
/* Status of NAP authentication hash comparison. */
/* TODO: change NAP_HASH_MATCH to non 0x00/0xFF value so it is more reliable */
#define NAP_HASH_MATCH 0
#define NAP_HASH_MISMATCH 1
#define NAP_HASH_NOTREADY 2

/** A complex IQ correlation. */
typedef struct {
s32 I; /**< In-phase correlation. */
Expand All @@ -63,27 +44,6 @@ extern binary_semaphore_t timing_strobe_sem;

void nap_setup(void);

u8 nap_conf_done(void);
u8 nap_hash_rd_done(void);

void nap_conf_b_set(void);
void nap_conf_b_clear(void);

void nap_xfer_blocking(u8 reg_id, u16 n_bytes, u8 data_in[],
const u8 data_out[]);

/** Convenience function to read 4 bytes from a register (writing zeros) and
* convert to host byte order (i.e. little-endian).
* \param reg_id NAP register ID.
* \return u32 register value
*/
inline u32 nap_read_u32(u8 reg_id)
{
u32 val = 0;
nap_xfer_blocking(reg_id, 4, (u8 *)&val, (u8 *)&val);
return __builtin_bswap32(val);
}

u32 nap_error_rd_blocking(void);

u8 nap_hash_status(void);
Expand All @@ -103,5 +63,7 @@ u32 nap_rw_ext_event(u8 *event_pin, ext_event_trigger_t *event_trig,
void nap_pps(u64 rising_edge_count_8x);
void nap_pps_width(u32 falling_edge_count);

#include "nap/nap_hw.h"

#endif /* SWIFTNAV_NAP_COMMON_H */

62 changes: 11 additions & 51 deletions src/board/nap/track_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,67 +17,27 @@
#include <libswiftnav/common.h>
#include <libswiftnav/signal.h>

#include "../../main.h"
#include "nap_common.h"

/** \addtogroup track_channel
* \{ */

/* SPI register IDs */
#define NAP_REG_TRACK_BASE 0x0A
#define NAP_TRACK_N_REGS 5
#define NAP_REG_TRACK_INIT_OFFSET 0x00
#define NAP_REG_TRACK_UPDATE_OFFSET 0x01
#define NAP_REG_TRACK_CORR_OFFSET 0x02
#define NAP_REG_TRACK_PHASE_OFFSET 0x03
#define NAP_REG_TRACK_CODE_OFFSET 0x04

/** Max number of tracking channels NAP configuration will be built with. */
#define NAP_MAX_N_TRACK_CHANNELS 12

extern u8 nap_track_n_channels;

/* NAP track channel parameters.
* TODO : get rid of some of these INIT reg specific defines by just writing
* whole phase through init register? Tracking channel init registers don't
* get written very often so it shouldn't increase SPI link budget much.
*/
#define NAP_TRACK_INIT_CODE_PHASE_WIDTH 14
#define NAP_TRACK_CARRIER_FREQ_WIDTH 24
#define NAP_TRACK_CODE_PHASE_WIDTH 29
#define NAP_TRACK_CODE_PHASE_FRACTIONAL_WIDTH 32

#define NAP_TRACK_INIT_CODE_PHASE_UNITS_PER_CHIP \
(1 << (NAP_TRACK_INIT_CODE_PHASE_WIDTH - 10))

#define NAP_TRACK_CARRIER_FREQ_UNITS_PER_HZ \
((1 << NAP_TRACK_CARRIER_FREQ_WIDTH) / (double)SAMPLE_FREQ)

#define NAP_TRACK_NOMINAL_CODE_PHASE_RATE \
(1 << (NAP_TRACK_CODE_PHASE_WIDTH - 1))

#define NAP_TRACK_CODE_PHASE_RATE_UNITS_PER_HZ \
(NAP_TRACK_NOMINAL_CODE_PHASE_RATE / 1.023e6)
/** \} */

#define NAP_TRACK_CODE_PHASE_UNITS_PER_CHIP \
((u64)1 << NAP_TRACK_CODE_PHASE_FRACTIONAL_WIDTH)
void nap_track_init(u8 channel, gnss_signal_t sid, u32 ref_timing_count,
float carrier_freq, float code_phase);

/** \} */
void nap_track_update(u8 channel, double carrier_freq,
double code_phase_rate, u8 rollover_count,
u8 corr_spacing);
void nap_track_read_results(u8 channel,
u32* count_snapshot, corr_t corrs[],
double *code_phase_early,
double *carrier_phase);

void nap_track_init_pack(u8 pack[], u8 prn, s32 carrier_phase, u16 code_phase);
void nap_track_init_wr_blocking(u8 channel, u8 prn, s32 carrier_phase,
u16 code_phase);
void nap_track_update_pack(u8 pack[], s32 carrier_freq, u32 code_phase_rate,
u8 rollover_count, u8 corr_spacing);
void nap_track_update_wr_blocking(u8 channel, s32 carrier_freq,
u32 code_phase_rate, u8 rollover_count,
u8 corr_spacing);
void nap_track_corr_unpack(u8 packed[], u32* sample_count, corr_t corrs[]);
void nap_track_corr_rd_blocking(u8 channel, u32* sample_count, corr_t corrs[]);
void nap_track_phase_unpack(u8 packed[], s32* carrier_phase, u64* code_phase);
void nap_track_phase_rd_blocking(u8 channel, s32* carrier_phase,
u64* code_phase);
void nap_track_code_wr_blocking(u8 channel, gnss_signal_t sid);
void nap_track_disable(u8 channel);

#endif /* SWIFTNAV_TRACK_CHANNEL_H */

1 change: 1 addition & 0 deletions src/board/v2/Makefile.inc
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ BOARDSRC := \
$(BOARDDIR)/nap/nap_acq.o \
$(BOARDDIR)/nap/acq_channel.o \
$(BOARDDIR)/nap/track_channel.o \
$(BOARDDIR)/nap/track_regs.o \
$(BOARDDIR)/m25_flash.o \
$(BOARDDIR)/max2769.o \
$(BOARDDIR)/usart_support.o \
Expand Down
2 changes: 2 additions & 0 deletions src/board/v2/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
#define STM32_HSECLK 16368000
#endif

#define SAMPLE_FREQ 16368000

/*
* Board voltages.
* Required for performance limits calculation.
Expand Down
74 changes: 74 additions & 0 deletions src/board/v2/nap/nap_hw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (C) 2011-2014 Swift Navigation Inc.
* Contact: Fergus Noble <[email protected]>
* Colin Beighley <[email protected]>
*
* This source is subject to the license found in the file 'LICENSE' which must
* be be distributed together with this source. All other rights reserved.
*
* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
* EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
*/

#ifndef SWIFTNAV_NAP_HW_V2_H
#define SWIFTNAV_NAP_HW_V2_H

#include <libswiftnav/signal.h>

/** \addtogroup nap
* \{ */

/* NAP Register Addresses. */
#define NAP_REG_IRQ 0x00
#define NAP_REG_ERROR 0x01
#define NAP_REG_PPS_WIDTH 0xF4
#define NAP_REG_PPS_COMPARE 0xF5
#define NAP_REG_EXT_EVENT_TIME 0xF6
#define NAP_REG_TIMING_COMPARE 0xF8
#define NAP_REG_TIMING_COUNT 0xF9
#define NAP_REG_TIMING_COUNT_LATCH 0xFA
#define NAP_REG_HASH_STATUS 0xFB
#define NAP_REG_DNA 0xFD
#define NAP_REG_RDWR 0xFE
#define NAP_REG_DECEASED_COW 0xFF
/* Status of NAP authentication hash comparison. */
/* TODO: change NAP_HASH_MATCH to non 0x00/0xFF value so it is more reliable */
#define NAP_HASH_MATCH 0
#define NAP_HASH_MISMATCH 1
#define NAP_HASH_NOTREADY 2

/** Max number of tracking channels NAP configuration will be built with. */
#define NAP_MAX_N_TRACK_CHANNELS 12

u8 nap_conf_done(void);
u8 nap_hash_rd_done(void);

void nap_conf_b_set(void);
void nap_conf_b_clear(void);

void nap_xfer_blocking(u8 reg_id, u16 n_bytes, u8 data_in[],
const u8 data_out[]);

/** Convenience function to read 4 bytes from a register (writing zeros) and
* convert to host byte order (i.e. little-endian).
* \param reg_id NAP register ID.
* \return u32 register value
*/
inline u32 nap_read_u32(u8 reg_id)
{
u32 val = 0;
nap_xfer_blocking(reg_id, 4, (u8 *)&val, (u8 *)&val);
return __builtin_bswap32(val);
}

void nap_track_code_wr_blocking(u8 channel, gnss_signal_t sid);
void nap_track_init_wr_blocking(u8 channel, u8 prn, s32 carrier_phase,
u16 code_phase);
void nap_track_update_wr_blocking(u8 channel, s32 carrier_freq,
u32 code_phase_rate, u8 rollover_count,
u8 corr_spacing);
void nap_track_corr_rd_blocking(u8 channel, u32* sample_count, corr_t corrs[]);

#endif

Loading

0 comments on commit 8f8dcc4

Please sign in to comment.