iSensor-SPI-Buffer  1.15
Firmware for the iSensor-SPI-Buffer board to enable full throughput buffered data capture on Analog Devices IMUs
reg.h
Go to the documentation of this file.
1 
11 #ifndef INC_REG_H_
12 #define INC_REG_H_
13 
14 /* Header includes require for prototypes */
15 #include <stdint.h>
16 #include "main.h"
17 
18 /* Number of registers per page */
19 #define REG_PER_PAGE 64
20 
22 #define NUM_REG_PAGES 4
23 
25 #define PAGE_ID 0
26 
28 #define OUTPUT_PAGE 252
29 
31 #define BUF_CONFIG_PAGE 253
32 
33 /* Non-volatile R/W regs */
34 #define BUF_CONFIG_REG 0x41
35 #define BUF_LEN_REG 0x42
36 #define BTN_CONFIG_REG 0x43
37 #define DIO_INPUT_CONFIG_REG 0x44
38 #define DIO_OUTPUT_CONFIG_REG 0x45
39 #define WATERMARK_INT_CONFIG_REG 0x46
40 #define ERROR_INT_CONFIG_REG 0x47
41 #define IMU_SPI_CONFIG_REG 0x48
42 #define USER_SPI_CONFIG_REG 0x49
43 #define CLI_CONFIG_REG 0x4A
44 #define USER_COMMAND_REG 0x4B /* Clears automatically */
45 #define SYNC_FREQ_REG 0x4C
46 /* Space for 12 more regs here */
47 #define USER_SCR_0_REG 0x5A
48 #define USER_SCR_3_REG 0x5D
49 #define UTC_TIMESTAMP_LWR_REG 0x5E
50 #define UTC_TIMESTAMP_UPR_REG 0x5F
51 
52 /* All page 253 regs after this are read only */
53 
54 /* Volatile general info regs */
55 #define STATUS_0_REG 0x60
56 #define FAULT_CODE_REG 0x61
57 #define BUF_CNT_0_REG 0x62
58 #define BUF_MAX_CNT_REG 0x63
59 
60 /* Volatile time stamp and output data regs */
61 #define TIMESTAMP_LWR_REG 0x65
62 #define TIMESTAMP_UPR_REG 0x66
63 #define TEMP_REG 0x67
64 #define VDD_REG 0x68
65 
66 /* Volatile script info regs */
67 #define SCR_LINE_REG 0x72
68 #define SCR_ERROR_REG 0x73
69 
70 /* Non-volatile device info regs */
71 #define ENDURANCE_REG 0x76
72 #define FW_REV_REG 0x77
73 #define FW_DAY_MONTH_REG 0x78
74 #define FW_YEAR_REG 0x79
75 #define DEV_SN_REG 0x7A
76 
78 #define BUF_WRITE_PAGE 254
79 
80 #define BUF_WRITE_0_REG 0x89
81 #define FLASH_SIG_DRV_REG 0xBE
82 #define FLASH_SIG_REG 0xBF
83 
85 #define BUF_READ_PAGE 255
86 
87 #define STATUS_1_REG 0xC1
88 #define BUF_CNT_1_REG 0xC2
89 #define BUF_RETRIEVE_REG 0xC3
90 #define BUF_UTC_TIMESTAMP_REG 0xC4
91 #define BUF_US_TIMESTAMP_REG 0xC6
92 #define BUF_SIG_REG 0xC8
93 #define BUF_DATA_0_REG 0xC9
94 
95 /* Register (non-zero) default values */
96 #define FW_REV_DEFAULT 0x0115
97 #define BUF_CONFIG_DEFAULT 0x0000
98 #define BUF_LEN_DEFAULT 0x0014
99 #define DIO_INPUT_CONFIG_DEFAULT 0x0011
100 #define DIO_OUTPUT_CONFIG_DEFAULT 0x8421
101 #define WATER_INT_CONFIG_DEFAULT 0x0020
102 #define ERROR_INT_CONFIG_DEFAULT 0xFFFC
103 #define IMU_SPI_CONFIG_DEFAULT 0x100F
104 #define USER_SPI_CONFIG_DEFAULT 0x0007
105 #define CLI_CONFIG_DEFAULT 0x2000
106 #define BTN_CONFIG_DEFAULT 0x8000
107 #define SYNC_FREQ_DEFAULT 2000
108 #define FLASH_SIG_DEFAULT 0x9D2A
109 
110 /* Update flags definitions */
111 #define DIO_OUTPUT_CONFIG_FLAG (1 << 0)
112 #define IMU_SPI_CONFIG_FLAG (1 << 1)
113 #define USER_SPI_CONFIG_FLAG (1 << 2)
114 #define USER_COMMAND_FLAG (1 << 3)
115 #define DIO_INPUT_CONFIG_FLAG (1 << 4)
116 #define ENABLE_CAPTURE_FLAG (1 << 5)
117 #define DEQUEUE_BUF_FLAG (1 << 6)
118 #define DISABLE_CAPTURE_FLAG (1 << 7)
119 
120 /* Command register bits */
121 #define CMD_CLEAR_BUFFER (1 << 0)
122 #define CMD_CLEAR_FAULT (1 << 1)
123 #define CMD_FACTORY_RESET (1 << 2)
124 #define CMD_FLASH_UPDATE (1 << 3)
125 #define CMD_PPS_ENABLE (1 << 4)
126 #define CMD_PPS_DISABLE (1 << 5)
127 #define CMD_START_SCRIPT (1 << 6)
128 #define CMD_STOP_SCRIPT (1 << 7)
129 #define CMD_WATERMARK_SET (1 << 8)
130 #define CMD_SYNC_GEN (1 << 9)
131 #define CMD_BOOTLOADER (1 << 13)
132 #define CMD_IMU_RESET (1 << 14)
133 #define CMD_SOFTWARE_RESET (1 << 15)
134 
135 /* User SPI config register bits */
136 #define SPI_CONF_CPHA (1 << 0)
137 #define SPI_CONF_CPOL (1 << 1)
138 #define SPI_CONF_MSB_FIRST (1 << 2)
139 #define SPI_CONF_MASK (SPI_CONF_CPHA|SPI_CONF_CPOL|SPI_CONF_MSB_FIRST)
140 
141 /* Status register bits */
142 #define STATUS_BUF_WATERMARK (1 << 0)
143 #define STATUS_BUF_FULL (1 << 1)
144 #define STATUS_SPI_ERROR (1 << 2)
145 #define STATUS_SPI_OVERFLOW (1 << 3)
146 #define STATUS_OVERRUN (1 << 4)
147 #define STATUS_DMA_ERROR (1 << 5)
148 #define STATUS_PPS_UNLOCK (1 << 6)
149 #define STATUS_TEMP_WARNING (1 << 7)
150 #define STATUS_SCR_ERROR (1 << 10)
151 #define STATUS_SCR_RUNNING (1 << 11)
152 #define STATUS_FLASH_ERROR (1 << 12)
153 #define STATUS_FLASH_UPDATE (1 << 13)
154 #define STATUS_FAULT (1 << 14)
155 #define STATUS_WATCHDOG (1 << 15)
156 
157 /* Status clear mask (defines status bits which are sticky) */
158 #define STATUS_CLEAR_MASK (STATUS_FLASH_ERROR|STATUS_FAULT|STATUS_FLASH_UPDATE|STATUS_WATCHDOG|STATUS_SCR_RUNNING)
159 
160 /* BUF_CONFIG bit definitions */
161 #define BUF_CFG_REPLACE_OLDEST (1 << 0)
162 #define BUF_CFG_IMU_BURST (1 << 1)
163 #define BUF_CFG_BUF_BURST (1 << 2)
164 #define BUF_CFG_MASK (BUF_CFG_REPLACE_OLDEST|BUF_CFG_IMU_BURST|BUF_CFG_BUF_BURST)
165 
166 /* Watermark int config pulse mode mask */
167 #define WATERMARK_PULSE_MASK (1 << 15)
168 
169 /* CLI_CONFIG register bit positions */
170 #define USB_STREAM_BITP 0
171 #define SD_STREAM_BITP 1
172 #define USB_ECHO_BITP 2
173 #define SD_AUTORUN_BITP 3
174 #define CLI_DELIM_BITP 8
175 
176 #define USB_STREAM_BITM (1 << USB_STREAM_BITP)
177 #define SD_STREAM_BITM (1 << SD_STREAM_BITP)
178 #define USB_ECHO_BITM (1 << USB_ECHO_BITP)
179 #define SD_AUTORUN_BITM (1 << SD_AUTORUN_BITP)
180 #define CLI_DELIM_BITM (0xFF << CLI_DELIM_BITP)
181 
182 #define CLI_CONFIG_CLEAR_MASK 0xFF0C
183 
184 /* Public variables exported from module */
185 extern volatile uint32_t g_update_flags;
186 extern volatile uint16_t g_regs[NUM_REG_PAGES * REG_PER_PAGE];
187 extern volatile uint16_t* g_CurrentBufEntry;
188 
189 /* Public function prototypes */
190 
191 /* @cond DOXYGEN_IGNORE */
192 void Reg_Init();
194 bool Reg_Is_Burst_Read(uint8_t addr);
195 uint16_t Reg_Read(uint8_t regAddr);
196 uint16_t Reg_Write(uint8_t regAddr, uint8_t regValue);
197 void Reg_Process_Command();
198 void Reg_Factory_Reset();
200 void Reg_Button_Handler();
201 /* @endcond */
202 
203 #endif /* INC_REG_H_ */
BUF_READ_PAGE
#define BUF_READ_PAGE
Definition: reg.h:85
DIO_Start_Sync_Gen
void DIO_Start_Sync_Gen()
Generates a clock on DIO2_Slave based on frequency in SYNC_FREQ.
Definition: dio.c:60
g_update_flags
volatile uint32_t g_update_flags
Definition: reg.c:32
reg.h
Header file for iSensor-SPI-Buffer register interfacing module.
BUF_WRITE_PAGE
#define BUF_WRITE_PAGE
Definition: reg.h:78
IMU_Reset
void IMU_Reset()
Hardware reset connected IMU.
Definition: imu.c:82
OUTPUT_PAGE
#define OUTPUT_PAGE
Definition: reg.h:28
User_Interrupt_Update_Output_Pins
void User_Interrupt_Update_Output_Pins(uint32_t watermark, uint32_t overflow, uint32_t error)
Updates the output pins based on given interrupt/overflow status.
Definition: user_interrupt.c:105
User_SPI_Burst_Setup
void User_SPI_Burst_Setup()
Configures SPI for a burst buffer read.
Definition: user_spi.c:88
dfu.h
Header file for iSensor-SPI-Buffer runtime firmware upgrade module.
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.
Definition: reg.c:158
user_spi.h
Header file for iSensor-SPI-Buffer user SPI (slave SPI) module.
sd_card.h
Header file for iSensor-SPI-Buffer SD card interfacing and script execution module.
dio.h
Header file for iSensor-SPI-Buffer DIO interfacing module.
DFU_Prepare_Reboot
void DFU_Prepare_Reboot()
Set DFU reboot flag in RAM and reset system.
Definition: dfu.c:54
g_update_flags
volatile uint32_t g_update_flags
Definition: reg.c:32
Flash_Log_Fault
void Flash_Log_Fault(uint32_t faultCode)
Stores an error code to flash memory.
Definition: flash.c:173
__attribute__
volatile uint16_t g_regs[NUM_REG_PAGES *REG_PER_PAGE] __attribute__((aligned(32)))
Reg_Read
uint16_t Reg_Read(uint8_t regAddr)
Process a register read request (from master)
Definition: reg.c:206
imu.h
Implementation for iSensor-SPI-Buffer IMU interfacing module.
SD_Card_Stop_Script
void SD_Card_Stop_Script()
Stop a running SD card script.
Definition: sd_card.c:201
NUM_REG_PAGES
#define NUM_REG_PAGES
Definition: reg.h:22
ProcessRegWrite
static uint16_t ProcessRegWrite(uint8_t regAddr, uint8_t regValue)
Process a write to the iSensor-SPI-Buffer registers.
Definition: reg.c:603
IMU_Read_Register
uint16_t IMU_Read_Register(uint8_t RegAddr)
Reads 16 bit value from the IMU.
Definition: imu.c:235
BUF_CONFIG_PAGE
#define BUF_CONFIG_PAGE
Definition: reg.h:31
timer.h
Header file for iSensor-SPI-Buffer timer module.
Flash_Check_Logged_Fault
void Flash_Check_Logged_Fault()
Checks for error codes which may have been logged to flash, and sets the status register bit.
Definition: flash.c:142
Timer_Disable_PPS
void Timer_Disable_PPS()
Disable PPS timer functionality.
Definition: timer.c:155
Flash_Update
void Flash_Update()
Flash update command handler.
Definition: flash.c:29
Data_Capture_Disable
void Data_Capture_Disable()
disables autonomous data capture by disabling DR ISR.
Definition: data_capture.c:53
Timer_Enable_PPS
void Timer_Enable_PPS()
Enable PPS input for time stamp synchronization (improved long term stability over 20ppm crystal).
Definition: timer.c:144
g_CurrentBufEntry
volatile uint16_t * g_CurrentBufEntry
Definition: reg.c:35
USER_SPI_CS_INT_MSK
#define USER_SPI_CS_INT_MSK
Definition: isr.h:18
GetBuildDate
static void GetBuildDate()
Populates the firmware date registers automatically.
Definition: reg.c:518
Reg_Is_Burst_Read
bool Reg_Is_Burst_Read(uint8_t addr)
Check if the requested read is a start of a burst.
Definition: reg.c:105
usb.h
Header file for iSensor-SPI-Buffer USB command line register interface.
IMU_Write_Register
uint16_t IMU_Write_Register(uint8_t RegAddr, uint8_t RegValue)
Writes an 8 bit value to the IMU.
Definition: imu.c:273
g_bufLastRegIndex
uint32_t g_bufLastRegIndex
Definition: buffer.c:16
Reg_Init
void Reg_Init()
Initialize the register module by loading all saves values from flash.
Definition: reg.c:125
User_SPI_Update_Config
void User_SPI_Update_Config(uint32_t CheckUnlock)
Updates the slave SPI (SPI2) config based on the USER_SPI_CONFIG register.
Definition: user_spi.c:163
Reg_Update_Identifiers
void Reg_Update_Identifiers()
Load SN and date code registers to SRAM.
Definition: reg.c:139
ERROR_NONE
#define ERROR_NONE
Definition: flash.h:36
buffer.h
Header file for iSensor-SPI-Buffer buffer data structure module.
User_SPI_Reset
void User_SPI_Reset(bool register_mode)
Reset user SPI port.
Definition: user_spi.c:40
DIO_Update_Output_Config
void DIO_Update_Output_Config()
Validates DIO_OUTPUT_CONFIG settings and applies to GPIO.
Definition: dio.c:291
GetSN
static void GetSN()
Populates the six SN registers automatically.
Definition: reg.c:499
user_interrupt.h
Header file for iSensor-SPI-Buffer user interrupt (data ready) config and generation functions.
Flash_Load_Registers
void Flash_Load_Registers()
Load register values from flash memory to SRAM.
Definition: flash.c:96
main.h
Header file for iSensor-SPI-Buffer main.
Reg_Process_Command
void Reg_Process_Command()
Processes a command register write. This function is called from main loop.
Definition: reg.c:322
g_CurrentBufEntry
volatile uint16_t * g_CurrentBufEntry
Definition: reg.c:35
data_capture.h
Header file for iSensor-SPI-Buffer autonomous IMU data acquisition module.
IMU_Update_SPI_Config
void IMU_Update_SPI_Config()
Processes any changes to IMU_SPI_CONFIG reg and applies.
Definition: imu.c:294
command
command
Definition: script.h:20
g_userburstRunning
volatile uint32_t g_userburstRunning
Definition: user_spi.c:17
Reg_Button_Handler
void Reg_Button_Handler()
Handler for when the user button is pressed.
Definition: reg.c:478
USB_Watermark_Autoset
void USB_Watermark_Autoset()
Helper function to set the watermark interrupt level for optimal USB streams.
Definition: usb.c:201
DIO_Update_Input_Config
void DIO_Update_Input_Config()
Validates and updates the data ready input configuration based on DIO_INPUT_CONFIG.
Definition: dio.c:186
Buffer_Take_Element
uint8_t * Buffer_Take_Element()
Take a single element from the buffer.
Definition: buffer.c:81
Buffer_Reset
void Buffer_Reset()
Clears the buffer data structure.
Definition: buffer.c:186
selected_page
static volatile uint32_t selected_page
Definition: reg.c:94
Reg_Factory_Reset
void Reg_Factory_Reset()
Load factory default values for all registers, and applies any settings changes.
Definition: reg.c:403
SD_Card_Start_Script
void SD_Card_Start_Script()
Start script run.
Definition: sd_card.c:139
Reg_Write
uint16_t Reg_Write(uint8_t regAddr, uint8_t regValue)
Process a register write request (from master)
Definition: reg.c:278
isr.h
Header file for the interrupt service routine module.
Timer_Get_Microsecond_Timestamp
uint32_t Timer_Get_Microsecond_Timestamp()
Gets the current 32-bit value from the IMU sample timestamp timer.
Definition: timer.c:103
flash.h
Header file for iSensor-SPI-Buffer flash memory interfacing functions.