iSensor-SPI-Buffer  1.15
Firmware for the iSensor-SPI-Buffer board to enable full throughput buffered data capture on Analog Devices IMUs
Functions | Variables
reg.c File Reference

iSensor-SPI-Buffer register interfacing module. Called by user SPI and USB CLI More...

#include "usb.h"
#include "reg.h"
#include "imu.h"
#include "sd_card.h"
#include "buffer.h"
#include "flash.h"
#include "data_capture.h"
#include "user_spi.h"
#include "dfu.h"
#include "dio.h"
#include "timer.h"
#include "user_interrupt.h"
#include "isr.h"
Include dependency graph for reg.c:

Functions

static uint16_t ProcessRegWrite (uint8_t regAddr, uint8_t regValue)
 Process a write to the iSensor-SPI-Buffer registers. More...
 
static void GetSN ()
 Populates the six SN registers automatically. More...
 
static void GetBuildDate ()
 Populates the firmware date registers automatically. More...
 
volatile uint16_t g_regs[NUM_REG_PAGES *REG_PER_PAGE] __attribute__ ((aligned(32)))
 
bool Reg_Is_Burst_Read (uint8_t addr)
 Check if the requested read is a start of a burst. More...
 
void Reg_Init ()
 Initialize the register module by loading all saves values from flash. More...
 
void Reg_Update_Identifiers ()
 Load SN and date code registers to SRAM. More...
 
void Reg_Buf_Dequeue_To_Outputs ()
 Dequeues an entry from the buffer and loads it to the primary output registers. More...
 
uint16_t Reg_Read (uint8_t regAddr)
 Process a register read request (from master) More...
 
uint16_t Reg_Write (uint8_t regAddr, uint8_t regValue)
 Process a register write request (from master) More...
 
void Reg_Process_Command ()
 Processes a command register write. This function is called from main loop. More...
 
void Reg_Factory_Reset ()
 Load factory default values for all registers, and applies any settings changes. More...
 
void Reg_Button_Handler ()
 Handler for when the user button is pressed. More...
 

Variables

volatile uint32_t g_update_flags = 0
 
volatile uint16_t * g_CurrentBufEntry
 
static volatile uint32_t selected_page = BUF_CONFIG_PAGE
 

Detailed Description

iSensor-SPI-Buffer register interfacing module. Called by user SPI and USB CLI

Copyright (c) Analog Devices Inc, 2020 All Rights Reserved.

Date
3/18/2020
Author
A. Nolan (alex..nosp@m.nola.nosp@m.n@ana.nosp@m.log..nosp@m.com)

Function Documentation

◆ __attribute__()

volatile uint16_t g_regs [NUM_REG_PAGES * REG_PER_PAGE] __attribute__ ( (aligned(32))  )

iSensor-SPI-Buffer global register array (read-able via SPI). Global scope

◆ GetBuildDate()

static void GetBuildDate ( )
static

Populates the firmware date registers automatically.

Returns
void

Registers are populated by parsing the DATE macro result, which is set at compile time

Here is the caller graph for this function:

◆ GetSN()

static void GetSN ( )
static

Populates the six SN registers automatically.

Returns
void

The SN registers are populated from the 96-bit unique ID (UID)

Here is the caller graph for this function:

◆ ProcessRegWrite()

static uint16_t ProcessRegWrite ( uint8_t  regAddr,
uint8_t  regValue 
)
static

Process a write to the iSensor-SPI-Buffer registers.

Returns
The index to the register within the global register array

This function handles filtering for read-only registers. It also handles setting the deferred processing flags as needed for any config/command register writes. This are processed on the next pass of the main loop.

◆ Reg_Buf_Dequeue_To_Outputs()

void Reg_Buf_Dequeue_To_Outputs ( )

Dequeues an entry from the buffer and loads it to the primary output registers.

Returns
void

This function is called from the main loop to preserve SPI responsiveness while a buffer entry is being dequeued into the output registers. This allows a user to read the buffer contents while the values are being moved (if they start reading at buffer entry 0). After moving all values to the correct location in the output register array, the function sets up the burst read DMA (if enabled in user SPI config).

◆ Reg_Button_Handler()

void Reg_Button_Handler ( )

Handler for when the user button is pressed.

Returns
void

This function executes commands based on the button configuration set in BTN_CONFIG. This function can be called from an interrupt context (EXTI rising edge interrupt for button). The EXTI pending interrupt register for the button line should be cleared before and after executing this function to add some implicit debouncing (interrupt won't trigger, then immediately trigger again).

◆ Reg_Factory_Reset()

void Reg_Factory_Reset ( )

Load factory default values for all registers, and applies any settings changes.

Returns
void

This is accomplished in "lazy" manner via a preprocessor define for each register default value (defaults are stored in program memory, storage is managed by compiler). This function only changes values in SRAM, does not change flash contents (registers will reset on next re-boot).

Here is the call graph for this function:

◆ Reg_Init()

void Reg_Init ( )

Initialize the register module by loading all saves values from flash.

Returns
void

Most register values are loaded directly from the flash register array. Some values (SN and FW date) are encoded into the code, and must be loaded separately using Update_Identifiers()

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reg_Is_Burst_Read()

bool Reg_Is_Burst_Read ( uint8_t  addr)

Check if the requested read is a start of a burst.

Returns
true if burst starting, false otherwise

For a burst to start, the buffer read page must be selected, the address must be BUF_RETRIEVE, and buffer burst mode must be enabled.

Here is the caller graph for this function:

◆ Reg_Process_Command()

void Reg_Process_Command ( )

Processes a command register write. This function is called from main loop.

Returns
void

Only one command can be executed per write to the USER_COMMAND register. Command execution priority is determined by the order in which the command flags are checked.

◆ Reg_Read()

uint16_t Reg_Read ( uint8_t  regAddr)

Process a register read request (from master)

Parameters
regAddrThe byte address of the register to read
Returns
Value of register requested

For selected pages not addressed by iSensor-SPI-Buffer, the read is passed through to the connected IMU, using the spi_passthrough module. If the selected page is [253 - 255] this read request is processed directly.

Here is the caller graph for this function:

◆ Reg_Update_Identifiers()

void Reg_Update_Identifiers ( )

Load SN and date code registers to SRAM.

Returns
void

These register values are encoded into the .text section of flash

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reg_Write()

uint16_t Reg_Write ( uint8_t  regAddr,
uint8_t  regValue 
)

Process a register write request (from master)

Parameters
regAddrThe address of the register to write to
regValueThe value to write to the register
Returns
The contents of the register being written, after write is processed

For selected pages not addressed by iSensor-SPI-Buffer, the write is passed through to the connected IMU, using the spi_passthrough module. If the selected page is [252 - 255] this write request is processed directly. The firmware echoes back the processed write value so that the master can verify the write contents on the next SPI transaction.

Here is the caller graph for this function:

Variable Documentation

◆ g_CurrentBufEntry

volatile uint16_t* g_CurrentBufEntry

Pointer to buffer entry. Will be 0 if no buffer entry "loaded" to output registers

◆ g_update_flags

volatile uint32_t g_update_flags = 0

Register update flags for main loop processing. Global scope

◆ selected_page

volatile uint32_t selected_page = BUF_CONFIG_PAGE
static

Selected page. Starts on 253 (config page)