]>
cloudbase.mooo.com Git - z180-stamp.git/blob - avr/main.c
7 #include <util/delay.h>
8 #include <avr/interrupt.h>
16 #include "con-utils.h"
22 /*--------------------------------------------------------------------------*/
24 void preset_ram (void) __attribute__ ((naked
)) \
25 __attribute__ ((section (".init3")));
29 for (uint8_t *p
= RAMSTART
; p
<= (uint8_t *) RAMEND
; p
++)
34 /*--------------------------------------------------------------------------*/
41 /* save and clear reset reason(s) */
49 /* Disable JTAG Interface regardless of the JTAGEN fuse setting. */
53 /* disable unused periphels */
54 PRR0
= _BV(PRTIM2
) | _BV(PRTIM0
) | _BV(PRADC
);
55 PRR1
= _BV(PRTIM5
) | _BV(PRTIM4
) | _BV(PRTIM3
) |
56 _BV(PRUSART3
) | _BV(PRUSART2
) | _BV(PRUSART1
);
58 /* disable analog comparator */
68 OCR1A
= F_CPU
/ 8 / 1000 - 1; // Timer1: 1000Hz interval (OC1A)
70 TIMSK1
= _BV(OCIE1A
); // Enable TC1.oca interrupt
73 static const FLASH
char * const FLASH rreasons
[] = {
82 void print_reset_reason(void)
84 uint8_t r
= mcusr
& 0x1f;
85 const FLASH
char * const FLASH
*p
= rreasons
;
87 printf_P(PSTR("Reset reason(s): %s"), r
? "" : "none");
88 for ( ; r
; p
++, r
>>= 1) {
95 printf_P(PSTR(".\n"));
99 /*******************************************************************************/
101 #define udelay(n) _delay_us(n)
104 /* Stored value of bootdelay, used by autoboot_command() */
105 static int stored_bootdelay
;
108 /***************************************************************************
109 * Watch for 'delay' seconds for autoboot stop.
110 * returns: 0 - no key, allow autoboot
114 static int abortboot(int bootdelay
)
120 printf_P(PSTR("Hit any key to stop autoboot: %2d "), bootdelay
);
122 #if defined CONFIG_ZERO_BOOTDELAY_CHECK
124 * Check if key already pressed
125 * Don't check if bootdelay < 0
127 if (bootdelay
>= 0) {
128 if (tstc()) { /* we got a key press */
129 (void) my_getchar(); /* consume input */
130 my_puts_P(PSTR("\b\b\b 0"));
131 abort
= 1; /* don't auto boot */
136 while ((bootdelay
> 0) && (!abort
)) {
141 if (tstc()) { /* we got a key press */
142 abort
= 1; /* don't auto boot */
143 bootdelay
= 0; /* no more delay */
147 } while (!abort
&& get_timer(ts
) < 1000);
149 printf_P(PSTR("\b\b\b%2d "), bootdelay
);
158 const char *bootdelay_process(void)
163 s
= getenv("bootdelay");
164 bootdelay
= s
? atoi(s
) : CONFIG_BOOTDELAY
;
167 debug("### main_loop entered: bootdelay=%d\n\n", bootdelay
);
170 s
= getenv("bootcmd");
171 stored_bootdelay
= bootdelay
;
176 void autoboot_command(const char *s
)
178 debug("### main_loop: bootcmd=\"%s\"\n", s
? s
: PSTR("<UNDEFINED>"));
181 if (stored_bootdelay
!= -1 && s
&& !abortboot(stored_bootdelay
)) {
182 run_command_list(s
, -1);
192 s
= bootdelay_process();
207 debug("\n=========================< (RE)START DEBUG >=========================\n");
208 print_reset_reason();
214 printf_P(PSTR("\n(ATMEGA1281+HD64180)_stamp Tester\n"));