Skip to content

Commit

Permalink
Merge pull request #22 from aslansq/9_hw_int_challenge
Browse files Browse the repository at this point in the history
9 hw int challenge
  • Loading branch information
aslansq authored Dec 29, 2024
2 parents fa98da4 + b26dfa0 commit a6d6379
Show file tree
Hide file tree
Showing 29 changed files with 838 additions and 32 deletions.
3 changes: 2 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"stdint.h": "c",
"task.h": "c",
"demo_hw.h": "c",
"stdarg.h": "c"
"stdarg.h": "c",
"ringbuffer.h": "c"
}
}
20 changes: 17 additions & 3 deletions 0_base/demo_hw.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
static void _uart1_update(void);

static uint8_t _led_st = 0;
static uint8_t _adc_val = 0;

// PUBLIC

Expand All @@ -26,6 +27,7 @@ void demo_hw_term_printf(const char *format, ...) {
}

void demo_hw_term_writeChar(char c) {
c = (c == '\r') ? '\n' : c;
UART0_TX_WAIT();
UART0_DATA = c;
if(c == '\n') {
Expand Down Expand Up @@ -117,11 +119,13 @@ void demo_hw_led_toggle(void) {
}

uint8_t demo_hw_adc_read(void) {
static uint8_t adcBuf[] = {160, 170, 200, 180, 150}; // :) behave like adc reading fluctuate like in real life
static uint8_t adcBuf[] = {160, 170, 200, 180, 150, 121}; // :) behave like adc reading fluctuate like in real life
static uint8_t adcBufIdx = 0;
++adcBufIdx;
if(adcBufIdx == sizeof(adcBuf))
adcBufIdx = 0;
_adc_val = adcBuf[adcBufIdx];
_uart1_update();
return adcBuf[adcBufIdx];
}

Expand All @@ -140,9 +144,19 @@ void demo_hw_init(void) {
* @brief rewrites everything
*/
static void _uart1_update(void) {
static char uart1_buf[] = "led : 0\r";
static char *ledStPtr = &uart1_buf[6];
static char uart1_buf[] =
"\
\x1b[H\
led : 0\n\r\
adc : 000\n\r\
";
static char *ledStPtr = &uart1_buf[9];
static char *adcValPtr = &uart1_buf[18];
*ledStPtr = (_led_st) ? '1' : '0';
adcValPtr[0] = ' ';
adcValPtr[1] = ' ';
adcValPtr[2] = ' ';
sprintf(adcValPtr, "%d", (int)_adc_val);
uint8_t idx = 0;
while(uart1_buf[idx] != '\0') {
UART1_TX_WAIT();
Expand Down
2 changes: 1 addition & 1 deletion 0_base/demo_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ void demo_hw_term_printf(const char *format, ...);
/**
* @brief write a byte to terminal
*/
void demo_hw_term_writeChar(char u8);
void demo_hw_term_writeChar(char c);

/**
* @brief writes null terminated buffer to stdout of your terminal
Expand Down
3 changes: 3 additions & 0 deletions 2_blinky/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# 2_blinky

Blinks every 1 second.
```
../shell/rebuild_run_qemu.sh .
```

## Terminal Output
```
Expand Down
3 changes: 3 additions & 0 deletions 3_task_scheduling/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# 3_task_scheduling

```
../shell/rebuild_run_qemu.sh .
```
[Introduction to RTOS Part 3 - Task Scheduling | Digi-Key Electronics](https://www.youtube.com/watch?v=95yUbClyf3E&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=3)

Task2 has higher priority and preempts task1.
Expand Down
4 changes: 3 additions & 1 deletion 3_task_scheduling_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 3_task_scheduling

```Please ignore race conditions for now```
```
../shell/rebuild_run_qemu.sh .
```

Challenge of [Introduction to RTOS Part 3 - Task Scheduling | Digi-Key Electronics](https://www.youtube.com/watch?v=95yUbClyf3E&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=3)

Expand Down
35 changes: 21 additions & 14 deletions 4_memory/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,40 @@

This file demonstrates memory management in FreeRTOS
Explanation of demos:

<mark>DEMO_1_C overflow stack by recursive call</mark>
```
DEMO_1_C
overflow stack by recursive call
../shell/rebuild_run_qemu.sh . -DDEMO_1_C:BOOL=ON
```

<mark>DEMO_2_C allocating huge array in stack to ovf</mark>
```
DEMO_2_C
allocating huge array in stack to ovf
../shell/rebuild_run_qemu.sh . -DDEMO_2_C:BOOL=ON
```

<mark>DEMO_3_C ovf heap u32 at a time</mark>
```
DEMO_3_C
ovf heap u32 at a time
../shell/rebuild_run_qemu.sh . -DDEMO_3_C:BOOL=ON
```

<mark>DEMO_4_C ovf heap in single shot</mark>
```
DEMO_4_C
ovf heap in single shot
../shell/rebuild_run_qemu.sh . -DDEMO_4_C:BOOL=ON
```

<mark>DEMO_5_C properly malloc and free. this should be fine</mark>
```
DEMO_5_C
properly malloc and free. this should be fine
../shell/rebuild_run_qemu.sh . -DDEMO_5_C:BOOL=ON
```

<mark>DEMO_6_C overflow of static stack by recursive call</mark>
```
DEMO_6_C
overflow of static stack by recursive call
../shell/rebuild_run_qemu.sh . -DDEMO_6_C:BOOL=ON
```

<mark> default DEMO_1_C
```
default
DEMO_1_C
../shell/rebuild_run_qemu.sh .
```

## Terminal Output
Expand Down
4 changes: 3 additions & 1 deletion 4_memory_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 4_memory_challenge

```Please ignore race conditions for now```
```
../shell/rebuild_run_qemu.sh .
```

Challenge of [Introduction to RTOS Part 4 - Memory Management ](https://www.youtube.com/watch?v=Qske3yZRW5I&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=4)

Expand Down
4 changes: 3 additions & 1 deletion 5_queue/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 5_queue

```
../shell/rebuild_run_qemu.sh .
```
[Introduction to RTOS Part 5 - Queue](https://www.youtube.com/watch?v=pHJ3lxOoWeI&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=5)

## Terminal Output
Expand Down
4 changes: 3 additions & 1 deletion 5_queue_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# 5_queue_challenge

```
../shell/rebuild_run_qemu.sh .
```
Challenge of [Introduction to RTOS Part 5 - Queue](https://www.youtube.com/watch?v=pHJ3lxOoWeI&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=5)

![Simple UI](./doc/challenge.png "Simple UI")
Expand Down
15 changes: 9 additions & 6 deletions 6_mutex/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# 6_mutex

Two demos available. Pass one of the arguments to CMake.

<mark>demo_mutex.c</mark>
```
demo_mutex.c
DEMO_MUTEX_C:BOOL=ON
../shell/rebuild_run_qemu.sh . -DDEMO_MUTEX_C:BOOL=ON
```

<mark>demo_race.c</mark>
```
demo_race.c
DEMO_RACE_C:BOOL=ON
../shell/rebuild_run_qemu.sh . -DDEMO_RACE_C:BOOL=ON
```

<mark>default demo.c</mark>
```
default
DEMO_MUTEX_C:BOOL=ON
../shell/rebuild_run_qemu.sh .
```

[Introduction to RTOS Part 6 - Mutex](https://www.youtube.com/watch?v=I55auRpbiTs&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=6)
Expand Down
4 changes: 4 additions & 0 deletions 6_mutex_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 6_mutex_challenge

```
../shell/rebuild_run_qemu.sh .
```

Challenge of [Introduction to RTOS Part 6 - Mutex](https://www.youtube.com/watch?v=I55auRpbiTs&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=6)

On the video he says this hack.
Expand Down
4 changes: 4 additions & 0 deletions 7_semaphore/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 7_semaphore

```
../shell/rebuild_run_qemu.sh .
```

[Introduction to RTOS Part 7 - Semaphore](https://www.youtube.com/watch?v=5JcMtbA9QEE&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=7)

## Terminal Output
Expand Down
4 changes: 4 additions & 0 deletions 7_semaphore_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 7_semaphore_challenge

```
../shell/rebuild_run_qemu.sh .
```

[Introduction to RTOS Part 7 - Semaphore](https://www.youtube.com/watch?v=5JcMtbA9QEE&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=7)

Interesting trace to see how some producers take longer than others because they wait for semaphore or mutex.
Expand Down
4 changes: 4 additions & 0 deletions 8_sw_timers/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 8_sw_timers

```
../shell/rebuild_run_qemu.sh .
```

[Introduction to RTOS Part 8 - Software Timer ](https://www.youtube.com/watch?v=b1f1Iex0Tso&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=8)

## Terminal Output
Expand Down
4 changes: 4 additions & 0 deletions 8_sw_timers_challenge/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# 8_sw_timers_challenge

```
../shell/rebuild_run_qemu.sh .
```

Challenge of [Introduction to RTOS Part 8 - Software Timer ](https://www.youtube.com/watch?v=b1f1Iex0Tso&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=8)

## Terminal Output
Expand Down
6 changes: 5 additions & 1 deletion 9_hw_int/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# 9_hw_int

<mark>demo_tm.c</mark>
```
../shell/rebuild_run_qemu.sh . -DDEMO_TM_C:BOOL=ON
Expand All @@ -12,6 +12,10 @@
```
../shell/rebuild_run_qemu.sh . -DDEMO_NOTIFY_C:BOOL=ON
```
<mark>default demo_adc.c</mark>
```
../shell/rebuild_run_qemu.sh .
```

[Introduction to RTOS Part 9 - Hardware Interrupts](https://www.youtube.com/watch?v=qsflCf6ahXU&list=PLEBQazB0HUyQ4hAPU1cJED6t3DU0h34bz&index=9)

Expand Down
19 changes: 19 additions & 0 deletions 9_hw_int_challenge/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch_QEMU",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/demo",
"cwd": "${workspaceFolder}",
"miDebuggerPath": "${env:GCC_ARM_NONE_EABI_BIN_PATH}/arm-none-eabi-gdb-py",
"miDebuggerServerAddress": "localhost:1234",
"stopAtEntry": true,
"preLaunchTask": "Run_QEMU",
},
]
}
Loading

0 comments on commit a6d6379

Please sign in to comment.