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"
|
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...
|
|
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)
◆ AboutHandler()
static void AboutHandler |
( |
uint8_t * |
outBuf, |
|
|
bool |
isUSB |
|
) |
| |
|
static |
Print about message to CLI.
- Returns
- void
- Parameters
-
outBuf | Buffer to write data to |
isUSB | Flag 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.
◆ ParseCommandArgs()
static uint32_t ParseCommandArgs |
( |
const uint8_t * |
commandBuf, |
|
|
uint32_t * |
args |
|
) |
| |
|
static |
Parse space delimited arguments out from a command.
- Parameters
-
commandBuf | Pointer to command string |
args | Pointer 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.
◆ ReadBufHandler()
static void ReadBufHandler |
( |
bool |
isUSB | ) |
|
|
static |
Handler for ReadBuf command.
- Returns
- void
- Parameters
-
isUSB | Flag 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
-
scr | Script element being executed. Contains read arguments |
outBuf | Buffer to write data to. Must be at least STREAM_BUF_SIZE bytes |
isUSB | Flag 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.
◆ 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
-
outBuf | Buffer to write data to. Must be at least 6 bytes |
isUSB | Flag indicating if output data should be sent to USB or SD card |
regIndex | the 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
- 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
-
commandBuf | Script command string (from CLI or SD card) |
scr | Script 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.
◆ Script_Run_Element()
void Script_Run_Element |
( |
script * |
scr, |
|
|
uint8_t * |
outBuf, |
|
|
bool |
isUSB |
|
) |
| |
Executes a script element.
- Returns
- void
- Parameters
-
scr | The script element to execute |
outBuf | Output buffer to write script result to |
isUSB | Flag 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
-
scr | Script element being executed |
isUSB | flag 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
-
string0 | First string to compare |
string1 | Second string to compare |
count | Number of chars to compare (from start) |
- Returns
- 1 for equal strings, 0 for not equal
◆ UptimeHandler()
static void UptimeHandler |
( |
uint8_t * |
outBuf, |
|
|
bool |
isUSB |
|
) |
| |
|
static |
Print system uptime CLI.
- Returns
- void
- Parameters
-
outBuf | Buffer to write data to |
isUSB | Flag indicating if output data should be sent to USB or SD card |
The system uptime is based on the HAL systick counter
◆ UShortToHex()
static void UShortToHex |
( |
uint8_t * |
outBuf, |
|
|
uint16_t |
val |
|
) |
| |
|
static |
Convert a 16 bit value to the corresponding hex string (4 chars)
- Parameters
-
outBuf | Buffer to place the string result in |
val | The 16 bit value to convert to a string |
- Returns
- void
◆ WriteHandler()
static void WriteHandler |
( |
script * |
scr | ) |
|
|
static |
Write command handler.
- Returns
- void
- Parameters
-
scr | pointer 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).
◆ AboutCmd
const uint8_t AboutCmd[] = "about" |
|
static |
String literal for about command.
◆ BufA
Track which buffer is in use
◆ cmdIndex
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
Flag to track if current command arguments are valid
◆ HelpCmd
const uint8_t HelpCmd[] = "help" |
|
static |
String literal for help command
◆ HelpStr
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
Buffer A for stream data (USB or SD card) ping/pong
◆ StreamBuf_B
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