how to write a windows ce sdio client driver 饶大春 技术专家 微软中国技术中心...

Post on 24-Dec-2015

318 Views

Category:

Documents

3 Downloads

Preview:

Click to see full reader

TRANSCRIPT

How To Write AWindows CE SDIO Client Driver

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

Overview

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

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

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

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

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

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

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

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!

Windows CE Provided Clients

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

How To Write A Client Driver

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

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

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

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

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

Slot Events

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

slot state – Example: SDCardEjected

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

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

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

Code Sample – Initialization

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

• CSdioDevice::Attach()

• 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;• }

• 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:• ……• }

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

SDGetTuple

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

– Maximum block size– Power draw– Manufacturer code

Code SampleMaximum Block Size

• CSdioDevice::GetMaxBlockLen()

• 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;• }

• 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;• ……• }

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…

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

Code Sample – Interrupts

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

• 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);• ……• }• }• ……• }

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

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()

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

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

Code Sample – Transfers

• CSdioDevice::SDSend()– Synchronous

• CSdioDevice::SDRecv()– Asynchronous

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

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

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

您还可以:

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

大会注意事项

top related