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
script.c File Reference

iSensor-SPI-Buffer script module (loaded from SD card or provided via USB CLI) More...

#include "script.h"
#include "reg.h"
#include <stdio.h>
#include "usb.h"
#include "main.h"
#include "sd_card.h"
Include dependency graph for script.c:

Functions

static uint32_t ParseCommandArgs (const uint8_t *commandBuf, uint32_t *args)
 Parse space delimited arguments out from a command. More...
 
static void ReadHandler (script *scr, uint8_t *outBuf, bool isUSB)
 Read command handler. More...
 
static void ReadBufHandler (bool isUSB)
 Handler for ReadBuf command. More...
 
static void RegAliasReadHandler (uint8_t *outBuf, bool isUSB, uint16_t regIndex)
 Read a register without changing page, and print to CLI. More...
 
static void WriteHandler (script *scr)
 Write command handler. More...
 
static void StreamCmdHandler (script *scr, bool isUSB)
 Handler for stream start/stop command. More...
 
static void AboutHandler (uint8_t *outBuf, bool isUSB)
 Print about message to CLI. More...
 
static void UptimeHandler (uint8_t *outBuf, bool isUSB)
 Print system uptime CLI. More...
 
static void FactoryResetHandler ()
 Executes a factory reset + flash update. More...
 
static void UShortToHex (uint8_t *outBuf, uint16_t val)
 Convert a 16 bit value to the corresponding hex string (4 chars) More...
 
static uint32_t HexToUInt (const uint8_t *commandBuf)
 Convert a hex string to a 32 bit uint. More...
 
static uint32_t StringEquals (const uint8_t *string0, const uint8_t *string1, uint32_t count)
 Check equality between two strings. More...
 
void Script_Check_Stream ()
 Check the stream status. More...
 
void Script_Parse_Element (const uint8_t *commandBuf, script *scr)
 Parse a command string into a script element. More...
 
void Script_Run_Element (script *scr, uint8_t *outBuf, bool isUSB)
 Executes a script element. More...
 

Variables

static uint8_t StreamBuf_A [STREAM_BUF_SIZE]
 
static uint8_t StreamBuf_B [STREAM_BUF_SIZE]
 
static bool BufA
 
static uint32_t cmdIndex
 
static uint32_t goodArg
 
static const uint8_t ReadCmd [] = "read "
 
static const uint8_t WriteCmd [] = "write "
 
static const uint8_t HelpCmd [] = "help"
 
static const uint8_t FactoryResetCmd [] = "freset"
 
static const uint8_t ReadBufCmd [] = "readbuf"
 
static const uint8_t EndloopCmd [] = "endloop"
 
static const uint8_t StatusCmd [] = "status"
 
static const uint8_t CntCmd [] = "cnt"
 
static const uint8_t AboutCmd [] = "about"
 
static const uint8_t UptimeCmd [] = "uptime"
 
static const uint8_t StreamCmd [] = "stream "
 
static const uint8_t DelimCmd [] = "delim "
 
static const uint8_t EchoCmd [] = "echo "
 
static const uint8_t SleepCmd [] = "sleep "
 
static const uint8_t LoopCmd [] = "loop "
 
static const uint8_t CommandCmd [] = "cmd "
 
static const uint8_t InvalidCmdStr [] = "Error: Invalid command! Type help for list of valid commands\r\n"
 
static const uint8_t NotAllowedStr [] = "Error: Command not allowed from USB! Type help for list of valid commands\r\n"
 
static const uint8_t InvalidArgStr [] = "Error: Invalid argument!\r\n"
 
static const uint8_t UnknownErrorStr [] = "An unknown error has occurred!\r\n"
 
static const uint8_t HelpStr []
 

Detailed Description

iSensor-SPI-Buffer script module (loaded from SD card or provided via USB CLI)

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

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

Function Documentation

◆ AboutHandler()

static void AboutHandler ( uint8_t *  outBuf,
bool  isUSB 
)
static

Print about message to CLI.

Returns
void
Parameters
outBufBuffer to write data to
isUSBFlag indicating if output data should be sent to USB or SD card

The function prints firmware version and date info, as well as a link to detailed docs on GitHub

◆ FactoryResetHandler()

static void FactoryResetHandler ( )
static

Executes a factory reset + flash update.

Returns
void

This function is called when the USB CLI executes a freset command.

◆ HexToUInt()

static uint32_t HexToUInt ( const uint8_t *  commandBuf)
static

Convert a hex string to a 32 bit uint.

Returns
void

The input string must be stored in CurrentCommand, with cmdIndex set to point at the first value in the string.

Here is the caller graph for this function:

◆ ParseCommandArgs()

static uint32_t ParseCommandArgs ( const uint8_t *  commandBuf,
uint32_t *  args 
)
static

Parse space delimited arguments out from a command.

Parameters
commandBufPointer to command string
argsPointer to an array which receives the command arguments
Returns
void

Arguments must be separated by a space. Each argument (up to 3) are placed into the args array. The total number of arguments in the current command is placed in numArgs. All arguments must be hex strings.

Here is the call graph for this function:

◆ ReadBufHandler()

static void ReadBufHandler ( bool  isUSB)
static

Handler for ReadBuf command.

Returns
void
Parameters
isUSBFlag indicating if output data should be sent to USB or SD card

This function uses a ping-pong architecture for the buffer transmit data. This avoids potential data corruption issues (USB transmit is non-blocking)

◆ ReadHandler()

static void ReadHandler ( script scr,
uint8_t *  outBuf,
bool  isUSB 
)
static

Read command handler.

Returns
void
Parameters
scrScript element being executed. Contains read arguments
outBufBuffer to write data to. Must be at least STREAM_BUF_SIZE bytes
isUSBFlag indicating if output data should be sent to USB or SD card

This function handles all read commands from SD scripts or the USB CLI. Output data is filled to STREAM_BUF_SIZE, then transmitted. The arguments provided in scr are assumed to be valid prior to this function being called, so no additional input validation is performed.

Here is the call graph for this function:

◆ RegAliasReadHandler()

static void RegAliasReadHandler ( uint8_t *  outBuf,
bool  isUSB,
uint16_t  regIndex 
)
static

Read a register without changing page, and print to CLI.

Returns
void
Parameters
outBufBuffer to write data to. Must be at least 6 bytes
isUSBFlag indicating if output data should be sent to USB or SD card
regIndexthe index of the register to access (in g_regs)

The function is used to implement register read alias commands.

◆ Script_Check_Stream()

void Script_Check_Stream ( )

Check the stream status.

This function checks if a watermark interrupt is asserted, based on a minimum watermark level of

  1. If a watermark is asserted, and a stream is running, then ReadBufHandler() is called, with isUSB set to match the stream source. SD card streams have priority over USB streams, and will cancel a running USB stream.

◆ Script_Parse_Element()

void Script_Parse_Element ( const uint8_t *  commandBuf,
script scr 
)

Parse a command string into a script element.

Returns
void
Parameters
commandBufScript command string (from CLI or SD card)
scrScript element to populate

This function parses the script command type from the available list of script commands, by comparison to a pre-defined string literal. Then, the arguments for each particular command type are parsed and validated.

Here is the call graph for this function:

◆ Script_Run_Element()

void Script_Run_Element ( script scr,
uint8_t *  outBuf,
bool  isUSB 
)

Executes a script element.

Returns
void
Parameters
scrThe script element to execute
outBufOutput buffer to write script result to
isUSBFlag indicating if output data should be transmitted to USB CLI or SD card

This function handles all non-control based script elements. It also performs input validation on the script object, and will print an error message for an invalid command or invalid arguments. If the command and arguments are good, this function calls the lower level handler corresponding to the script item. Currently is just a switch statement, could do some neat stuff with a function pointer table in the future.

◆ StreamCmdHandler()

static void StreamCmdHandler ( script scr,
bool  isUSB 
)
static

Handler for stream start/stop command.

Returns
void
Parameters
scrScript element being executed
isUSBflag indicating if command came from SD script or USB CLI

This function manages stream priorities. If a stream is already running for the SD card script, a USB stream will not be started. The system currently only supports streaming data to one destination at a time.

◆ StringEquals()

static uint32_t StringEquals ( const uint8_t *  string0,
const uint8_t *  string1,
uint32_t  count 
)
static

Check equality between two strings.

Parameters
string0First string to compare
string1Second string to compare
countNumber of chars to compare (from start)
Returns
1 for equal strings, 0 for not equal
Here is the caller graph for this function:

◆ UptimeHandler()

static void UptimeHandler ( uint8_t *  outBuf,
bool  isUSB 
)
static

Print system uptime CLI.

Returns
void
Parameters
outBufBuffer to write data to
isUSBFlag indicating if output data should be sent to USB or SD card

The system uptime is based on the HAL systick counter

Here is the call graph for this function:

◆ UShortToHex()

static void UShortToHex ( uint8_t *  outBuf,
uint16_t  val 
)
static

Convert a 16 bit value to the corresponding hex string (4 chars)

Parameters
outBufBuffer to place the string result in
valThe 16 bit value to convert to a string
Returns
void
Here is the caller graph for this function:

◆ WriteHandler()

static void WriteHandler ( script scr)
static

Write command handler.

Returns
void
Parameters
scrpointer to script element containing write arguments

The write address is passed in args[0]. The address is masked to only 7 bits (address space of a page). The write value is passed in args[1]. The write value is masked to 8 bits (byte-wise writes).

Here is the call graph for this function:

Variable Documentation

◆ AboutCmd

const uint8_t AboutCmd[] = "about"
static

String literal for about command.

◆ BufA

bool BufA
static

Track which buffer is in use

◆ cmdIndex

uint32_t cmdIndex
static

Current index within command buffer

◆ CntCmd

const uint8_t CntCmd[] = "cnt"
static

String literal for cnt command.

◆ CommandCmd

const uint8_t CommandCmd[] = "cmd "
static

String literal for command run command. Must be followed by a space

◆ DelimCmd

const uint8_t DelimCmd[] = "delim "
static

String literal for delim set command. Must be followed by a space

◆ EchoCmd

const uint8_t EchoCmd[] = "echo "
static

String literal for echo enable/disable command. Must be followed by a space

◆ EndloopCmd

const uint8_t EndloopCmd[] = "endloop"
static

String literal for endloop command.

◆ FactoryResetCmd

const uint8_t FactoryResetCmd[] = "freset"
static

String literal for factory reset command

◆ goodArg

uint32_t goodArg
static

Flag to track if current command arguments are valid

◆ HelpCmd

const uint8_t HelpCmd[] = "help"
static

String literal for help command

◆ HelpStr

const uint8_t HelpStr[]
static

Print string for help command

◆ InvalidArgStr

const uint8_t InvalidArgStr[] = "Error: Invalid argument!\r\n"
static

Print string for invalid argument

◆ InvalidCmdStr

const uint8_t InvalidCmdStr[] = "Error: Invalid command! Type help for list of valid commands\r\n"
static

Print string for invalid command

◆ LoopCmd

const uint8_t LoopCmd[] = "loop "
static

String literal for loop command. Must be followed by a space

◆ NotAllowedStr

const uint8_t NotAllowedStr[] = "Error: Command not allowed from USB! Type help for list of valid commands\r\n"
static

Print string for not allowed command

◆ ReadBufCmd

const uint8_t ReadBufCmd[] = "readbuf"
static

String literal for read buffer command

◆ ReadCmd

const uint8_t ReadCmd[] = "read "
static

String literal for read command. Must be followed by a space

◆ SleepCmd

const uint8_t SleepCmd[] = "sleep "
static

String literal for sleep command. Must be followed by a space

◆ StatusCmd

const uint8_t StatusCmd[] = "status"
static

String literal for status command.

◆ StreamBuf_A

uint8_t StreamBuf_A[STREAM_BUF_SIZE]
static

Buffer A for stream data (USB or SD card) ping/pong

◆ StreamBuf_B

uint8_t StreamBuf_B[STREAM_BUF_SIZE]
static

Buffer B for stream data (USB or SD card) ping/pong

◆ StreamCmd

const uint8_t StreamCmd[] = "stream "
static

String literal for stream command. Must be followed by a space

◆ UnknownErrorStr

const uint8_t UnknownErrorStr[] = "An unknown error has occurred!\r\n"
static

Print string for unexpected processing

◆ UptimeCmd

const uint8_t UptimeCmd[] = "uptime"
static

String literal for uptime command.

◆ WriteCmd

const uint8_t WriteCmd[] = "write "
static

String literal for write command. Must be followed by a space