« SE4Binome2025-2 » : différence entre les versions

De projets-se.plil.fr
Aller à la navigation Aller à la recherche
Aucun résumé des modifications
Ligne 37 : Ligne 37 :
= Firmware: RTOS =
= Firmware: RTOS =


=== Architecture Report ===


'''1 System Architecture Overview'''
====== System Architecture Overview ======


The firmware implements a cooperative real-time operating system (RTOS) for AT-
The firmware implements a cooperative real-time operating system (RTOS) for ATmega328p microcontrollers, featuring a memory-optimized kernel with round-robin scheduling capabilities.


mega328p microcontrollers, featuring a memory-optimized kernel with round-robin schedul-
===== Component Hierarchy =====
 
ing capabilities.
 
'''1.1''' '''Component Hierarchy'''


<code>
firmware/
firmware/
├── kernel/
│  ├── kernel.[ch]      - Core kernel management
│  ├── scheduler.[ch]  - Task scheduler implementation
│  ├── task.[ch]        - Task control block system
│  └── config.h        - Resource configuration
└── main.c              - Application layer
</code>


<blockquote>kernel/
====== Core Kernel Mechanisms ======
 
kernel.[ch] - Core kernel management
 
scheduler.[ch] - Task scheduler implementation
 
task.[ch] - Task control block system
 
config.h - Resource configuration


main.c- Application layer
===== Task Management System =====
</blockquote>
'''2 Core Kernel Mechanisms'''
 
'''2.1''' '''Task Management System'''


The kernel implements a static task control block (TCB) architecture:
The kernel implements a static task control block (TCB) architecture:


<blockquote>'''typedef struct'''
<code objc>
typedef struct task_control_block {
    void (*function)(void*);    // Task entry point
    void* arg;                  // Task parameters
    uint8_t* stack_base;        // Stack memory (96 bytes)
    task_state_t state;        // Current task state
    uint16_t sleep_ticks;      // Sleep countdown
    uint8_t priority;          // Execution priority (0-3)
    char name[TASK_NAME_LENGTH]; // Task identifier
} task_t;
</code>


'''void''' (∗function )( '''void''' ∗) ; t a sk co n t r o lb l ock ''{ // Task entry'' ''point''
===== Task State Transitions =====
 
'''void'''∗arg ; ''// Task parameters''
 
uint8t ∗stackbase ; ''// Stack memory (96 bytes )''
 
t a s k s t a t e t state ; ''// Current'' ''task'' ''s t a t e''
 
uint16t s l e e p t i c k s ; ''// Sleep countdown''
 
uint8t p r i o r i t y ; ''// Execution'' ''p r i o r i t y (0−3)''
 
'''char''' name [TASKNAMELENGTH] ; ''// Task'' ''i d e n t i f i e r''
 
''}'' taskt ;
</blockquote>
'''2.2''' '''Task State Transitions'''


The system implements a finite state machine for task management:
The system implements a finite state machine for task management:


<blockquote>TASKREADY''⇀↽''TASKRUNNING ''→''TASKSLEEPING ''→''TASKREADY
$$\text{TASK\_READY} \rightleftharpoons \text{TASK\_RUNNING} \rightarrow \text{TASK\_SLEEPING} \rightarrow \text{TASK\_READY}$$
</blockquote>
1


'''2.3''' '''Task Creation Protocol'''
===== Task Creation Protocol =====


<blockquote>i n t 8 t taskcr eat e ( '''const char'''∗name , '''void''' (∗function )( '''void''' ∗) ,
<code objc>
int8_t task_create(const char* name, void (*function)(void*),  
                  void* arg, uint8_t priority, uint8_t* stack_buffer)
</code>


'''void'''∗arg , uint8t priority , uint8t ∗s t a c k b u f f e r )
**Creation Constraints:**


'''Creation Constraints:'''
  * Maximum task count: $MAX\_TASKS = 4$
  * Stack size: $STACK\_SIZE = 96$ bytes
  * Priority levels: $\{PRIORITY\_IDLE, PRIORITY\_LOW, PRIORITY\_MEDIUM, PRIORITY\_HIGH\}$


• Maximum task count: ''MAXTASKS'' = 4
====== Scheduling Algorithm ======


• Stack size: ''STACKSIZE'' = 96 bytes
===== Round-Robin Implementation =====
 
• Priority levels: ''{PRIORITYIDLE, PRIORITYLOW, PRIORITYMEDIUM, PRIORITY''
</blockquote>
'''3 Scheduling Algorithm'''
 
'''3.1''' '''Round-Robin Implementation'''


The scheduler employs a circular search algorithm to find the next executable task:
The scheduler employs a circular search algorithm to find the next executable task:


<blockquote>'''static'''
<code objc>
 
static uint8_t get_next_task(void) {
uint8t<br />
    uint8_t next_task = (current_task_id + 1) % MAX_TASKS;
uint8 t
    for (uint8_t i = 0; i < MAX_TASKS; i++) {
 
        if (is_task_valid(next_task) &&
nexttask = ( c u r r e n t t a s k i d + 1) % MAXTASKS; get next task ( '''void''' ) ''{''
            task_table[next_task].state == TASK_READY) {
            return next_task;
        }
        next_task = (next_task + 1) % MAX_TASKS;
    }
    return current_task_id;
}
</code>


'''for''' ( uint8t
===== Execution Flow =====
 
'''i f''' ( i s t a s k v a l i d ( nexttask ) &amp;&amp; i = 0; i ''&lt;'' MAX TASKS; i++) ''{''
 
'''return''' nexttask ; task table [ next task ] . state == TASK READY) ''{''
 
''}'' nexttask = ( nexttask + 1) % MAXTASKS;
 
''}'' '''return''' c u r r e n t t a s ki d ;
 
''}''
</blockquote>
'''3.2''' '''Execution Flow'''


The main scheduler loop follows this sequence:
The main scheduler loop follows this sequence:


<blockquote>1. Enter critical section (disable interrupts)
  - Enter critical section (disable interrupts)
  - Execute current task function
  - Calculate next task ID using round-robin
  - Leave critical section (enable interrupts)
  - Apply 1ms CPU delay to prevent overload


2. Execute current task function
====== Memory Management ======


3. Calculate next task ID using round-robin
===== Resource Allocation =====
 
4. Leave critical section (enable interrupts)
 
5. Apply 1ms CPU delay to prevent overload
</blockquote>
'''4 Memory Management'''
 
'''4.1''' '''Resource Allocation'''


The system employs static memory allocation for predictable resource usage:
The system employs static memory allocation for predictable resource usage:


2
$$\begin{align*}
 
\text{Total RAM for stacks} &= MAX\_TASKS \times STACK\_SIZE = 4 \times 96 = 384 \text{ bytes} \\
<blockquote>Total RAM for stacks = ''MAXTASKS × STACKSIZE'' = 4 ''×'' 96 = 384 bytes
\text{TCB memory footprint} &= MAX\_TASKS \times sizeof(task\_t) \approx 112 \text{ bytes} \\
 
\text{Global variables} &\approx 20 \text{ bytes} \\
TCB memory footprint = ''MAXTASKS × sizeof''(''taskt'') ''≈''112 bytes
\text{Total estimated usage} &\approx 516 \text{ bytes}
 
\end{align*}$$
Global variables ''≈''20 bytes


Total estimated usage ''≈''516 bytes
===== Configuration Parameters =====


'''4.2''' '''Configuration Parameters'''
<code objc>
</blockquote>
#define MAX_TASKS 4           // Maximum concurrent tasks
'''#define''' MAXTASKS 4 ''// Maximum concurrent'' ''tasks''
#define STACK_SIZE 96        // Bytes per task stack
#define TICK_FREQUENCY 100    // Hz - scheduler frequency
#define TASK_NAME_LENGTH 8    // Maximum task name characters
</code>


'''#define''' STACKSIZE 96 ''// Bytes per'' ''task'' ''stack''
====== Interrupt and Critical Section Management ======


'''#define''' TICKFREQUENCY 100 ''// Hz −scheduler'' ''frequency''
===== Atomic Operation Protection =====
 
'''#define''' TASKNAMELENGTH 8 ''// Maximum task name characters''
 
<blockquote>'''5 Interrupt and Critical Section Management'''
 
'''5.1''' '''Atomic Operation Protection'''


The kernel implements nested critical sections to protect shared resources:
The kernel implements nested critical sections to protect shared resources:


'''void'''
<code objc>
void enter_critical_section(void) {
    cli();                    // Disable interrupts
    critical_nesting++;      // Track nesting depth
}


c l i ( ) ; e n t e r c r i t i c a l s e c t i o n ( '''void''' ) ''{ // Disable'' ''i n t e r r u p t s''
void leave_critical_section(void) {
    if (critical_nesting > 0) critical_nesting--;
    if (critical_nesting == 0) sei();  // Re-enable interrupts
}
</code>


c r i t i c a l n e s t i n g ++; ''// Track nesting'' ''depth''
===== Timer Interrupt Configuration =====
 
''}''
</blockquote>
{|
!width="16%"| '''void'''
!width="16%"|
<blockquote>'''i f''' l e a v e c r i t i c a l s e c t i o n ( '''void''' ) ''{'' ( c r i t i c a l n e s t i n g ''&gt;'' 0) c r i t i c a l n e s t i n g −−;
</blockquote>
!width="16%"|
!width="16%"|
!width="16%"|
!width="16%"| ''i n t e r r u p t s''
|-
|
| '''i f'''
| ( c r i t i c a l n e s t i n g == 0)
| s e i ( ) ;
|
<blockquote>''// Re−enable''
</blockquote>
|
|}
 
<blockquote>''}''
 
'''5.2''' '''Timer Interrupt Configuration'''


The system timer generates 100Hz interrupts for tick management:
The system timer generates 100Hz interrupts for tick management:
</blockquote>
''OCR''1''A'' = ''Prescaler × Frequency−''1 = 16'','' 000'','' 000''−''1 = 2499


<blockquote>''// Timer1 configuration'' ''for 100Hz''
$$OCR1A = \frac{F\_CPU}{Prescaler \times Frequency} - 1 = \frac{16,000,000}{64 \times 100} - 1 = 2499$$


<code objc>
// Timer1 configuration for 100Hz
TCCR1A = 0;
TCCR1A = 0;
</blockquote>
TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10);
{|
OCR1A = 2499;
!width="20%"| TCCR1B = (1 ''&lt;&lt;'' WGM12)
TIMSK1 |= (1 << OCIE1A);
!width="20%"| ''|''
</code>
!width="20%"| (1 ''&lt;&lt;'' CS11)
!width="20%"| ''|''
!width="20%"|
<blockquote>(1 ''&lt;&lt;'' CS10 ) ;
</blockquote>
|-
|
<blockquote>OCR1A = 2499;
</blockquote>
|
|
|
|
|}


<blockquote>TIMSK1 ''|''= (1 ''&lt;&lt;'' OCIE1A) ;
====== Sleep and Timing Mechanisms ======


'''6 Sleep and Timing Mechanisms'''
===== Tick-Based Sleep System =====


'''6.1''' '''Tick-Based Sleep System'''
Tasks can suspend execution for precise durations using system ticks:


Tasks can suspend execution for precise durations using system ticks:
$$\text{sleep\_ticks} = \left\lceil \frac{\text{milliseconds}}{10} \right\rceil$$
</blockquote>
3


{|
<code objc>
!width="50%"| slpicks=
void task_sleep(uint16_t ticks) {
!width="50%"| milliseconds
    enter_critical_section();
|-
    task_table[current_task_id].sleep_ticks = ticks;
| slpicks=
    task_table[current_task_id].state = TASK_SLEEPING;
| 10
    leave_critical_section();
|-
    schedule();
|
}
<blockquote>'''void''' t a s k s l e e p ( uint16t e n t e r c r i t i c a l s e c t i o n ( ) ; t i c k s ) ''{''
</code>
</blockquote>
|
|}


<blockquote>tasktable [ c u r r e n tt a s ki d ] . s l e e p t i c k s = t i c k s ; tasktable [ c u r r e n tt a s ki d ] . state = TASKSLEEPING; l e a v e c r i t i c a l s e c t i o n ( ) ;<br />
===== Tick Update Algorithm =====
schedule ( ) ;<br />
''}''
</blockquote>
'''6.2''' '''Tick Update Algorithm'''


The interrupt service routine manages sleeping tasks:
The interrupt service routine manages sleeping tasks:


<blockquote>ISR(TIMER1COMPAvect) ''{'' systemticks++;<br />
<code objc>
'''for''' ( uint8t '''i f''' ( tasktable [ i ] . state == TASKSLEEPING &amp;&amp; i = 0; i ''&lt;'' MAX TASKS; i++) ''{''
ISR(TIMER1_COMPA_vect) {
    system_ticks++;
    for (uint8_t i = 0; i < MAX_TASKS; i++) {
        if (task_table[i].state == TASK_SLEEPING &&  
            task_table[i].sleep_ticks > 0) {
            task_table[i].sleep_ticks--;
            if (task_table[i].sleep_ticks == 0) {
                task_table[i].state = TASK_READY;
            }
        }
    }
}
</code>


tasktable [ i ] . s l e e p t i c k s ''&gt;'' 0) ''{'' tasktable [ i ] . s l e e p t i c k s −−;<br />
====== System Initialization Sequence ======
'''i f''' ( tasktable [ i ] . s l e e p t i c k s == 0) ''{'' tasktable [ i ] . state = TASKREADY; ''}''<br />
''}''<br />
''}''<br />
''}''
</blockquote>
'''7 System Initialization Sequence'''


'''7.1''' '''Boot Process'''
===== Boot Process =====


<blockquote>1. '''Memory Zeroing''': Clear task table and global variables
  - **Memory Zeroing**: Clear task table and global variables
  - **Timer Configuration**: Setup 100Hz interrupt timer
  - **Idle Task Creation**: Initialize fallback task with lowest priority
  - **Interrupt Enable**: Start scheduler tick generation
  - **Task Validation**: Mark all created tasks as READY state


2. '''Timer Configuration''': Setup 100Hz interrupt timer
====== Error Handling and Robustness ======


3. '''Idle Task Creation''': Initialize fallback task with lowest priority
===== Boundary Condition Management =====


4. '''Interrupt Enable''': Start scheduler tick generation
  * **Task Validation**: All task executions verify function pointer validity
  * **Sleep Sanitization**: Zero-tick sleep requests default to 1 tick
  * **Circular Search**: Scheduler handles empty task tables gracefully
  * **Nesting Safety**: Critical sections properly handle nested calls


5. '''Task Validation''': Mark all created tasks as READY state
===== Recovery Mechanisms =====
</blockquote>
'''8 Error Handling and Robustness'''


'''8.1''' '''Boundary Condition Management'''
<code objc>
static uint8_t is_task_valid(uint8_t task_id) {
    return (task_id < MAX_TASKS && task_table[task_id].function != NULL);
}
</code>


<blockquote>• '''Task Validation''': All task executions verify function pointer validity
====== Performance Characteristics ======
</blockquote>
4


<blockquote>• '''Sleep Sanitization''': Zero-tick sleep requests default to 1 tick• '''Circular Search''': Scheduler handles empty task tables gracefully• '''Nesting Safety''': Critical sections properly handle nested calls
===== Computational Complexity =====


'''8.2''' '''Recovery Mechanisms'''
Algorithm Complexity Analysis
^**Operation**    ^**Time Complexity**  ^**Space Complexity**  ^
|Task Creation    |$O(n)$              |$O(1)$                |
|Task Scheduling  |$O(n)$              |$O(1)$                |
|Sleep Update    |$O(n)$              |$O(1)$                |
|Context Switch  |$O(1)$              |$O(1)$                |


'''static return''' ( taskid ''&lt;'' MAX TASKS &amp;&amp; task table [ taskid ] . function != NULL) ; uint8 t i s t a s k v a l i d ( uint8 t task id ) ''{''<br />
===== Memory Efficiency =====
''}''
</blockquote>
{|
!width="50%"|
<blockquote>'''9'''<br />
'''9.1'''
</blockquote>
!width="50%"|
<blockquote>'''Performance Characteristics''' '''Computational Complexity'''
</blockquote>
|}


{|
The system achieves high memory efficiency through:
!width="33%"|
<blockquote>'''Operation'''
</blockquote>
!width="33%"| '''Time Complexity'''
!width="33%"| '''Space Complexity'''
|-
|
<blockquote>Task Creation<br />
Task Scheduling Sleep Update<br />
Context Switch
</blockquote>
|
<blockquote>''O''(''n'')<br />
''O''(''n'')<br />
''O''(''n'')<br />
''O''(1)
</blockquote>
|
<blockquote>''O''(1)<br />
''O''(1)<br />
''O''(1)<br />
''O''(1)
</blockquote>
|}


<blockquote>Table 1: Algorithm Complexity Analysis
  * Static allocation eliminating heap fragmentation
  * Fixed-size arrays for predictable memory usage
  * Stack sharing between kernel and application
  * Minimal TCB overhead (28 bytes per task)


'''9.2''' '''Memory Efficiency'''
====== Build System Integration ======


The system achieves high memory efficiency through:• Static allocation eliminating heap fragmentation• Fixed-size arrays for predictable memory usage• Stack sharing between kernel and application• Minimal TCB overhead (28 bytes per task)
===== Compilation Configuration =====


'''10''' '''Build System Integration'''
<code make>
MCU = atmega328p
F_CPU = 16000000UL
CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Os -Wall -std=c99
</code>


'''10.1''' '''Compilation Configuration'''
===== Memory Section Allocation =====
</blockquote>
MCU = atmega328p<br />
FCPU = 16000000UL<br />
CFLAGS = −mmcu=$ (MCU) −DFCPU=$ (FCPU) −Os −Wall −std=c99


<blockquote>'''10.2''' '''Memory Section Allocation'''<br />
$$\begin{align*}
Program Memory = .text + .data<br />
\text{Program Memory} &= \text{.text} + \text{.data} \\
RAM Usage = .data + .bss + Stack
\text{RAM Usage} &= \text{.data} + \text{.bss} + \text{Stack}
</blockquote>
\end{align*}$$
5

Version du 11 novembre 2025 à 13:56

Objectif

L'objectif du projet est de concevoir un pico-ordinateur complet, intégrant :

  • Une carte mère basée sue le microcontrôleur AT90USB1286

Une partie logicielle permettant l'éxecution de de commandes telles que ls, cp ou mv

Shield Arduino

Une première étape du projet a consisté à développer un shield pour Aduino uno, servant de plateforme de test et de développement pour les cartes filles SPI.

Fonctionalités:

  • Connexion de 5 périphériques SPI via des cartes filles.
  • Gestion des signaux Reset et Interruption.
  • Ajout d'une mémoire externe carte micro-SD via un connecteur Molex 10431.
  • Adaptation des niveaux logiques (5V a 3,3V) grâce à la puce 74LV125.

Ce shield joue le rôle de plateforme de développement temporaire, en attendant la carte mère du pico-ordinateur.

Schématique et routage

Schema shield arduino.jpg

Objectif

Schema shield arduino


Routage shield arduino


Carte mère

Schématique

Schéma carte mère du pico ordinateur



Firmware: RTOS

System Architecture Overview

The firmware implements a cooperative real-time operating system (RTOS) for ATmega328p microcontrollers, featuring a memory-optimized kernel with round-robin scheduling capabilities.

Component Hierarchy

firmware/ ├── kernel/ │ ├── kernel.[ch] - Core kernel management │ ├── scheduler.[ch] - Task scheduler implementation │ ├── task.[ch] - Task control block system │ └── config.h - Resource configuration └── main.c - Application layer

Core Kernel Mechanisms
Task Management System

The kernel implements a static task control block (TCB) architecture:

typedef struct task_control_block {

   void (*function)(void*);    // Task entry point
   void* arg;                  // Task parameters
   uint8_t* stack_base;        // Stack memory (96 bytes)
   task_state_t state;         // Current task state
   uint16_t sleep_ticks;       // Sleep countdown
   uint8_t priority;          // Execution priority (0-3)
   char name[TASK_NAME_LENGTH]; // Task identifier

} task_t;

Task State Transitions

The system implements a finite state machine for task management:

$$\text{TASK\_READY} \rightleftharpoons \text{TASK\_RUNNING} \rightarrow \text{TASK\_SLEEPING} \rightarrow \text{TASK\_READY}$$

Task Creation Protocol

int8_t task_create(const char* name, void (*function)(void*),

                  void* arg, uint8_t priority, uint8_t* stack_buffer)

    • Creation Constraints:**
 * Maximum task count: $MAX\_TASKS = 4$
 * Stack size: $STACK\_SIZE = 96$ bytes
 * Priority levels: $\{PRIORITY\_IDLE, PRIORITY\_LOW, PRIORITY\_MEDIUM, PRIORITY\_HIGH\}$
Scheduling Algorithm
Round-Robin Implementation

The scheduler employs a circular search algorithm to find the next executable task:

static uint8_t get_next_task(void) {

   uint8_t next_task = (current_task_id + 1) % MAX_TASKS;
   for (uint8_t i = 0; i < MAX_TASKS; i++) {
       if (is_task_valid(next_task) && 
           task_table[next_task].state == TASK_READY) {
           return next_task;
       }
       next_task = (next_task + 1) % MAX_TASKS;
   }
   return current_task_id;

}

Execution Flow

The main scheduler loop follows this sequence:

 - Enter critical section (disable interrupts)
 - Execute current task function
 - Calculate next task ID using round-robin
 - Leave critical section (enable interrupts)
 - Apply 1ms CPU delay to prevent overload
Memory Management
Resource Allocation

The system employs static memory allocation for predictable resource usage:

$$\begin{align*} \text{Total RAM for stacks} &= MAX\_TASKS \times STACK\_SIZE = 4 \times 96 = 384 \text{ bytes} \\ \text{TCB memory footprint} &= MAX\_TASKS \times sizeof(task\_t) \approx 112 \text{ bytes} \\ \text{Global variables} &\approx 20 \text{ bytes} \\ \text{Total estimated usage} &\approx 516 \text{ bytes} \end{align*}$$

Configuration Parameters

  1. define MAX_TASKS 4 // Maximum concurrent tasks
  2. define STACK_SIZE 96 // Bytes per task stack
  3. define TICK_FREQUENCY 100 // Hz - scheduler frequency
  4. define TASK_NAME_LENGTH 8 // Maximum task name characters

Interrupt and Critical Section Management
Atomic Operation Protection

The kernel implements nested critical sections to protect shared resources:

void enter_critical_section(void) {

   cli();                    // Disable interrupts
   critical_nesting++;       // Track nesting depth

}

void leave_critical_section(void) {

   if (critical_nesting > 0) critical_nesting--;
   if (critical_nesting == 0) sei();  // Re-enable interrupts

}

Timer Interrupt Configuration

The system timer generates 100Hz interrupts for tick management:

$$OCR1A = \frac{F\_CPU}{Prescaler \times Frequency} - 1 = \frac{16,000,000}{64 \times 100} - 1 = 2499$$

// Timer1 configuration for 100Hz TCCR1A = 0; TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10); OCR1A = 2499; TIMSK1 |= (1 << OCIE1A);

Sleep and Timing Mechanisms
Tick-Based Sleep System

Tasks can suspend execution for precise durations using system ticks:

$$\text{sleep\_ticks} = \left\lceil \frac{\text{milliseconds}}{10} \right\rceil$$

void task_sleep(uint16_t ticks) {

   enter_critical_section();
   task_table[current_task_id].sleep_ticks = ticks;
   task_table[current_task_id].state = TASK_SLEEPING;
   leave_critical_section();
   schedule();

}

Tick Update Algorithm

The interrupt service routine manages sleeping tasks:

ISR(TIMER1_COMPA_vect) {

   system_ticks++;
   for (uint8_t i = 0; i < MAX_TASKS; i++) {
       if (task_table[i].state == TASK_SLEEPING && 
           task_table[i].sleep_ticks > 0) {
           task_table[i].sleep_ticks--;
           if (task_table[i].sleep_ticks == 0) {
               task_table[i].state = TASK_READY;
           }
       }
   }

}

System Initialization Sequence
Boot Process
 - **Memory Zeroing**: Clear task table and global variables
 - **Timer Configuration**: Setup 100Hz interrupt timer
 - **Idle Task Creation**: Initialize fallback task with lowest priority
 - **Interrupt Enable**: Start scheduler tick generation
 - **Task Validation**: Mark all created tasks as READY state
Error Handling and Robustness
Boundary Condition Management
 * **Task Validation**: All task executions verify function pointer validity
 * **Sleep Sanitization**: Zero-tick sleep requests default to 1 tick
 * **Circular Search**: Scheduler handles empty task tables gracefully
 * **Nesting Safety**: Critical sections properly handle nested calls
Recovery Mechanisms

static uint8_t is_task_valid(uint8_t task_id) {

   return (task_id < MAX_TASKS && task_table[task_id].function != NULL);

}

Performance Characteristics
Computational Complexity

Algorithm Complexity Analysis ^**Operation** ^**Time Complexity** ^**Space Complexity** ^ |Task Creation |$O(n)$ |$O(1)$ | |Task Scheduling |$O(n)$ |$O(1)$ | |Sleep Update |$O(n)$ |$O(1)$ | |Context Switch |$O(1)$ |$O(1)$ |

Memory Efficiency

The system achieves high memory efficiency through:

 * Static allocation eliminating heap fragmentation
 * Fixed-size arrays for predictable memory usage
 * Stack sharing between kernel and application
 * Minimal TCB overhead (28 bytes per task)
Build System Integration
Compilation Configuration

MCU = atmega328p F_CPU = 16000000UL CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Os -Wall -std=c99

Memory Section Allocation

$$\begin{align*} \text{Program Memory} &= \text{.text} + \text{.data} \\ \text{RAM Usage} &= \text{.data} + \text{.bss} + \text{Stack} \end{align*}$$