40

How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Embed Size (px)

Citation preview

Page 1: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司
Page 2: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

How To Write AWindows CE SDIO Client Driver

饶大春技术专家微软中国技术中心微软(中国)有限公司

Page 3: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Overview

• CE SDIO Stack Features• How to write a client driver• Bluetooth code walkthrough

Page 4: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDA and MMCA

• SD and MultiMediaCard Associations• SPI mode vs. SD/MMC mode• 9 pins vs. 7 pins• 4 bits vs. 1 bits• Command different• MMC,SD Memory card and IO card• RS-MMC,miniSD and TransFlash

Page 5: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SD(IO) Support In CE 5.0• Dynamic insert/remove

• DMA (optional in standard host spec, platform dependent)

• SDIO interrupts

• Dynamic clock control

• Error recovery

• Soft-block support

• Wake-up

• Power will be handled using CE Power Manager– Clients may be power-managed and tell the controller to put its slot into a different power

state

• Multi-function and Combo devices

• Also support MMC v3.0 basic functionality

• In the next Windows Mobile release we’re adding:– Support MMC v4.0 basic functionality

– Performance enhancements for single block cards

Page 6: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

The Secure In SD• SDA SD Memory specification provides a mechani

sm to lock content to a specific machine

• We are not providing a block driver supporting it in 5.0 release explicitly. SDBus does allow you to build your own though

• Digital Rights Management (DRM) for all of CE is being supplied by a filesystem filter driver at a level above the SD Memory block driver

Page 7: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SD GPSCard

SD Host Controller

HostHost SoftwareSoftware

StackStack

HardwareHardware

ClientClientDriversDrivers

SD HostDriver

FatFS Location Services

SDBus Driver

SDIO GPSClient Driver

SD Memory(block driver)

SD MemoryCard

Page 8: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SD Bus Driver• Enumerates cards to determine if MMC,

SD Memory or SDIO• Determines voltage to use for card• Loads clients based on registry values• Queues bus requests• Queues asynchronous notifications from host controll

er– Bus request completion, SDIO interrupts,

device insertion/removal

• Performs error handling with retry

Page 9: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Standard Host Controller• SDA Host Working Group

Defined Standard Host Register Specification to standardize hardware interface from bus to controller

• Currently ratified to v1.0 by SDA executive committee

• MSFT strongly advocating this standard to all IHVs, ODMs, OEMs and Silicons

• Also support for PXa270, OMAP730, SMDK2410

Page 10: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Compatibility With SDIO Now!

• BSquare has an install base• PPCs on the market today• Target was to maintain client driver compatibil

ity to ensure smooth transition of marketplace• Have verified we’re compatible using SDIO N

ow!

Page 11: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Windows CE Provided Clients

• SD Memory (MMC support verified)• SDIO Bluetooth Type A class• SDIO GPS class• SDIO WiFi

Page 12: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

How To Write A Client Driver

• Client Driver model• Registry loads driver• Checklist of functions

Page 13: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Client Driver Model

• Streams interface for API• Init, Deinit are the only ones strictly required• Suggested use of Open, Close, Read, Write, I

OControl, PowerUp/Down as appropriate

Page 14: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Registry EntriesCustom Driver:[HKEY_LOCAL_MACHINE\Drivers \SDCARD\ClientDrivers\Custom \MANF-02DB-CARDID-0002-FUNC-1]

"Dll"=“mydriver.dll""Prefix"=“XXX“

Class Driver:[HKEY_LOCAL_MACHINE\Drivers \SDCARD\ClientDrivers\Class\SDIO_Class\3] "Dll"=“bthsdio.dll" "Prefix"=“BSD“SD Memory and MMC have special class keys as well

Page 15: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Checklist• Get SDA specs and card manufacturer specs.

Use Bluetooth driver as an example• XXX_Init()• Get the unique identification handle

for the client– SDGetDeviceHandle

Page 16: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Checklist

• Create a function to receive asynchronous slot state change notifications

• Register the client driver with the SD Bus driver

• [SDIO] Enable the SDIO function• [SDIO] Determine which function on the card t

he driver is associated with

Page 17: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Slot Events

• Recommended • SlotEventCallBack()• Provides Asynchronous info about changes in

slot state – Example: SDCardEjected

Page 18: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDRegisterClient

• Fill in structure with the local device context, slot event callback, and a friendly name

• Friendly name used for debug output• After successful registration, all other SD Bus

APIs may be called

Page 19: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDSetCardFeature

• Configures the card– SD_IO_FUNCTION_ENABLE– SD_IO_FUNCTION_DISABLE– SD_IO_FUNCTION_SET_BLOCK_SIZE– SD_SET_CARD_INTERFACE

• Sets both the bus width and the bus clock frequency

Page 20: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDCardInfoQuery• Provides information about card and host contr

oller– Function number– Host controller maximum block size– Current bus clock and width– Address of function’s SDIO CIS region– Parsed card register structures

• CSD• CID• DSR• RCA• SCR

Page 21: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Code Sample – Initialization

• public\common\oak\drivers\sdcard\sdclientdrivers\bluetooth\bthsdio.cpp

• CSdioDevice::Attach()

Page 22: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

• BOOL CSdioDevice::Attach(DWORD dwContext)• {

……m_hDevice = SDGetDeviceHandle(dwContext, &m_pRegPath);

• if (NULL == m_hDevice) {• goto exit;• }• wcscpy(clientInfo.ClientName, TEXT("Bluetooth Card"));

• if (! SD_API_SUCCESS(SDRegisterClient(m_hDevice, this, &clientInfo))) {

• goto exit;• }

• if (! SD_API_SUCCESS(SDIOConnectInterrupt(m_hDevice, SDIOIsrCallBack))) {

• goto exit;• }

Page 23: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

• functionEnable.Interval = DEFAULT_SDIO_FUNCTION_RETRY_TIMEOUT;

• functionEnable.ReadyRetryCount = DEFAULT_SDIO_FUNCTION_RETRIES;

• if (! SD_API_SUCCESS(SDSetCardFeature(m_hDevice, SD_IO_FUNCTION_ENABLE, &functionEnable, sizeof(functionEnable)))) {

• ASSERT(0);• fRetVal = FALSE;• goto exit;• }

• if (! SD_API_SUCCESS(SDCardInfoQuery(m_hDevice, SD_INFO_SDIO, &sdioInfo, sizeof(sdioInfo)))) {

• ASSERT(0);• fRetVal = FALSE;• goto exit;• }• Exit:• ……• }

Page 24: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Checklist

• Retrieve the host controller’s max block size– Use SDCardInfoQuery

• [SDIO] Retrieve the function’s max block size from the card tuples– Use the smaller maximum block size

• [SDIO] Set the block size on the card– Use SDSetCardFeature

Page 25: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDGetTuple

• Simplifies reading tuples from the CIS• Information residing in tuples:

– Maximum block size– Power draw– Manufacturer code

Page 26: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Code SampleMaximum Block Size

• CSdioDevice::GetMaxBlockLen()

Page 27: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

• BOOL CSdioDevice::GetMaxBlockLen(void)• {• ……• if (! SD_API_SUCCESS(SDGetTuple(m_hDevice, SD_CISTP

L_FUNCE, NULL, &ulLength, FALSE)) ||• (ulLength > sizeof(rgucTuple)) ) {• ASSERT(0);• fRetVal = FALSE;• goto exit;• }

• if (! SD_API_SUCCESS(SDGetTuple(m_hDevice, SD_CISTPL_FUNCE, rgucTuple, &ulLength, FALSE)) ||

• (pFunce->bType != SD_CISTPL_FUNCE_FUNCTION_TYPE) ) {

• ASSERT(0);• fRetVal = FALSE;• goto exit;• }

Page 28: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

• usCardBlockLen = pFunce->wMaxBlkSize;

• ……• if (! SD_API_SUCCESS(SDCardInfoQuery(m_hDe

vice, SD_INFO_HOST_BLOCK_CAPABILITY, &blockCapability, sizeof(blockCapability)))) {

• goto exit;• }• m_usBlockLen = (usHostBlockLen < usCardBlockL

en) ? usHostBlockLen : usCardBlockLen;• ……• }

Page 29: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Checklist• [SDIO] Determine if the card supports multi-blo

ck transfers– Read from CCCR

• [SDIO] Create and register a function to receive interrupt notifications

• Transfer data via Bus Requests…

Page 30: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

SDIO Interrupts

• Card notifies driver of Asynchronous events via SDIO interrupts

• SDIOConnectInterrupt() to register for a callback

• Client must clear the interrupt before exiting callback

• Return SD_API_STATUS_SUCCESS

Page 31: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Code Sample – Interrupts

• CSdioDevice::SDIOIsrCallBack()• CSdioDevice::SDIOIsrCallback_Int()

Page 32: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

• SD_API_STATUS CSdioDevice::SDIOIsrCallback_Int(void)• {• ……• status = SDGetRegister(REG_INTRD, m_ucFunction, &ucRe

gValue, 1);• if (!SD_API_SUCCESS(status)) {

……• }• if (ucRegValue) {• SetEvent(m_hReadPacketEvent);

• // Clear INTRD register• ucRegValue = 0x01;• status = SDSetRegister(REG_INTRD, m_ucFunction, &uc

RegValue, 1);• ……• }• }• ……• }

Page 33: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Touching Card Registers• SDReadWriteRegistersDirect() – for multiple single-b

yte transfers• Single-byte transfers are slow so try

to avoid them• Used for doing things like:

– Determining if the card is multi-block capable (CCCR)

– Clearing and enabling card specific interrupt settings

– Setting card specific modes

– Read if data is available

Page 34: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Read/Write – Bus Requests• Client driver interacts with the card via the Bus driver

using Bus Requests. These requests pass the SD CMD to the card

• Sync – must wait for response before issuing subsequent commands

SDSynchronousBusRequest()• Async – subsequent commands are queued by Bus d

river. You must free the bus request after completionSDBusRequest()

• Second parameter of both is the SD CommandSDCancelBusRequest()

Page 35: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Sync Versus Async• Async helps the most when sending many sm

all blocks (Not multi-block)• Async will always be at least as fast or faster t

hen Sync– If you submit a bunch of async requests, they’ll be queued by

the bus driver, good because bus driver optimizes bus activity

• Sync is easier to program, less logic in client

Page 36: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Issuing An SDIO Command• CMDs are listed in the SDA specifications• You should build the arguments

via Macros• Two macros that build the complex command sta

tements for you:– BUILD_IO_RW_DIRECT_ARG()– BUILD_IO_RW_EXTENDED_ARG()

• Call SDSynchronousBusRequest() or SDBusRequest() with the command argument

Page 37: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Code Sample – Transfers

• CSdioDevice::SDSend()– Synchronous

• CSdioDevice::SDRecv()– Asynchronous

Page 38: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

Tools & Resources

msdn.microsoft.com/msdn.microsoft.com/ embeddedembedded

microsoft.public.microsoft.public. windowsxp.embeddedwindowsxp.embedded windowsce.platbuilderwindowsce.platbuilder windowsce.embedded.vcwindowsce.embedded.vc

blogs.msdn.com/blogs.msdn.com/ mikehallmikehall

Windows CE 5.0 Eval KitWindows CE 5.0 Eval KitWindows XP Embedded Eval KitWindows XP Embedded Eval Kit

msdn.microsoft.com/msdn.microsoft.com/ mobilitymobility

microsoft.public.microsoft.public. pocketpc.developer pocketpc.developer smartphone.developer smartphone.developer dotnet.framework.compactframeworkdotnet.framework.compactframework

blogs.msdn.com/blogs.msdn.com/ windowsmobilewindowsmobile vsdteamvsdteam netcfteamnetcfteam

Windows Mobile 5.0 Eval KitWindows Mobile 5.0 Eval Kit

WebsitesWebsites

NewsgroupsNewsgroups

BlogsBlogs

ToolsTools

BuildBuild DevelopDevelop

Page 39: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司

请填写资料袋内的黄色大会来宾反馈表 , 到大会接待台领取大会纪念包。

请在课程结束后填写课程培训反馈表,参加抽奖。

您还可以:

参加 Windows Mobile 动手实验室;参观微软及合作伙伴展区;体验基于 Windows Mobile 平台开发的最新硬件产品及解决方案。

大会注意事项

Page 40: How To Write A Windows CE SDIO Client Driver 饶大春 技术专家 微软中国技术中心 微软(中国)有限公司