1 / 40

How To Write A Windows CE SDIO Client Driver

How To Write A Windows 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

Download Presentation

How To Write A Windows CE SDIO Client Driver

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

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

  3. 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

  4. 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

  5. The Secure In SD • SDA SD Memory specification provides a mechanism 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

  6. Location Services FatFS SDIO GPS Client Driver SD Memory (block driver) Client Drivers SDBus Driver Host Software Stack SD Host Driver SD Host Controller Hardware SDMemory Card SD GPS Card

  7. 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 controller • Bus request completion, SDIO interrupts, device insertion/removal • Performs error handling with retry

  8. 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

  9. Compatibility With SDIO Now! • BSquare has an install base • PPCs on the market today • Target was to maintain client driver compatibility to ensure smooth transition of marketplace • Have verified we’re compatible using SDIO Now!

  10. Windows CE Provided Clients • SD Memory (MMC support verified) • SDIO Bluetooth Type A class • SDIO GPS class • SDIO WiFi

  11. How To Write A Client Driver • Client Driver model • Registry loads driver • Checklist of functions

  12. Client Driver Model • Streams interface for API • Init, Deinit are the only ones strictly required • Suggested use of Open, Close, Read, Write, IOControl, PowerUp/Down as appropriate

  13. Registry Entries Custom 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

  14. 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

  15. 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 the driver is associated with

  16. Slot Events • Recommended • SlotEventCallBack() • Provides Asynchronous info about changes in slot state • Example: SDCardEjected

  17. 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

  18. 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

  19. SDCardInfoQuery • Provides information about card and host controller • 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

  20. Code Sample – Initialization • public\common\oak\drivers\sdcard\sdclientdrivers\bluetooth\bthsdio.cpp • CSdioDevice::Attach()

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

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

  23. 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

  24. SDGetTuple • Simplifies reading tuples from the CIS • Information residing in tuples: • Maximum block size • Power draw • Manufacturer code

  25. Code SampleMaximum Block Size • CSdioDevice::GetMaxBlockLen()

  26. BOOL CSdioDevice::GetMaxBlockLen(void) • { • …… • if (! SD_API_SUCCESS(SDGetTuple(m_hDevice, SD_CISTPL_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; • }

  27. usCardBlockLen = pFunce->wMaxBlkSize; • …… • if (! SD_API_SUCCESS(SDCardInfoQuery(m_hDevice, SD_INFO_HOST_BLOCK_CAPABILITY, &blockCapability, sizeof(blockCapability)))) { • goto exit; • } • m_usBlockLen = (usHostBlockLen < usCardBlockLen) ? usHostBlockLen : usCardBlockLen; • …… • }

  28. Checklist • [SDIO] Determine if the card supports multi-block transfers • Read from CCCR • [SDIO] Create and register a function to receive interrupt notifications • Transfer data via Bus Requests…

  29. 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

  30. Code Sample – Interrupts • CSdioDevice::SDIOIsrCallBack() • CSdioDevice::SDIOIsrCallback_Int()

  31. SD_API_STATUS CSdioDevice::SDIOIsrCallback_Int(void) • { • …… • status = SDGetRegister(REG_INTRD, m_ucFunction, &ucRegValue, 1); • if (!SD_API_SUCCESS(status)) { …… • } • if (ucRegValue) { • SetEvent(m_hReadPacketEvent); • // Clear INTRD register • ucRegValue = 0x01; • status = SDSetRegister(REG_INTRD, m_ucFunction, &ucRegValue, 1); • …… • } • } • …… • }

  32. Touching Card Registers • SDReadWriteRegistersDirect() – for multiple single-byte 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

  33. 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 driver. You must free the bus request after completion SDBusRequest() • Second parameter of both is the SD Command SDCancelBusRequest()

  34. Sync Versus Async • Async helps the most when sending many small blocks (Not multi-block) • Async will always be at least as fast or faster then 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

  35. 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 statements for you: • BUILD_IO_RW_DIRECT_ARG() • BUILD_IO_RW_EXTENDED_ARG() • Call SDSynchronousBusRequest()or SDBusRequest() with the command argument

  36. Code Sample – Transfers • CSdioDevice::SDSend() • Synchronous • CSdioDevice::SDRecv() • Asynchronous

  37. Tools & Resources Build Develop Websites msdn.microsoft.com/embedded msdn.microsoft.com/mobility Newsgroups microsoft.public.pocketpc.developer smartphone.developer dotnet.framework.compactframework microsoft.public.windowsxp.embedded windowsce.platbuilder windowsce.embedded.vc Blogs blogs.msdn.com/mikehall blogs.msdn.com/windowsmobilevsdteamnetcfteam Tools Windows CE 5.0 Eval KitWindows XP Embedded Eval Kit Windows Mobile 5.0 Eval Kit

  38. 大会注意事项 请在课程结束后填写课程培训反馈表,参加抽奖。 请填写资料袋内的黄色大会来宾反馈表,到大会接待台领取大会纪念包。 您还可以: 参加Windows Mobile动手实验室; 参观微软及合作伙伴展区; 体验基于 Windows Mobile平台开发的最新硬件产品及解决方案。

More Related