Rev 437 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
75 | chrv | 1 | #include <avr/io.h> |
2 | #include <util/delay.h> |
||
3 | |||
4 | #include "pins.h" |
||
5 | #include "mytypes.h" |
||
6 | |||
219 | chrv | 7 | #include "main.h" |
75 | chrv | 8 | #include "atx.h" |
9 | #include "rs232.h" |
||
163 | chrv | 10 | #include "zx.h" |
75 | chrv | 11 | |
179 | chrv | 12 | //if want Log than comment next string |
13 | #undef LOGENABLE |
||
14 | |||
75 | chrv | 15 | volatile UWORD atx_counter; |
16 | |||
17 | void wait_for_atx_power(void) |
||
18 | { |
||
19 | UBYTE j = MCUCSR; |
||
20 | |||
21 | //clear status register |
||
22 | MCUCSR = 0; |
||
23 | |||
24 | #ifdef LOGENABLE |
||
25 | char log_ps2keyboard_parse[] = "MC..\r\n"; |
||
26 | log_ps2keyboard_parse[2] = ((j >> 4) <= 9 )?'0'+(j >> 4):'A'+(j >> 4)-10; |
||
27 | log_ps2keyboard_parse[3] = ((j & 0x0F) <= 9 )?'0'+(j & 0x0F):'A'+(j & 0x0F)-10; |
||
28 | to_log(log_ps2keyboard_parse); |
||
29 | #endif |
||
30 | |||
31 | //check power |
||
32 | if ( (nCONFIG_PIN & (1<<nCONFIG)) == 0 ) |
||
33 | { |
||
34 | //if not external reset |
||
35 | //then wait for atx power on button (SOFTRESET) |
||
36 | if ( !(j & ((1<<JTRF)|(1<<WDRF)|(1<<BORF)|(1<<EXTRF))) || |
||
37 | (j & (1<<PORF)) ) |
||
38 | while( SOFTRES_PIN&(1<<SOFTRES) ); |
||
39 | |||
40 | //switch on ATX power |
||
41 | ATXPWRON_PORT |= (1<<ATXPWRON); |
||
42 | |||
43 | //1 sec delay |
||
44 | j=50; |
||
45 | do _delay_ms(20); while(--j); |
||
46 | } |
||
47 | |||
48 | //init port F |
||
49 | PORTF = 0b11111000; |
||
50 | //clear counter |
||
51 | atx_counter = 0; |
||
52 | } |
||
53 | |||
219 | chrv | 54 | void atx_power_task(void) |
75 | chrv | 55 | { |
163 | chrv | 56 | static UWORD last_count = 0; |
75 | chrv | 57 | UBYTE j = 50; |
58 | |||
59 | if ( atx_counter > 1700 ) |
||
60 | { |
||
240 | chrv | 61 | if ( ( SOFTRES_PIN & (1<<SOFTRES) ) == 0 ) |
229 | lvd | 62 | { |
240 | chrv | 63 | //atx power off button pressed (~5 sec) |
64 | |||
65 | //switch off atx power |
||
66 | ATXPWRON_PORT &= ~(1<<ATXPWRON); |
||
67 | } |
||
68 | else |
||
69 | { |
||
229 | lvd | 70 | //enable hard reset |
71 | flags_register |= FLAG_HARD_RESET; |
||
72 | } |
||
75 | chrv | 73 | } |
74 | |||
163 | chrv | 75 | if ( ( last_count > 0 ) && ( atx_counter == 0 ) ) |
76 | { |
||
77 | //soft reset (reset Z80 only) |
||
78 | zx_spi_send(SPI_RST_REG, 0, 0x7F); |
||
79 | } |
||
80 | last_count = atx_counter; |
||
81 | |||
75 | chrv | 82 | if ( ( nCONFIG_PIN & (1<<nCONFIG) ) == 0 ) |
83 | { |
||
84 | //power down |
||
85 | |||
172 | chrv | 86 | //power led off (timer output disconnect from led pin) |
87 | TCCR2 &= ~((1<<COM20)|(1<<COM21)); |
||
88 | |||
75 | chrv | 89 | //wait for button released |
90 | while ( ( SOFTRES_PIN & (1<<SOFTRES) ) == 0 ); |
||
91 | |||
92 | //1 sec delay |
||
93 | do _delay_ms(20); while(--j); |
||
163 | chrv | 94 | |
95 | last_count = 0; |
||
219 | chrv | 96 | |
97 | //enable hard reset |
||
98 | flags_register |= FLAG_HARD_RESET; |
||
75 | chrv | 99 | } |
100 | } |