Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Examples): Add CLI Library to MSDK #679

Merged
merged 44 commits into from
Sep 21, 2023

Conversation

Suraj-Ajjampur
Copy link
Contributor

@Suraj-Ajjampur Suraj-Ajjampur commented Jul 19, 2023

Description

Requirements captured during functional testing of MAX78000 Examples. Ticket - MSDK-1197

Features added

  • Asynchronous UART to read characters entered by the user
  • Callback function calls a Line_Accumulator function which reads incoming characters, accumulates into a line buffer, echos characters back to the emulator, handles functions like backspace (future arrow keys, tab key etc.) and Enter key.
  • Process command is called when user hits the Enter Key. This function Processes user command input into a series of tokens, all tokes are separated by whitespace characters and then it dispatches to handler functions based on the first token.
  • The structure of the lookup table (command_table_t) makes it trivially easy to add a new commands to this command processor.

This implementation has been exported as a library as all clients can export this cli implementation and provide an isolation of functionality. This design is suited to be retrofitted to different CLI implementations as different arguments of a function which are separated as tokens can be passed in through the handler function.

@Suraj-Ajjampur Suraj-Ajjampur changed the title feat/Examples: Add CLI Library to MSDK feat/Examples: MSDK-1197 Add CLI Library to MSDK Jul 19, 2023
@github-actions github-actions bot added the MAX78000 Related to the MAX78000 (AI85) label Jul 19, 2023
@Suraj-Ajjampur Suraj-Ajjampur changed the title feat/Examples: MSDK-1197 Add CLI Library to MSDK feat(Examples): MSDK-1197 Add CLI Library to MSDK Jul 19, 2023
@Suraj-Ajjampur
Copy link
Contributor Author

/clang-format-run

Libraries/CLI/src/cli.c Outdated Show resolved Hide resolved
Comment on lines 127 to 128
//Find end of string
for (end = input; *end != '\0'; end++) {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One suggestion here,
Instead of using a for loop, you can use strlen(), that would give the number of characters in the input buffer. Then you can do pointer arithmetic to find the end ptr.

Libraries/CLI/src/cli.c Outdated Show resolved Hide resolved
// Handle Enter or carriage return
MXC_UART_WriteCharacter(MXC_UART_GET_UART(CONSOLE_UART), NEW_LINE);
MXC_UART_WriteCharacter(MXC_UART_GET_UART(CONSOLE_UART), ENTER);
buf[idx++] = '\r';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need a carriage return in this line?
Because I see in the process command we are looking for a NULL terminated char pointer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line accumulator here enters a '\r' character every time the enter key is pressed by the user.
Later the process_command function looks for carriage return while iterating over each character in the input command to check the end of the string and break from the iterating for loop.

Comment on lines 139 to 141
//Iterate over each character in input
for (p = input; p < end; p++) {
//If in a token
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of iterating over all characters in the array, I would suggest using strchr() function, search for white_space, then create argv[][] array with all arguments given by the user. I think that could be computationally efficient.

Libraries/CLI/src/cli.c Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.c Outdated Show resolved Hide resolved
Examples/MAX78000/SDHC_FTHR/.vscode/settings.json Outdated Show resolved Hide resolved
Examples/MAX78000/SDHC_FTHR/user-cli.c Outdated Show resolved Hide resolved
Examples/MAX78000/SDHC_FTHR/user-cli.c Outdated Show resolved Hide resolved
USERGUIDE.md Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
Libraries/CLI/src/cli.h Outdated Show resolved Hide resolved
@Suraj-Ajjampur
Copy link
Contributor Author

/clang-format-run

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default board is the FTHR_RevA for the SDHC example

@Jacob-Scheiffler Jacob-Scheiffler requested review from sihyung-maxim and removed request for EdwinFairchild September 14, 2023 20:00
@github-actions github-actions bot added the documentation Improvements or additions to documentation label Sep 20, 2023
Copy link
Contributor

@Jake-Carter Jake-Carter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will merge once final checks pass

@Jake-Carter Jake-Carter changed the title feat(Examples): MSDK-1197 Add CLI Library to MSDK feat(Examples): Add CLI Library to MSDK Sep 20, 2023
@Jake-Carter Jake-Carter merged commit 7cc3386 into analogdevicesinc:main Sep 21, 2023
@Suraj-Ajjampur Suraj-Ajjampur deleted the fix/msdk-1197 branch September 24, 2023 06:38
EricB-ADI pushed a commit that referenced this pull request Nov 21, 2023
Co-authored-by: Suraj-Ajjampur <suraj.ajjampur@analog.com>
Co-authored-by: Suraj-Ajjampur <Suraj-Ajjampur@users.noreply.github.com>
Co-authored-by: Scheiffler <Jacob.Scheiffler@analog.com>
Co-authored-by: Jacob Scheiffler <86001820+Jacob-Scheiffler@users.noreply.github.com>
Co-authored-by: Jake Carter <Jake.Carter@analog.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation MAX78000 Related to the MAX78000 (AI85)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants