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
// 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...
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...
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...
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...
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...
Good luck,
Michel Verhagen
PTS Software
"Kristian Vang" <kv...@easy-print.com> wrote in message
news:u6DAZY6BCHA.2540@tkmsftngp05...
Best regards
Kristian Vang
"Michel Verhagen" <michel....@nospam.pts.nl> wrote in message
news:OvCutk6BCHA.1360@tkmsftngp05...