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線程,這裏優先級給最低
在這裏插入圖片描述
此外直接之一會報錯因爲##拼接符號在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);

然後開機打印:
在這裏插入圖片描述

END

繼續搬磚了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章