SD card driver development under WinCE

Source: Internet
Author: User
Reprinted from: http://www.cnblogs.com/nesta/archive/2008/05/30/967860.html The stuff on this blog is worth learning. 

Development of SD card driver under wince 5.0. This was my first project. At that time, I spent a lot of time and energy doing it. It can be said that he was not familiar with wince at the time. I don't know where to start. Let's look at the East and the West. It was a mess. Fortunately, both the boss and the boss are more tolerant, giving me plenty of time and support, and putting their own SD cards in wince 5. 0. The driver's understanding below is recorded, hoping to help others.
Currently, the driver of Wince mainly has two types of architecture: Host, bus, and client ). In addition, the driver is directly written as a block driver, which is divided into a real driver and a program dedicated to loader. I use the three-tier architecture that comes with Microsoft. Next I will introduce this architecture in detail and how to implement the SD card driver in this architecture. (We recommend that you first check the spec of the SD card (download sdspec) Before making the SD card driver, and know some of its features, including the initialization process and what the commands are. There are also internal registers. These registers are obtained through the commands again. After understanding these registers, you can have a good debugging later .) This article will not introduce some SD card specifications (many of them are available everywhere on the internet). It mainly introduces the implementation of the SD card in wince.
Shows the architecture of the SD card below wince:

: The bottom part is your h/W, where SD host controller is the part of your SD hardware controller, and you need the spec for writing the driver. Then, the above SD host controller driver is the part you need to implement and directly deal with your controller. The bus layer is located at the layer between the host and the client. It is mainly used for communication between two layers and loading different client drivers according to different devices, if it is an SD memory card, load the SD memory. If the sdio card has Wifi function, the sdio WIF driver will be loaded.
Both the driver bus driver and client driver are provided by Microsoft, but not by Microsoft itself. It looks like it was developed by bsquare. The code of the bus layer is located in C:/wince500/public/common/oak/Drivers/sdcard/sdbusdriver. (C:/wince500 is the directory where you install wince ). The client code is located in C:/wince500/public/common/oak/Drivers/sdcard/sdclientdrivers. Microsoft has two client drivers (Bluetooth and sdmemory ). The following describes the main functions of each layer. The main function of the bus layer is to enumerate cards on the board, determine their types (MMC, SD memory or sdio), and configure appropriate current to the card, load clients according to the registry value, request the bus to the queue, and asynchronously notify the host controller to the queue. The bus must be completed, sdio is interrupted, and the device is inserted/unplugged, retry when an error occurs.
The main processing process is sdhceventhandlers. handleadddevice () in CPP includes card recognition, card power-on, card type identification, and loading client drivers. During debugging, you can add some debug information here to see where errors occur during initialization, and follow the corresponding response to drive the error. Where
While (null! = Pcurrentdevice)
{
// Try to load devices
Csdbusdriver: sdloaddevice (pcurrentdevice );
Pcurrentdevice = pcurrentdevice-> pnext;
}
This section is mainly used to load the client Driver Based on the information obtained above. If it is only a memory card, it will load sdmemory. dll. If the sdio WiFi card is used, the corresponding WiFi client driver will be loaded. The initialization process is mainly implemented in this function:
The main Commands are: CMD5----CMD55/CMD41---CMD2--CMD3 and so on, the specific cmd reference SD spec. These commands are provided to the host controller layer at the bus layer.
In the host controller layer, commands are run to H/W and corresponding response is obtained. The response is put into a buffer and transmitted to the bus layer according to the corresponding format, it is handled by the bus layer. The bus layer determines the card type, card size, card transmission speed, and card attributes based on these response.
Card read/write: The file system read/write will first go to the sdmemory layer. sdmemory first converts cardio to diskio and then passes it to the host controller through the bus layer. The read/write mainly consists of memory 17 and memory 18, and listen 24 and listen 25. After each processing of the bus layer, you must send a busrequest handle complete event to the bus layer to notify the bus layer that the read and write operations have been completed. The DMA Operation is required for read/write operations, and the copy operation is required here, because the DMA requires a physical address, and the Buf passed down by the layer is a virtual address.
The above section is probably about the SD card driver under wince, which is not clearly explained in many places. It took so long to finish writing. Alas, a lot of things are not very clear. What's the problem? I hope you can communicate with us,

 

 

 

 

USB function switch [Provide download]: http://gopise.blog.ccidnet.com/blog-htm-do-showone-uid-50640-type-blog-itemid-247151.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.