Friday, July 10, 2009

More ooBasic Quirkiness (Custom Type)

Problem with no able to use custom type as global. Basically once it exit a sub/function, the custom type object is whip out. Like this:

Type MyType
Some variables
End Type

Global gMyTypeObject as MyType ' Or as Dim, Public. Or as New MyType. Doesn't matter

Function DoA()
Read gMyTypeObject here but it's always empty...
End Function

Function DoB()
Do something and set gMyTypeObject
End Function

Amazingly this method below works...

Global gMyTypeVarObject as Variant

Function CreateMyTypeObject() as Variant
Dim x as MyType
CreateMyTypeObject = x
End Function

Sub Init() ' Call during initialization
gMyTypeVarObject = CreateMyTypeObject()
End

' Now all functions/subs can see gMyTypeVarObject as an object of MyType.

Brilliant...

Wednesday, July 08, 2009

Seagate Interview (+Delphi)

Talked a lot of non sense again... >_<|||

Some questions:
1. HW architecture of past projects
2. Thread scheduling, Preemptive, Cooperative OS
3. Task/Process synchronization
4. Atomic Operation (link)

Delphi:
- use #define to return number of seconds for a year, ignore leap year
- define a MIN macro, return minimum value of 2 arguments
- What's static used for
- How to infinite loop
- volatile and its 3 different usage
http://publications.gbdirect.co.uk/c_book/chapter8/const_and_volatile.html
http://ou800doc.caldera.com/en/SDK_cprog/_When_to_Use_volatile.html
http://www.netrino.com/node/80 (Y)

1. Memory-mapped peripheral registers

2. Global variables modified by an interrupt service routine

3. Global variables accessed by multiple tasks within a multi-threaded application


- what is #error used for?

During the preprocessing phase, you can report errors by using the #error preprocessor directive.

- const
const int a;
int const a;
const int *a; // a is pointer to a constant int
int * const a; // a is a constant pointer to a int variable
int * const a const;

- write 2 code segments that set and clear bit 3 of a respectively
unsigned int a;
a |= 0x00000004;
a &= 0xFFFFFFFB;

Delphi and Seagate use similar questions below (quite standard for firmware positions I guess)
- ANSI compiler, write code to assign value to specific memory location

int *p = (int *)0x6638;
*p = 0xaa55;

- Spot errors in ISR
__interrupt double doISR(double a) // ISR doesn't take input
{
double area = some calculation(a);
printf("area is %f", area); // NO printf in ISR
return area; // NO return in ISR
}

- Explain the output
unsigned int a = 6;
int b = -20

(a+b > 6) ? puts("> 6) : puts("<= 6");