Work Notes

Frank is a Software Engineer with rich experiences on messeging system, embedded system and communication system development. This is his work notes.

Thursday, September 23, 2010

Argument Passing and Naming Conventions

The following calling conventions are supported by the Visual C/C++ compiler.

Keyword Stack cleanup Parameter passing
__cdecl Caller Pushes parameters on the stack, in reverse order (right to left)
__stdcall Callee Pushes parameters on the stack, in reverse order (right to left)
__fastcall Callee Stored in registers, then pushed on stack
thiscall
(not a keyword) Callee Pushed on stack; this pointer stored in ECX

Tuesday, March 09, 2010

use CELOG

1)Build a debug copy of the dll and deploy it to your device with a cab file. Remember to build with WINCESHIP= and WINCEDEBUG=debug
2)Get the following files from your emulator FRD and copy to the windows directory on device
a.celog.exe,
b.oscapture.exe
c.celogflush.exe
d.perfman.exe
3)start celogflush.exe
4)Start perfman.exe

select the zones. 0x800000 is the debug zone.
When done collecting data go to the root directory on your pocket pc and find the file . perfman.log

Parse celog:
readlog perman.log output.txt

Here are some more flags.
LZONE_PROCESS (0x00000040)
CELZONE_THREAD (0x00000020)
CELZONE_RESCHEDULE (0x00000002)
CELZONE_CRITSECT (0x00000100)
CELZONE_SYNCH (0x00000200)
CELZONE_DEMANDPAGE (0x00000010)
CELZONE_HEAP (0x00000800)
CELZONE_INTERRUPT (0x00000001)
CELZONE_DEBUG (0x00800000)
CELZONE_MIGRATE (0x00000004)
CELZONE_PRIORITYINV (0x00000080)

Tuesday, February 02, 2010

.NET concept

The .NET Framework has two main components:
the common language runtime and
the .NET Framework class library.

The common language runtime is the foundation of the .NET Framework.

The runtime as an agent that manages code at execution time, providing core services such as memory management, thread management, and remoting, while also enforcing strict type safety and other forms of code accuracy that promote security and robustness.

the concept of code management is a fundamental principle of the runtime. Code that targets the runtime is known as managed code, while code that does not target the runtime is known as unmanaged code.

The class library, the other main component of the .NET Framework, is a comprehensive, object-oriented collection of reusable types that you can use to develop applications ranging from traditional command-line or graphical user interface (GUI) applications to applications based on the latest innovations provided by ASP.NET, such as Web Forms and XML Web services.

Wednesday, October 07, 2009

Winmobile Suspend/Resume

The following list shows the characteristics of the power model for Windows Mobile 6 Standard:
1. Windows Mobile 6 Standard never suspends.
2. You can turn off the backlight and the screen.
3. You can run threads.
4. Power handling in the OEMIdle function is more important than it is in the power model for Windows Mobile 6 Classic and Windows Mobile 6 Professional.
5. Low overhead and fast wake-ups from low power states.

Windows Mobile 6 Classic and Windows Mobile 6 Professional: The Suspend Path
1. Power Manager disables all Power Manager-aware non-block drivers.
2. Power Manager calls the IOCTL_HAL_PRESUSPEND input/output control code.
3. Power Manager notifies file systems.
4. Power Manager disables all Power Manager-aware block drivers.
5. The operating system transitions to single threaded mode.
6. Power Manager calls all legacy XXX_PowerDown (Device Manager)callback functions. There can be no system calls in the xxx_PowerDown callback function, because they will make the driver non-pageable.
7. Power Manager calls the OEMPowerOff function, which is the OEM code that suspends the CPU.


Windows Mobile 6 Classic and Windows Mobile 6 Professional: Behavior While Suspended
1. The CPU is suspended, so no threads are running. Only a hardware interrupt can wake the CPU, and multiple interrupts are multiplexed to the CPU pin. Typical hardware interrupt wake sources are the keyboard, the power button, a real-time clock (RTC) alarm, or a ring from the cell radio.


Windows Mobile 6 Classic and Windows Mobile 6 Professional: The Resume Path
The resume path for Windows Mobile 6 Classic and Windows Mobile 6 Professional is the reverse of the suspend path for Windows Mobile 6 Classic and Windows Mobile 6 Professional.
1. CPU wakes up and continues executing where left off in the OEMPowerOff function.
2. The OEMPowerOff function returns.
3. Power Manager calls all legacy XXX_PowerUp (Device Manager) callback functions.
4. The operating system transitions into multi-threaded mode.
5. Power Manager enables Power Manager-aware drivers, Power Manager-aware block drivers, and Power Manager-aware file systems.

Wednesday, September 30, 2009

segment of program assembly

Text : This portion contains the actual m/c instructions to be executed. On many Operating Systems this is set to read only, so that the process can't modify its instructions. This allows multiple instances of the program to share the single copy of the text.

Data : This portion contains the program's data part. It furthere divided into
1) Initialized Read Only Data : This contains the data elements that are initialized by the program and they are read only during the execution of the process.
2) Initialized Read Write Data : This contains the data elements that are initialized by the program and will be modified in the course of process execution.
3)Uninitalized Data : This contains the elements are not initialized by the program and are set 0 before the processes executes. These can also be modified and referred as BSS(Block Started Symbol). The adv of such elements are, system doesn't have to allocate space in the program file for this area, b'coz it is initialized to 0 by OS before the process begins to execute.

Stack: This portion is used for local variables, stack frames

Heap: This portion contains the dynamically allocated memory, it begins at the end of BSS.

In embedded software, the BSS segment is mapped into "Uninitialized RAM" that in fact is initialized to zero by the C runtime before main () is entered

RTOS

A Real-Time Operating System (RTOS) is a multitasking operating system intended for real-time applications
Key factors in an RTOS are:
* a minimal interrupt latency
* and a minimal thread switching latency.

Scheduling:
* Event-driven (priority scheduling) designs switch tasks only when an event of higher priority needs service, called pre-emptive priority.
* Time-sharing designs switch tasks on a clock interrupt, and on events, called round robin.

Intertask communication and resource sharing:
* Temporarily masking/disabling interrupts
* Binary semaphores
* Message passing

A binary semaphore is either locked or unlocked. When it is locked, a queue of tasks can wait for the semaphore. Typically a task can set a timeout on its wait for a semaphore. Problems with semaphore based designs are well known: priority inversion and deadlocks.

Monday, September 28, 2009

first app of DirectShow

Follow Windows Mobile 6 - Sample playback Program.

Problems that I met:
1. Compile error which is couldn't find some interface GUID;
Solved: after include the header file like "strmif.h" "control.h", problem got solved;

2. got linking error 2001: couldn't find extern definition;
Solved: follow MS link to solve http://support.microsoft.com/kb/130869, and also include 'strmiids.lib";

3. while running app, render function return errors and couldn't play media file;
Solved: codec is not properly used, after using the popular file .wav, it can play the wave file.

void TestPlay(void)
{
IGraphBuilder *pGraph;
IMediaControl *pMediaControl;
HRESULT hRes;

CoInitialize(NULL);
CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
IID_IGraphBuilder, (void **)&pGraph);
pGraph->QueryInterface(IID_IMediaControl, (void **)&pMediaControl);
// Query for IMediaControl (not shown)
// Filenames start with a \\ instead of a drive letter.
//hRes = pGraph->RenderFile(L"\\music\\AllGoodThings\\drive.wma", NULL);
hRes = pGraph->RenderFile(L"\\music\\pegconn.wav", NULL);
hRes = pMediaControl->Run();
// Block until the user clicks the OK button.
// The filter graph runs on a separate thread.
MessageBox(NULL, L"Click me to end playback.", L"DirectShow", MB_OK);
// Clean up.
pMediaControl->Release();
pGraph->Release();
CoUninitialize();

};

Monday, September 21, 2009

local variable

In C , a variable declared as static is local to a particular function. It is initialised once and on leaving the function, the static variable retains the value. Next time when the function is called again, the static variable already has the value from the previous function call.

global and static variables are stored in DSS.

In memory. A variable of static storage duration must beavailable throughout the lifetime of the program. The C standarddoesn't require any specific method of making this happen, and different compilers can do it differently

ARM registers

ARM registers

R0 : Argument1, Return Value; Temporary register
R1 : Argument2, Second 32-bits if double/int Return Value; Temporary register
R2-R3 : Arguments; Temporary registers
R4-R10 : R7 is THUMB frame pointer; Permanent registers.
R11 : ARM frame pointer; Permanent register
R12 : Temporary register
R13 : Stack pointer; Permanent register
R14 : Link register; Permanent register
R15 : Program Counter

Followers