Parallel port interrupt revisited

Tech-Archive recommends: Fix windows errors by optimizing your registry




Hi,

i am trying to implement a parallel port IST on WinCE Embedded 6.0. I
adapted and compiled a code from this thread from this newsgroup:

http://groups.google.com/group/microsoft.public.windowsce.platbuilder/browse_thread/thread/fb4481d040a441c3/f9d4344da01bce1a?lnk=gst&q=ISR+irq+7#f9d4344da01bce1a

Well, my code is like this:

// Subproject5.cpp : Defines the entry point for the console
application.
//

#include "stdafx.h"
#include <Pkfuncs.h>
#include "nkintr.h"

#define IOBASE 0x300 // default LPT base address
#define PORTA IOBASE
#define PORTB IOBASE+1
#define PORTC IOBASE+2
#define CONTROL IOBASE+3
#define INTE 0x80
#define PORT_A_OUTPUT 0x03
#define PORT_B_OUTPUT 0xC0
#define PORT_C_OUTPUT 0x30

// Parallel interrupt event handle
HANDLE hIntPar;

// IST Thread handle
HANDLE hThreadIST;

void WritePortUchar (PUCHAR port, UCHAR value)
{
__asm
{
mov dx, word ptr port
mov al, value
out dx, al
}
}

void PAR_IST(void)
{
int result;

for(;;)
{
// Wait for the interrupt event
result = WaitForSingleObject(hIntPar, INFINITE);
if (result != WAIT_OBJECT_0)
{
_tprintf(_T("ERROR: ThreadProc - WaitForSingleObject\n"));
}
else
{
_tprintf(_T("Interrupt Received from PRN Port\n"));
}
InterruptDone(SYSINTR_FIRMWARE + 7);
}

}

int _tmain(int argc, TCHAR *argv[], TCHAR *envp[])
{

DWORD dwThrdID;

_tprintf(_T("Starting...\n"));

OEMInterruptEnable(SYSINTR_FIRMWARE + 7, NULL, NULL);


if (InterruptInitialize(SYSINTR_FIRMWARE + 7, hIntPar, NULL,
NULL)) // Initialize IRQ 7 and map it to the hIntPar event
_tprintf(_T("Interrupt Initialized\n"));
else

_tprintf(_T("ERROR: Interrupt NOT initialized at first attempt\n"));

InterruptDisable(SYSINTR_FIRMWARE + 7); // Try if this works


if (InterruptInitialize (SYSINTR_FIRMWARE + 7, hIntPar, NULL, NULL))
_tprintf(_T("Interrupt Initialized at 2nd attempt\n"));
else {

_tprintf(_T("ERROR: Interrupt NOT initialized!\n"));
//CloseHandle(hIntPar); // kill the event handle
//TerminateThread(hThreadIST, 0); // kill the IST
//CloseHandle(hThreadIST);
return FALSE;
}

hIntPar = CreateEvent(NULL, FALSE, FALSE, TEXT("IntParEvent")); //
This Event is going to wakeup the IST when an interrupt occures

if (hIntPar == NULL)
{
_tprintf(_T("ERROR: CreateEvent\n"));
return FALSE;
}

hThreadIST = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE) PAR_IST,
NULL, CREATE_SUSPENDED, (LPDWORD) &dwThrdID); // create the IST
if (hThreadIST == NULL)
{
_tprintf(_T("ERROR: CreateThread\n"));
CloseHandle(hIntPar); // kill the event handle
return FALSE;
}

CeSetThreadPriority(hThreadIST, 240); // Set thread priority


ResumeThread(hThreadIST);// Start the IST

WritePortUchar((unsigned char *) (CONTROL), (INTE |
PORT_C_OUTPUT));
// Write 0 to data and status registers
// WRITE_PORT_UCHAR((unsigned char *) (LPTBase+1), 0);
// WRITE_PORT_UCHAR((unsigned char *) (LPTBase+2), 0x10); // Enable
IRQ on ACK (bit 4 of status register)
while (getchar() != 'Q');
return 0;



return 0;
}



After running it on a x86 target, i get the error:

\> Subproject5.exe
Starting again and over agin...
ERROR: Interrupt NOT initialized at first attempt
ERROR: Interrupt NOT initialized!


In intr\init.c i also have:

OALIntrStaticTranslate(SYSINTR_FIRMWARE + 7, 7);

which already came pre-included.

any hints?

any kind of help would be really great

thanks

Rafael
.



Relevant Pages

  • Re: Parallel port interrupt revisited
    ... -It is better if you first set up all your interrupt stuff, ... Defines the entry point for the console ... if (InterruptInitialize(SYSINTR_FIRMWARE + 7, hIntPar, NULL, ... NULL)) // Initialize IRQ 7 and map it to the hIntPar event ...
    (microsoft.public.windowsce.platbuilder)
  • races when reserving an event in the unified trace buffer
    ... I am doing some load testing with our kernel tracing prototype ... "an interrupt storm that made it all the way around the buffer". ... The interrupt event moves the tail_page ...
    (Linux-Kernel)
  • Re: races when reserving an event in the unified trace buffer
    ... I am doing some load testing with our kernel tracing prototype ... "an interrupt storm that made it all the way around the buffer". ... The interrupt event moves the tail_page ...
    (Linux-Kernel)
  • Re: races when reserving an event in the unified trace buffer
    ... I am doing some load testing with our kernel tracing prototype ... "an interrupt storm that made it all the way around the buffer". ... The interrupt event moves the tail_page ...
    (Linux-Kernel)
  • Re: event <--> interrupt association.
    ... In CE6 it wouldn't be possible since you are isolated from the kernel. ... You are associating an event with interrupt when calling ... setting the interrupt event ). ... I can check that since I have the source code for the drivers in my ...
    (microsoft.public.windowsce.embedded)