mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-23 05:08:45 +00:00
[update][shell] support shell with os
This commit is contained in:
parent
2db77dee27
commit
3f480f087b
14 changed files with 305 additions and 44 deletions
|
@ -1,3 +1,7 @@
|
|||
sdk_generate_library()
|
||||
sdk_library_add_sources(shell.c)
|
||||
sdk_add_include_directories(.)
|
||||
sdk_add_include_directories(.)
|
||||
|
||||
if(CONFIG_FREERTOS)
|
||||
sdk_library_add_sources(shell_freertos.c)
|
||||
endif()
|
|
@ -1,27 +1,24 @@
|
|||
/**
|
||||
* @file shell.c
|
||||
* @brief
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2006-04-30 Bernard the first version for FinSH
|
||||
* 2006-05-08 Bernard change finsh thread stack to 2048
|
||||
* 2006-06-03 Bernard add support for skyeye
|
||||
* 2006-09-24 Bernard remove the code related with hardware
|
||||
* 2010-01-18 Bernard fix down then up key bug.
|
||||
* 2010-03-19 Bernard fix backspace issue and fix device read in shell.
|
||||
* 2010-04-01 Bernard add prompt output when start and remove the empty history
|
||||
* 2011-02-23 Bernard fix variable section end issue of finsh shell
|
||||
* initialization when use GNU GCC compiler.
|
||||
* 2016-11-26 armink add password authentication
|
||||
* 2018-07-02 aozima add custom prompt support.
|
||||
*/
|
||||
|
||||
#include "shell.h"
|
||||
#include <ctype.h>
|
||||
#if defined(SHELL_USING_FS)
|
||||
#include "ff.h"
|
||||
#endif
|
||||
|
|
|
@ -1,24 +1,11 @@
|
|||
/**
|
||||
* @file shell.h
|
||||
* @brief
|
||||
/*
|
||||
* Copyright (c) 2006-2021, RT-Thread Development Team
|
||||
*
|
||||
* Copyright (c) 2021 Bouffalolab team
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*
|
||||
* Change Logs:
|
||||
* Date Author Notes
|
||||
* 2011-06-02 Bernard Add finsh_get_prompt function declaration
|
||||
*/
|
||||
#ifndef __SHELL_H__
|
||||
#define __SHELL_H__
|
||||
|
|
|
@ -28,4 +28,12 @@
|
|||
//#define SHELL_USING_FS
|
||||
//#define SHELL_USING_COLOR
|
||||
|
||||
#ifndef SHELL_THREAD_STACK_SIZE
|
||||
#define SHELL_THREAD_STACK_SIZE 1024
|
||||
#endif
|
||||
|
||||
#ifndef SHELL_THREAD_PRIO
|
||||
#define SHELL_THREAD_PRIO 5
|
||||
#endif
|
||||
|
||||
#endif
|
71
components/shell/shell_freertos.c
Normal file
71
components/shell/shell_freertos.c
Normal file
|
@ -0,0 +1,71 @@
|
|||
#include "shell.h"
|
||||
#include <FreeRTOS.h>
|
||||
#include "semphr.h"
|
||||
#include "ring_buffer.h"
|
||||
#include "bflb_uart.h"
|
||||
|
||||
static TaskHandle_t shell_handle;
|
||||
SemaphoreHandle_t sem_shell = NULL;
|
||||
|
||||
Ring_Buffer_Type shell_rb;
|
||||
|
||||
uint8_t shell_buffer[512];
|
||||
|
||||
void shell_release_sem(void)
|
||||
{
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
int ret = xSemaphoreGiveFromISR(sem_shell, &xHigherPriorityTaskWoken);
|
||||
if (ret == pdPASS) {
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
}
|
||||
|
||||
static struct bflb_device_s *uart_shell;
|
||||
|
||||
void uart_shell_isr(int irq, void *arg)
|
||||
{
|
||||
uint32_t intstatus = bflb_uart_get_intstatus(uart_shell);
|
||||
if (intstatus & UART_INTSTS_RX_FIFO) {
|
||||
while (bflb_uart_rxavailable(uart_shell)) {
|
||||
Ring_Buffer_Write_Byte(&shell_rb, bflb_uart_getchar(uart_shell));
|
||||
}
|
||||
shell_release_sem();
|
||||
}
|
||||
if (intstatus & UART_INTSTS_RTO) {
|
||||
while (bflb_uart_rxavailable(uart_shell)) {
|
||||
Ring_Buffer_Write_Byte(&shell_rb, bflb_uart_getchar(uart_shell));
|
||||
}
|
||||
shell_release_sem();
|
||||
bflb_uart_int_clear(uart_shell, UART_INTCLR_RTO);
|
||||
}
|
||||
}
|
||||
|
||||
static void shell_task(void *pvParameters)
|
||||
{
|
||||
uint8_t data;
|
||||
uint32_t len;
|
||||
while (1) {
|
||||
if (xSemaphoreTake(sem_shell, portMAX_DELAY) == pdTRUE) {
|
||||
len = Ring_Buffer_Get_Length(&shell_rb);
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
Ring_Buffer_Read_Byte(&shell_rb, &data);
|
||||
shell_handler(data);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void shell_init_with_task(struct bflb_device_s *shell)
|
||||
{
|
||||
uart_shell = shell;
|
||||
bflb_uart_rxint_mask(uart_shell, false);
|
||||
bflb_irq_attach(uart_shell->irq_num, uart_shell_isr, NULL);
|
||||
bflb_irq_enable(uart_shell->irq_num);
|
||||
|
||||
Ring_Buffer_Init(&shell_rb, shell_buffer, sizeof(shell_buffer), NULL, NULL);
|
||||
|
||||
shell_init();
|
||||
vSemaphoreCreateBinary(sem_shell);
|
||||
xTaskCreate(shell_task, (char *)"shell_task", SHELL_THREAD_STACK_SIZE, NULL, SHELL_THREAD_PRIO, &shell_handle);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue