Saturday, May 23, 2009

How NAND Flash driver works!!! [WinCE]



This article includes the basic NAND driver porting as well as the key problem developer usually face during development. 

The article is explain in the following points:

  1. What is NAND Flash driver.
       Flash memory is non-volatile, which means that no power is needed to maintain the information stored in the chip. In addition, flash memory offers fast read access times (although not as fast as volatile DRAM memory used for main memory in PCs) and better kinetic shock resistance than hard disks. In devices, it is used as boot as well storage devices like SD Card. We flash the step loader image in NAND and while booting, the processor start boot time; we configure the processor to boot from NAND. Later processor boot from NAND and we see the image up. Also in the image we can see the NAND Flash folder which can be used as storage space. The storage space will be space left after flashing step loader.

2. Overview knowledge before devlopment start
       The flash driver is devided in two parts in WinCE 6.0. 
1. Stream driver which is under public or private. It is provided by microsoft and we have to plug in the our code with it.
2. This is called PDD which implement the platform depending on our NAND flash controller and NAND flash. 
The upper layer is called FAL, Flash Abstraction layer and this is implemented by MS. Hence we need to implement just the funtion required by the FAL. This is a normal disk storage stream driver.


3. Porting function required

These functions are required to be implemented and implementation depends on the Flash controller and flash card type. Thease function are called by the FAL. If you don't support all functionality then also you have to define this function as empty function. 

4. Registry setting and it’s significance.
When we write NAND Flash driver, our aim is that our NAND device should work as booting device as well as persistent storage device.
[HKEY_LOCAL_MACHINE\System\StorageManager\Profiles\NANDFLASH\FATFS]
 "Flags"=dword:14
 "FormatExfat"=dword:1 ; to format the NAND with exFat file system
"CheckForFormat"=dword:1 ; it is used to tell the OS that format or not it if it is a clean boot or normal one.
"EnableWriteBack"=dword:1 ; This is cache properties whether to enable write through cache or write back.
Similarly you can set properties for cache filter.

5. Refering question and solution in one page



Refereces:
www.e-consystems.com/images/fmd%20blockdig.jpg

Thank you very much

~~Mike


Saturday, March 7, 2009

How ExitThread works!!! [WinCE]


This function ends a thread.This API takes exit code for the calling thread. To retrieve a thread's exit code, use the GetExitCodeThread function.
The steps are:
  1. It will release the owner process by using API GetCurrentThreadId which gives it current thread and check for the current process which own the thread and if it's the same application which own the thread then release all CS.
  2. Check for thread type:
    1. If it is the primary thread then
      1. Kill all other thread.
      2. Detach all DLL from the process.
      3. Call Dllmain function of dll with thread detach ioctl.
      4. Call core dll to detach the thread.
      5. Close all handle
    2. Else
      1. Get the thread attach status and call dllmain of dll with thread detach ioctl.
  3. Now it will call NKTerminateThread.
Note: If the primary thread calls ExitThread, the application will exit.

Friday, February 20, 2009

How InterruptInitialize wokrs!!! [WinCE]

This API takes basically two parameters:
1. Event name
2. Interrupt id(IRQ) which we choose manually.

It wil verify interrupt id is valid by comparing with SYSINTR_DEVICES, and SYSINTR_MAXIMUM.

Now check for valid event after getting handle for the event.
Next check for manualset and proxylist member.

Now it will convert the IRQ into sysirq and will check for maximum limit.

 If less then it will call OEMInterruptEnable whcih will send the sysintr.

So after that it will again call oalinterruptenable in intr.c.

For wince5.0 only!!!

Thursday, February 19, 2009

How CreateEvent works!!! [WinCE]

The API takes three parameters:
1. Initial status (we determine).
2. Set/reset option like manual or automatic
3. Name of event

First it will validate the parameter like caller needs to be trusted if the named object is system prefixed.
Next check for the name of event in the linked list if it has been already used.

Now call critical section.

Now if the name exists then it will return with error.
Next check for the same object is already opened but name does not exist.

Now if the object does not exist then it will get allocated memory from heap for synchronous object.

Now it will get a pointer of the memory allocated before, and will check the size if available.
If available, then grab the memory and then will call INTERRUPTS_ON() which is nesting interrupts.

Then it will get handle for the object.
Name and security related check will be done.
Also for out of memory.

Now after getting memory, we will clear it by filling 0.
Then copy name and security descriptor. Now will call pfnInit() for the particular object.
Then we will have to set the parameter on manual set/reset.
Note - wince5.0

How InitializeCriticalSection works!!! [WinCE]

This api Initializes a critical section object.
It will take the critical section object and initialize the member of the object with null then will call function CreateCrit which will again take the parameter as the critical section object and in the function it will check for the process trust level and then if it fulfill the trust level then if the object is equal to 1 then will map the critical section object to the base address of process VM base.
Now it verify the valid kernel pointer for the critical section's cric member.
After than it will call EnterCriticalSection on the global critical section object and then will do traversing to find in which location to save the new critical section object using linked list data structure.
When it will find the exact location then it will save there and then will call leave global critical section object (NameCS).
Note - This is for WCE5.0.