Subversion Repositories pentevo

Rev

Rev 602 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed | ?url?

  1. #include "_global.h"
  2. #include "_output.h"
  3. #include "_ps2k.h"
  4. #include "_screen.h"
  5. #include "_uart.h"
  6. #include "_pintest.h"
  7. #include "_t_dram.h"
  8. #include "_t_video.h"
  9. #include "_t_beep.h"
  10. #include "_t_zxkbd.h"
  11. #include "_t_ps2k.h"
  12. #include "_t_ps2m.h"
  13. #include "_t_rs232.h"
  14. #include "_t_sd.h"
  15. #include <avr/interrupt.h>
  16. #include <util/delay_basic.h>
  17.  
  18. extern uint_farptr_t fpgadat1;
  19.  
  20. //-----------------------------------------------------------------------------
  21.  
  22. void nothing(void)
  23. {
  24.  asm volatile ("nop");
  25. }
  26.  
  27. //-----------------------------------------------------------------------------
  28.  
  29. const PITEMHNDL hndl_menu_main[8] PROGMEM = {
  30.   Test_PS2Keyb,
  31.   Test_ZXKeyb,
  32.   Test_PS2Mouse,
  33.   Test_Beep,
  34.   Test_Video,
  35.   Test_RS232,
  36.   Test_SD_MMC,
  37.   nothing
  38. };
  39.  
  40. const MENU_DESC menu_main PROGMEM = {
  41.   6,3,26,8,
  42.   Test_DRAM,
  43.   1000,
  44.   hndl_menu_main,
  45.   str_menu_main
  46. };
  47. #define p_menu_main ((const P_MENU_DESC)&menu_main)
  48.  
  49. //-----------------------------------------------------------------------------
  50.  
  51. void TestFpgaExchange(void)
  52. {
  53.  u8 i, curr, prev;
  54.  curr=random8();
  55.  fpga_reg(SCR_ATTR,curr);
  56.  i=0;
  57.  do
  58.  {
  59.   prev=~curr;
  60.   curr=random8();
  61.   if (fpga_same_reg(curr)!=prev)
  62.   {
  63.    print_mlmsg(mlmsg_someerrors);
  64.    while (1)
  65.    {
  66.     u16 j, errors;
  67.     errors=0;
  68.     j=50000;
  69.     do
  70.     {
  71.      prev=~curr;
  72.      curr=random8();
  73.      if (fpga_same_reg(curr)!=prev) errors++;
  74.     }while (--j);
  75.     print_mlmsg(mlmsg_spi_test);
  76.     print_dec16(errors);
  77.    }
  78.   }
  79.  }while (--i);
  80. }
  81.  
  82. //-----------------------------------------------------------------------------
  83.  
  84. void PowerStatus(const u8 * const *mlmsg)
  85. {
  86.  print_mlmsg(mlmsg);
  87.  print_msg(msg_power_pg);
  88.  u8 ch;
  89.  ch='0';
  90.  if (PINC&(1<<PC5)) ch++;
  91.  put_char(ch);
  92.  print_msg(msg_power_vcc5);
  93.  ch='0';
  94.  if (PINF&(1<<PF0)) ch++;
  95.  put_char(ch);
  96. }
  97.  
  98. //-----------------------------------------------------------------------------
  99.  
  100. void PowerUp(void)
  101. {
  102.  PowerStatus(mlmsg_statusof_crlf);
  103.  u8 i;
  104.  i=PINF&(1<<PF0);
  105.  if ( (i==0) || ((PINC&(1<<PC5))==0) )
  106.  {
  107.   if (i==0)
  108.   {
  109.    print_mlmsg(mlmsg_power_on);
  110.    while ((PINF&(1<<PF0))==0)
  111.     PowerStatus(mlmsg_statusof_cr);
  112.   }
  113.   i=170;
  114.   do
  115.    PowerStatus(mlmsg_statusof_cr);
  116.   while (--i);
  117.  }
  118. }
  119.  
  120. //-----------------------------------------------------------------------------
  121.  
  122. int main(void)
  123. {
  124.  cli();
  125.  MCUCSR=0;
  126.  _EEGET(mode1,ee_mode1);
  127.  _EEGET(lang,ee_lang);
  128.  if (lang>=TOTAL_LANG) lang=0;
  129.  
  130.  PinTest();                                     // проверка ножек ATMEGA128
  131.                                                 // активирует вывод через UART без буфера FIFO
  132.  // configure pins
  133.  PORTG = 0b11111111;
  134.  DDRG  = 0b00000000;
  135.  
  136.  PORTF = 0b00001000;
  137.  DDRF  = 0b00001000;
  138.  
  139.  PORTE = 0b11110011;
  140.  DDRE  = 0b00000000;
  141.  
  142.  PORTD = 0b11111111;
  143.  DDRD  = 0b00000000;
  144.  
  145.  PORTC = 0b11011111;
  146.  DDRC  = 0b00000000;
  147.  
  148.  PORTB = 0b11111001;
  149.  DDRB  = 0b10000111;
  150.  
  151.  PORTA = 0b11111111;
  152.  DDRA  = 0b00000000;
  153.  
  154.  PowerUp();
  155.  
  156.  print_mlmsg(mlmsg_cfgfpga);
  157.  load_fpga(GET_FAR_ADDRESS(fpgadat1));          //инициализация SPI и загрузка FPGA
  158.  SPCR=(1<<SPE)|(0<<DORD)|(1<<MSTR)|(0<<CPOL)|(0<<CPHA); // SPI reinit
  159.  print_mlmsg(mlmsg_done1);
  160.  
  161.  TestFpgaExchange();
  162.  print_msg(msg_ok);
  163.  
  164.  _delay_loop_2(553); // 200 us
  165.  uart_init();
  166.  ps2k_init();
  167.  timers_init();
  168.  EICRB|=(1<<ISC61)|(0<<ISC60);
  169.  EIMSK|=(1<<INT6);
  170.  sei();
  171.  
  172.  fpga_reg(SCR_MODE,mode1&0b10000000);
  173.  fpga_reg(INT_CONTROL,0b00000000);
  174.  
  175.  ps2k_detect_kbd();
  176.  
  177.  fpga_reg(MTST_CONTROL,0b00000001);
  178.  
  179.  print_msg(msg_ready);
  180.  ps2k_setsysled();
  181.  
  182.  while (1) scr_menu(p_menu_main);
  183. }
  184.  
  185. //-----------------------------------------------------------------------------
  186.