]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/cmd_boot.c
2 * (C) Copyright 2014-2016 Leo C. <erbl259-lmu@yahoo.de>
4 * (C) Copyright 2000-2003
5 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
7 * SPDX-License-Identifier: GPL-2.0
16 #include <util/atomic.h>
19 #include "cli_readline.h" /* console_buffer[] */
20 #include "cli.h" /* run_command() */
22 #include "con-utils.h"
24 #include "z180-serv.h" /* restart_z180_serv() */
27 /* ugly hack to get Z180 loadfile into flash memory */
28 #define const const FLASH
29 #include "../z180/hdrom.h"
34 static void z80_load_mem(void)
37 uint32_t sec_base
= hdrom_start
;
39 printf_P(PSTR("Loading Z180 memory... \n"));
41 while (sec
< hdrom_sections
) {
42 printf_P(PSTR(" From: 0x%.5lX to: 0x%.5lX (%5li bytes)\n"),
44 hdrom_address
[sec
]+hdrom_length_of_sections
[sec
] - 1,
45 hdrom_length_of_sections
[sec
]);
47 z80_write_block_P((const FLASH
unsigned char *) &hdrom
[sec_base
], /* src */
48 hdrom_address
[sec
], /* dest */
49 hdrom_length_of_sections
[sec
]); /* len */
50 sec_base
+=hdrom_length_of_sections
[sec
];
55 command_ret_t
do_loadf(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
57 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
59 if (z80_bus_state() & ZST_RUNNING
) {
60 my_puts_P(PSTR("Can't load while CPU is running!\n"));
61 return CMD_RET_FAILURE
;
63 if (!(z80_bus_cmd(Request
) & ZST_ACQUIRED
)) {
64 my_puts_P(PSTR("Bus timeout\n"));
65 return CMD_RET_FAILURE
;
70 return CMD_RET_SUCCESS
;
74 command_ret_t
do_busreq_pulse(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
78 (void) cmdtp
; (void) flag
;
80 if (!(z80_bus_state() & ZST_RUNNING
)) {
81 printf_P(PSTR("## CPU is not running!\n"));
82 return CMD_RET_FAILURE
;
86 count
= (uint16_t) strtoul(argv
[1], NULL
, 16);
92 return CMD_RET_SUCCESS
;
96 command_ret_t
do_go(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
100 (void) cmdtp
; (void) flag
;
103 return CMD_RET_USAGE
;
104 addr
= strtoul(argv
[1], NULL
, 16);
105 if (addr
>= (1UL<<16)) {
106 printf_P(PSTR("## Startaddress 0x%05lx too high.\n"
107 " (Out of logical address space (0x00000-0x0ffff))\n"),
109 return CMD_RET_FAILURE
;
112 if (z80_bus_state() & ZST_RUNNING
) {
113 printf_P(PSTR("## CPU allready running!\n"));
114 return CMD_RET_FAILURE
;
117 printf_P(PSTR("## Starting application at 0x%04lx ...\n"), addr
);
122 z80_bus_cmd(Request
);
123 z80_read_block (tmp
, 0, 3);
126 z80_write(2, (addr
>> 8));
129 z80_bus_cmd(M_Cycle
);
130 z80_bus_cmd(M_Cycle
);
131 z80_write_block(tmp
, 0, 3);
135 z80_bus_cmd(Release
);
137 return CMD_RET_SUCCESS
;
141 void reset_cpu(bus_cmd_t mode
)
148 command_ret_t
do_reset(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
150 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
152 printf_P(PSTR("CPU now in reset state.\n"));
155 return CMD_RET_SUCCESS
;
158 command_ret_t
do_restart(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
160 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
164 return CMD_RET_SUCCESS
;
168 void print_con_usage(char esc
)
170 "------------------------------------------------\n"
172 " Q,X - Return to command line\n"
173 " R - Reset (Restart) CPU\n"
174 " : - Execute monitor command\n"
175 " \\ - code input:\n"
176 " \\nnn 3 decimal digits character code\n"
177 " \\Xhh 2 hexadecimal digits character code\n"
178 " ^%c - (Escape char) Type again to send itself\n"
183 command_ret_t
do_console(cmd_tbl_t
*cmdtp
, int flag
, int argc
, char * const argv
[])
187 // uint8_t help_prompt = 0;
190 char esc_char
= (char) getenv_ulong(PSTR(ENV_ESC_CHAR
), 16, CONFIG_ESC_CHAR
);
192 (void) cmdtp
; (void) flag
; (void) argc
; (void) argv
;
194 printf_P(PSTR("Connecting to CPU. Escape character is '^%c'.\n"),
199 ATOMIC_BLOCK(ATOMIC_FORCEON
) {
200 pending
= (Stat
& S_CON_PENDING
) != 0;
201 Stat
&= ~S_CON_PENDING
;
205 while ((ch
= z80_memfifo_getc(fifo_conout
)) >= 0 && --count
)
209 if ((ch
= my_getchar(0)) >= 0) {
212 if (ch
== esc_char
) {
214 /* TODO: Timer starten */
216 z80_memfifo_putc(fifo_conin
, ch
);
221 "------------------------------------------------\n"));
224 switch (toupper(ch
)) {
228 print_con_usage(esc_char
);
238 printf_P(PSTR("\n"));
244 int cmdlen
= cli_readline(PSTR(": "), 1);
246 run_command(console_buffer
, 0);
256 z80_memfifo_putc(fifo_conin
, ch
);
261 if (toupper(ch
) == 'X') {
269 code
= code
* 10 + ch
- '0';
273 z80_memfifo_putc(fifo_conin
, code
);
274 z80_memfifo_putc(fifo_conin
, ch
);
278 z80_memfifo_putc(fifo_conin
, code
);
288 code
= code
* 16 + ch
- '0';
292 z80_memfifo_putc(fifo_conin
, code
);
293 z80_memfifo_putc(fifo_conin
, ch
);
297 z80_memfifo_putc(fifo_conin
, code
);
305 return CMD_RET_SUCCESS
;