luckfox-pico-sdk/sysdrv/source/mcu/rt-thread/components/finsh/finsh_node.c
luckfox-eng29 8f34c2760d project:build.sh: Added fastboot support; custom modifications to U-Boot and kernel implemented using patches.
project:cfg:BoardConfig_IPC: Added fastboot BoardConfig file and firmware post-scripts, distinguishing between
the BoardConfigs for Luckfox Pico Pro and Luckfox Pico Max. project:app: Added fastboot_client and rk_smart_door
for quick boot applications; updated rkipc app to adapt to the latest media library. media:samples: Added more
usage examples. media:rockit: Fixed bugs; removed support for retrieving data frames from VPSS. media:isp:
Updated rkaiq library and related tools to support connection to RKISP_Tuner. sysdrv:Makefile: Added support for
compiling drv_ko on Luckfox Pico Ultra W using Ubuntu; added support for custom root filesystem.
sysdrv:tools:board: Updated Buildroot optional mirror sources, updated some software versions, and stored device
tree files and configuration files that undergo multiple modifications for U-Boot and kernel separately.
sysdrv:source:mcu: Used RISC-V MCU SDK with RT-Thread system, mainly for initializing camera AE during quick
boot. sysdrv:source:uboot: Added support for fastboot; added high baud rate DDR bin for serial firmware upgrades.
sysdrv:source:kernel: Upgraded to version 5.10.160; increased NPU frequency for RV1106G3; added support for
fastboot.

Signed-off-by: luckfox-eng29 <eng29@luckfox.com>
2024-10-14 09:47:04 +08:00

184 lines
3.9 KiB
C

/*
* Copyright (c) 2006-2018, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2010-03-22 Bernard first version
*/
#include <finsh.h>
#include "finsh_node.h"
#include "finsh_error.h"
#include "finsh_var.h"
#include "finsh_heap.h"
struct finsh_node global_node_table[FINSH_NODE_MAX];
int finsh_node_init()
{
memset(global_node_table, 0, sizeof(global_node_table));
return 0;
}
struct finsh_node* finsh_node_allocate(uint8_t type)
{
int i;
/* find an empty entry */
for (i = 0; i < FINSH_NODE_MAX; i ++)
{
if (global_node_table[i].node_type == FINSH_NODE_UNKNOWN) break;
}
if (i == FINSH_NODE_MAX) return NULL;
/* fill type field */
global_node_table[i].node_type = type;
/* return this allocated node */
return &global_node_table[i];
}
struct finsh_node* finsh_node_new_id(char* id)
{
struct finsh_node* node;
void* symbol;
unsigned char type;
symbol = NULL;
type = 0;
node = NULL;
/* lookup variable firstly */
symbol = (void*)finsh_var_lookup(id);
if (symbol == NULL)
{
/* then lookup system variable */
symbol = (void*)finsh_sysvar_lookup(id);
if (symbol == NULL)
{
/* then lookup system call */
symbol = (void*)finsh_syscall_lookup(id);
if (symbol != NULL) type = FINSH_IDTYPE_SYSCALL;
}
else type = FINSH_IDTYPE_SYSVAR;
}
else type = FINSH_IDTYPE_VAR;
if (symbol != NULL)
{
/* allocate a new node */
node = finsh_node_allocate(FINSH_NODE_ID);
/* allocate node error */
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
/* fill node value according type */
switch (type)
{
case FINSH_IDTYPE_VAR:
node->id.var = (struct finsh_var*)symbol;
break;
case FINSH_IDTYPE_SYSVAR:
node->id.sysvar = (struct finsh_sysvar*)symbol;
break;
case FINSH_IDTYPE_SYSCALL:
node->id.syscall = (struct finsh_syscall*)symbol;
break;
}
/* fill identifier type */
node->idtype = type;
}
else finsh_error_set(FINSH_ERROR_UNKNOWN_SYMBOL);
return node;
}
struct finsh_node* finsh_node_new_char(char c)
{
struct finsh_node* node;
node = finsh_node_allocate(FINSH_NODE_VALUE_CHAR);
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
node->value.char_value = c;
return node;
}
struct finsh_node* finsh_node_new_int(int i)
{
struct finsh_node* node;
node = finsh_node_allocate(FINSH_NODE_VALUE_INT);
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
node->value.int_value = i;
return node;
}
struct finsh_node* finsh_node_new_long(long l)
{
struct finsh_node* node;
node = finsh_node_allocate(FINSH_NODE_VALUE_LONG);
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
node->value.long_value = l;
return node;
}
struct finsh_node* finsh_node_new_string(char* s)
{
struct finsh_node* node;
node = finsh_node_allocate(FINSH_NODE_VALUE_STRING);
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
/* make string */
node->value.ptr = finsh_heap_allocate(strlen(s) + 1);
strncpy(node->value.ptr, s, strlen(s));
((uint8_t*)node->value.ptr)[strlen(s)] = '\0';
return node;
}
struct finsh_node* finsh_node_new_ptr(void* ptr)
{
struct finsh_node* node;
node = finsh_node_allocate(FINSH_NODE_VALUE_NULL);
if (node == NULL)
{
finsh_error_set(FINSH_ERROR_MEMORY_FULL);
return NULL;
}
node->value.ptr = ptr;
return node;
}