Hi,

Before digging to deep in trying to implement and learn about IISR I would
like to get some advises/answers if possible:

- Is it possible to use e.g. math functions like e.g. sin() etc. in an ISR?
- Is it possible to use memcpy()?
- Is it possible to use the IoControl of the ISR to pass parameters/data
FROM the IST?
- Is it possible to use the IoControl of the ISR to pass parameters/data TO
the IST (lpOutBuf in KernelLibIoControl)?
- I understand that the KLibAllocShareMem can be used to allocate a common
buffer of ISR and IST but what is the parameter nPages defined - what if I
would like to allocate e.g. 3000 bytes -what should nPages then be set to?

Any comment and answers are highly appriciated.

Thanks
Ole

Re: Installable ISR - general questions by Valter

Valter
Thu Sep 28 04:50:48 CDT 2006

"Ole" <ole@blabla.com> wrote in
news:OeCqMGu4GHA.4820@TK2MSFTNGP06.phx.gbl:

> Hi,
>
> Before digging to deep in trying to implement and learn about IISR
> I would like to get some advises/answers if possible:
>
> - Is it possible to use e.g. math functions like e.g. sin() etc.
> in an ISR? - Is it possible to use memcpy()?

Those function may be used, provided that their implementation
doesn't involve some particulare hardware interaction (using DMA for
memcpy or using a math co-processor for sin). I think that you can
exclude this for the versions provided in the CE standard library.

> - Is it possible to use the IoControl of the ISR to pass
> parameters/data FROM the IST?
> - Is it possible to use the IoControl of the ISR to pass
> parameters/data TO the IST (lpOutBuf in KernelLibIoControl)?

This is what the IoControl mechanism is meant for.
The only issue is that the memory should be caller allocated so, if
the library needs to return a variable-lenght structure you'll have
to "over-allocate" it to the maximum size or provide 2 IO control
codes: one to retrieve the data size and one to read the actual data
(or provide a mechanism to handle the return of the size if the
buffer is too small from a single Io control code).

> - I understand that the KLibAllocShareMem can be used to allocate
> a common buffer of ISR and IST but what is the parameter nPages
> defined - what if I would like to allocate e.g. 3000 bytes -what
> should nPages then be set to?

This depends on your hardware architecture. You can retrieve it
using the GetSystemInfo API (from an application or driver, not
inside the kernel lib).


--
Valter Minute
(the reply address of this message is invalid)
(l'indirizzo di reply di questo messaggio non è valido)

Re: Installable ISR - general questions by Ole

Ole
Thu Sep 28 06:55:25 CDT 2006

>> - I understand that the KLibAllocShareMem can be used to allocate
>> a common buffer of ISR and IST but what is the parameter nPages
>> defined - what if I would like to allocate e.g. 3000 bytes -what
>> should nPages then be set to?
>

"Valter Minute" <v_a_l_t_e_r.m_i_n_u_t_e@g_m_a_i_l.com> wrote in message
news:Xns984C788368602VALTERMINUTE@207.46.248.16...
> This depends on your hardware architecture. You can retrieve it
> using the GetSystemInfo API (from an application or driver, not
> inside the kernel lib).
>

OK thanks. If the page size is 4K and the granularity is 64K is it then
possible to allocate e.g. 3K for my buffer or will i have to allocate in
portion of 4K?

Thanks
Ole



Re: Installable ISR - general questions by Ole

Ole
Thu Sep 28 07:06:37 CDT 2006

On MSDN it says: "If the IsrHandler and IsrDll values are provided in the
device's registry key, then the driver should load the ISR DLL through the
LoadIntChainHandler call."
-Are there any other ways to load the installable ISR handler?

if so - then: if my ISR is the only one that uses e.g. irq 11 - will I then
have to use the chainhandler?

Thanks
Ole



Re: Installable ISR - general questions by Valter

Valter
Thu Sep 28 07:14:22 CDT 2006

"Ole" <ole@blabla.com> wrote in
news:uJy2GUv4GHA.772@TK2MSFTNGP02.phx.gbl:

[...]
> OK thanks. If the page size is 4K and the granularity is 64K is it
> then possible to allocate e.g. 3K for my buffer or will i have to
> allocate in portion of 4K?

The KLibAllocShareMem function requires the number of pages to be
allocated, so you'll need to allocate at least 4Kb.
If you need to allocate many small chunks of memory you may try to
implement an heap over a pool of pages allocate with that API but I
think that this effort is worth only if you've to allocate an amount of
blocks that you can't calculate in advance since this allocation policy
could be complex to debug and, with heap fragmentation, could lead to a
waste of memory in the long term bigger that the 1K every 4 you have
now.

--
Valter Minute
(the reply address of this message is invalid)
(l'indirizzo di reply di questo messaggio non è valido)

Re: Installable ISR - general questions by Valter

Valter
Thu Sep 28 07:22:59 CDT 2006

"Ole" <ole@blabla.com> wrote in
news:ObppXav4GHA.1460@TK2MSFTNGP05.phx.gbl:

> On MSDN it says: "If the IsrHandler and IsrDll values are provided
> in the device's registry key, then the driver should load the ISR
> DLL through the LoadIntChainHandler call."
> -Are there any other ways to load the installable ISR handler?

I don't undestand your question.
If you mean other ways than calling LoadIntChainHandler, I think
that the answer is not (or not in a simple and clean way).
If you mean if your driver has to handle those registry keys, you
can decide. If it's something you'll use only inside your products,
you may choose other ways to handle it. If it will be distributed to
other third parties developers choosing the "standard" approach will
made simpler for them to learn how to use your driver, IMHO.

> if so - then: if my ISR is the only one that uses e.g. irq 11 -
> will I then have to use the chainhandler?

No, you may change the BSP ISR routine to convert irq 11 to your
specific sysintr code. Some BSP have a more flexible mechanism that
allows you to request a sysintr for a specific IRQ via
KernelIoControl calls. If your BSP implements this mechanism I think
that using it is a good idea.
The installable ISR could be useful if your IST can't process the
IRQ fast enough. Using an installable ISR you can put some of the
processing inside the ISR routine (ex: adding an extra level of
buffering) and reducing the number of times that the IST is invoked.
Once again you don't need an installable ISR to do that. You can
modify your BSPs OEMInterruptHandler but if your BSP provides
support for loadable handlers, using them is a good way to have a
driver with few BSP dependencies that could be easily ported to
other architectures or integrated into other BSPs.

--
Valter Minute
(the reply address of this message is invalid)
(l'indirizzo di reply di questo messaggio non è valido)

Re: Installable ISR - general questions by Ole

Ole
Thu Sep 28 08:37:38 CDT 2006

> No, you may change the BSP ISR routine to convert irq 11 to your
> specific sysintr code. Some BSP have a more flexible mechanism that
> allows you to request a sysintr for a specific IRQ via
> KernelIoControl calls. If your BSP implements this mechanism I think
> that using it is a good idea.
> The installable ISR could be useful if your IST can't process the
> IRQ fast enough. Using an installable ISR you can put some of the
> processing inside the ISR routine (ex: adding an extra level of
> buffering) and reducing the number of times that the IST is invoked.
> Once again you don't need an installable ISR to do that. You can
> modify your BSPs OEMInterruptHandler but if your BSP provides
> support for loadable handlers, using them is a good way to have a
> driver with few BSP dependencies that could be easily ported to
> other architectures or integrated into other BSPs.
>

Ehh - OK - the interrupt structure and implementation in CE is hard for me
to understand - so please be patiented with me.
Cuurently I have implemented an IST in a dll that handles the interrupt from
IRQ 11, but the IST is called on every interrupt. The load on the system is
quite high and I would like to implement my code in an ISR directly, only
calling the IST when the buffer is ready to be emptied. Therefore I thought
that an installable ISR could be a solution, but I do not know anything
about it yet. From what you wrote I assume that there is a better and a more
direct/efficient way to do it - right? by reading about the
OEMInterruptHandler I understand that it is only used in systems with one
ISR like in ARMs (mine is a X86) so the other option you mention (loadable
handler - couldn't find any information on it) seems to be the one I should
use - right? please clarify to me how that method works and if possible
where to find further information.

Thank you for all your help - it is very usefull to me!

Best regard
Ole



Re: Installable ISR - general questions by Valter

Valter
Thu Sep 28 09:11:58 CDT 2006

"Ole" <ole@blabla.com> wrote in
news:#OXsONw4GHA.3600@TK2MSFTNGP03.phx.gbl:

[...]
> Ehh - OK - the interrupt structure and implementation in CE is
> hard for me to understand - so please be patiented with me.

I think that my poor english (I'm Italian) is another factor in
making this seem to complex.
In CE the interrupt is handled at 2 layers:
The ISR (Interrupt Service Routine) is called by the interrupt
handler (or handlers in the case of x86) installed by the OS.
It should "tranlate" the interrupt into a numeric value (the
SYSINTR). On some platforms (x86) this may be straightforward, on
other device this could mean interrogating internal or external
hardware (FPGAs) to understand what generated the interrupt.
Some SYSINTR codes have a special meaning for the OS. For example,
SYSINTR_RESCHEDULE tells the kernel that it should check if a thread
reschedule is needed or SYSINTR_NOP means that the interrupt has
been handled inside the ISR and so no other operation is needed by
the kernel and the OS irq handler should return ASAP.
The ISR it's part of the OAL, the part of the BSP that is linked
with the kernel (in CE 6.0 it will be a DLL) so changing the ISR
requires a rebuild of the kernel (and of the OS image, of course).
ISRs can hadle out interrupt they don't recognize to "external"
handlers using the NKCallIntChain kernel function. A BSP can skip
this call for some or all the interrupt and so the support for
external ISRs is not granted on every CE device.
The external ISR is implemented in a DLL that contains the ISR
routine (called via NkCallIntChain) and also other functions:
- one is called when the DLL is loaded (an application or driver
should call LoadIntChainHandler to do that)
- the other one is invoked when an application/driver (usually the
one who loaded the DLL inside the kernel) calls KernelIOControl,
providing a mean to exchangs informations between the
application/driver layer and the kernel layer.
The ISR function inside the DLL can return a specific SYSINTR,
meaning that it has recognized the interrupt, SYSINTR_NOP if it has
already completed the interrupt handling or SYSINTR_CHAIN to pass
the interrupt to the next installable ISR in chain (this is useful
for devices that shares an IRQ, for example PCI cards).
If the kernel receives a SYSINTR code back from the ISR that is
different than SYSINTR_NOP,SYSINTR_RESCHEDULE or SYSINTR_CHAIN, it
checks if an application has connected an event to that specific
SYSINTR using InterruptInitialize and set the event.
Usually the driver/application that invoked InterruptInitialize has
a thread stopped waiting for the event to be set. When the kernel
set the event two things may happen:
- the currently running thread has a priority lower than that the
thread waiting for the event (don't forget that 0 is the hightest
priority!) and so it suspend the current thread and restarts the one
that was waiting for the interrupt.
- if the currently running thread has an higher priority, it will
continue to run but the IST will be put back in running state and
will be schedule as soon as no other high-priority threads need the
CPU.

> Cuurently I have implemented an IST in a dll that handles the
> interrupt from IRQ 11, but the IST is called on every interrupt.
> The load on the system is quite high and I would like to implement
> my code in an ISR directly, only calling the IST when the buffer
> is ready to be emptied. Therefore I thought that an installable
> ISR could be a solution, but I do not know anything about it yet.

I hope that my explanation helped you to undertand it a little
more...

> From what you wrote I assume that there is a better and a more
> direct/efficient way to do it - right? by reading about the
> OEMInterruptHandler I understand that it is only used in systems
> with one ISR like in ARMs (mine is a X86) so the other option you
> mention (loadable handler - couldn't find any information on it)

Loadable and installable are the same thing, I forgot the term used
in PB docs and called it "loadable" because the function that loads
it is called "LoadIntChainHandler" and not Install... :)

OEMInterruptHandler is specific for the single interrupt vector
platform, on the x86 architecture HookInterrupt allows you to write
an interrupt handler and link it to a specific interrupt inside the
kernel, but the result doesn't change because you need to modify the
OAL to do that and also to add some codes to OEMIOControl inside the
BSP if you need to exchange some data between the kernel and the
high-level code.

IMHO installable handlers are the best option if your BSP support
them. You may loose a little bit of performance (the time needed to
call NKCallIntChain, I think not a noticeable overhead) but your
driver will remain independent from the rest of the BSP, making it
more portable and maintainable.

--
Valter Minute
(the reply address of this message is invalid)
(l'indirizzo di reply di questo messaggio non è valido)

Re: Installable ISR - general questions by Ole

Ole
Thu Sep 28 12:51:18 CDT 2006

Thanks a lot!

That explanation was really really great and helped me understand the
interrupt system much much better!
I will try to implement the Installable ISR in my system and'll let you know
the outcome.

Thanks
Ole



Re: Installable ISR - general questions by Ole

Ole
Thu Sep 28 13:42:19 CDT 2006

Had a look at the isr16550.c trying to learn something from it, but to me it
seems like it's not fully implemented (the ISRHandler simply check to see if
the InstanceIndex is OOK and then returns the ISR16550Handle for that
index - shouldn't it read the 16550 and fill a FIFO buffer etc?), so is it
the board manufacturer that supply it or is it Microsoft?

Are there any other examples to view?

Thanks
Ole