ZCU106 裸机NR SHELL移植

ZCU106 裸机NR SHELL移植

许久没更了,画了一个月的板子,终于初版画完了,剩下的和师兄对一下接口、然后细节问题就可以投板了,接下来就继续我的裸机VCU了~
裸机(用RTOS了其实)没有shell的情况就感觉很别扭,每次下程序又比较麻烦,所以这里便用一个shell去控制,网上有开源了的,所以这里移植一个在我的ZCU106板子上方便后续开发
源码github:https://codeload.github.com/Nrusher/nr_micro_shell/zip/master
开源的魅力就在于不必再去重复造轮子~哈哈

添加源码到自己的工程下

inc是头、src目录是c文件位置、nr_xxx_commands.c用于添加自己的指令、shell_thread.c是我们的shell线程,这里优先级给最低
ZCU106 裸机NR SHELL移植_第1张图片
此外直接之一会报错因为##拼接符号在gcc下面会认为不安全,所以改成

#define NR_ANSI_CLR_R_MV_L_NCHAR(cmd) ((const char *)"\033["## #cmd##"P")
修改后:
#define NR_ANSI_CLR_R_MV_L_NCHAR_M(cmd) ((const char *)"\033[1P")

然后将shell_printf修改成自己的xil_printf:

/* If you use RTOS, you may need to do some special processing for printf(). */
#define shell_printf(fmt, args...) xil_printf(fmt, ##args)
#define ansi_show_char(x) outbyte(x)

此外修改名字、配置都在shell_config.h下修改:

/* ANSI command line buffer size. */
#define NR_ANSI_LINE_SIZE 100

/* Maximum user name length. */
#define NR_SHELL_USER_NAME_MAX_LENGTH 30

/* Maximum command name length. */
#define NR_SHELL_CMD_NAME_MAX_LENGTH 10

/* Command line buffer size. */
#define NR_SHELL_CMD_LINE_MAX_LENGTH NR_ANSI_LINE_SIZE

/* The maximum number of parameters in the command. */
#define NR_SHELL_CMD_PARAS_MAX_NUM 10

/* Command stores the most history commands (the maximum number here refers to the maximum number of commands that can be stored. When the history command line cache is full, it will automatically release the earliest command record) */
#define NR_SHELL_MAX_CMD_HISTORY_NUM 3

/* History command cache length */
#define NR_SHELL_CMD_HISTORY_BUF_LENGTH 253

/* The user's name. */
#define NR_SHELL_USER_NAME "nr@root:"

/*
0: \n
1: \r
2: \r\n
*/
#define NR_SHELL_END_OF_LINE 1

这里的shell end of line根据自己用的软件回车发送的是啥来修改,我是只有\r所以1
这里的shell_tread在freeRtos下运行,代码如下:

static char nr_shell_getchar(void)
{
	char ch = 0;

	if(xSemaphoreTake(shell_semaphore, SH_WAIT_MAX_TIME)){
		ch = recv_buf[0];
	}

	return ch;
}


void nr_shell_thread_entry(void *parameter)
{
	char ch;
	
	shell_semaphore= xSemaphoreCreateBinary();
	if(shell_semaphore== NULL) {
			printf("ERR Cretae Shell Sem!\n");
			vTaskDelete(NULL);
	}

	shell_init();
	open_stdio_uart();

	while (1)
	{
		ch = nr_shell_getchar();
		shell(ch);
	}
}

上面的open_uart是我们自己的配置uart的函数,主要配置中断等,这里注意把fifo阈值修改为1:

	XUartPs_SetFifoThreshold(uart_inst_ptr, 1);

然后开机打印:
ZCU106 裸机NR SHELL移植_第2张图片

END

继续搬砖了

你可能感兴趣的:(ARM,zynq)