快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

金沙国际娱城app_酒文化网进入



近来在进修Windows Embedd CE 6.0和Windows桌面系统内部一些常识,这篇文章是对部分内核常识的收拾和总结,跟各位博客园的同伙分享。Windows Embedded CE 6.0是异常优秀的嵌入式系统(不是做广告哦^^),对其内核的进修对我们开拓、移植驱动和利用法度榜样,对开拓、移植嵌入式系统都异常有好处。最好的进修要领便是看源码啦,直接看源码有点艰苦,以是这篇文章便是帮你更好的看源码的。迎接各位园友的品评斧正。

1.Windows Embedded CE 6.0系统的一些关键特点

★32位多义务操作系统

★多义务抢占、硬实时

★支持的处置惩罚器体系布局:ARM, x86, SH4, MIPS

★组件化

★Based on Win32 API Set,桌面系统的一个扩展子集,跨越2000个函数可以应用。

★标准的Portable Executable(PE)文件款式

别的必要留意的是Platform Builder开拓对象集成的Visual Studio中,作为后者的一个插件。开拓Windows Mobile 6.x时应用的照样自力的Platform Builder for Windows Mobile,信托到Windows Mobile 7.0时会有所变更。

作为通用性桌面操作系统的Windows XP取得了伟大年夜的成功,关于其系统特点请看这。以是微软又推出了Windows XP Embedded。与Window XP Embedded必要借助第三方插件才能实实际时操作系统比拟,Windows Embedded CE 6.0是具有32 位本机实时支持的统一内核的。微软另一款具有本机实时支持统一内核的嵌入式操作系统是Windows Embedded NavReady。更多Windows Embedded系统看这里。

今朝Windows Embedded CE 6.0到今朝为止着末一次较大年夜更新为R2(2007年11月15日),其它小更新看这里。

2.系统架构

下图为Windows CE 5.0系统架构,与下下6.0的架构图比拟,我们发明:

(1).5.0时的NK.EXE被分为6.0的NK.EXE(交给OEM开拓)和Kernel.DLL(微软开拓)。

(2).驱动分成内核态和用户态。

(3).从图上看不出来的内存架构变更。

以下为Windows Embedded CE 6.0系统总架构:

以下为更具体的架构图,结合上图我们可以看到:

1.OEM商主要承担OAL模块(包括:NK.EXE和Bootloader)以及内核态驱动的开拓。

2.着实从现在的市场来看OEM商无意偶尔也会认真利用和用户态驱动的开拓。

注:ISV(Independent Software Vendors):自力软件开拓商。

对上图中的用户态进程进一步懂得:

Shell, provides the user with an interface to the objects necessary for running applications and managing the Windows Embedded CE operating system on a target device.

ServicesD.EXE is a process that supplements the Udevice.exe process. ServicesD.exe provides enhanced loading capabilities such as support for starting, pausing, and stopping services.

内核态进程及DLL

FILESYS.DLL, responsible for the initialization sequence, object store, registry, CEDB databases, device notifications and other miscellaneous tasks.

FSDMGR.DLL, esponsible for managing file systems, filters, and the storage manager.

GWES.DLL, Windows Embedded CE 6.0 combines the Microsoft Win32 application programming interface (API), user interface (UI), and graphics device interface (GDI) libraries into the Graphics, Windowing, and Events Subsystem (GWES) module. GWES is the interface between the user, your application, and the operating system (OS).

Networking DLLs, NDIS based networking services.

DEVMGR.DLL, the Device Manager is loaded by the kernel, it runs continuously, and it manages loaded device drivers and their interfaces. When the Device Manager loads, it also loads the I/O Resource Manager to read a list of available resources from the registry.

KITL.DLL is Optional.

K.COREDLL.DLL, DLL Kernel version of COREDLL.

KERNEL.DLL - The core operating system (OS) services consist of the Windows Embedded CE 6.0 kernel and other features common to all Windows Embedded CE 6.0 OS designs. Core OS services enable low-level tasks, such as process, thread, and memory management.

3.中断机制

下图为中断模型:

(1).设备提议一个硬件中断。->

(2).内核(Kernel.DLL)相应该中断,并call对应的中断办事例程(ISR)。->

(3).中断办事例程快速处置惩罚该中断。->

(4).驱动中的中断办事线程(IST)被看护处置惩罚该中断,这里内核应用Event看护IST。

这个历程中涉及到的ISR和IST都邑处置惩罚中断,但有所不合,前者的中断级别更高,所做的事情也很简单,而后者做主要的处置惩罚事情。详细请看以下的先容。

"Real-time applications use interrupts to respond to external events in a timely manner. To do this, Windows Embedded CE 6.0 breaks interrupt processing into two steps: an interrupt service routine (ISR) and an interrupt service thread (IST). The ISR runs immediately to identify and mask the interrupt, and perform any high priority tasks. The corresponding IST is a normal system thread (although typically of high priority) and can perform the bulk of the handling that is not time critical. This two stage model allows the operating system to maximize the amount of time the system is able to respond to other high priority interrupts.

The kernel is able to handle a total of 64 interrupts from external sources, some of which are predefined (e.g. system timer interrupt, real time clock etc). Devices that have more than 64 interrupt sources that need to be exposed (rare) must implement a mechanism to share interrupt identifiers. Typically this is done by multiplexing related interrupts together in the ISR, and demultiplexing them in the IST.”

关于中断在此就先容这么多,更具体的内容等我逐步消化了再先容。

4.线程、线程调整、线程同步

线程是被系统自力调整和分派的基础单位,当系统创建一个进程时,至少会存在一个线程(主线程)。以是进程可以被理解为一个壳子。关于线程更多基础常识在此略去。

以下为Windows Embedded CE 6.0的线程各优先级,0优先级最高,255优先级最低:

Priority

Component

0 - 96

Typically reserved for real-time drivers

97-152

Used by the default Windows Embedded CE–based device drivers

153-247

Typically reserved for non-real-time drivers

248-255

Mapped to other non-real-time priorities

利用法度榜样一样平常运行在248-255优先级,被创建的线程默认优先级为251。

别的我们要留意的一个很紧张问题是优先级反转(Priority Inversion)问题,比如现在有三个优先级不合的线程A、B、C, A的优先级最高,B次之,C最低。此中A和C必要的资本部分相同。处置惩罚器当前履行线程C,比C优先级更高的B有可能打断C而进入运行状态,这样C占领的资本什么时刻开释便是一个未知的光阴。A只有在C开释了它所必要的资本后才能被调整,A被壅闭的光阴也是未知的。这样,低优先级的B先于高优先级的A被调整,优先级发生了逆转。

这个问题在XP里面不是一个严重的问题,最多A被多壅闭了一段光阴。然则,在实时系统里面,分外是硬实时系统里是个很严重的问题。这个问题的办理措施一样平常有两种,Windows Embedded CE 6.0采纳的后一种措施,从下面的图可以看出优先级反转是如何的。

"Single Leve金沙国际娱城appl and Fully Nested. In the Fully Nested Mode the OS will walk through all threads blocked and keep boosting each one until the high priority thread can run. This prevents an entire class of deadlocks. Unfortunately it also means an O(n) operation with pre-emption turned off while the scheduler figures out how to get everything unblocked to keep things going. This is a major problem for real-time systems that need deterministic response times.

In order to support hard real-time systems WindowsCE 6.0 uses a single level handling of priority inversion. That is the OS will boost only one thread to release a block. In this scenario the OS will boost the priority of the low priority thread to the priority of the high priority thread until it is able to release needed resource. This is It is therefore the responsibility of the developer to structure code such that deadlocks are avoided. “

更多相关常识请看维基和Embedded网站。

线程相关API

CeSetThreadPriority/CeGetThreadPriority在CE中可以造访全部256个优先级。

SetThreadPriority/GetThreadPriority是遗留下来的函数,在新版本CE系统中仍旧可以应用,然则只能造访最低的8个优先级(248-255)。

Sleep(n)至少挂起n毫秒。

Sleep(0)放弃光阴片,履行其它线程。

SleepTillTick挂起线程直到下一次系统tick。

WaitForSingleObject壅闭直到指定的内查工具被置为有旌旗灯号状态。

WaitForMultipleObjects壅闭直到指定的内查工具集(大年夜于即是1)被置为有旌旗灯号状态。

线程同步

被用于线程同步的工具有很多种:临界区(Critical Setions)、互斥体(Mutexes)、旌旗灯号量(Semaphores)、事故(Events)、Interlocked Fuctions,这里对此进行简单的先容,关于更具体的资料(比如临界区和互斥体的本色差别以及机能对照)请从收集上查阅,比如这里。

在CE 6.0系统中每个同步工具都有自己自力的名字空间,比如一个空字符串"”被作为一个名字工具处置惩罚。在桌面系统中所有同步工具是共享名字的空间的。

1.Critical Sections

应用临界区的好处是,当你必要的资本不被其它线程竞争时是不会进入内核的,以是在同个进程里,并且很少的资本竞争存在时,应用临界区会更好。

InitializeCriticalSection初始化临界区数据布局。

EnterCriticalSection 线程会壅闭不停到取得临界区的所有权。

TryEnterCriticalSection 考试测验取得临界区的所有权,不会造成线程壅闭,假如当前竞争存在将会掉败。

LeaveCriticalSection 开释临界区的所有权。

DeleteCriticalSection 清理资本。

2.Mutexes

CreateMutex 创建命名的或未命名的互斥体工具。

A handle to the mutex object indicates success. If the named mutex object existed before the function call, the function returns a handle to the existing object, and GetLastError returns ERROR_ALREADY_EXISTS. Otherwise, the caller created the mutex.

NULL indicates failure. To get extended error information, call GetLastError.

Non-blocking with return status for already exists or abandoned.

WaitForSingleObject/WaitForMultipleObjects Calls blocked until current owner releases specified mutex object. Calls non-blocking while waiting for a mutex object it already owns.

ReleaseMutex Called once per call returned from Wait function. Abandoned state if not called before owner thread termina金沙国际娱城apptes.

CloseHandle Releases and Destroys mutex object upon last handle close.

3.Semaphores

CreateSemaphore Creates named or unnamed semaphore object if it doesn’t already exist.

WaitForSingleObject/WaitForMultipleObjects Calls blocked until semaphore count is non-zero. Semaphore count decreased when wait succeeds.

ReleaseSemaphore Increments semaphore count by specified amount.

CloseHandle Destroys a semaphore object upon closing its last handle.

4.Manual Events

Signaled with SetEvent. Kernel releases all waiting threads. Kernel releases all subsequently waiting threads. Must explicitly set to non-signaled with ResetEvent.

Signaled with PulseEvent. Kernel releases all waiting threads. Kernel automatically transitions event to non-signaled.

5.Autoreset Events

Signaled with SetEvent. Kernel releases a single waiting thread. Other waiting threads remain blocked. Kernel automatically transitions event to non-signaled. Event remains signaled until a single thread is released.

Signaled with PulseEvent. Kernel releases at most one waiting thread. Kernel automatically transitions event to non-signaled. Even if no thread has been released.

6.Interlocked Functions

办理对资本的原子拜拜访题。

The interlocked functions allow a thread to safely perform a read/modify/write sequence on 32 bit aligned shared data without disabling interrupts or incurring the overhead of a kernel call. The interlocked functions are the most efficient mechanism for safely performing this t金沙国际娱城appype of access. The kernel implements this functionality by restarting the function call if it is interrupted by an interrupt or data abort before completing.

InterlockedIncrement Increment a shared variable and check resulting value.

InterlockedDecrement Decrement shared variable and check resulting value.

InterlockedExchange Exchange values of specified variables.

InterlockedTestExchange Exchange values 金沙国际娱城appwhen a variable matches.

InterlockedCompareE金沙国际娱城appxchange Atomic exchange based on compare.

InterlockedCompareExchangePointer Exchange values on atomic compare.

InterlockedExchangePointer Atomic exchange of a pair of values.

InterlockedExchangeAdd Atomic increment of an Addend variable.

下一篇将涉及到内存构架方面常识。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: