1414#include "flash.h"
1515#include <soc.h>
1616
17- extern const struct shell * ctx_shell ;
18-
19- #define print (_sh , _ft , ...) \
20- shell_fprintf(_sh ? _sh : ctx_shell, SHELL_NORMAL, _ft "\r\n", \
21- ##__VA_ARGS__)
22- #define error (_sh , _ft , ...) \
23- shell_fprintf(_sh ? _sh : ctx_shell, SHELL_ERROR, _ft "\r\n", \
24- ##__VA_ARGS__)
25-
2617#define FLASH_SHELL_MODULE "flash"
2718#define BUF_ARRAY_CNT 16
2819#define TEST_ARR_SIZE 0x1000
@@ -38,12 +29,12 @@ static int cmd_erase(const struct shell *shell, size_t argc, char *argv[])
3829
3930 flash_dev = device_get_binding (DT_FLASH_DEV_NAME );
4031 if (!flash_dev ) {
41- error (shell , "Flash driver was not found!" );
32+ shell_error (shell , "Flash driver was not found!" );
4233 return - ENODEV ;
4334 }
4435
4536 if (argc < 2 ) {
46- error (shell , "Missing page address." );
37+ shell_error (shell , "Missing page address." );
4738 return - EINVAL ;
4839 }
4940
@@ -58,7 +49,7 @@ static int cmd_erase(const struct shell *shell, size_t argc, char *argv[])
5849 & info );
5950
6051 if (result != 0 ) {
61- error (shell , "Could not determine page size, "
52+ shell_error (shell , "Could not determine page size, "
6253 "code %d." , result );
6354 return - EINVAL ;
6455 }
@@ -71,9 +62,9 @@ static int cmd_erase(const struct shell *shell, size_t argc, char *argv[])
7162 result = flash_erase (flash_dev , page_addr , size );
7263
7364 if (result ) {
74- error (shell , "Erase Failed, code %d." , result );
65+ shell_error (shell , "Erase Failed, code %d." , result );
7566 } else {
76- print (shell , "Erase success." );
67+ shell_print (shell , "Erase success." );
7768 }
7869
7970 return result ;
@@ -89,17 +80,17 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
8980
9081 flash_dev = device_get_binding (DT_FLASH_DEV_NAME );
9182 if (!flash_dev ) {
92- error (shell , "Flash driver was not found!" );
83+ shell_error (shell , "Flash driver was not found!" );
9384 return - ENODEV ;
9485 }
9586
9687 if (argc < 2 ) {
97- error (shell , "Missing address." );
88+ shell_error (shell , "Missing address." );
9889 return - EINVAL ;
9990 }
10091
10192 if (argc <= 2 ) {
102- error (shell , "Type data to be written." );
93+ shell_error (shell , "Type data to be written." );
10394 return - EINVAL ;
10495 }
10596
@@ -115,18 +106,18 @@ static int cmd_write(const struct shell *shell, size_t argc, char *argv[])
115106
116107 if (flash_write (flash_dev , w_addr , buf_array ,
117108 sizeof (buf_array [0 ]) * j ) != 0 ) {
118- error (shell , "Write internal ERROR!" );
109+ shell_error (shell , "Write internal ERROR!" );
119110 return - EIO ;
120111 }
121112
122- print (shell , "Write OK." );
113+ shell_print (shell , "Write OK." );
123114
124115 flash_read (flash_dev , w_addr , check_array , sizeof (buf_array [0 ]) * j );
125116
126117 if (memcmp (buf_array , check_array , sizeof (buf_array [0 ]) * j ) == 0 ) {
127- print (shell , "Verified." );
118+ shell_print (shell , "Verified." );
128119 } else {
129- error (shell , "Verification ERROR!" );
120+ shell_error (shell , "Verification ERROR!" );
130121 return - EIO ;
131122 }
132123
@@ -141,12 +132,12 @@ static int cmd_read(const struct shell *shell, size_t argc, char *argv[])
141132
142133 flash_dev = device_get_binding (DT_FLASH_DEV_NAME );
143134 if (!flash_dev ) {
144- error (shell , "Flash driver was not found!" );
135+ shell_error (shell , "Flash driver was not found!" );
145136 return - ENODEV ;
146137 }
147138
148139 if (argc < 2 ) {
149- error (shell , "Missing address." );
140+ shell_error (shell , "Missing address." );
150141 return - EINVAL ;
151142 }
152143
@@ -162,11 +153,11 @@ static int cmd_read(const struct shell *shell, size_t argc, char *argv[])
162153 u32_t data ;
163154
164155 flash_read (flash_dev , addr , & data , sizeof (data ));
165- print (shell , "0x%08x " , data );
156+ shell_print (shell , "0x%08x " , data );
166157 addr += sizeof (data );
167158 }
168159
169- print (shell , "" );
160+ shell_print (shell , "" );
170161
171162 return 0 ;
172163}
@@ -181,12 +172,12 @@ static int cmd_test(const struct shell *shell, size_t argc, char *argv[])
181172
182173 flash_dev = device_get_binding (DT_FLASH_DEV_NAME );
183174 if (!flash_dev ) {
184- error (shell , "Flash driver was not found!" );
175+ shell_error (shell , "Flash driver was not found!" );
185176 return - ENODEV ;
186177 }
187178
188179 if (argc != 4 ) {
189- error (shell , "3 parameters reqired." );
180+ shell_error (shell , "3 parameters reqired." );
190181 return - EINVAL ;
191182 }
192183
@@ -195,7 +186,8 @@ static int cmd_test(const struct shell *shell, size_t argc, char *argv[])
195186 repeat = strtoul (argv [3 ], NULL , 16 );
196187
197188 if (size > TEST_ARR_SIZE ) {
198- error (shell , "<size> must be at most 0x%x." , TEST_ARR_SIZE );
189+ shell_error (shell , "<size> must be at most 0x%x." ,
190+ TEST_ARR_SIZE );
199191 return - EINVAL ;
200192 }
201193
@@ -208,21 +200,21 @@ static int cmd_test(const struct shell *shell, size_t argc, char *argv[])
208200 while (repeat -- ) {
209201 result = flash_erase (flash_dev , addr , size );
210202 if (result ) {
211- error (shell , "Erase Failed, code %d." , result );
203+ shell_error (shell , "Erase Failed, code %d." , result );
212204 return - EIO ;
213205 }
214206
215- print (shell , "Erase OK." );
207+ shell_print (shell , "Erase OK." );
216208
217209 if (flash_write (flash_dev , addr , test_arr , size ) != 0 ) {
218- error (shell , "Write internal ERROR!" );
210+ shell_error (shell , "Write internal ERROR!" );
219211 return - EIO ;
220212 }
221213
222- print (shell , "Write OK." );
214+ shell_print (shell , "Write OK." );
223215 }
224216
225- print (shell , "Erase-Write test done." );
217+ shell_print (shell , "Erase-Write test done." );
226218
227219 return 0 ;
228220}
@@ -237,7 +229,7 @@ SHELL_CREATE_STATIC_SUBCMD_SET(flash_cmds) {
237229
238230static int cmd_flash (const struct shell * shell , size_t argc , char * * argv )
239231{
240- error (shell , "%s:unknown parameter: %s" , argv [0 ], argv [1 ]);
232+ shell_error (shell , "%s:unknown parameter: %s" , argv [0 ], argv [1 ]);
241233 return - EINVAL ;
242234}
243235
0 commit comments