99#include "chip_info.h"
1010#include "led.h"
1111#include "log.h"
12+ #include "version.h"
1213#include <stdio.h>
1314#include <string.h>
1415#include <stddef.h>
@@ -31,7 +32,8 @@ typedef enum
3132 NP_CMD_NAND_WRITE_E = 0x05 ,
3233 NP_CMD_NAND_CONF = 0x06 ,
3334 NP_CMD_NAND_READ_BB = 0x07 ,
34- NP_CMD_NAND_LAST = 0x08 ,
35+ NP_CMD_VERSION_GET = 0x08 ,
36+ NP_CMD_NAND_LAST = 0x09 ,
3537} np_cmd_code_t ;
3638
3739enum
@@ -160,6 +162,19 @@ typedef struct __attribute__((__packed__))
160162 uint8_t err_code ;
161163} np_resp_err_t ;
162164
165+ typedef struct __attribute__((__packed__ ))
166+ {
167+ uint8_t major ;
168+ uint8_t minor ;
169+ uint16_t build ;
170+ } version_t ;
171+
172+ typedef struct __attribute__((__packed__ ))
173+ {
174+ np_resp_t header ;
175+ version_t version ;
176+ } np_resp_version_t ;
177+
163178typedef struct
164179{
165180 uint32_t addr ;
@@ -908,6 +923,25 @@ int np_cmd_read_bad_blocks(np_prog_t *prog)
908923 return np_send_ok_status ();
909924}
910925
926+ int np_cmd_version_get (np_prog_t * prog )
927+ {
928+ np_resp_version_t resp ;
929+ size_t resp_len = sizeof (resp );
930+
931+ DEBUG_PRINT ("Read version command\r\n" );
932+
933+ resp .header .code = NP_RESP_DATA ;
934+ resp .header .info = resp_len - sizeof (resp .header );
935+ resp .version .major = SW_VERSION_MAJOR ;
936+ resp .version .minor = SW_VERSION_MINOR ;
937+ resp .version .build = SW_VERSION_BUILD ;
938+
939+ if (np_comm_cb )
940+ np_comm_cb -> send ((uint8_t * )& resp , resp_len );
941+
942+ return 0 ;
943+ }
944+
911945static np_cmd_handler_t cmd_handler [] =
912946{
913947 { NP_CMD_NAND_READ_ID , np_cmd_nand_read_id },
@@ -918,6 +952,7 @@ static np_cmd_handler_t cmd_handler[] =
918952 { NP_CMD_NAND_WRITE_E , np_cmd_nand_write },
919953 { NP_CMD_NAND_CONF , np_cmd_nand_conf },
920954 { NP_CMD_NAND_READ_BB , np_cmd_read_bad_blocks },
955+ { NP_CMD_VERSION_GET , np_cmd_version_get },
921956};
922957
923958static bool np_cmd_is_valid (np_cmd_code_t code )
@@ -929,7 +964,8 @@ static int np_cmd_handler(np_prog_t *prog)
929964{
930965 np_cmd_t * cmd = (np_cmd_t * )prog -> rx_buf ;
931966
932- if (!prog -> chip_is_conf && cmd -> code != NP_CMD_NAND_CONF )
967+ if (!prog -> chip_is_conf && cmd -> code != NP_CMD_NAND_CONF &&
968+ cmd -> code != NP_CMD_VERSION_GET )
933969 {
934970 ERROR_PRINT ("Chip is not configured\r\n" );
935971 return NP_ERR_CHIP_NOT_CONF ;
0 commit comments