正点原子学习小组
直播中

jf_1137202360

8年用户 1359经验值
擅长:嵌入式技术
私信 关注

【正点原子STM32精英V2开发板体验】基于环形缓冲区串口驱动实现SHELL命令交互

本帖最后由 jf_1137202360 于 2023-4-15 17:33 编辑

转自公众号,欢迎关注

工程源码
test.zip (4.92 MB)
(下载次数: 1, 2023-4-14 18:00 上传)

前言

    为了方便后面开发测试,我们需要一定的和开发板交互的手段,所以我们先来基于串口实现一个简单的命令行工具。

过程实现串口FIFO
首先实现基于环形缓冲区的串口接收驱动。
添加uart fifo实现代码
图片1.png

Drivers\\\\\\\\SYSTEM\\\\\\\\usart\\\\\\\\usart.c
  1. #include \\\\\\\"./SYSTEM/usart/usart_fifo.h\\\\\\\"

HAL_UART_RxCpltCallback修改为
  1. void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
  2. {
  3.     if (huart->Instance == USART_UX)                    /* 如果是串口1 */
  4.     {
  5.                         #if 0
  6.         if ((g_usart_rx_sta & 0x8000) == 0)             /* 接收未完成 */
  7.         {
  8.             if (g_usart_rx_sta & 0x4000)                /* 接收到了0x0d(即回车键) */
  9.             {
  10.                 if (g_rx_buffer[0] != 0x0a)             /* 接收到的不是0x0a(即不是换行键) */
  11.                 {
  12.                     g_usart_rx_sta = 0;                 /* 接收错误,重新开始 */
  13.                 }
  14.                 else                                    /* 接收到的是0x0a(即换行键) */
  15.                 {
  16.                     g_usart_rx_sta |= 0x8000;           /* 接收完成了 */
  17.                 }
  18.             }
  19.             else                                        /* 还没收到0X0d(即回车键) */
  20.             {
  21.                 if (g_rx_buffer[0] == 0x0d)
  22.                     g_usart_rx_sta |= 0x4000;
  23.                 else
  24.                 {
  25.                     g_usart_rx_buf[g_usart_rx_sta & 0X3FFF] = g_rx_buffer[0];
  26.                     g_usart_rx_sta++;

  27.                     if (g_usart_rx_sta > (USART_REC_LEN - 1))
  28.                     {
  29.                         g_usart_rx_sta = 0;             /* 接收数据错误,重新开始接收 */
  30.                     }
  31.                 }
  32.             }
  33.         }
  34.                                 #endif
  35.                                 uart_rx_handler(&g_rx_buffer[0], 1);
  36.     }
  37. }

即收到数据调用uart_rx_handler进行入缓冲区操作。

添加发送接口
  1. void usart_send(uint8_t value)

  2. {

  3.     while ((USART_UX->SR & 0X40) == 0);     /* 等待上一个字符发送完成 */

  4.     USART_UX->DR = value;                   /* 将要发送的字符 ch 写入到DR寄存器 */

  5. }

对应.h中添加申明void usart_send(uint8_t value);

usart_fifo.c

  1. #include
  2. #include
  3. #include <ARM_compat.h>
  4. #include \\\"SYSTEM/usart/usart.h\\\"

  5. uint8_t uart_ring_buffer[128];

  6. typedef struct
  7. {
  8.     uint32_t datalen_u32;
  9.     uint32_t maxlen_u32;
  10.     uint32_t in_u32;
  11.     uint32_t out_u32;
  12.     uint8_t* buffer_pu8;
  13. }ring_buffer_t;

  14. ring_buffer_t s_ring_buffer_t=
  15. {
  16.   .datalen_u32 = 0,
  17.   .maxlen_u32 = sizeof(uart_ring_buffer),
  18.   .in_u32 = 0,
  19.   .out_u32 = 0,
  20.   .buffer_pu8 = uart_ring_buffer,
  21. };

  22. void uart_rx_handler(const uint8_t *buffer, uint32_t length)
  23. {
  24.     for(uint32_t i=0;i
  25.     {
  26.         if(s_ring_buffer_t.datalen_u32 < s_ring_buffer_t.maxlen_u32)
  27.         {
  28.             s_ring_buffer_t.buffer_pu8[s_ring_buffer_t.in_u32] = buffer[i];
  29.             s_ring_buffer_t.datalen_u32++;
  30.             s_ring_buffer_t.in_u32++;
  31.             s_ring_buffer_t.in_u32 %= s_ring_buffer_t.maxlen_u32;
  32.         }
  33.         else
  34.         {
  35.             /* full */
  36.             break;
  37.         }
  38.     }
  39. }

  40. int uart_read(uint8_t *buff, uint32_t len)
  41. {
  42.     uint32_t readlen = 0;
  43.     uint32_t mask;
  44.     if(s_ring_buffer_t.datalen_u32 == 0)
  45.     {
  46.         return 0;
  47.     }
  48.     __disable_irq();
  49.     for(uint32_t i=0;i
  50.     {
  51.         if(s_ring_buffer_t.datalen_u32 > 0)
  52.         {
  53.           buff[i] = s_ring_buffer_t.buffer_pu8[s_ring_buffer_t.out_u32];
  54.           s_ring_buffer_t.datalen_u32--;
  55.           s_ring_buffer_t.out_u32++;
  56.           s_ring_buffer_t.out_u32 %= s_ring_buffer_t.maxlen_u32;
  57.           readlen++;
  58.         }
  59.         else
  60.         {
  61.           break;
  62.         }
  63.     }
  64.     __enable_irq();
  65.     return readlen;
  66. }

  67. int uart_write(uint8_t *buff, uint32_t len)
  68. {
  69.     for(uint32_t i=0; i
  70.     {
  71.         usart_send(buff[i]);
  72.     }
  73.     return 0;
  74. }

  75. void uart_init(void)
  76. {

  77. }

usart_fifo.h

  1. #ifndef UART_FIFO_H

准备shell代码
添加代码
图片2.png

添加头文件包含路径
图片3.png

shell依赖
需要实现shell.c中的shell_getcharputchar
  1. static int shell_getchar(unsigned char *data)
  2. {
  3.     int erro=0;
  4.     //driver_uart_recv(getstdiouart(), data, 1,10,&erro);
  5.           if(0 == uart_read(data, 1))
  6.                 {
  7.                         erro = 1;
  8.                 }
  9.     if(erro!=0)
  10.     {
  11.         return -1;
  12.     }
  13.     return 0;
  14. }


putchar因为重定向了标准输入输出已经有了。

测试
main.c
  1. #include \\\\\\\"shell.h\\\\\\\"



  2. while (1)

  3.     { shell_exec_shellcmd();

  4.       delay_ms(1);

  5.     }
接上串口,回车打印sh>
输入help打印如下
图片4.png
这样可以自由的添加交互命令了。

总结
    以上通过实现串口接收环形FIFO的驱动,方便应用层进行调用。并给予此实现了简洁的SHELL交互命令,非阻塞,可以方便的添加命令。

附录源码
shell.c
  1. /**
  2. *****************************************************************************        
  3. * \\\\\\\\brief       平台相关(PLATFORM)SHELL模块(SHELL)相关接口实现.
  4. * \\\\\\\\details     
  5. *              All rights reserved.   
  6. * \\\\\\\\file        shell.c  
  7. * \\\\\\\\author      
  8. * \\\\\\\\version     1.0
  9. * \\\\\\\\date      
  10. * \\\\\\\\note        使用前请参考注释.\\\\\\\\n
  11. * \\\\\\\\since       新建
  12. * \\\\\\\\par 修订记录
  13. * - 初始版本
  14. * \\\\\\\\par 资源说明
  15. * - RAM:              
  16. * - ROM:
  17. *****************************************************************************
  18. */

  19. #include
  20. #include
  21. #include \\\\\\\"shell.h\\\\\\\"
  22. #include \\\\\\\"SYSTEM/usart/usart_fifo.h\\\\\\\"

  23. /*****************************************************************************   
  24. *                                                                           
  25. *                             内部数据                                   
  26. *                                                                           
  27. ****************************************************************************/
  28. #define SHELL_CMD_LEN 64                          /**< shell命令缓冲区长度  */
  29. extern const shell_cmd_cfg shell_cmd_list[ ];     /**< shell_fun中定义  */
  30. extern const shell_cmd_cfg shell_cmd_list_app[ ]; /**< app_shellfun中定义  */
  31. static int shellpassed = 1;  /**< shell密码是否校验 0已经校验 1未校验  */
  32. static unsigned char cmd_buf[SHELL_CMD_LEN]=\\\\\\\"\\\\\\\\r\\\\\\\";
  33. static int cmd_buf_index=0;  /**< 当前接收到的命令字符数  */

  34. /*****************************************************************************   
  35. *                                                                           
  36. *                             内部接口函数实现                                   
  37. *                                                                           
  38. ****************************************************************************/

  39. /**
  40. *****************************************************************************
  41. * \\\\\\\\fn          static int shell_getchar(unsigned char *data)
  42. * \\\\\\\\brief       读取一个字符.
  43. * \\\\\\\\note        .
  44. * \\\\\\\\param[out]  data 存储读到的数据.
  45. * retval       0  成功.
  46. * retval       -1 失败.
  47. *****************************************************************************
  48. */
  49. static int shell_getchar(unsigned char *data)
  50. {
  51.     int erro=0;
  52.     //driver_uart_recv(getstdiouart(), data, 1,10,&erro);
  53.           if(0 == uart_read(data, 1))
  54.                 {
  55.                         erro = 1;
  56.                 }
  57.     if(erro!=0)
  58.     {
  59.         return -1;
  60.     }
  61.     return 0;
  62. }


  63. /**
  64. *****************************************************************************
  65. * \\\\\\\\fn          static unsigned int shell_cmd_len(char const *cmd)
  66. * \\\\\\\\brief       获取命令字符长度.
  67. * \\\\\\\\note        空格或者\\\\\\\\0结束.
  68. * \\\\\\\\param[in]   cmd 字符串
  69. * return       unsigned int 命令字符的长度
  70. *****************************************************************************
  71. */
  72. static unsigned int shell_cmd_len(unsigned char const *cmd)
  73. {
  74.     unsigned char const *p = cmd;
  75.     unsigned int len = 0;
  76.     while((*p != \\\\\\\' \\\\\\\') && (*p != 0))
  77.     {
  78.         p++;
  79.         len++;
  80.     }
  81.     return len;
  82. }

  83. /**
  84. *****************************************************************************
  85. * \\\\\\\\fn          static void shell_check_passwd(void)
  86. * \\\\\\\\brief       shell密码确认.
  87. * \\\\\\\\note        空格或者\\\\\\\\0结束.
  88. *****************************************************************************
  89. */
  90. static void shell_check_passwd(void)
  91. {
  92.         unsigned int i;
  93.     unsigned char ch[6] = {0};
  94.     unsigned char pw[7] = SHELL_PASSWORD_STR;

  95.     while(1)
  96.     {
  97.         printf(\\\\\\\"\\\\\\\\r\\\\\\\\nPassword:\\\\\\\");
  98.         memset(ch, 0, sizeof(ch));
  99.         for (i = 0; i < sizeof(ch); i++)
  100.         {
  101.             ch[i] = getchar();
  102.             putchar(\\\\\\\'\\\\\\\\b\\\\\\\');
  103.             putchar(\\\\\\\'*\\\\\\\');
  104.         }
  105.         if (memcmp(pw, ch, sizeof(ch)) == 0)
  106.         {
  107.             printf(\\\\\\\"\\\\\\\\r\\\\\\\\n\\\\\\\");
  108.             break;
  109.         }
  110.         printf(\\\\\\\"\\\\\\\\r\\\\\\\\nAccess denied\\\\\\\\r\\\\\\\\n\\\\\\\");
  111.     }
  112. }

  113. /**
  114. *****************************************************************************
  115. * \\\\\\\\fn          static int shell_cmd_check(unsigned char *cmd, char const *str)
  116. * \\\\\\\\brief       匹配命令字符.
  117. * \\\\\\\\note        .
  118. * \\\\\\\\param[in]   cmd 字符串
  119. * \\\\\\\\param[in]   str 匹配字符
  120. * retval       0 匹配成功
  121. * retval       1 匹配失败
  122. *****************************************************************************
  123. */
  124. static int shell_cmd_check(unsigned char *cmd, unsigned char const *str)
  125. {
  126.     unsigned int len1 = shell_cmd_len((unsigned char const *)cmd);
  127.     unsigned int len2 = shell_cmd_len(str);
  128.     if(len1 != len2)
  129.     {
  130.         return 1;
  131.     }
  132.     return memcmp(cmd, str, len1);
  133. }

  134. /**
  135. *****************************************************************************
  136. * \\\\\\\\fn          static unsigned int shell_read_line(int get(void), unsigned int len)
  137. * \\\\\\\\brief       shell读命令行.
  138. * \\\\\\\\note        回车结束,可以使用Backspace键清除输入.
  139. * \\\\\\\\param[in]   get 输入接口函数
  140. * \\\\\\\\param[in]   p   接收缓冲区
  141. * \\\\\\\\param[in]   len 需要接收的长度
  142. * return       unsigned int 实际接收的长度
  143. *****************************************************************************
  144. */
  145. static unsigned int shell_read_line(int get(unsigned char* tmp))
  146. {
  147.     unsigned char ch = \\\\\\\'\\\\\\\\r\\\\\\\';
  148.     unsigned int count;
  149.     unsigned char tmp;
  150.     /*开始打印一次\\\\\\\"sh>\\\\\\\"*/
  151.     if(cmd_buf[0]==\\\\\\\'\\\\\\\\r\\\\\\\')
  152.     {
  153.         printf(\\\\\\\"sh>\\\\\\\\r\\\\\\\\n\\\\\\\");
  154.         memset(cmd_buf,0x00,sizeof(cmd_buf));
  155.     }
  156.     /*如果接收到字符往下走,否则返回*/
  157.     if(get(&tmp)==0)
  158.     {
  159.         ch = tmp;
  160.     }
  161.     else
  162.     {
  163.         return 0;
  164.     }
  165.     /*如果接收到非打印字符且当前接收缓冲区不为0则认为接收到一帧否则打印\\\\\\\"SH>\\\\\\\"*/
  166.     if((ch == \\\\\\\'\\\\\\\\r\\\\\\\' || ch == \\\\\\\'\\\\\\\\n\\\\\\\' || ch < \\\\\\\' \\\\\\\' || ch > \\\\\\\'~\\\\\\\') && (ch != \\\\\\\'\\\\\\\\b\\\\\\\'))
  167.     {
  168.         if(cmd_buf_index==0)
  169.         {
  170.             printf(\\\\\\\"sh>\\\\\\\\r\\\\\\\\n\\\\\\\");
  171.         }
  172.         else
  173.         {
  174.             count = cmd_buf_index;
  175.             cmd_buf[cmd_buf_index]=0;
  176.             cmd_buf_index =0;
  177.             printf(\\\\\\\"\\\\\\\\r\\\\\\\\n\\\\\\\");
  178.             return count;
  179.         }
  180.     }
  181.     else
  182.     {
  183.         if(ch == \\\\\\\'\\\\\\\\b\\\\\\\')
  184.         {
  185.             if(cmd_buf_index != 0)
  186.             {
  187.                 cmd_buf_index--;
  188.                 putchar(\\\\\\\'\\\\\\\\b\\\\\\\');
  189.                 putchar(\\\\\\\' \\\\\\\');
  190.                 putchar(\\\\\\\'\\\\\\\\b\\\\\\\');
  191.                 cmd_buf[cmd_buf_index]= \\\\\\\'\\\\\\\\0\\\\\\\';
  192.             }
  193.         }
  194.         else
  195.         {
  196.             /*如果接收到打印字符且当前接收缓冲区满则认为接收完一帧\\\\\\\"*/
  197.             putchar(ch);
  198.             cmd_buf[cmd_buf_index++] = ch;
  199.             if(cmd_buf_index>=(sizeof(cmd_buf)-1))
  200.             {
  201.                 count = cmd_buf_index;
  202.                 cmd_buf[cmd_buf_index]=0;
  203.                 cmd_buf_index =0;
  204.                 printf(\\\\\\\"\\\\\\\\r\\\\\\\\n\\\\\\\");
  205.                 return count;
  206.             }
  207.         }
  208.     }
  209.     return 0;
  210. }

  211. /**
  212. *****************************************************************************
  213. * \\\\\\\\fn          int shell_exec_cmdlist(unsigned char* cmd)
  214. * \\\\\\\\brief       搜索命令列表并执行.
  215. * retval       0 成功
  216. * retval       -1 失败
  217. * \\\\\\\\note        .
  218. *****************************************************************************
  219. */
  220. int shell_exec_cmdlist(unsigned char* cmd)
  221. {
  222.     int i;
  223.     /*平台相关命令*/
  224.     for (i=0; shell_cmd_list[i].name != 0; i++)
  225.     {
  226.         if (shell_cmd_check(cmd, shell_cmd_list[i].name) == 0)
  227.         {
  228.             shell_cmd_list[i].func(cmd);
  229.             return 0;
  230.         }            
  231.     }
  232. //    /*应用相关命令*/
  233. //    for (i=0; shell_cmd_list_app[i].name != 0; i++)
  234. //    {
  235. //        if (shell_cmd_check(cmd, shell_cmd_list_app[i].name) == 0)
  236. //        {
  237. //            shell_cmd_list_app[i].func(cmd);
  238. //            return 0;
  239. //        }            
  240. //    }  
  241.     if(shell_cmd_list[i].name == NULL)
  242.     {
  243.         printf(\\\\\\\"unkown command\\\\\\\\r\\\\\\\\n\\\\\\\");
  244.         return -1;
  245.     }
  246.     return 0;
  247. }

  248. /*****************************************************************************   
  249. *                                                                           
  250. *                             对外接口函数实现                                   
  251. *                                                                           
  252. ****************************************************************************/
  253. /**
  254. *****************************************************************************
  255. * \\\\\\\\fn          void shell_exec_shellcmd(void)
  256. * \\\\\\\\brief       执行shell命令.
  257. * \\\\\\\\note        任务周期调用该函数.
  258. *****************************************************************************
  259. */
  260. void shell_exec_shellcmd(void)
  261. {
  262.     if (!shellpassed)
  263.     {
  264.         shell_check_passwd();
  265.         shellpassed = 1;
  266.     }
  267.     if(shell_read_line(shell_getchar))
  268.     {
  269.         shell_exec_cmdlist(cmd_buf);
  270.     }
  271. }
shell.h
  1. /**
  2. *****************************************************************************        
  3. * \\\\\\\\brief       平台相关(PLATFORM)SHELL模块(SHELL)相关数据结构和接口描述.
  4. * \\\\\\\\details     
  5. *              All rights reserved.   
  6. * \\\\\\\\file        shell.h  
  7. * \\\\\\\\author      
  8. * \\\\\\\\version     1.0
  9. * \\\\\\\\date      
  10. * \\\\\\\\note        使用前请参考注释.\\\\\\\\n
  11. * \\\\\\\\since       新建
  12. * \\\\\\\\par 修订记录
  13. * - 初始版本
  14. * \\\\\\\\par 资源说明
  15. * - RAM:              
  16. * - ROM:
  17. *****************************************************************************
  18. */

  19. #ifndef _SHELL_H_
  20. #define _SHELL_H_

  21. #ifdef __cplusplus
  22. extern \\\\\\\"C\\\\\\\" {
  23. #endif
  24.      
  25. /** \\\\\\\\addtogroup PLATFORM PLATFORM
  26. *  \\\\\\\\{
  27. */
  28.          
  29. /** \\\\\\\\addtogroup PLATFORM_SHELL PLATFORM_SHELL
  30. *  \\\\\\\\{
  31. */
  32. /*****************************************************************************   
  33. *                                                                           *
  34. *                             数据结构描述                                  *
  35. *                                                                          *
  36. ****************************************************************************/
  37.      
  38. /** \\\\\\\\defgroup PLATFORM_SHELL_data PLATFORM_SHELL_data
  39.   * \\\\\\\\{
  40.   */

  41. typedef void ( * CommandFunc )( void *);   /**< shell命令回调函数 */

  42. /**
  43. * \\\\\\\\struct shell_cmd_cfg
  44. * SHELL命令结构体.
  45. */
  46. typedef struct
  47. {
  48.     unsigned char const* name;           /**< shell命令名 */
  49.     CommandFunc func;           /**< shell命令回调函数 */
  50.     char const* helpstr;       /**< 帮助字符串 */
  51. }shell_cmd_cfg;

  52. #define SHELL_PASSWORD_STR \\\\\\\"DSWYBS\\\\\\\"  /**< shell密码固定6个字符  */
  53. #define SHELL_CMDBUF_SIZE  64         /**< shell命令缓冲区大小  */


  54. /**
  55.   * \\\\\\\\}
  56.   */
  57.      
  58. /*****************************************************************************   
  59. *                                                                           
  60. *                             接口函数描述                                   
  61. *                                                                           
  62. ****************************************************************************/

  63. /** \\\\\\\\defgroup PLATFORM_SHELL_if PLATFORM_SHELL_if
  64.   * \\\\\\\\{
  65.   */
  66.    
  67. /**
  68. *****************************************************************************
  69. * \\\\\\\\fn          void shell_exec_shellcmd(void)
  70. * \\\\\\\\brief       执行shell命令.
  71. * \\\\\\\\note        任务周期调用该函数.
  72. *****************************************************************************
  73. */
  74. void shell_exec_shellcmd(void);
  75. /**
  76. *****************************************************************************
  77. * \\\\\\\\fn          int shell_exec_cmdlist(unsigned char* cmd)
  78. * \\\\\\\\brief       搜索命令列表并执行.
  79. * retval       0 成功
  80. * retval       -11 失败
  81. * \\\\\\\\note        .
  82. *****************************************************************************
  83. */
  84. int shell_exec_cmdlist(unsigned char* cmd);
  85. /**
  86.   * \\\\\\\\}
  87.   */

  88. /**
  89.   * \\\\\\\\}
  90.   */

  91. /**
  92.   * \\\\\\\\}
  93.   */

  94. #ifdef __cplusplus
  95. }
  96. #endif

  97. #endif
shell_fun.c
  1.   /**
  2. *****************************************************************************        
  3. * \\\\\\\\brief       平台层(PLATFORM)SHELL命令模块(SHELL_FUN)相关接口实现.
  4. * \\\\\\\\details     
  5. *              All rights reserved.   
  6. * \\\\\\\\file        shell_fun.c
  7. * \\\\\\\\author     
  8. * \\\\\\\\version     1.0
  9. * \\\\\\\\date      
  10. * \\\\\\\\note        平台相关命令.\\\\\\\\n
  11. * \\\\\\\\since       新建
  12. * \\\\\\\\par 修订记录
  13. * - 初始版本
  14. * \\\\\\\\par 资源说明
  15. * - RAM:              
  16. * - ROM:
  17. *****************************************************************************
  18. */

  19. #include
  20. #include
  21. #include
  22. #include
  23. #include \\\\\\\"shell_fun.h\\\\\\\"
  24. #include \\\\\\\"shell.h\\\\\\\"


  25. /*****************************************************************************   
  26. *                                                                           
  27. *                             内部数据                                   
  28. *                                                                           
  29. ****************************************************************************/

  30. const shell_cmd_cfg shell_cmd_list[ ] =
  31. {
  32.   /*1.帮助相关*/
  33.   { \\\\\\\"help\\\\\\\",         HelpFun,           \\\\\\\"help\\\\\\\"},    /*打印帮助信息*/
  34.   { 0,                0 },
  35. };

  36. /*****************************************************************************   
  37. *                                                                           
  38. *                             内部接口函数实现                                   
  39. *                                                                           
  40. ****************************************************************************/

  41. /*****************************************************************************   
  42. *                                                                           
  43. *                             对外接口函数实现                                   
  44. *                                                                           
  45. ****************************************************************************/

  46. /*****************************************************************************   
  47. *                                                                           
  48. *                             帮助相关                                 
  49. *                                                                           
  50. ****************************************************************************/

  51. void HelpFun(void* param)
  52. {
  53.     unsigned int i;
  54.     printf(\\\\\\\"\\\\\\\\r\\\\\\\\n\\\\\\\");
  55.     printf(\\\\\\\"**************\\\\\\\\r\\\\\\\\n\\\\\\\");
  56.     printf(\\\\\\\"*   SHELL    *\\\\\\\\r\\\\\\\\n\\\\\\\");
  57.     printf(\\\\\\\"*   V1.0     *\\\\\\\\r\\\\\\\\n\\\\\\\");
  58.     printf(\\\\\\\"**************\\\\\\\\r\\\\\\\\n\\\\\\\");
  59.     printf(\\\\\\\"\\\\\\\\r\\\\\\\\n\\\\\\\");
  60.     for (i=0; shell_cmd_list[i].name != 0; i++)
  61.     {
  62.         printf(\\\\\\\"%02d.\\\\\\\",i);
  63.         printf(\\\\\\\"%-16s\\\\\\\",shell_cmd_list[i].name);
  64.         printf(\\\\\\\"%s\\\\\\\\r\\\\\\\\n\\\\\\\",shell_cmd_list[i].helpstr);
  65.     }
  66. }


  67. #if 0
  68. void SetTimeFun(void * cmdbuf)
  69. {
  70.         unsigned int year, month, day, week, hour, minute, second;
  71.         unsigned int len = sscanf((char const *)cmdbuf, \\\\\\\"%*s %d %d %d %d %d %d %d\\\\\\\", &year, &month, &day, &week, &hour, &minute, &second);
  72.         if (len == 7)
  73.         {
  74.                 struct tm tm_time;
  75.                 tm_time.tm_year = year -1900;
  76.                 tm_time.tm_mon = month - 1;
  77.                 tm_time.tm_mday = day;
  78.                 tm_time.tm_wday = week;
  79.                 tm_time.tm_hour = hour;
  80.                 tm_time.tm_min = minute;
  81.                 tm_time.tm_sec = second;
  82.                 tm_time.tm_isdst = -1;
  83.         driver_time_settm(&tm_time);
  84.         }
  85.         else
  86.         {
  87.                 printf(\\\\\\\"usage: \\\\\\\\r\\\\\\\\n\\\\\\\\tsettime \\\\\\\\r\\\\\\\\n\\\\\\\");
  88.         }
  89. }

  90. #endif
shell_fun.h
  1. /**
  2. *****************************************************************************        
  3. * \\\\\\\\brief       平台层(PLATFORM)SHELL命令模块(SHELL_FUN)相关数据结构和接口描述.
  4. * \\\\\\\\details     
  5. *              All rights reserved.   
  6. * \\\\\\\\file        shell_fun.h
  7. * \\\\\\\\author      
  8. * \\\\\\\\version     1.0
  9. * \\\\\\\\date        
  10. * \\\\\\\\note        平台相关命令.\\\\\\\\n
  11. * \\\\\\\\since        新建
  12. * \\\\\\\\par 修订记录
  13. * -
  14. * \\\\\\\\par 资源说明
  15. * - RAM:              
  16. * - ROM:
  17. *****************************************************************************
  18. */

  19. #ifndef __SHELL_FUN_H
  20. #define __SHELL_FUN_H

  21. #ifdef __cplusplus
  22. extern \\\\\\\"C\\\\\\\" {
  23. #endif

  24. /*****************************************************************************   
  25. *                                                                           
  26. *                             帮助相关                                 
  27. *                                                                           
  28. ****************************************************************************/   
  29. void HelpFun(void* param);

  30. /*****************************************************************************   
  31. *                                                                           
  32. *                                                              
  33. *                                                                           
  34. ****************************************************************************/

  35. #ifdef __cplusplus
  36. }
  37. #endif

  38. #endif


更多回帖

发帖
×
20
完善资料,
赚取积分