Skip to content

Commit 4ffa2c0

Browse files
Add memory map io
1 parent d9f1196 commit 4ffa2c0

File tree

5 files changed

+106
-20
lines changed

5 files changed

+106
-20
lines changed
206 KB
Loading
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## Memory map IO register Implementation
2+
3+
### **Problem statement**
4+
5+
*Suppose we have a GPIO memory map as follow, please implement a data struture that enables setting/clear certain register in the map in a clean and easy-to-understand manner. This is a **little endian** machine.*
6+
7+
![GPIO Memory Map](GPIO_memory_map.png)
8+
9+
```Please set 1 to GPIO 15.```
10+
11+
*(GPIO<pin_num> are set by writting 1 to the bit<pin_num> of ODR register)*.
12+
13+
### **Implementation**
14+
15+
```c
16+
// Volatile for register values. Hardware may change its value at any time
17+
typedef struct {
18+
voltatile uint32_t MODER, // little endian, LSB at lowest address
19+
voltatile uint32_t OTYPER,
20+
voltatile uint32_t OSPEEDR,
21+
voltatile uint32_t PUPDR,
22+
voltatile uint32_t IDR,
23+
voltatile uint32_t ODR,
24+
voltatile uint32_t BSRR,
25+
voltatile uint32_t LCKR,
26+
voltatile uint32_t AFR[2],
27+
voltatile uint32_t BRR,
28+
voltatile uint32_t ASCR,
29+
} GPIO_REG;
30+
31+
// Register port map
32+
#define GPIO_A = ((GPIO_REG*) 0x48000000)
33+
#define GPIO_B = ((GPIO_REG*) 0x48000400)
34+
#define GPIO_C = ((GPIO_REG*) 0x48000800)
35+
36+
// Set pin 15 of GPIOA to 1
37+
GPIO_A->ODR |= 1UL << 15;
38+
39+
// Macro to set arbitrary GPIO pin of any port
40+
#define SET_GPIO(pin_num, GPIO_PORT) (GPIO_PORT->ODR = 1UL<<pin_num;)
41+
42+
```
43+
44+
### **Follow up question**
45+
46+
*What if in the original memory map, the following registers are 16-bit register instead of 32-bit? How will you change the data structure?*
47+
48+
```
49+
uint16_t OTYPER
50+
uint16_t IDR
51+
uint16_t ODR
52+
```
53+
54+
### **Implementation**
55+
56+
```c
57+
#define voltatile _IO
58+
59+
typedef struct {
60+
_IO uint32_t MODER,
61+
_IO uint16_t OTYPER,
62+
uint16_t rev0, // 2 byte padding
63+
_IO uint32_t OSPEEDR,
64+
_IO uint32_t PUPDR,
65+
_IO uint16_t IDR,
66+
uint16_t rev1, // 2 byte padding
67+
_IO uint16_t ODR,
68+
uint16_t rev2, // 2 byte padding
69+
_IO uint32_t BSRR,
70+
_IO uint32_t LCKR,
71+
_IO uint32_t AFR[2],
72+
_IO uint32_t BRR,
73+
_IO uint32_t ASCR,
74+
} GPIO_REG;
75+
```

Interview/Company/apple.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## Apple On-site interview process
22

3-
```45 minutes per round```
3+
```Disclaimer: all information are from public online resources!```
44

55
### 1st round
66
- Hiring Manager round

Interview/Company/lyft.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
### Lyft Level 5 questions
22

3+
```Disclaimer: all information are from public online resources!```
4+
35
### Phone screen
46

57
**Question: Interrupts are an important part of embedded systems. Consequently, many compiler vendors offer an extension to standard C to support interrupts. Typically, this new key word is __interrupt. The following code uses __interrupt to define an interrupt service routine. Comment on the code.**

README.md

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -49,30 +49,39 @@
4949
5. Assembly
5050

5151
### C. Data Structures & Implementation
52-
1. [Ring Buffer](./Data_Struct_Implementation/circularRingBuffer/README.md)
53-
2. [Hash Table](./Data_Struct_Implementation/hashTable/README.md)
54-
3. [Heap (priority queue)](./Data_Struct_Implementation/binaryHeap/README.md)
55-
4. [Stack](./Data_Struct_Implementation/stack/README.md)
56-
5. [Queue](./Data_Struct_Implementation/queue/README.md)
57-
6. [Binary Search Tree](Data_Struct_Implementation/BST/README.md)
58-
7. Red Black Tree
59-
8. Minium Spanning Tree (MST)
60-
9. [Finite State Machine](Data_Struct_Implementation/stateMachine/README.md)
61-
10. Simple Task Scheduler
62-
11. [Endianess Check](Data_Struct_Implementation/endianess/README.md)
63-
12. [Swap Endianess](Data_Struct_Implementation/endianessSwap/README.md)
64-
13. Signness Check
65-
14. [Array of Bits](Data_Struct_Implementation/bitsArray/README.md)
66-
15. Low Pass Filter
67-
16. Common STL function implementation
52+
1. [Finite State Machine](Data_Struct_Implementation/stateMachine/README.md)
53+
2. Simple Task Scheduler
54+
3. [Endianess Check](Data_Struct_Implementation/endianess/README.md)
55+
4. [Swap Endianess](Data_Struct_Implementation/endianessSwap/README.md)
56+
5. Signness Check
57+
6. [Array of Bits](Data_Struct_Implementation/bitsArray/README.md)
58+
7. Low Pass Filter
59+
8. [Memory map IO register manipulation](Data_Struct_Implementation/memoryMap/memory_map_io.md)
60+
9. Data Structure
61+
1. [Ring Buffer](./Data_Struct_Implementation/circularRingBuffer/README.md)
62+
2. [Hash Table](./Data_Struct_Implementation/hashTable/README.md)
63+
3. [Heap (priority queue)](./Data_Struct_Implementation/binaryHeap/README.md)
64+
4. [Stack](./Data_Struct_Implementation/stack/README.md)
65+
5. [Queue](./Data_Struct_Implementation/queue/README.md)
66+
6. [Binary Search Tree](Data_Struct_Implementation/BST/README.md)
67+
7. Red Black Tree
68+
8. Minium Spanning Tree (MST)
69+
10. Math
70+
1. Rolling average
71+
2. Taylor Series
72+
3. Dividing by a constant
73+
4. Sine Functions with Lookup table
74+
5. Linear Interpolation
75+
6. Floating Point Arthimetic
76+
11. Common STL function implementation
6877
1. [Safe memcpy (memmove)](Data_Struct_Implementation/memcpy_memmove/README.md)
6978
2. [itoa](Data_Struct_Implementation/itoa/README.md)
7079
3. [atoi](Data_Struct_Implementation/atoi/README.md)
7180
4. [sizeof](Data_Struct_Implementation/sizeof/README.md)
7281
5. [Aligned Malloc](Data_Struct_Implementation/alignedMalloc/README.md)
7382
6. Malloc()
7483
7. [strstr()](Data_Struct_Implementation\strstr\Makefile)
75-
17. Concurrency
84+
12. Concurrency
7685
1. Implement a Spinlock/Mutex
7786
1. [Test-and-set](https://en.wikipedia.org/wiki/Test-and-set)
7887
2. [Compare-and-swap](https://en.wikipedia.org/wiki/Compare-and-swap)
@@ -85,14 +94,14 @@
8594
7. [Print In Order](Data_Struct_Implementation/concurrency/PrintInorder.md)
8695
8. [Building H2O](Data_Struct_Implementation/concurrency/BuildingH2O.md)
8796
9. [The Dining Philosophers](Data_Struct_Implementation/concurrency/TheDiningPhilosophers.md)
88-
18. Other Implementations
97+
13. Other Implementations
8998
1. Shuffle cards
9099
2. Accurately (emphasize) read 64bit register with read32
91100
3. Given a matrix and its center coordinates, draw the circle
92101
4. Find a 32 bit frame start sequence in a raw byte stream buffer
93102
5. Memory tracker to hook into glibc library to keep track of dynamic memory allocations, including statistics
94103
6. Given an array of angles and an array of voltages for these angles, now there is a new angle coming in, calculate its voltage.
95-
1. [Other Common C algorithm](https://github.com/fragglet/c-algorithms)
104+
14. [Other Common C algorithm](https://github.com/fragglet/c-algorithms)
96105

97106

98107

0 commit comments

Comments
 (0)