windows ce学习笔记

WINDOWS CE体系结构图:
名词:
OALOEM(原始设备制造商) adaptation layer 
OAL MigrationOAL的移植合并
boot loader:系统最初的启动
ActiveSync:是WinCE/Windows Mobile设备和PC同步的软件
SDK:software development kit.
 
GWES:The Shell and User Interface functionality in Microsoft? Windows? CE 5.0 includes the parts of the Graphics, Windowing, and Events Subsystem (GWES) that are included in all display-based OS designs by default. GWES is the interface between the user, your application, and the operating system (OS).
 
1:BSP的作用:The BSP creation process for Windows Mobile 5.0 involves the following tasks: 
Developing a loader that conforms to the new Image Update model 
Developing an OAL 
Developing device drivers 
Modifying run-time image configuration files 
A board support package (BSP) is the common name for all board hardware-specific code. It typically consists of the following: 
The boot loader 
The OEM adaptation layer (OAL) 
Board-specific device drivers 
BSP是介于主板硬件和操作系统之间的一层,也可以说是操作系统的一部分。Windows CE中的BSP无论是结构还是功能与OEM都是一致的,为了方便,也可把Windows CE中的OEM层和BSP作为同一个概念来理解。
 
2:design template 
A pre-defined selection of operating system (OS) components that Microsoft provides for a category of target devices. A design template is a starting point. When saved or modified, the design template becomes an OS design. 
 
3:OS design 
A selection of Catalog items that defines the characteristics of an OS. You can begin an OS design with or without a design template. An OS design corresponds to a set of Sysgen variables. 
 
4:run-time image 
Software to deploy on a target device, or the same software running on a target device. A run-time image contains the OS and associated software. 
target device, Windows CE–based device 
An instance of a hardware architecture or an instance of a combined hardware and software architecture. 
 
5:内核模式中断服务例程 (ISR) 和用户模式中断服务线程 (IST)
6:NT/2000/XP从安全性、可靠性、稳定性上考虑,应用程序和操作系统是分开的,操作系统代码运行在核心态,有权访问系统数据和硬件,能执行特权指令;应用程序运行在用户态,能够使用的接口和访问系统数据的权限都受到严格限制;
7:通过DeviceManager为应用程序和驱动程序暴露设备接口的方法:
The following list shows the ways you can expose device interfaces to applications and drivers through Device Manager: 
You can define the interface in the IClass value of the registry key used to activate the device. 
You can define the IClass value in the Active key by a device driver's Init function. 
You can define the IClass value in the REGINI parameter to ActivateDeviceEx. 
Defining the value requires advance access to the instance information for the driver that is about to be loaded. It also requires that the driver make statements concerning that driver's ability to conform to some interface. 
 
You can explicitly call AdvertiseInterface for the interfaces that your driver supports.
 
8: GUIDs and UUIDs:
The globally unique identifier (GUID) is also known as the universally unique identifier (UUID). The GUID, or UUID, is a unique, 128-bit value used to identify objects. 
Objects — such as OLE servers, interfaces, manager entry-point vectors, and client objects — are each assigned a GUID or UUID. Thereafter, the object is identified by that value.
Typically, the GUID or UUID is represented as a string of hexadecimal numbers with the following format: 
{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx} 
For example, {4208fb66-e22a-11d1-a7d7-00a0c982c00d}.
Microsoft has defined the following structure as a container for the 16 bytes that are required by a UUID or by a /GUID.
typedef struct _GUID
{
  DWORD Data1;
  WORD Data2;
  WORD Data3;
  BYTE Data4[8];
} GUID;
You can use the GUIDGEN tool to create a GUID. GUIDGEN.exe is in the %_WINCEROOT%\Sdk\Bin\i386 directory.
You can dynamically generate a GUID on a device that supports COM. To do so, call CoCreateGuid. 
 
9:IClass(Interface Class):IClass是一个128位的GUID,用来描述设备的某种能力。通常IClass有两个作用:1:用来告诉应用程序设备具有哪些能力2:通知应用程序自己已经就绪。一个设备可以公开多个IClass,也可以一个IClass都不公开。
10:操作系统层:
10.1系统调用与CoreDll.DLLCoreDLL.DLL不是一个单独的进程,它是一个会被所有用户进程都加载的动态链接库。所有的应用程序都不能与操作系统或硬件打交道,如应用程序希望访问Windows CE所提供的服务,那么只能通过CourDLL.DLL进行。CoreDLL.DLL的主要功能是负责应用程序与Windows CE通信以及完成Windows CE的系统调用。
11At a minimum, a Windows CE OS design contains the following elements: 
Run-time image 
OEM adaptation layer (OAL) 
Device drivers 
Configuration files 
 

GetCurrentPermissions

This function obtains the kernel's internal thread permissions bitmask for the current thread.
DWORD GetCurrentPermissions (void); 
Parameters
None.
Return Values
The returned DWORD specifies the thread permissions.

 

SetProcPermissions

This function sets the internal permissions bitmask for the current thread, thereby enabling access to the address space of another process.
DWORD SetProcPermissions(
  DWORD newperms 
);
Parameters
newperms 
[in] Bitmask specifying the new permissions. Use the value 0xFFFFFFFF to set access rights to the whole system; otherwise, use the values returned by GetCurrentPermissions. 
Return Values
The returned DWORD specifies the old permissions.

InterlockedIncrement

This function both increments (increases by one) the value of the specified 32-bit variable and checks the resulting value. InterlockedIncrement prevents more than one thread from using the InterlockedDecrement function or InterlockedIncrement function to access the same variable simultaneously. 
LONG InterlockedIncrement( 
  LPLONG lpAddend 
); 
Parameters
lpAddend 
[in] Pointer to the LONG variable to increment. 
Return Values
The return value is the resulting incremented value. 
 

ActivateDeviceEx

This function loads a driver and adds its registry values to the Active key in the registry.

HANDLE ActivateDeviceEx(
  LPCWSTR lpszDevKey, 
  LPCVOID lpRegEnts, 
  DWORD cRegEnts, 
  LPVOID lpvParam
);

Parameters

lpszDevKey

[in] Pointer to a string containing the registry path of the device driver's registry key. This key contains the driver's DLL name, prefix, and other data. For information about the subkeys of the HKEY_LOCAL_MACHINE\Drivers\Active registry key, see Device Manager Registry Keys.

lpRegEnts

[in] Pointer to an array of REGINI structures, each of which defines a registry value to add to the device's Active registry key before its driver is loaded. Set to NULL unless it is for a bus driver.

cRegEnts

[in] Count of the number of REGINI structures to which lpRegEnts points. This affects a generalization of the ActivateDevice function.

lpvParam

[in] Opaque pointer to a driver-specific data structure. You can use it to pass parameters to the loaded driver without having to write them through the registry. lpvParam is passed to the XXX_Init function as a second parameter. lpvParam can be used by bus drivers to pass bus-specific information, entry points, or both to loaded drivers. Using this parameter prevents clients of that bus from becoming bus-agnostic. This is acceptable for some busses, especially those whose drivers cannot become bus-agnostic.

REGINI

This structure passes additional registry settings to ActivateDeviceEx before the driver is loaded.

typedef struct _REGINI {
  LPCWSTR lpszVal;
  LPBYTE pData;
  DWORD dwLen;
  DWORD dwType;
} REGINI;

Members

lpszVal

Name of a value to add to the device instance key.

pData

Pointer to the data to add as the value.

dwLen

Length of the data referenced by pData.

dwType

Registry type of the named value.

 

XXX_PreClose (Device Manager)

This function notifies the driver to mark the closing handle as invalid and to wake any sleeping threads.

BOOL XXX_PreClose(
  DWORD hOpenContext 
);

Parameters

hDeviceContext

[in] Handle to the device context. The XXX_Init (Device Manager) function creates and returns this identifier.

 

 

Windows CE 嵌入式系统

2章 Windows CE 的体系结构和功能

v      Windows CE中,进程本身不参与系统的调度,也没有优先级和上下文。真正参加系统调用的是线程。每个进程在创建的时候都会创建一个主线程作为该进程默认的执行体。从某种意义上说,进程只是线程的容器。
v      Windows CE最多只支持32个进程同时运行。每个进程占据32MB的虚地址空间。创建复杂的应用程序的时候,应尽量选择多线程而不是多进程。
v      Windows CE的进程不支持环境变量和当前目录。
v      应用程序可使用CreateProcess()创建一个进程,使进程终止的最佳方法是从WinMain()函数返回。当然,也可调用ExitThread()函数使进程的主线程退出从而终止进程。此外,Windows CE还提供了ExitProcess()TerminateProcess()函数用来使进程终止。

线程:

v     线程除了占有内存之外,还占有其它资源,例如处理器的寄存器和,每个线程都有自己独立的。这些资源构成了线程的上下文。

v     线程可运行在核心态或用户态。在核心态,线程可访问操作系统所有的资源。一般来说,操作系统线程和ISR运行在核心态,应用程序和设备驱动程序的中段服务线程(IST)运行在用户态。Windows CE允许所有的线程都运行在核心态下,这被称作“Full Kernel Mode”。尽管这样做会导致整个系统不稳定,但是这样也可以提高系统的效率。

 

v     Windows CE提供了一系列函数,使线程可以等待,然后得到这些同步对象,这些函数称为等待函数。最常用的等待函数有两个,它们的函数原型如下:

DWORD WaitForSingleObject( 
  HANDLE hHandle, //同步对象的句柄
  DWORD dwMilliseconds  //等待的ms
);
DWORD WaitForMultipleObjects(
  DWORD nCount, 
  CONST HANDLE* lpHandles, 
  BOOL fWaitAll, 
  DWORD dwMilliseconds 
);

其中WaitForSingleObject()用来等待单个同步对象;WaitForMultipleObjects()用来等待多个同步对象。

v     线程同步的内核机制:

?      Mutex(互斥)

创建一个Mutex同步对象:HANDLE CreateMutex();释放对Mutex的占有

?      Semaphore

Semaphore中文通常译为信标或者信号灯。通常可把Semaphore理解成是带有引用计数的Mutex。如果一个Semaphore带有计数n,这表示同时最多可以有n线程占有Semaphore。当n线程占有了Semaphore后,其他希望占有该Semaphore的线程才会进入等待状态。

如果某些资源同时只能被固定数量的线程使用,那么应该先用Semaphore对它进行同步。相关函数:HANDLE CreateSemaphore();BOOL ReleaseSemaphore();

?      Event

如果一个线程需要通知其他线程某个事件发生了,那么可使用事件Event同步对象。事件是用得比较广泛的同步对象。

This function creates a named or an unnamed event object.

HANDLE CreateEvent(
  LPSECURITY_ATTRIBUTES lpEventAttributes, 
  BOOL bManualReset, 
  BOOL bInitialState, 
  LPTSTR lpName 
); 

Parameters

lpEventAttributes

[in] Ignored. Must be NULL.

bManualReset

[in] Boolean that specifies whether a manual-reset or auto-reset event object is created. If TRUE, then you must use the ResetEvent function to manually reset the state to nonsignaled. If FALSE, the system automatically resets the state to nonsignaled after a single waiting thread has been released.

bInitialState

[in] Boolean that specifies the initial state of the event object. If TRUE, the initial state is signaled; otherwise, it is nonsignaled.

lpName

[in] Pointer to a null-terminated string that specifies the name of the event object. The name is limited to MAX_PATH characters and can contain any character except the backslash path-separator character (\). Name comparison is case sensitive.

If lpName matches the name of an existing named event object, the bManualReset and bInitialState parameters are ignored because they have already been set by the creation process.

If lpName is NULL, the event object is created without a name.

If lpName matches the name of an existing semaphore, mutex, or file-mapping object, the function fails and the GetLastError function returns ERROR_INVALID_HANDLE. This occurs because these objects share the same name space.

Return Values

A handle to the event object indicates success. If the named event object existed before the function call, the function returns a handle to the existing object and GetLastError returns ERROR_ALREADY_EXISTS. NULL indicates failure. To get extended error information, call GetLastError.

This function sets the state of the specified event object to nonsignaled.

BOOL ResetEvent( 
  HANDLE hEvent 
); 

Parameters

hEvent

[in] Handle to the event object. The CreateEvent function returns this handle.

Return Values

Nonzero indicates success. Zero indicates failure. To get extended error information, call GetLastError.

关于RAM

       RAMWinCE 系统中被分为两个区域:第一个是程序的存储区(program memory),也叫做系统堆(system heap)。第二个是对象存储区(object store)。这个对象存储区有点像一个永久的虚拟RAM磁盘。不同于PC上的旧式的虚拟RAM磁盘,对象存储区保留存储的文件甚至当系统被关闭以后。(脚注)这种安排的原因是WinCE 系统,例如Pocket PC代表性地具有一个主电池和一个备用电池。当用户更换主电池的时候,备用电池的工作是提供电源给RAM以便维持文件在对象存储区的存储。当用户按了重启键之后,WinCE核心就开始寻找在关闭系统前建立的对象存储区,如果找到的话就将继续使用它。

       RAM中的另一个区域则用作程序存储区。程序存储区有点像个人电脑中的RAM,它为正在运行的应用程序保存堆和的内容。在对象存储区和程序存储区之间的分界线是可以通过移动它来改变的,用户可以在控制面板中找到改变这条分界线的设置。在可用内存降低的(low-memory)条件下,系统将会弹出对话框询问用户是否要将对象存储区RAM划分一些给程序存储区RAM以满足要运行的应用程序的需求。

 

posted on 2008-01-19 11:11  山本二十八  阅读(2495)  评论(0编辑  收藏  举报

导航