Autor Thema: Parallel Port  (Gelesen 4967 mal)

SSJ7Gohan

  • Beiträge: 398
    • Profil anzeigen
Gespeichert
« am: 13. August 2005, 22:04 »
Hi,
ich wollte den Parallel Port nutzen, um über Bochs in die Parallelport Logfile Debuginformationen auszugeben. Wie kann ich das realisieren? Kennt jemand Tutorials dafür?

Mein bisheriger Code sieht so aus:
char *ptr = text;
while( *ptr != 0 ) {
outByte( 0x378, *ptr++ );
}


Leider funktioniert das nicht :/
Ich bräuchte den Parallelport wie gesagt nur, um über Bochs Informationen auszugeben.

maumo

  • Beiträge: 182
    • Profil anzeigen
    • http://maumo.50webs.com/
Gespeichert
« Antwort #1 am: 14. August 2005, 14:23 »

typedef union
{
  struct
  {
    unsigned undef:    3;
    unsigned error:    1;
    unsigned selected: 1;
    unsigned no_paper: 1;
    unsigned ack:      1;
    unsigned busy:     1;
  } bits;

  unsigned char value;
} LPT_Status_Byte;

typedef union
{
  struct
  {
    unsigned undef:              2;
    unsigned bidirectional_ps_2: 1;
    unsigned interrupt_control:  1;
    unsigned select:             1;
    unsigned initialize:         1;
    unsigned auto_feed:          1;
    unsigned strobe:             1;
  } bits;

  unsigned char value;
} LPT_Control_Byte;

typedef struct
{
  unsigned long    base;
  unsigned long    id;
  unsigned char    mode;
  LPT_Status_Byte  state;
  LPT_Control_Byte ctrl;
} LPT_Port;

short test_transaction(unsigned long base)
{
  outb(0x55, base);
  inb(base);
  if(inb(base) != 0x55)
    return 0;

  outb(0xaa, base);
  inb(base);
  if(inb(base) != 0xaa)
    return 0;

  return 1;
}

/*
 *  Init
 */
void init_lpt()
{
  unsigned char i       = 0;
  unsigned char oldctrl = 0;
  unsigned char oldval  = 0;
  LPT_Control_Byte* ctrl = {0};

  for(i = 1; i < 4; i++)
  {
    lpt_ports[i].base = *((unsigned short*)(0x406 + (i*2)));
    if(lpt_ports[i].base == 0)
      continue;

    oldctrl = inb(lpt_ports[i].base+2);
    ctrl = (LPT_Control_Byte*)&oldctrl;
    outb(oldctrl & 0xdf, lpt_ports[i].base+2);
    inb(lpt_ports[i].base);
    oldval = inb(lpt_ports[i].base);

    if(test_transaction(lpt_ports[i].base) == 0)
    {
      printk("\nLPT%d is faulty or set to input mode (%h)", i, lpt_ports[i].base);
      outb(oldctrl, lpt_ports[i].base+2);
      outb(oldval, lpt_ports[i].base);
      continue;
    }

    outb(oldctrl | 0x20, lpt_ports[i].base+2);

    if(test_transaction(lpt_ports[i].base))
    {
      lpt_ports[i].mode = 0;
      //printk("\nLPT%d is non-bidirectional or in standard mode (%h)", i, lpt_ports[i].base);
    }
    else
    {
      lpt_ports[i].mode = 1;
      //printk("\nLPT%d is bidirectional using control port bit 5 (%h)", i, lpt_ports[i].base);
    }

    outb(oldctrl, lpt_ports[i].base+2);
    outb(oldval, lpt_ports[i].base);

    lpt_ports[i].state.value = inb(lpt_ports[i].base+1);
    lpt_ports[i].ctrl.value  = inb(lpt_ports[i].base+2);

    if(lpt_ports[i].id == ERROR)
      return INIT_ERROR;
  }

  return SUCCESS;
}    


LPT_Port lpt_ports[4] = {0};

short read_lpt(unsigned char num, unsigned long reg, unsigned long* buffer)
{
  if(lpt_ports[num].base == 0)
    return ERROR;

  *buffer = inl(lpt_ports[num].base);
  return SUCCESS;
}

short write_lpt(unsigned char num, unsigned long reg, unsigned long* buffer)
{
  if(lpt_ports[num].base == 0)
    return ERROR;

  outl(*buffer, lpt_ports[num].base);
  return SUCCESS;
}  


also so hab ichs gemacht  :D

infos dazu: http://www.wotsit.org

und nun kannste einfach write_lpt(bla, bla, bla)
und bekommst ne menge debug infos :wink:

 

Einloggen