Changeset 432
- Timestamp:
- Jul 5, 2020, 6:30:00 PM (3 years ago)
- Location:
- EcnlProtoTool/trunk/ntshell/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
EcnlProtoTool/trunk/ntshell/src/main.c
r431 r432 79 79 char command[NTOPT_TEXT_MAXLEN]; 80 80 ntstdio_t ntstdio; 81 ntshell_t ntshell;82 81 83 82 unsigned char ntstdio_xi(struct ntstdio_t *handle) … … 118 117 119 118 struct main_obj_t { 119 ntshell_t ntshell; 120 120 TMO timer; 121 121 enum main_state_t state; … … 127 127 struct main_obj_t main_obj; 128 128 129 static void netif_link_callback(T_IFNET *ether);130 static void main_initialize( );131 static TMO main_get_timer( );132 static void main_progress( TMO interval);133 static void main_timeout( );129 static void main_change_netif_link(T_IFNET *ether); 130 static void main_initialize(struct main_obj_t *obj); 131 static TMO main_get_timer(struct main_obj_t *obj); 132 static void main_progress(struct main_obj_t *obj, TMO elapse); 133 static void main_timeout(struct main_obj_t *obj); 134 134 extern int execute_command(int wait); 135 135 static int usrcmd_ntopt_callback(long *args, void *extobj); … … 143 143 { 144 144 return serial_rea_dat(SIO_PORTID, (char *)buf, cnt); 145 #if 0146 int result = cnt;147 ER ret;148 bool_t tmo = false;149 150 while (cnt > 0) {151 /* タイムアウト処理 */152 if (tmo) {153 tmo = false;154 main_timeout();155 }156 157 if (main_obj.rcvmsg.ptr == NULL) {158 ER ret2;159 TMO timer;160 WS_FBS_ID msg;161 162 main_obj.prev = main_obj.now;163 164 timer = main_get_timer();165 166 ret = trcv_dtq(MAIN_DATAQUEUE, (intptr_t *)&msg, timer);167 if ((ret != E_OK) && (ret != E_TMOUT)) {168 syslog(LOG_ERROR, "trcv_dtq => %d", ret);169 ext_tsk();170 return 0;171 }172 173 ret2 = get_tim(&main_obj.now);174 if (ret2 != E_OK) {175 syslog(LOG_ERROR, "get_tim");176 ext_tsk();177 return 0;178 }179 180 /* 時間経過 */181 main_progress(main_obj.now - main_obj.prev);182 183 if (ret == E_OK) {184 /* メッセージ受信処理 */185 if (main_obj.rcvmsg.ptr == NULL) {186 main_obj.rcvmsg = msg;187 }188 else {189 ws_fbs_enqueue(&main_obj.wbs_queue, msg.ptr);190 }191 }192 193 tmo = true;194 }195 else {196 WS_FBS_SSIZE_T len, slen;197 198 len = _ws_fbs_get_datalen(main_obj.rcvmsg);199 if (len > cnt)200 len = cnt;201 202 ret = _ws_fbs_get_data(main_obj.rcvmsg, buf, len, &slen);203 if (ret != E_OK) {204 syslog(LOG_ERROR, "_ws_fbs_get_data msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);205 ext_tsk();206 }207 cnt -= slen;208 209 /* データが空の場合 */210 if (!_ws_fbs_exist_data(main_obj.rcvmsg)) {211 ret = _ws_fbs_del(main_obj.rcvmsg);212 if (ret != E_OK) {213 syslog(LOG_ERROR, "trcv_dtq msg = %p, type = %d, result = %d", main_obj.rcvmsg.ptr, main_obj.rcvmsg.ptr->hdr.type, ret);214 ext_tsk();215 }216 217 main_obj.rcvmsg.ptr = NULL;218 219 /* キューからデータを取得 */220 ret = ws_fbs_dequeue(&main_obj.wbs_queue, &main_obj.rcvmsg.ptr);221 }222 }223 }224 225 return result;226 #endif227 145 } 228 146 … … 230 148 { 231 149 return serial_wri_dat(SIO_PORTID, buf, cnt); 232 #if 0 233 int result = cnt; 234 ER ret; 235 236 while (cnt > 0) { 237 _ws_fbs_cre(cnt, &main_obj.sndmsg); 238 239 //((ID *)main_obj.sndmsg.ptr->_gap)[0] = wbsid; 240 _ws_fbs_add_data(main_obj.sndmsg, buf, cnt); 241 242 ret = psnd_dtq(WEBSOCKET_MBXID, (intptr_t)main_obj.sndmsg.ptr); 243 if (ret != E_OK) { 244 syslog(LOG_ERROR, "psnd_dtq(WEBSOCKET_MBXID) : result=%d", ret); 245 _ws_fbs_del(main_obj.sndmsg); 246 return ret; 247 } 248 } 249 250 return result; 251 #endif 252 } 253 254 static int cmd_execute(const char *text, void *extobj) 150 } 151 152 int cmd_execute(const char *text, void *extobj) 255 153 { 256 154 if (text != NULL) { … … 273 171 void main_task(intptr_t exinf) 274 172 { 275 main_initialize(); 276 277 ntshell_init(&ntshell, uart_read, uart_write, cmd_execute, NULL); 278 ntshell_set_prompt(&ntshell, "NTShell>"); 279 ntshell_execute(&ntshell); 173 struct main_obj_t *obj = (struct main_obj_t *)&main_obj; 174 175 main_initialize(obj); 176 177 ntshell_init(&obj->ntshell, uart_read, uart_write, cmd_execute, obj); 178 ntshell_set_prompt(&obj->ntshell, "NTShell>"); 179 ntshell_execute(&obj->ntshell); 280 180 } 281 181 … … 283 183 * 初期化 284 184 */ 285 static void main_initialize( )185 static void main_initialize(struct main_obj_t *obj) 286 186 { 287 187 FILINFO fno; … … 291 191 fno.lfsize = _MAX_LFN + 1; 292 192 #endif 293 ER ret 2;193 ER ret; 294 194 295 195 ntstdio_init(&ntstdio, NTSTDIO_OPTION_LINE_ECHO | NTSTDIO_OPTION_CANON | NTSTDIO_OPTION_LF_CRLF | NTSTDIO_OPTION_LF_CR, ntstdio_xi, ntstdio_xo); 296 196 297 main_obj.timer = TMO_FEVR;298 main_obj.state = main_state_start;197 obj->timer = TMO_FEVR; 198 obj->state = main_state_start; 299 199 300 200 gpio_t led_blue, led_green, led_red, sw; … … 310 210 gpio_write(&led_red, 0); 311 211 312 ether_set_link_callback( netif_link_callback);212 ether_set_link_callback(main_change_netif_link); 313 213 314 214 /* 初期化 */ … … 336 236 } 337 237 338 ret 2 = get_tim(&main_obj.now);339 if (ret 2!= E_OK) {238 ret = get_tim(&obj->now); 239 if (ret != E_OK) { 340 240 syslog(LOG_ERROR, "get_tim"); 341 241 ext_tsk(); … … 347 247 * タイマー取得 348 248 */ 349 static TMO main_get_timer( )350 { 351 TMO timer = main_obj.timer;249 static TMO main_get_timer(struct main_obj_t *obj) 250 { 251 TMO timer = obj->timer; 352 252 353 253 return timer; … … 357 257 * 時間経過 358 258 */ 359 static void main_progress( TMO interval)360 { 361 if ( main_obj.timer != TMO_FEVR) {362 main_obj.timer -= interval;363 if ( main_obj.timer < 0) {364 main_obj.timer = 0;259 static void main_progress(struct main_obj_t *obj, TMO elapse) 260 { 261 if (obj->timer != TMO_FEVR) { 262 obj->timer -= elapse; 263 if (obj->timer < 0) { 264 obj->timer = 0; 365 265 } 366 266 } … … 370 270 * タイムアウト処理 371 271 */ 372 static void main_timeout( )373 { 374 //if ( main_obj.timer == 0) {272 static void main_timeout(struct main_obj_t *obj) 273 { 274 //if (obj->timer == 0) { 375 275 //} 376 276 } … … 382 282 } 383 283 384 static void netif_link_callback(T_IFNET *ether)284 static void main_change_netif_link(T_IFNET *ether) 385 285 { 386 286 FLGPTN flgptn; … … 406 306 shellcmd_state = 2; 407 307 } 408 409 typedef struct410 {411 const cmd_table_t *table;412 int count;413 } cmd_table_info_t;414 308 415 309 static const cmd_table_t cmdlist[] = { … … 429 323 { 430 324 const cmd_table_t *p = cmd_table_info.table; 325 int result = 0; 326 int found = 0; 327 328 if (*args == 0) 329 return result; 330 431 331 if (ntlibc_strcmp((const char *)args[1], "help") == 0) { 432 332 usrcmd_help(args[0], (char **)&args[1]); -
EcnlProtoTool/trunk/ntshell/src/main.h
r431 r432 52 52 */ 53 53 54 #define MAIN_PRIORITY 5 /* メインタスクの優先度 */54 #define MAIN_PRIORITY 5 /* メインタスクの優先度 */ 55 55 #define SHELLCMD_PRIORITY 4 /* shellcmdタスクの優先度 */ 56 56 … … 58 58 #define SHELLCMD_STACK_SIZE 0x00800000 /* shellcmdタスクのスタック領域のサイズ */ 59 59 60 #define NUM_MAIN_DATAQUEUE 1 /* メインタスクで待ち受けているデータキューのサイズ */60 #define NUM_MAIN_DATAQUEUE 1 /* メインタスクで待ち受けているデータキューのサイズ */ 61 61 #define NUM_SHELLCMD_DATAQUEUE 1 /* shellcmdタスクで待ち受けているデータキューのサイズ */ 62 62 … … 66 66 #ifndef TOPPERS_MACRO_ONLY 67 67 68 typedef struct 69 { 70 const cmd_table_t *table; 71 int count; 72 } cmd_table_info_t; 73 68 74 /* メインタスク */ 69 externvoid main_task(intptr_t exinf);75 void main_task(intptr_t exinf); 70 76 71 77 /* shellcmdタスク */ 72 extern void shellcmd_task(intptr_t exinf); 78 void shellcmd_task(intptr_t exinf); 79 80 /* コマンド実行 */ 81 int cmd_execute(const char *text, void *extobj); 73 82 74 83 /*
Note:
See TracChangeset
for help on using the changeset viewer.