OEM adaptation layer programming in Wince OAL

xiaoxiao2021-03-06  39

Author: Fu Linlin Source: NEW YORK

For example, CE's help documentation, creating OAL is a very complex task, and the usual way is to copy the original identical platform OAL code and then modify to adapt to the platform's special requirements. That is to say, for a platform without special requirements, copy the OAL code of the original same platform is sufficient. Due to the complexity of OAL in this article I only explain the commonly used part. First, the Concept of implementing ISR 1. ISR isR (Interrupt Service Routine) is a program that handles IRQS (Interrupt Request Line). Windows CE uses an ISR to process all IRQ requests. When an interrupt occurs, the kernel's exception handler first calls the kernel ISR, the kernel ISR disables all interrupts with the same priority and lower priority, then call the registered OAL ISR program, general ISR has the following features: 1) Execute The smallest interrupt processing, the smallest interrupt processing refers to the hardware that can be checked, reply to the hardware that generates an interrupt, and leaves more processing to IST (Interrupt Service Thread). 2) Returns the interrupt ID when the ISR is completed (most of the interrupt ID is predefined). 2. The ISR structure X86 platform of the X86 platform is saved in% _winceroot% / public / common / Oak / CSP / I486 / OAL / FWPC.C, the function is called Perpisr. Let's analyze the main code of this function:

Ulong perpisr (void) {ulong ulret = sysintr_nop; /// return value, interrupt ID (in sysintr_ is prefixed) uchar ucrrentinterRupt; // /////fintime) // FINTRTIME is used to test SR and IST Delay time, test tools are iltiming.exe. ... uccurrentinterRupt = PicgetCurrentInterRupt (); Return the current interrupt IRQ if (uccurrentinterrupt == IRQ0, IRQ0 is interrupted by system Tick, specifically "second, realizing system clock" ... ... if (dwrebootaddress) needs to restart reboothldler (); ... if (uccurrentinterrupt == INTR_RTC) IRQ8, Real-Time Clock interrupt ... Else If (uccurrentinterrupt <= INTR_MAXIMUM) /// If the interrupt is smaller than INTR_MAXIMUM {ulret = nkcallintchain (UCCURRENTERRUPT); calling the interrupt chain if (ulret == sysintr_chain) /// If the interrupt chain does not include interrupt ulret = OEMTRANSLATEIRQ (UCCurrentInterrupt); convert between IRQ and SysIntr The function returns the sysintr ...... PicenableInterrupt (UccurrentInterrupt, false); /// enabling all interrupts other than the current interrupt} ///}} o oDicateintSource (ULRET); // Notification The kernel has occurred }

It is not difficult to see the above code to see the ISR's task is to return an interrupt ID with "sysintr_" as a prefix. If you don't need to further execute IST, then returns SysInTr_nop. 3. Interrupt registration steps

Refer to the code of the X86 platform, the interrupt registration steps are as follows:

1) Use setup_interrupt_map macro to the SysIntr and IRQ. The constant prefixed with "sysintr_" is used by the kernel, and the hardware used to uniquely identify the interrupt. Predetermined some sysintrs in nkintr.h files, OEM can customize SysIntr.h files in oalintr.h files.

2) Use the hookinterrupt function to associate the hardware interrupt number and ISR. The hardware here is the physical interrupt number, not the logical interrupt number IRQ. The hookinterrupt function is called at the initpics function (and the above ISR located in the same file), as follows:

For (i = 64; i <80; i ) hookinterrupt (i, (void *) perpisr); // uses ISR associated 16 interrupt numbers

4. Interrupt Process Steps

1) Call the InterruptInitialize function to associate SysIntr and IST, which is specific to the IST wait event. Generally prepared as follows in the driver:

HEVENT = CREATEEVENT (...) // Create an event object Interruptinitialize (sysintr_serial, hever, ...) /// Associate a serial interrupt ID and this event hthd = CreateThread (..., myistroutine, hevert, .. .) // Create a thread (IST) CESETTHREADPRIORITY (HTHD, 152); // / / Improve the priority of this thread

2) IST executes I / O operation, general IST is written as follows:

FOR (;;) /// The driver has been in service status {WaitForsingleObject (HEVENT, Infinite); unlimited wait event ... I / O operation interruptdone (interruptid); /// End Current interrupt processing}

3) Data transmission between ISR and IST

If we want to read data frequently from a device, each read is very small, then call IST each time you read will reduce performance. As a solution, ISR can read operation (stored into buffers) and read by IST to buffer after the buffer is stored. Because ISR runs in kernel mode and IST runs in user mode, IST does not easily access the ISR buffer, providing a way for this CE (see the title "Passing Data Between An isr and anly" help documentation), you Can also

The Anniversary Network Embedded Development Forum inquiry.

Second, realize system clock

1. System Tick Concept

The system clock is the only interrupt (IRQ0) required by the kernel. The system clock generates an interrupt every millisecond. When an interrupt occurs, the core is accumulated in the ISR, and the multiple of 1000 is a second. In the ISR of the processing system clock, not only the count is required, but also decide whether the kernel is notified to start re-scheduled all the current threads. To achieve an OAL, the system clock is the first thing to do.

2. The processing of the X86 platform system clock interrupt work system clock is responsible for initialization by the initclock function, usually calls in the Oeminit function. When an interruption occurs, the ISR first counts the following statement:

Curmsec = system_tick_ms; / system_tick_ms = 1

Then determine what the value should be returned according to the following statement:

IF ((int) (dwreschedtime - curmsec)> = 0) Return SysIntr_resched; /// Re-scheduled Else Return SysIntr_nop; /// No longer performs any operation of the global variable DWRESCHEDTIME in SCHEDULE.C, that is, The scheduling module of the kernel decides when to start a re-scheduled thread. Curmsec has accumulated how many System Ticks have been generated from Windowsce to the current total. Implement the system clock, you have to implement an OEMIdle function. When there is no thread to prepare the runtime, the OEMIdle function places the CPU in idle mode, but still has to accumulate system clock in idle mode.

Third, I / O control code

1. I / O control code role

Application software or driver can call the KernelioControl function to communicate with the OAL layer, and KernelioControl calls the Oemiocontrol function internally. OemioControl is an OAL API, OEM can write your own I / O control code in OemioControl, or communicate with application software. An example of the I / O control code is used to restart the computer, obtain the system information, set the RTC to obtain the device ID, etc. There are also some special I / O control code used by the system program. Here, it explains that I have confirmed that the device ID method provided by CE is not effective.

2. Write your own I / O control code steps

1) In pkfuncs.h or newly prepared. In the file, in the format:

#define ioctl_my_control ctl_code (file_device_hal, 3000, method_neither, file_any_access)

2) Modify the OEMIOCONTROL function in OemiOctl.c, add the following code:

Case IOCTL_MY_CONTROL: ......

3) Call the kernelioControl function in the application, and see the help documentation in the specific parameters. Conclusion: OAL All interface functions and global variables See the Help documentation titled "Supported OAL APIS". Previous article "Encrypted Windows CE System" introduced OEMLOADINIT_T POEMLOADINIT and OEMLOADMODULE_T POEMLOADULE are global variables used to create trusted environments, and we can assign the function address to both variables after writing a function. OAL is indeed complicated. When we actually need it, we will specify some part because it is the most efficient research. I hope that these two articles will be able to throw bricks, let developers who are more familiar with OAL can disclose their research results, share with you.

Pay Lin Lin:

2001 computer majors graduated. From graduation, we have been engaged in software development work. Currently engaged in operating system core customization and application development under Windows CE. Some experiences developed under CE were accumulated in actual work. I hope to communicate with the developers under CE, and I hope that you can enlighten me. My email: windowsce@tom.com If you have a technical issue, please visit the Yeodend Network Embedded Development Forum, I will reply to your question in this forum. The exchange will be more convenient in the forum, and other netizens can answer the participation and make up for my shortcomings.

转载请注明原文地址:https://www.9cbs.com/read-62538.html

New Post(0)