shell: make flag modification atomic

Add Z_SHELL_SET_FLAG_ATOMIC macro to use technique from
shell_process() to atomically set and return the previous
value.

Change all void z_flag_*_set() functions to bool z_flag_*_set()
and use macro to return previous value after setting.

Modify shell_process() to use this modified z_flag_processing_set()
function.

Reorder flags to keep last_nl on byte boundary.

Add public setters for insert_mode, echo, and mode_delete for
completeness.

Signed-off-by: Pete Skeggs <peter.skeggs@nordicsemi.no>
This commit is contained in:
Pete Skeggs 2021-03-10 15:56:32 -08:00 committed by Anas Nashif
commit 75a74bfad2
3 changed files with 149 additions and 43 deletions

View file

@ -613,8 +613,8 @@ struct shell_flags {
uint32_t tx_rdy :1;
uint32_t mode_delete :1; /*!< Operation mode of backspace key */
uint32_t history_exit:1; /*!< Request to exit history mode */
uint32_t cmd_ctx :1; /*!< Shell is executing command */
uint32_t last_nl :8; /*!< Last received new line character */
uint32_t cmd_ctx :1; /*!< Shell is executing command */
uint32_t print_noinit:1; /*!< Print request from not initialized shell*/
};
@ -1036,29 +1036,68 @@ int shell_execute_cmd(const struct shell *shell, const char *cmd);
int shell_set_root_cmd(const char *cmd);
/**
* @brief Allow application to control whether terminal output uses colored
* syntax.
* @brief Allow application to control text insert mode.
* Value is modified atomically and the previous value is returned.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] use_colors Color mode.
* @param[in] val Insert mode.
*
* @retval 0 if set.
* @retval 0 or 1: previous value
* @retval -EINVAL if shell is NULL.
*/
int shell_use_colors_set(const struct shell *shell, bool use_colors);
int shell_insert_mode_set(const struct shell *shell, bool val);
/**
* @brief Allow application to control whether terminal output uses colored
* syntax.
* Value is modified atomically and the previous value is returned.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] val Color mode.
*
* @retval 0 or 1: previous value
* @retval -EINVAL if shell is NULL.
*/
int shell_use_colors_set(const struct shell *shell, bool val);
/**
* @brief Allow application to control whether user input is echoed back.
* Value is modified atomically and the previous value is returned.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] val Echo mode.
*
* @retval 0 or 1: previous value
* @retval -EINVAL if shell is NULL.
*/
int shell_echo_set(const struct shell *shell, bool val);
/**
* @brief Allow application to control whether user input is obscured with
* asterisks -- useful for implementing passwords.
* Value is modified atomically and the previous value is returned.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] obscure Obscure mode.
*
* @retval 0 if set.
* @retval 0 or 1: previous value.
* @retval -EINVAL if shell is NULL.
*/
int shell_obscure_set(const struct shell *shell, bool obscure);
/**
* @brief Allow application to control whether the delete key backspaces or
* deletes.
* Value is modified atomically and the previous value is returned.
*
* @param[in] shell Pointer to the shell instance.
* @param[in] val Delete mode.
*
* @retval 0 or 1: previous value
* @retval -EINVAL if shell is NULL.
*/
int shell_mode_delete_set(const struct shell *shell, bool val);
/**
* @}
*/