]>
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 /*--------------------------------------------------------------------------*/
37 /* save and clear reset reason(s) */
45 /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
49 /* disable unused periphels */
50 PRR0
= _BV(PRTIM2
) | _BV(PRTIM0
) | _BV(PRADC
);
51 PRR1
= _BV(PRTIM5
) | _BV(PRTIM4
) | _BV(PRTIM3
) |
52 _BV(PRUSART3
) | _BV(PRUSART2
) | _BV(PRUSART1
);
54 /* disable analog comparator */
64 OCR1A
= F_CPU
/ 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
66 TIMSK1
= _BV(OCIE1A
); // Enable TC1.oca interrupt
69 static const FLASH
char * const FLASH rreasons
[] = {
78 void print_reset_reason(void)
80 uint8_t r
= mcusr
& 0x1f;
81 const FLASH
char * const FLASH
*p
= rreasons
;
83 printf_P(PSTR("Reset reason(s): "));
84 for ( ; r
; p
++, r
>>= 1) {
91 printf_P(PSTR(".\n"));
95 /*******************************************************************************/
96 /*******************************************************************************/
98 #define udelay(n) _delay_us(n)
101 /* Stored value of bootdelay, used by autoboot_command() */
102 static int stored_bootdelay
;
105 /***************************************************************************
106 * Watch for 'delay' seconds for autoboot stop.
107 * returns: 0 - no key, allow autoboot
111 static int abortboot(int bootdelay
)
117 printf_P(PSTR("Hit any key to stop autoboot: %2d "), bootdelay
);
119 #if defined CONFIG_ZERO_BOOTDELAY_CHECK
121 * Check if key already pressed
122 * Don't check if bootdelay < 0
124 if (bootdelay
>= 0) {
125 if (tstc()) { /* we got a key press */
126 (void) my_getchar(); /* consume input */
127 my_puts_P(PSTR("\b\b\b 0"));
128 abort
= 1; /* don't auto boot */
133 while ((bootdelay
> 0) && (!abort
)) {
138 if (tstc()) { /* we got a key press */
139 abort
= 1; /* don't auto boot */
140 bootdelay
= 0; /* no more delay */
144 } while (!abort
&& get_timer(ts
) < 1000);
146 printf_P(PSTR("\b\b\b%2d "), bootdelay
);
155 const char *bootdelay_process(void)
160 s
= getenv("bootdelay");
161 bootdelay
= s
? atoi(s
) : CONFIG_BOOTDELAY
;
164 debug("### main_loop entered: bootdelay=%d\n\n", bootdelay
);
167 s
= getenv("bootcmd");
168 stored_bootdelay
= bootdelay
;
173 void autoboot_command(const char *s
)
175 debug("### main_loop: bootcmd=\"%s\"\n", s
? s
: PSTR("<UNDEFINED>"));
178 if (stored_bootdelay
!= -1 && s
&& !abortboot(stored_bootdelay
)) {
179 run_command_list(s
, -1);
189 s
= bootdelay_process();
202 debug("\n=========================< (RE)START DEBUG >=========================\n");
204 print_reset_reason();
209 printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n"));