SE4Binome2025-2

De projets-se.plil.fr
Aller à la navigation Aller à la recherche

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
  1. GitHub Wiki — Dual-LED Binary Clock Firmware

Below is a structured wiki layout with properly formatted Markdown files ready for upload to a GitHub Wiki.

---

    1. Home.md

```markdown

  1. Dual-LED Binary Clock Firmware
    1. Project Overview
    • Dual-LED Binary Clock Firmware** is a sophisticated real-time operating system (RTOS) implementation for ATmega328p microcontrollers, demonstrating advanced embedded systems concepts with minimal resource utilization.
    1. Quick Links

- **[System Architecture](System-Architecture)** - High-level design and components - **[Kernel Design](Kernel-Design)** - RTOS kernel implementation details - **[Scheduler](Scheduler)** - Task scheduling algorithms - **[Memory Management](Memory-Management)** - Resource allocation and constraints - **[API Reference](API-Reference)** - Complete function documentation - **[Build System](Build-System)** - Compilation and deployment guide - **[Performance Analysis](Performance-Analysis)** - Timing and resource metrics

    1. Key Features

✅ **Cooperative RTOS** with round-robin scheduling ✅ **Memory-optimized** for ATmega328p (2KB RAM) ✅ **Tick-based timing** with 100Hz resolution ✅ **Priority-based** task execution (4 levels) ✅ **Sleep/wake** functionality for power management ✅ **Critical section** protection for shared resources

    1. Repository Structure

```

firmware/ ├── src/ │ ├── kernel/ │ │ ├── kernel.c/h # Core kernel management │ │ ├── scheduler.c/h # Task scheduler │ │ ├── task.c/h # Task control blocks │ │ └── config.h # System configuration │ └── main.c # Application example ├── Makefile └── README.md

```

    1. Getting Started

1. **Prerequisites**: `avr-gcc`, `avrdude`, `make` 2. **Clone**: `git clone <repository-url>` 3. **Build**: `make` 4. **Flash**: `make flash` ```

---

    1. System-Architecture.md

```markdown

  1. System Architecture
    1. Component Hierarchy

The firmware is organized into a modular RTOS architecture:

```

// Core RTOS Components kernel/ // Real-time kernel foundation ├── kernel.c/h // System initialization and management ├── scheduler.c/h // Task scheduling algorithms ├── task.c/h // Task control block implementation └── config.h // Resource constraints and tuning

// Application Layer main.c // User tasks and application logic

```

    1. Data Flow

```

Hardware Interrupts → Scheduler Tick → Task State Update → Task Execution ↑ ↓ ↓ ↓ Timer ISR Update sleepers Ready → Running User code

```

    1. Key Design Patterns
    • Static Allocation Pattern**

- All memory allocated at compile time - No dynamic memory management - Fixed-size arrays for predictable behavior

    • Cooperative Multitasking**

- Tasks voluntarily yield control - No preemptive context switching - Simplified synchronization

    • Layered Architecture**

- Hardware abstraction through interrupts - Kernel services for task management - Application-specific logic in tasks ```

---

    1. Kernel-Design.md

````markdown

  1. Kernel Design
    1. Core Data Structures
      1. Task Control Block (TCB)

```c typedef struct task_control_block {

   void (*function)(void*);     // Task entry point
   void* arg;                   // Task parameters
   uint8_t* stack_base;         // 96-byte stack memory
   task_state_t state;          // Current execution state
   uint16_t sleep_ticks;        // Sleep duration counter
   uint8_t priority;            // Execution priority (0-3)
   char name[TASK_NAME_LENGTH]; // Task identifier

} task_t; ````

      1. System Globals

```c // Shared kernel state task_t task_table[MAX_TASKS]; // Static task array volatile uint8_t current_task_id; // Currently executing task volatile uint8_t task_count; // Active task counter volatile uint32_t system_ticks; // Global time reference volatile uint8_t critical_nesting; // Interrupt disable counter ```

    1. State Management
      1. Task Lifecycle

``` CREATED → READY ↔ RUNNING → SLEEPING → READY

   ↓        ↓                   ↓
EXITED ← COMPLETED         (sleep expired)

```

      1. State Transitions

| Operation | From State | To State | Conditions | | --------------- | ---------- | --------- | ---------------------------- | | `task_create()` | - | READY | Slot available, valid params | | `schedule()` | RUNNING | READY | Voluntary yield | | `task_sleep()` | RUNNING | SLEEPING | ticks > 0 | | Timer ISR | SLEEPING | READY | sleep_ticks == 0 | | `task_exit()` | RUNNING | COMPLETED | Task finished |

    1. Initialization Sequence

```c void kernel_init(void) {

   // 1. Clear all system state
   memset(task_table, 0, sizeof(task_table));
   
   // 2. Configure 100Hz system timer
   TCCR1B = (1 << WGM12) | (1 << CS11) | (1 << CS10);
   OCR1A = 2499;  // 16MHz/64/100Hz - 1
   TIMSK1 |= (1 << OCIE1A);
   
   // 3. Create idle task
   task_create("idle", idle_task, NULL, PRIORITY_IDLE, idle_stack);
   
   // 4. Enable global interrupts
   sei();

} ```

````

---

    1. Scheduler.md

```markdown

  1. Scheduler
    1. Round-Robin Algorithm
      1. Next Task Selection

```c 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;

} ````

      1. Task Validation

```c static uint8_t is_task_valid(uint8_t task_id) {

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

} ```

    1. Execution Loop

```c void scheduler_start(void) {

   scheduler_running = 1;
   
   while (scheduler_running) {
       enter_critical_section();
       
       if (is_task_valid(current_task_id)) {
           leave_critical_section();
           task_table[current_task_id].function(task_table[current_task_id].arg);
           enter_critical_section();
       }
       current_task_id = get_next_task();
       leave_critical_section();
       _delay_us(1000);
   }

} ```

    1. Priority Handling

While primarily round-robin, priorities influence task creation order, manual scheduling, and idle task execution.

````

---

    1. Memory-Management.md

```markdown

  1. Memory Management
    1. Resource Constraints

| Resource | Allocation | Usage | |----------|------------|-------| | **Total Tasks** | 4 slots | System + application tasks | | **Stack Size** | 96 bytes/task | Function calls and locals | | **TCB Size** | 28 bytes/task | Task metadata storage | | **Total RAM** | ~516 bytes | 25% of ATmega328p capacity |

    1. Memory Layout

````

0x0000 +----------------+ | .data (init) | +----------------+ | .bss (zero) | +----------------+ | task_table[4] | +----------------+ | stack_0[96] | +----------------+ | stack_1[96] | +----------------+ | stack_2[96] | +----------------+ | stack_3[96] | +----------------+ | Heap (unused) | +----------------+ 0x0800 | Stack (down) | +----------------+

````

    1. Configuration Tuning
      1. config.h Parameters

```c

  1. define MAX_TASKS 4
  2. define STACK_SIZE 96
  3. define TASK_NAME_LENGTH 8
  4. define TICK_FREQUENCY 100
  5. define F_CPU 16000000UL
  6. define PRIORITY_IDLE 0
  7. define PRIORITY_LOW 1
  8. define PRIORITY_MEDIUM 2
  9. define PRIORITY_HIGH 3

````

````

---

    1. API-Reference.md

```markdown

  1. API Reference
    1. Kernel API
      1. `kernel_init()`

```c void kernel_init(void); ````

Initializes all kernel subsystems, clears task table, sets up timer, and enables interrupts.

      1. `kernel_start()`

```c void kernel_start(void); ```

Begins task execution. Requires prior initialization.

      1. `kernel_delay_ms()`

```c void kernel_delay_ms(uint16_t ms); ```

Cooperative delay without busy-waiting.

    1. Task Management API
      1. `task_create()`

```c int8_t task_create(const char* name, void (*function)(void*), void* arg, uint8_t priority, uint8_t* stack_buffer); ```

Creates a new task. Returns task ID or -1 on error.

      1. `task_sleep()`

```c void task_sleep(uint16_t ticks); ```

Transitions running task to sleeping state.

      1. `task_exit()`

```c void task_exit(void); ```

Marks current task as completed.

    1. Scheduler Control API
      1. `enter_critical_section()`

```c void enter_critical_section(void); ```

Disables interrupts and protects critical resources.

      1. `schedule()`

```c void schedule(void); ```

Yields control to next ready task.

````

---

    1. Build-System.md

```markdown

  1. Build System
    1. Toolchain Requirements

```bash sudo apt install avr-gcc avr-libc avrdude make brew install avr-gcc avrdude ````

    1. Makefile Targets

| Target | Purpose | Output | | ------------ | ---------------------- | --------------- | | `make` | Build firmware | `firmware.hex` | | `make flash` | Program device | Serial upload | | `make clean` | Remove build artifacts | Clean directory | | `make size` | Display memory usage | Text report |

    1. Compilation Flags

```makefile CFLAGS = -mmcu=atmega328p \

        -DF_CPU=16000000UL \
        -Os -Wall -std=c99

```

    1. Programming Configuration

```makefile PROGRAMMER = arduino PORT = /dev/ttyACM0 BAUD = 115200 ```

Use `make flash` to upload via Arduino bootloader.

````

---

    1. Performance-Analysis.md

```markdown

  1. Performance Analysis
    1. Timing Characteristics

| Operation | CPU Cycles | Real Time @16MHz | |-----------|------------|------------------| | Context Switch | ~16000 | 1ms | | Tick ISR | ~800 | 50μs | | Task Search | 80-320 | 5-20μs | | Sleep Update | 20-80 | 1.25-5μs |

    1. Memory Utilization

````

Program Memory: ~3KB of 32KB (9%) Data Memory: ~516B of 2KB (25%) Stack Headroom: ~384B per task (conservative)

```

    1. Interrupt Timing

```

Input Frequency: 16,000,000 Hz Prescaler: 64 Timer Frequency: 250,000 Hz Compare Match: 2500 counts Interrupt Frequency: 100 Hz Interrupt Period: 10 ms

```

Critical section disable time <1ms during switches. ```

---

    1. _Sidebar.md

```markdown

    • Navigation**

- Home - System Architecture - Kernel Design - Scheduler - Memory Management - API Reference - Build System - Performance Analysis

    • External Links**

- [Repository](https://github.com/your-username/your-repo) - [Issues](https://github.com/your-username/your-repo/issues) - [Releases](https://github.com/your-username/your-repo/releases) ```

---

These Markdown files can be directly uploaded into the GitHub Wiki via the web interface or the `wiki.git` repository clone.