Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Interrupt ?

19 views
Skip to first unread message

Kristian Vang

unread,
May 24, 2002, 5:30:50 AM5/24/02
to
Hi
I'm developing a Thermal Transfer Printer based on a industrial PC using
Windows CE 4.0. We have developed our own PC104 (ISA) card and everything is
working great except interrupt.

I don't know how to program CE to work with interrupt and what I find in the
help files seems very complicated. (I have never developed drivers before).

Can anyone help me out here?

Is there a simple way to use interrupt? All I want is that e.g. IRQ 9
trigger one routine in my program.

Does anyone have some sample code doing something similar?

Best regards

Kristian Vang

Easyprint


wik

unread,
May 24, 2002, 5:55:25 AM5/24/02
to
Hi, this does the trick for me on IRQ 7. Please check OEMinit() if your IRQ
is being setup right.

Wik

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

#include "stdafx.h"
#include <windows.h>
#include "pkfuncs.h"
#include "nkintr.h"
#include "oalintr.h"
#include <wdm.h>
#include <Dbgapi.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 PAR_IST(void)
{
int result;

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

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
DWORD dwThrdID;

hIntPar = CreateEvent(NULL, FALSE, FALSE, TEXT("IntParEvent")); // This Event is going to wakeup the IST when an interrupt occures
if (hIntPar == NULL)
{
OutputDebugString (TEXT("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)
{
OutputDebugString (TEXT("ERROR: CreateThread\n"));
CloseHandle(hIntPar); // kill the event handle
return FALSE;
}
CeSetThreadPriority(hThreadIST, 240); // Set thread priority
if (InterruptInitialize(MapIrq2SysIntr(7), hIntPar, NULL, NULL)) // Initialize
IRQ 7 and map it to the hIntPar event
OutputDebugString (TEXT("Interrupt Initialized\n"));
else


OutputDebugString (TEXT("ERROR: Interrupt NOT initialized at first
attempt\n"));
InterruptDisable(MapIrq2SysIntr(7)); // Try if this works
if (InterruptInitialize (MapIrq2SysIntr(7), hIntPar, NULL, NULL))
OutputDebugString (TEXT("Interrupt Initialized at 2nd attempt\n"));
else


OutputDebugString (TEXT("ERROR: Interrupt NOT initialized!\n"));
CloseHandle(hIntPar); // kill the event handle
TerminateThread(hThreadIST, 0); // kill the IST
CloseHandle(hThreadIST);
return FALSE;
}
}
ResumeThread(hThreadIST);// Start the IST
WRITE_PORT_UCHAR((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;
}

"Kristian Vang" <kv...@easy-print.com> wrote in message
news:OyRvJWwACHA.992@tkmsftngp02...

Kristian Vang

unread,
May 24, 2002, 10:23:03 AM5/24/02
to
Hi
Thanks

I feel like getting closer now.

I tried to use your program as a starting point but i get 1 undefined
identifier "MapIrq2SysIntr" is this a routine of yours?

I'm not sure if it will work sine it's my own hardware and IRQ 9 is probably
not initialised. I don't know if I need to write a ISR of my own.

I get extra returns when I copy / paste from the newsgroup. Can you by any
chance attach your .c and .h as files instead.

Best regard

Kristian Vang

Easyprint


"wik" <willem...@getronics.com> wrote in message
news:Ou30GkwACHA.1300@tkmsftngp04...

Kristian Vang

unread,
May 29, 2002, 9:37:19 AM5/29/02
to
Hi
I now got to the point where the program reports "Interrupt NOT
initialized!".
To have the program compiling i created a function "MapIrq2SysIntr" just
returning the same value. Would this work or can you tell me how to include
this function.
You were referring to OEMinit() where is this function? or should i create
it myself?

best regards

Kristian Vang

"Willem Haring [eMVP]" <willem...@getronics.com> wrote in message
news:u#rP0GzACHA.1696@tkmsftngp05...
> MapIrq2SysIntr is just a function that is in there. But, it is not in the
> help.
>
> You don't need to write your own ISR handler, since the CEPC uses just one
> big IRQ function. This function allows you to attach your own thread to
the
> IRQ.
>
>
>
> Willem


>
>
> "Kristian Vang" <kv...@easy-print.com> wrote in message

> news:eh5Lc5yACHA.992@tkmsftngp02...

Michel Verhagen

unread,
May 29, 2002, 1:01:48 PM5/29/02
to
Kristian,

In CE.NET, there's no MapIrq2SysIntr macro anymore. Just use SYSINTR =
SYSINTR_FIRMWARE + irq

So if you need the SYSINTR value for Irq 9, it would be SYSINTR_FIRMWARE +
9, which is in fact (SYSINTR_DEVICES+8) + 9, which is (8+8) + 9, which is
25.

Some more info:

SYSINTR_FIRMWARE is defined in D:\WINCE400\PUBLIC\COMMON\OAK\INC\nkintr.h

The function OEMTranslateIrq in cfwpc.c in directory PLATFORM\[BSP]\Kernel
OAL (or in D:\WINCE400\PUBLIC\COMMON\OAK\CSP\I486\OAL if you are using
standard CEPC stuff) shows how to calculate this stuff.

DWORD OEMTranslateIrq(DWORD Irq)
{
if (Irq > INTR_MAXIMUM) {
return -1;
}

if (g_Intr2SysintrMap[Irq] == -1) {
// Not previously mapped
DWORD SysIntr = SYSINTR_FIRMWARE + Irq;

g_Intr2SysintrMap[Irq] = SysIntr;
g_Sysintr2IntrMap[SysIntr] = Irq;
}

return g_Intr2SysintrMap[Irq];
}

I think this function in the OEM has some "outside" application level API,
but I don't remember how it was called.... a little searching through some
examples or the MSDN might help...

Oh, and don't forget to setup the IRQ in OEMInit() like this:

SETUP_INTERRUPT_MAP(SYSINTR_FIRMWARE+9, 9);

Now that combined with the sources from Willem should do the trick...


Best regards,

Michel Verhagen
PTS Software

[if you want to reply to my email address directly, please remove "nospam."
right after the @]

"Kristian Vang" <kv...@easy-print.com> wrote in message

news:OeY7KXxBCHA.1108@tkmsftngp04...

Kristian Vang

unread,
May 30, 2002, 2:50:17 AM5/30/02
to
Hi Michel
Thank you!

This OEMinit() does it exsist already or do i have to create my own
OEMinit()

Best regards

Kristian

"Michel Verhagen" <michel....@nospam.pts.nl> wrote in message
news:ezdWSKzBCHA.1696@tkmsftngp04...

Michel Verhagen

unread,
May 30, 2002, 3:10:56 AM5/30/02
to
The OEMInit function is defined in cfwpc.c in your KERNEL\OAL directory (see
previous post also)

Good luck,

Michel Verhagen
PTS Software

"Kristian Vang" <kv...@easy-print.com> wrote in message

news:u6DAZY6BCHA.2540@tkmsftngp05...

Kristian Vang

unread,
May 30, 2002, 6:30:48 AM5/30/02
to
Thank you Michel and Thank you Willem
My irq system is now working. Great!!!

Best regards

Kristian Vang

"Michel Verhagen" <michel....@nospam.pts.nl> wrote in message

news:OvCutk6BCHA.1360@tkmsftngp05...

0 new messages