Subversion Repositories pentevo

Rev

Rev 172 | Rev 229 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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