Rev 855 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
75 | chrv | 1 | #include <avr/io.h> |
854 | lvd | 2 | #include <avr/interrupt.h> |
75 | chrv | 3 | #include <util/delay.h> |
4 | |||
5 | #include "pins.h" |
||
6 | #include "mytypes.h" |
||
7 | |||
219 | chrv | 8 | #include "main.h" |
75 | chrv | 9 | #include "atx.h" |
10 | #include "rs232.h" |
||
163 | chrv | 11 | #include "zx.h" |
75 | chrv | 12 | |
179 | chrv | 13 | //if want Log than comment next string |
14 | #undef LOGENABLE |
||
15 | |||
75 | chrv | 16 | volatile UWORD atx_counter; |
17 | |||
18 | void wait_for_atx_power(void) |
||
19 | { |
||
20 | UBYTE j = MCUCSR; |
||
21 | |||
22 | //clear status register |
||
23 | MCUCSR = 0; |
||
24 | |||
25 | #ifdef LOGENABLE |
||
26 | char log_ps2keyboard_parse[] = "MC..\r\n"; |
||
27 | log_ps2keyboard_parse[2] = ((j >> 4) <= 9 )?'0'+(j >> 4):'A'+(j >> 4)-10; |
||
28 | log_ps2keyboard_parse[3] = ((j & 0x0F) <= 9 )?'0'+(j & 0x0F):'A'+(j & 0x0F)-10; |
||
29 | to_log(log_ps2keyboard_parse); |
||
30 | #endif |
||
31 | |||
32 | //check power |
||
33 | if ( (nCONFIG_PIN & (1<<nCONFIG)) == 0 ) |
||
34 | { |
||
861 | lvd | 35 | // only after poweron reset we should wait for soft reset button before powering on |
36 | if( !(j & ((1<<JTRF)|(1<<WDRF)|(1<<BORF)|(1<<EXTRF))) || (j & (1<<PORF)) ) |
||
37 | { |
||
38 | // have at least 2 sec pause before turning on, as this hopefully gives enough time |
||
39 | // for FPGA voltages to drop and it will powerup cleanly without compromising the firmware |
||
40 | UBYTE soft_rst_pressed = 0; |
||
41 | UBYTE i = PRE_PWRON_WAIT; |
||
75 | chrv | 42 | |
861 | lvd | 43 | do |
44 | { |
||
45 | // blink power LED |
||
46 | if( i&7 ) |
||
47 | LED_PORT |= (1<<LED); |
||
48 | else |
||
49 | LED_PORT &= ~(1<<LED); |
||
50 | |||
51 | _delay_ms(20); |
||
52 | |||
53 | // if soft reset was pressed during wait, remember it and go poweron immediately after the wait ends |
||
54 | soft_rst_pressed |= !(SOFTRES_PIN & (1<<SOFTRES)); |
||
55 | |||
56 | } while(--i); |
||
57 | |||
58 | // wait further for soft reset press |
||
59 | if( !soft_rst_pressed ) while( SOFTRES_PIN&(1<<SOFTRES) ); |
||
60 | } |
||
61 | |||
855 | lvd | 62 | //switch on ATX power (PF3 pin in PORTF) |
75 | chrv | 63 | ATXPWRON_PORT |= (1<<ATXPWRON); |
64 | |||
65 | //1 sec delay |
||
855 | lvd | 66 | UBYTE i=50; |
67 | do {_delay_ms(20);} while(--i); |
||
75 | chrv | 68 | } |
69 | |||
70 | //clear counter |
||
71 | atx_counter = 0; |
||
72 | } |
||
73 | |||
219 | chrv | 74 | void atx_power_task(void) |
75 | chrv | 75 | { |
854 | lvd | 76 | UBYTE i; |
77 | |||
163 | chrv | 78 | static UWORD last_count = 0; |
75 | chrv | 79 | |
854 | lvd | 80 | if ( atx_counter > PWROFF_KEY_TIME ) |
75 | chrv | 81 | { |
852 | lvd | 82 | //here if either SOFTRES_PIN or F12 held for more than ~5 seconds |
83 | |||
84 | |||
854 | lvd | 85 | |
86 | // no more need in executing mainloop and servicing interrupts |
||
87 | cli(); |
||
88 | |||
852 | lvd | 89 | UBYTE was_soft_rst = !(SOFTRES_PIN & (1<<SOFTRES)); |
90 | |||
91 | // switch off ATX power |
||
92 | ATXPWRON_PORT &= ~(1<<ATXPWRON); |
||
93 | |||
854 | lvd | 94 | // wait for ATX power to actually drop -- for no more than 2 second. |
95 | // if the wait would be infinite, hang will result on non-ATX power supplies |
||
96 | i=PWROFF_WAIT; |
||
97 | do |
||
98 | { |
||
99 | if( !(nCONFIG_PIN & (1<<nCONFIG)) ) break; |
||
100 | _delay_ms(20); |
||
101 | } while( --i ); |
||
852 | lvd | 102 | |
854 | lvd | 103 | |
852 | lvd | 104 | // if it was soft reset switch initiated -- wait for it to release |
105 | if( was_soft_rst ) |
||
229 | lvd | 106 | { |
852 | lvd | 107 | while( !(SOFTRES_PIN & (1<<SOFTRES)) ); |
240 | chrv | 108 | |
854 | lvd | 109 | i=SOFT_RST_DEBOUNCE; // and then debounce it |
110 | do _delay_ms(20); while(--i); |
||
240 | chrv | 111 | } |
852 | lvd | 112 | |
113 | //power led off (timer output disconnect from led pin) |
||
114 | TCCR2 &= ~((1<<COM20)|(1<<COM21)); |
||
115 | |||
116 | // signal HARD_RESET to exit out of mainloop in main.c -- and eventually return to wait_for_atx_power() |
||
117 | flags_register |= FLAG_HARD_RESET; |
||
75 | chrv | 118 | } |
852 | lvd | 119 | else if ( ( last_count > 0 ) && ( atx_counter == 0 ) ) |
163 | chrv | 120 | { |
852 | lvd | 121 | //soft reset (reset Z80 only) -- F12 or softreset pressed for less than 1700 ticks |
163 | chrv | 122 | zx_spi_send(SPI_RST_REG, 0, 0x7F); |
123 | } |
||
124 | last_count = atx_counter; |
||
125 | |||
75 | chrv | 126 | |
127 | } |