Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1029 | chrv | 1 | #include <avr/io.h> |
2 | #include <util/delay.h> |
||
3 | |||
4 | #include "pins.h" |
||
5 | #include "mytypes.h" |
||
6 | |||
7 | #include "main.h" |
||
8 | #include "atx.h" |
||
9 | #include "rs232.h" |
||
10 | #include "zx.h" |
||
11 | |||
12 | //if want Log than comment next string |
||
13 | #undef LOGENABLE |
||
14 | |||
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 | |||
54 | void atx_power_task(void) |
||
55 | { |
||
56 | static UWORD last_count = 0; |
||
57 | UBYTE j = 50; |
||
58 | |||
59 | if ( atx_counter > 1700 ) |
||
60 | { |
||
61 | |||
62 | |||
63 | if ( ( SOFTRES_PIN & (1<<SOFTRES) ) == 0 ) |
||
64 | { |
||
65 | //atx power off button pressed (~5 sec) |
||
66 | |||
67 | //switch off atx power |
||
68 | ATXPWRON_PORT &= ~(1<<ATXPWRON); |
||
69 | } |
||
70 | else |
||
71 | { |
||
72 | //enable hard reset |
||
73 | flags_register |= FLAG_HARD_RESET; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | if ( ( last_count > 0 ) && ( atx_counter == 0 ) ) |
||
78 | { |
||
79 | //soft reset (reset Z80 only) |
||
80 | zx_spi_send(SPI_RST_REG, 0, 0x7F); |
||
81 | } |
||
82 | last_count = atx_counter; |
||
83 | |||
84 | if ( ( nCONFIG_PIN & (1<<nCONFIG) ) == 0 ) |
||
85 | { |
||
86 | //power down |
||
87 | |||
88 | //power led off (timer output disconnect from led pin) |
||
89 | TCCR2 &= ~((1<<COM20)|(1<<COM21)); |
||
90 | |||
91 | //wait for button released |
||
92 | while ( ( SOFTRES_PIN & (1<<SOFTRES) ) == 0 ); |
||
93 | |||
94 | //1 sec delay |
||
95 | do _delay_ms(20); while(--j); |
||
96 | |||
97 | last_count = 0; |
||
98 | |||
99 | //enable hard reset |
||
100 | flags_register |= FLAG_HARD_RESET; |
||
101 | } |
||
102 | } |