-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
110 lines (92 loc) · 4.9 KB
/
Copy pathmain.c
File metadata and controls
110 lines (92 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/*******************************************************************************
** File: main.c
** Description: Demo Entry Point - Simulates ECU Lifecycle
**
** ELI5: This is the "car turning on and off" simulator.
** It runs through: START → DRIVE → SHUTDOWN
**
** ELI25: Simulates ECU lifecycle per Mihai Suciu's slides:
** 1. STARTUP: Initialize all modules, call NvM_ReadAll
** 2. NORMAL: Cyclic MainFunction calls
** 3. SHUTDOWN: Call NvM_WriteAll, cleanup
*******************************************************************************/
#include <stdio.h>
#include "Std_Types.h"
#include "Fls.h"
#include "Eep.h"
#include "Fee.h"
#include "Ea.h"
#include "MemIf.h"
#include "NvM.h"
#include "Autosar_CDD.h"
/*------------------------------------------------------------------------------
* Demo Configuration
*----------------------------------------------------------------------------*/
#define DEMO_MAIN_FUNCTION_CYCLES (6U) /* Number of 10ms cycles to simulate */
/*******************************************************************************
* MAIN FUNCTION - ECU Lifecycle Simulation
******************************************************************************/
int main(void)
{
uint32 cycle;
/*=========================================================================
* PHASE 1: ECU STARTUP (Ignition ON)
*
* ELI5: Car is turning on! Initialize everything in order:
* First the hardware (Flash, EEPROM), then the software layers.
*
* ELI25: AUTOSAR defines initialization order - lower layers first:
* Fls → Fee → Eep → Ea → NvM → Application
*========================================================================*/
/* Initialize MCAL (Microcontroller Abstraction Layer) */
Fls_Init(); /* Flash driver */
Eep_Init(); /* EEPROM driver */
/* Initialize Abstraction Layer */
Fee_Init(); /* Flash EEPROM Emulation */
Ea_Init(); /* EEPROM Abstraction */
/* Initialize Service Layer */
NvM_Init(); /* NVRAM Manager */
/* Load all saved data */
NvM_ReadAll();
/* Initialize Application */
Autosar_CDD_Init();
/*=========================================================================
* PHASE 2: NORMAL OPERATION (Driving)
*
* ELI5: Now we're driving! The car checks things every 10 milliseconds.
*
* ELI25: OS scheduler calls MainFunction cyclically. Real period is
* typically 10ms as shown in Mihai's Task_10ms diagram.
*========================================================================*/
printf("═══════════════════ NORMAL OPERATION ═══════════════════\n\n");
printf("[MAIN] Simulating %u cycles of 10ms task...\n\n", DEMO_MAIN_FUNCTION_CYCLES);
for (cycle = 1; cycle <= DEMO_MAIN_FUNCTION_CYCLES; cycle++) {
/* Simulate OS calling our cyclic task */
Autosar_CDD_MainFunction();
}
printf("\n[MAIN] Simulation ended. Driver turns key to OFF.\n");
/*=========================================================================
* PHASE 3: SHUTDOWN (Ignition OFF)
*
* ELI5: Driver is leaving! Save everything before power goes away!
*
* ELI25: ECU State Manager triggers shutdown sequence.
* NvM_WriteAll must complete before power loss.
*========================================================================*/
Autosar_CDD_Stop();
NvM_WriteAll();
/*=========================================================================
* FINAL OUTPUT
*========================================================================*/
printf("\n");
printf("╔══════════════════════════════════════════════════════════════╗\n");
printf("║ DEMO COMPLETE ║\n");
printf("╠══════════════════════════════════════════════════════════════╣\n");
printf("║ Data has been saved to: ║\n");
printf("║ • sim_flash.bin (Driver Profile via Fee) ║\n");
printf("║ • sim_eeprom.bin (Odometer via EA) ║\n");
printf("║ ║\n");
printf("║ Run the demo again to see data being RESTORED! ║\n");
printf("╚══════════════════════════════════════════════════════════════╝\n");
return 0;
}