]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/main.c
7 #include <util/delay.h>
8 //#include <avr/power.h>
9 //#include <avr/pgmspace.h>
10 #include <avr/interrupt.h>
11 //#include <util/atomic.h>
12 //#include <avr/sleep.h>
15 #include <util/delay.h>
24 #include "con-utils.h"
30 /*--------------------------------------------------------------------------*/
32 void preset_ram (void) __attribute__ ((naked
)) \
33 __attribute__ ((section (".init3")));
37 for (uint8_t *p
= RAMSTART
; p
<= (uint8_t *) RAMEND
; p
++)
42 /*--------------------------------------------------------------------------*/
49 /* save and clear reset reason(s) */
57 /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
61 /* disable unused periphels */
62 PRR0
= _BV(PRTIM2
) | _BV(PRTIM0
) | _BV(PRADC
);
63 PRR1
= _BV(PRTIM5
) | _BV(PRTIM4
) | _BV(PRTIM3
) |
64 _BV(PRUSART3
) | _BV(PRUSART2
) | _BV(PRUSART1
);
66 /* disable analog comparator */
76 OCR1A
= F_CPU
/ 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
78 TIMSK1
= _BV(OCIE1A
); // Enable TC1.oca interrupt
81 static const FLASH
char * const FLASH rreasons
[] = {
90 void print_reset_reason(void)
92 uint8_t r
= mcusr
& 0x1f;
93 const FLASH
char * const FLASH
*p
= rreasons
;
95 printf_P(PSTR("Reset reason(s): "));
96 for ( ; r
; p
++, r
>>= 1) {
100 printf_P(PSTR(", "));
103 printf_P(PSTR(".\n"));
107 /*******************************************************************************/
109 #define udelay(n) _delay_us(n)
112 /* Stored value of bootdelay, used by autoboot_command() */
113 static int stored_bootdelay
;
116 /***************************************************************************
117 * Watch for 'delay' seconds for autoboot stop.
118 * returns: 0 - no key, allow autoboot
122 static int abortboot(int bootdelay
)
128 printf_P(PSTR("Hit any key to stop autoboot: %2d "), bootdelay
);
130 #if defined CONFIG_ZERO_BOOTDELAY_CHECK
132 * Check if key already pressed
133 * Don't check if bootdelay < 0
135 if (bootdelay
>= 0) {
136 if (tstc()) { /* we got a key press */
137 (void) my_getchar(); /* consume input */
138 my_puts_P(PSTR("\b\b\b 0"));
139 abort
= 1; /* don't auto boot */
144 while ((bootdelay
> 0) && (!abort
)) {
149 if (tstc()) { /* we got a key press */
150 abort
= 1; /* don't auto boot */
151 bootdelay
= 0; /* no more delay */
155 } while (!abort
&& get_timer(ts
) < 1000);
157 printf_P(PSTR("\b\b\b%2d "), bootdelay
);
166 const char *bootdelay_process(void)
171 s
= getenv("bootdelay");
172 bootdelay
= s
? atoi(s
) : CONFIG_BOOTDELAY
;
175 debug("### main_loop entered: bootdelay=%d\n\n", bootdelay
);
178 s
= getenv("bootcmd");
179 stored_bootdelay
= bootdelay
;
184 void autoboot_command(const char *s
)
186 debug("### main_loop: bootcmd=\"%s\"\n", s
? s
: PSTR("<UNDEFINED>"));
189 if (stored_bootdelay
!= -1 && s
&& !abortboot(stored_bootdelay
)) {
190 run_command_list(s
, -1);
200 s
= bootdelay_process();
215 debug("\n=========================< (RE)START DEBUG >=========================\n");
216 print_reset_reason();
221 printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n"));