Subversion Repositories pentevo

Rev

Rev 172 | 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.  
  10. volatile UWORD atx_counter;
  11.  
  12. void wait_for_atx_power(void)
  13. {
  14.         UBYTE j = MCUCSR;
  15.  
  16.         //clear status register
  17.         MCUCSR = 0;
  18.  
  19. #ifdef LOGENABLE
  20.         char log_ps2keyboard_parse[] = "MC..\r\n";
  21.         log_ps2keyboard_parse[2] = ((j >> 4) <= 9 )?'0'+(j >> 4):'A'+(j >> 4)-10;
  22.         log_ps2keyboard_parse[3] = ((j & 0x0F) <= 9 )?'0'+(j & 0x0F):'A'+(j & 0x0F)-10;
  23.         to_log(log_ps2keyboard_parse);
  24. #endif
  25.  
  26.         //check power
  27.         if ( (nCONFIG_PIN & (1<<nCONFIG)) == 0 )
  28.         {
  29.                 //if not external reset
  30.                 //then wait for atx power on button (SOFTRESET)
  31.                 if ( !(j & ((1<<JTRF)|(1<<WDRF)|(1<<BORF)|(1<<EXTRF))) ||
  32.                          (j & (1<<PORF)) )
  33.                 while( SOFTRES_PIN&(1<<SOFTRES) );
  34.  
  35.                 //switch on ATX power
  36.                 ATXPWRON_PORT |= (1<<ATXPWRON);
  37.  
  38.                 //1 sec delay
  39.                 j=50;
  40.                 do _delay_ms(20); while(--j);
  41.         }
  42.  
  43.         //init port F
  44.         PORTF = 0b11111000;
  45.         //clear counter
  46.         atx_counter = 0;
  47. }
  48.  
  49. UBYTE atx_power_task(void)
  50. {
  51.         UBYTE j = 50;
  52.  
  53.         if ( atx_counter > 1700 )
  54.         {
  55.                 //atx power off button pressed (~5 sec)
  56.  
  57.                 //switch off atx power
  58.                 ATXPWRON_PORT &= ~(1<<ATXPWRON);
  59.         }
  60.  
  61.         if ( ( nCONFIG_PIN & (1<<nCONFIG) ) == 0 )
  62.         {
  63.                 //power down
  64.  
  65.                 //wait for button released
  66.                 while (  ( SOFTRES_PIN & (1<<SOFTRES) ) == 0 );
  67.  
  68.                 //1 sec delay
  69.                 do _delay_ms(20); while(--j);
  70.         }
  71.         return j;
  72. }
  73.