Upload
others
View
2
Download
0
Embed Size (px)
Citation preview
Windows CE.Net 1
Windows CEDevice Driver
Windows CE.Net 2
강의 내용
Device Driver 구조
Device Driver 개발 실습 #1
Windows CE.Net 3
Device Driver 구조
Device Driver Overview
Built-in Device Driver vs Installable Device Driver
Native Interface Device Driver vs Stream Interface Device Driver
Stream Interface Device Driver
Device Driver Loading
Windows CE.Net 4
Device Driver Overview
다른 운영체제들과 마찬가지로 Windows CE도 하드웨어 장치를 관리하고 운영하기 위한 Device Driver라고 불리는 소프트웨어를 필요
Device Driver는 운영체제와 디바이스를 연결하여 운영체제가디바이스를 인식하고 디바이스가 제공하는 기능을 어플리케이션이 사용할 수 있도록 함.
Windows CE에서 대개의 경우 Device Driver는 DLL (Dynamic-link library) 형식을 가지며, 기능 접근을 위해서Win32 API를 사용한다.
Windows CE.Net 5
Stream Interface
Stream- Interface Driver
Card and Socket Services
Device ManagerStream Interface
(DDI)
MDD
Layer Native Driver
Device Driver Service-Provider Interface (DDSI)
PDD
Stream Interface
NDIS
Card and Socket Services
NDIS Wrapper
NDIS
Miniport
NDIS Wrapper
Stream Interface
USBD
HCD
USB Interface
USB Driver
Device Driver Interface(DDI)
Monolithic Native Driver
Graphics, Windowing, and Events Subsystem (GWES)
Device Driver Interface(DDI)
MDD
Layerd Native Driver
Device Driver Service-Provider Interface(DDSI)
PDD
The DDIInterface of nativeDrivers is definedby Microsoft for Each device class
Windows CE.Net 6
Device Manager
“Device.exe” – 장치관리자 프로세스
Kernel에 의해 실행 되는 user-level 프로세스[HKEY_LOCAL_MACHINE\init]
“Launch20”=“Device.exe”
디바이스 드라이버를 찾는 검색 루틴인 Regenum.dll을 호출
스트림 인터페이스 드라이브 등록 함수를 호출하여 디바이스 드라이브 등록
RegisterDevice() / ActivateDevice() / ActivateDeviceEX()
스트림 인터페이스 드라이브 등록 해제 함수를 호출하여 드라이브 제거
DeregisterDevice() / DeactivateDevice()
Windows CE.Net 7
Built-in Device Driver vs Installable Device Driver
Built-in Device Driver
하드웨어 플랫폼에 내장된 장치에 대해 OEM에 의해 기본적으로 제공되는 드라이버
디스플레이 / PC Card / USB 컨트롤러
Installable Device Driver
Third Party가 공급
CE 장치의 최종 사용자가 하드웨어 소켓을 통해 언제든지설치 가능한 장치를 지원
프린터나 PC Card 장치
Windows CE.Net 8
Native Interface Device Driver vs Stream Interface Device Driver
Native Interface Device DriverBuilt-In Device Driver
OS에 필수적인 Device Driver
GWES.exe에 의해 로딩 및 관리GWES.exe 프로세스 문맥하에서 동작
GWES.exe는 드라이버를 시스템이 부트 될 때 로드
Display, Keyboard, Mouse, Touch driver, battery, Notification LED
Stream Interface Device DriverApplication에서 Driver를 file처럼 다룬다.
DEVICE.exe (Device Manager)에 의해 로딩 및 관리DEVICE.exe 프로세스 문맥하에서 동작
DEVICE.exe 는 드라이버를 부트 시에 로드
부팅된 후에는 모든 프로세스가 stream interface driver를 로드 가능
Serial, Block, Audio driver
Windows CE.Net 9
Bus Interface Device Driver
Bus Interface Device DriverWindows CE가 지원하는 특정 버스에 대하 서비스 드라이버
응용 프로그램에게 서비스를 제공하는 것이 아니라 클라이언트 디바이스 드라이버에게 서비스를 제공
예 : Serial driver가 USB 버스 또는 1394 버스를 사용하는 경우USB 버스 드라이버가 serial driver에게 서비스를 제공 USB-serial driver
1394 버스 드라이버가 serial driver에 서비스를 제공 1394-serial driver
DEVICE.exe 프로세스에 의해 로딩 및 관리스트림 인터페이스 드라이버와 같은 프로세스 문맥하에 동작
종류 :REGENUM.dll(Legacy BUS)
PCI.dll(CPI BUS)
USBD.dll(USB BUS)
PCMCIA.dll(PCMCIA BUS)
Windows CE.Net 10
Monolithic Device Driver vsLayered Device Driver (1)
Layered Device Driver
드라이버 기능을 계층화하여 구현상위 계층 – MDD(Model Device Driver)
하위 계층 – PDD(Platform Dependent Driver)
MDD(Model Device Driver)디바이스 드라이버의 공통된 코드 부분 해당
응용 프로그램과의 인터페이스를 지원
DDI(Device Driver Interface) 지원
native interface 또는 stream interface를 제공
소스, 정적 라이브러리(lib) 또는 DLL 형식으로 제공
PDD(Platform Dependent Driver)특정 하드웨어에 맞추어 작성된 코드 부분 해당
하드웨어에 대해 직접적으로 입출력 또는 제어
MDD와의 인터페이스 지원 – DDSI(Device Driver Service Provider
Interface)
Windows CE.Net 11
Monolithic Device Driver vsLayered Device Driver (2)
Layered Device Driver (con’t)Windows CE Platform Builder에 포함된 많은 드라이버들이Layered Driver 형식을 가짐
$(_PUBLICROOT)/COMMON/OAK/DRIVERS 폴더
MDD는 이미 작성된 것을 적용함으로써 하드웨어와 관련된 사항(PDD)만을 구현하면 되므로 드라이버 개발 부담이 줄어듬
Monolithic Device Driver
동작과 관련된 인터페이스를 직접 구현
불필요한 call을 하지 않아 효율이 좋다
Interrupt service thread code, platform에 한정된 code
Windows CE.Net 12
Monolithic Device Driver vsLayered Device Driver (3)
Miniport Device Driver
Layered device driver 유형
MDD가 정형화된 드라이버 형태(DLL)로 제공
디바이스 드라이버로서의 DDI를 지원
PDD
하드웨어를 직접 제어하는 부분을 DLL로 구현
MDD dll이 직접 로딩하여 접근
이런 유형의 PDD를 미니포트 드라이브(Miniport Device Driver)라고 한다
Windows CE.Net 13
Monolithic Device Driver vs Layered Device Driver (4)
GWES(Graphics, Windowing, and Events Subsystem)
MDD
Hardware
Monolithic Device Drivers
Layered Device Drivers
PDDDDSI functions
DDI functions DDI functions
Windows CE.Net 14
Stream Interface Device Driver (1)
Stream Interface
I/O 장치를 하나의 파일로 간주하여 접근할 수 있도록 지원하는 인터페이스 방식
연속적인 데이터 전송을 지원하는 I/O 장치에 적합
장치 종류(ex: usb, ethernet)에 상관없는 일관된 인터페이스를 제공디바이스 드라이버 개발이 용이
인터페이스 함수가 File system Win32 API와 매칭CreateFile(), CloseHandle(), ReadFile(), WriteFile(), SetFilePointer(), DeviceIOControl() 등
응용 프로그램에서 입출력 기능 구현이 용이
Windows CE.Net 15
Stream Interface Device Driver (2)
Stream Interface Device Driver 요건
디바이스 드라이버 이름 지정Prefix(예, ‘COM1') 세 자리 문자 + Index 한 자리 숫자
Prefix와 Index는 레지스트리(Registry)에 저장
Windows CE에서는 드라이버 이름 뒤에 ‘:’을 항상 붙인다
디바이스 드라이버로서의 시스템 레지스트리가 필요디바이스 드리이버 이름 및 드라이버 파일명
인터페이스 GUID 등
DLL 형식으로 작성하며, DDI 함수를 반드시 구현
DDI와 관련된 모든 함수는 export하여야 함(DEF 파일 사용)
DEVICE.exe 프로세스에 의해 로딩되어 이 프로세스 문맥하에 동작
Windows CE.Net 16
Stream Interface Device Driver (3)
10개의 스트림 인터페이스 함수를 기본적으로 제공
xxx는 디바이스의 Prefix(예, Block 드라이버인 경우 DSK)
xxx_Init
xxx_Deinit
xxx_Open
xxx_Close
xxx_Read
xxx_Write
xxx_Seek
xxx_IOControl
xxx_PowerDown
xxx_PowerUp
Windows CE.Net 17
Stream Interface Device Driver (4)
DWORD XXX_Init( DWORD dwContext );
BOOL XXX_Deinit( DWORD hDeviceContext );
DWORD XXX_Open( DWORD hOpenContext, DWORD AccessCode, DWORD ShareMode );
DWORD XXX_Close( DWORD hOpenContext );
DWORD XXX_Read( DWORD hOpenContext, LPVOID pBuffer, DWOR Count );
DWORD XXX_Write( DWORD hOpenContext, LPCVOID pBuffer, DWORD Count );
DWORD XXX_Seek( DWORD hOpenContext, long Amount, WORD Type );
BOOL XXX_IOControl( DWORD hOpenContext, DWORD dwCode, PBYTE pBufIn, DWORD dwLenIn, PBYTE pBufOut, DWORD dwLenOut, PDWORD pdwActualOut );
void XXX_PowerDown( DWORD hDeviceContext );
void XXX_PowerUp( DWORD hDeviceContext );
Windows CE.Net 18
Stream Interface Entry Points: Init and Deinit
XXX_Init()Device Manager가 driver를 load할 때, 호출
사용되어지는 resource를 초기화 한다.
Memory mapping
XXX_Deinit()Device Manager가 driver를 unload할 때, 호출
Resource를 해제, IST 정지
XXX_PreDeinit()
Windows CE.Net 19
Stream Interface Entry Points: Open and Close
XXX_Open()Device를 read / write하기 위해 open
특정한 device fie이름을 open하기 위해 CreateFile을 호출할 때, application이 직접 이 function을 불러 낸다.
이 function이 호출되면, device는 각각의 context open과동작을 위한 준비를 필요로 하는 resource에 allocate될 것이다.
XXX_Close()CloseHandle은 OS에서 이 function을 불러 낸다.
XXX_PreClose()
Windows CE.Net 20
Stream Interface Entry Points: Read, Write and Seek
XXX_Read()Application이 ReadFile function을 호출할 때 불려짐
XXX_Write()Application이 WriteFile function을 호출할 때 불려짐
XXX_Seek()현재 I/O pointer를 이동하는 것을 허용
Windows CE.Net 21
Stream Interface Entry Points: IOControl
XXX_IOControl()File에 따라 필수적이지 않은 custom operation의 허용
I/O control code는 동작을 정의
I/O control code 은 device 마다 다름
Windows CE.Net 22
Stream Interface Entry Points: PowerUp and PowerDown
XXX_PowerUp()Device에서 power를 돌려 받음
XXX_PowerDown()Device에 power를 정지
Software의 제어 하에 shut off 될 수 있는 device인 경우유용
Windows CE.Net 23
Stream Interface 호출 (1)
Application
Windows CE Kernel
Hardware Platforms
FilesystemIOCTLs
OAL Loaded at boot time
Stream Interface Driver
File System
Built-in Device
Device Manager
File APLs
Interrupt Events
Windows CE.Net 24
Stream Interface 호출 (2)
xxx_Initxxx_Deinit
xxx_Openxxx_Closexxx_Readxxx_Writexxx_Seek
xxx_IOControl
CreateFile
xxx_PowerDown
ReadFile
WriteFile
DeviceIoCtlontrol
SetFilePointer
xxx_PowerUp
CloseHandle
Device Driver ApplicationKERNEL
DEVICE.EXE
Interrupt Handler()
Windows CE.Net 25
Device Driver Loading (1)
Device Manager(Device.exe)가 시스템에 로드Device.exe는 Regenum.dll(장치 열거자)을 이용
레지스트리에서 [HKEY_LOCAL_MACHINE₩Drivers₩Builtin] 안에 있는 드라이버들을 조사목록과 초기화 할 순서를 생성
위 내용은 레지스트리에 있는 gpio_led 드라이버의 설정 값‘DLL' 드라이버 파일 이름(gpio_led)'Prefix' - 디바이스 이름을 구성하는 세 글자의 이름‘Index' - Prefix와 디바이스 이름을 구성하는 숫자‘Order' - Regenum.dll가 드라이버 로딩할 순서를 결정
[HKEY_LOCAL_MACHINE\Drivers\BuiltIn\GPIO_LED]"Dll"="gpio_led.dll""Prefix"="LED""Index"=dword:1"Order"=dword:0
Windows CE.Net 26
Device Driver Loading (2)
Regenum.dll는 위의 레지스트리를 읽어 드라이버(DLL)를 로드
드라이버의 Active 키를 생성
ActivateDevice 혹은 ActivateDeviceEx 함수를 사용 새로운 키생성
[HKEY_LOCAL_MACHINE₩Drivers₩Active]에 생성
RegisterDevice 함수를 실행, 드라이버 로드 완료
RegisterDevice는 xxx_Init 함수를 호출하여 드라이버를 초기화
CreateFile이 드라이버를 Open
Open 한 후, WriteFile, ReadFile, DeviceIoControl 등으로 디바이스를 제어
Windows CE.Net 27
Stream Device Driver 제작 (1)
다음과 같은 파일 작성Driver file(.c, .cpp, .h) : device driver source 파일
Sources file : make source 등을 정의
.def file : export된 함수 포함
Makefile
Dirs : Build 실행 시에 참조할 subdirectory 정의
BIB file : Kernel image에 포함할 모듈을 정의
REG file : Kernel 부팅 시에 로드할 드라이브를 정의
Windows CE.Net 28
Stream Device Driver 제작 (2)
PLATFORM/pxa255pro3/INC/xsc1bd.h에 Device Driver address 등록
(주)휴인스의 PXA255PRO보드의 CS3에 FPGA Board가 연결
OFFSET을 각각의 Device IO의 Physical / Virtual(cached, uncached) addess 등록
Device Driver는 이 address에 접근하여 IO Device 제어
Windows CE.Net 29
FPGA Memory Map
Physical Memory
Debug Serial Port
32MB Flash
64MB RAM
0x 8200 0000
0x 8000 0000
0x 0400 0000
0x 0000 0000
Reserved
32MB Flash
64MB RAM
64MB RAM
32MB Flash
User
0x c000 0000
0x a000 0000
0x 8000 0000
512MBCached
512MBUnCached
Kernel V irtual Address
Windows CE.Net 30
FPGA Board I/O Port Address
AddressI/O device 비고
PXA255Pro1
0x0c000002 LED LED 출력 포트
0x0c000004 FND FND 출력 포트
0x0c00001e DOT #1 DOT #1 출력 포트
0x0c000018 Step Motor Step Motor 제어 포트
0x0c00001c Text LCD 명령어 포트
0x0c00001a Text LCD 데이터 포트
0x0c000006 ~0x0c000014
ADC ADC 입력값 FIFO(16Btes)
0x0d000016 DAC DAC 출력값FIFO(16Btes)
Windows CE.Net 31
FPGA Board I/O Port Address
AddressI/O device 비고
PXA255Pro3
0x0c000016 LED LED 출력 포트
0x0c000002 FND FND 출력 포트
0x0c000004 DOT #1 DOT #1 출력 포트
0x0c00000c Step Motor Step Motor 제어 포트
0x0c000014 Text LCD 명령어 포트
0x0c000012 Text LCD 데이터 포트
0x0c800000 ADC ADC 입력값 FIFO(16Btes)
0x0d000000~0x0d000020
DAC DAC 출력값FIFO(16Btes)
0x0c800004 CDS CDS 출력값
Windows CE.Net 32
HAL(Hardware Adaptation Layer)
주소 맵을 HAL 소스에 추가C:/WINCE420/PLATFORM/PXA255PRO3/INC/xsc1bd.h
Windows CE.Net 33
Device Driver 개발실습 #1 (1)
LED Device Driver 제작
Kernel에 Address 등록
Stream device driver 작성
fpga_led.def 파일 작성
sources 파일 작성
makefile 파일 작성
Platform.bib / platform.reg 수정
Application 작성
LED control
Windows CE.Net 34
Device Driver 개발실습 #1 (2)
Test Application 제작디버깅 모드에서 디바이스를 테스트 할 수 있는 어플리케이션 제작
Platform Builder에서 작성
Windows CE.Net 35
LED 개요
Light Emitting Diode
순방향 전압시 다이오드 접합부 발광
D1 –D4 : Red
D5 – D8 : Green
D1~D8 주소에 0 : On, 1 : Off
Bit 7 6 5 4 3 2 1 0
LED D8 D7 D6 D5 D4 D3 D2 D1
Windows CE.Net 36
LED 디바이스 드라이버 작성 (1)
1. 디바이스 드라이버 작성/wince500/platform/Huinspro3/drivers/fpga_led/fpga_led.cpp
2. 헤드파일 작성/wince500/platform/Huinspro3/drivers/fpga_led/fpga_led.h
3. Def 파일 작성/wince500/platform/Huinspro3/drivers/fpga_led/fpga_led.def
Windows CE.Net 37
LED 디바이스 드라이버 작성 (2)
4. Sources 파일 작성/wince420/platform/pxa255pro3/drivers/fpga_led/sources
5. OS 이미지에 드라이버 추가/wince420/platform/pxa255pro3/cesysgen/files/platform.bib
6. 레지스트리 등록/wince420/platform/pxa255pro3/cesysgen/files/platform.reg
Windows CE.Net 38
LED 디바이스 드라이버 작성 (3)
7. 소스 빌드1. PB상에서 build – open build release directory
2. fpga_led 디렉토리로 이동
3. 커맨드라인에서 set WINCEREL = 1 입력
4. 커맨드라인에서 build –cfs
8. OS이미지 생성1. 커맨드라인에서 makeimg
Windows CE.Net 39
LED 테스트 프로그램 작성 (1)
신규 작성1. Platform Builder의 File 메뉴에서 New Project or File..을
실행
2. 적절한 어플이케이션 이름을 Project name에 작성한다.
3. A simple Windows CE application을 선택한다.
4. 소스코드를 작성
5. Build 또는 Build(selection only)를 실행하여 빌드한다.
Windows CE.Net 40
LED 테스트 프로그램 작성 (2)
기존의 프로젝트 추가1. 소스코드를 적절한 경로에 복사한다.(예,
C:₩WINCE420₩PUBLIC₩huinspro3_HH)
2. Platform Builder의 File View 창에서 Insert Existing Project를 선택
3. *.pbp 파일을 선택한다.(제공된 소스를 카피한 디렉토리의파일)
4. 프로젝트가 추가되었다.(File View 창에서 확인)
5. Build 또는 Build(selection only)를 실행하여 빌드한다.
Windows CE.Net 41
다운로드 및 테스트
다운로드
테스트PB 상에서 Target – Run programs
Available program에서 led_test_app.exe 선택
테스트 프로그램 종료PB상에서 Target – CE Target Control
타겟 컨트롤창에서 gi all 입력
타겟 컨트롤창에서 kp 프로세스번호 입력