1 /*
2 * Copyright (C) 2022 Beken Corporation
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16
17 #include <os/os.h>
18 #include "cli.h"
19 #include <driver/efuse.h>
20
cli_efuse_help(void)21 static void cli_efuse_help(void)
22 {
23 CLI_LOGI("efuse_driver init\r\n");
24 CLI_LOGI("efuse_driver deinit\r\n");
25 CLI_LOGI("efuse_test write [addr] [data]\r\n");
26 CLI_LOGI("efuse_test read [addr]\r\n");
27 }
28
cli_efuse_driver_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)29 static void cli_efuse_driver_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
30 {
31 if (argc < 2) {
32 cli_efuse_help();
33 return;
34 }
35
36 if (os_strcmp(argv[1], "init") == 0) {
37 BK_LOG_ON_ERR(bk_efuse_driver_init());
38 CLI_LOGI("efuse driver init\n");
39 } else if (os_strcmp(argv[1], "deinit") == 0) {
40 BK_LOG_ON_ERR(bk_efuse_driver_deinit());
41 CLI_LOGI("efuse driver deinit\n");
42 } else {
43 cli_efuse_help();
44 return;
45 }
46 }
47
cli_efuse_cmd(char * pcWriteBuffer,int xWriteBufferLen,int argc,char ** argv)48 static void cli_efuse_cmd(char *pcWriteBuffer, int xWriteBufferLen, int argc, char **argv)
49 {
50 if (argc < 2) {
51 cli_efuse_help();
52 return;
53 }
54
55 uint8_t addr, data;
56
57 if (os_strcmp(argv[1], "write") == 0) {
58 addr = os_strtoul(argv[2], NULL, 16);
59 data = os_strtoul(argv[3], NULL, 16);
60 BK_LOG_ON_ERR(bk_efuse_write_byte(addr, data));
61 CLI_LOGI("efuse write addr:0x%02x, data:0x%02x\r\n", addr, data);
62 } else if (os_strcmp(argv[1], "read") == 0) {
63 addr = os_strtoul(argv[2], NULL, 16);
64 data = 0;
65 BK_LOG_ON_ERR(bk_efuse_read_byte(addr, &data));
66 CLI_LOGI("efuse read addr:0x%02x, data:0x%02x\r\n", addr, data);
67 } else {
68 cli_efuse_help();
69 return;
70 }
71 }
72
73 #define EFUSE_CMD_CNT (sizeof(s_efuse_commands) / sizeof(struct cli_command))
74 static const struct cli_command s_efuse_commands[] = {
75 {"efuse_driver", "efuse_driver {init|deinit}", cli_efuse_driver_cmd},
76 {"efuse_test", "efuse_test {write|read}", cli_efuse_cmd}
77 };
78
cli_efuse_init(void)79 int cli_efuse_init(void)
80 {
81 BK_LOG_ON_ERR(bk_efuse_driver_init());
82 return cli_register_commands(s_efuse_commands, EFUSE_CMD_CNT);
83 }
84