Choco OS  V.0.16.9.0
Join to the chocolate world
oc_boot.c
Go to the documentation of this file.
1 
27 #include <oc_boot.h>
28 #include <oc_memman.h>
29 #include <oc_threadman.h>
30 #include <oc_programman.h>
31 #include <oc_processman.h>
32 #include <oc_streamman.h>
33 #include <oc_userman.h>
34 #include <oc_driverman.h>
35 #include <oc_moduleman.h>
36 
37 #include <oc_clock_lld.h>
38 #include <oc_sys_lld.h>
39 #include <oc_gpio_lld.h>
40 #include <oc_timer_lld.h>
41 #include <oc_dma_lld.h>
42 
43 #include <oc_threadman.h>
44 #include <oc_processman.h>
45 #include <oc_intman.h>
46 #include <oc_semaphore.h>
47 #include <oc_timer.h>
48 #include <oc_system_cfg.h>
49 #include <oc_userman.h>
50 #include <oc_driverman.h>
51 #include <oc_kprint.h>
52 #include <oc_stdio.h>
53 #include <oc_vfs.h>
54 #include <oc_screenman.h>
55 #include <oc_netifman.h>
56 #include <oc_udp.h>
57 #include <oc_exchan.h>
58 #include <oc_icmp.h>
59 #include <oc_tcp.h>
60 #include <oc_portman.h>
61 #include <oc_serviceman.h>
62 
68 #define _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________
69 
70 static oC_Boot_Level_t CurrentBootLevel = oC_Boot_Level_0;
71 static oC_Timestamp_t StartupTimestamp = 0;
72 
73 #undef _________________________________________LOCAL_VARIABLES_SECTION____________________________________________________________________
74 
75 
81 #define _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
82 
85 static void InitializeSystem(void);
86 static void InitializeLevel0(void);
87 static void InitializeLevel1(void);
88 static void InitializeLevel2(void);
89 static void InitializeLevel3(void);
90 static void InitializeLevel4(void);
91 static void InitializeLevel5(void);
92 static void InitializeLevel6(void);
93 
94 #undef _________________________________________LOCAL_PROTOTYPES_SECTION___________________________________________________________________
95 
102 #define _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
103 
106 //==========================================================================================================================================
110 //==========================================================================================================================================
111 void oC_Boot_Main(void)
112 {
113  InitializeSystem();
114 
115  CurrentBootLevel = oC_Boot_Level_SystemRunning;
116 
117  while(1)
118  {
119  /* IDLE Task */
123  oC_ProcessMan_KillAllZombies();
124  oC_ProgramMan_RerunDefualtIfNotRun(oC_UserMan_GetRootUser());
126  }
127 }
128 
129 //==========================================================================================================================================
130 //==========================================================================================================================================
131 oC_Boot_Level_t oC_Boot_GetCurrentBootLevel( void )
132 {
133  return CurrentBootLevel;
134 }
135 
136 //==========================================================================================================================================
137 //==========================================================================================================================================
138 oC_Timestamp_t oC_Boot_GetStartupTimestamp( void )
139 {
140  return StartupTimestamp;
141 }
142 
143 //==========================================================================================================================================
144 //==========================================================================================================================================
145 void oC_Boot_Restart( oC_Boot_Reason_t Reason , oC_User_t User )
146 {
148 }
149 
150 #undef _________________________________________INTERFACE_FUNCTIONS_SECTION________________________________________________________________
151 
158 #define _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
159 
162 //==========================================================================================================================================
163 //==========================================================================================================================================
164 static void InitializeSystem(void)
165 {
166  InitializeLevel0();
167  InitializeLevel1();
168  InitializeLevel2();
169  InitializeLevel3();
170  InitializeLevel4();
171  InitializeLevel5();
172  InitializeLevel6();
173 
174  StartupTimestamp = oC_KTime_GetTimestamp();
175 
176  //======================================================================================================================================
177  /*
178  * Run default program
179  */
180  //======================================================================================================================================
181  oC_ErrorCode_t errorCode = oC_ProgramMan_RunDefaultProgram(oC_UserMan_GetRootUser());
182 
183  if(oC_ErrorOccur(errorCode))
184  {
185  oC_SaveError("Run default program error: ",errorCode);
186  }
187 }
188 
189 //==========================================================================================================================================
190 //==========================================================================================================================================
191 static void InitializeLevel0(void)
192 {
193  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
194 
195  //======================================================================================================================================
196  /*
197  * Prepare level
198  */
199  //======================================================================================================================================
200  CurrentBootLevel = oC_Boot_Level_0;
201 
202  //======================================================================================================================================
203  /*
204  * Clock configuration
205  */
206  //======================================================================================================================================
207  errorCode = oC_CLOCK_LLD_TurnOnDriver();
208 
209  if(oC_ErrorOccur(errorCode))
210  {
211  oC_SaveError("Turn on clock driver error: " , errorCode);
212  }
213 
214  /* Prepare target frequency */
215 #define MAX 0
216  oC_Frequency_t targetFrequency = CFG_FREQUENCY_TARGET_FREQUENCY;
217 #undef MAX
218 
219  if(targetFrequency == 0)
220  {
221  targetFrequency = oC_CLOCK_LLD_GetMaximumClockFrequency();
222  }
223 
224  /* Configuration of clock */
225 #if CFG_BOOL_EXTERNAL_CLOCK_SOURCE
226  errorCode = oC_CLOCK_LLD_ConfigureExternalClock(targetFrequency,CFG_FREQUENCY_PERMISSIBLE_FREQUENCY_DIFFERENCE,CFG_FREQUENCY_EXTERNAL_CLOCK);
227 #else
228  errorCode = oC_CLOCK_LLD_ConfigureInternalClock(targetFrequency,CFG_FREQUENCY_PERMISSIBLE_FREQUENCY_DIFFERENCE);
229 #endif
230 
231  if(oC_ErrorOccur(errorCode))
232  {
233  oC_SaveError("Clock configuration error: " , errorCode );
234  }
235 
236  //======================================================================================================================================
237  /*
238  * Memory manager configuration
239  */
240  //======================================================================================================================================
241  errorCode = oC_MemMan_TurnOn();
242 
243  if(oC_ErrorOccur(errorCode))
244  {
245  oC_SaveError("Turn on memory manager error: " , errorCode );
246  }
247 
248  //======================================================================================================================================
249  /*
250  * Turning on Exception Handler module
251  */
252  //======================================================================================================================================
253  errorCode = oC_ExcHan_TurnOn();
254 
255  if(oC_ErrorOccur(errorCode))
256  {
257  oC_SaveError("Turn on exception handler error: " , errorCode );
258  }
259 
260  //======================================================================================================================================
261  /*
262  * Turning on drivers manager module
263  */
264  //======================================================================================================================================
265  errorCode = oC_DriverMan_TurnOn();
266 
267  if(oC_ErrorOccur(errorCode))
268  {
269  oC_SaveError("Driver manager error: " , errorCode );
270  }
271 
272 #if CFG_BOOL_GUI_ENABLED
273  //======================================================================================================================================
274  /*
275  * Turning on screens manager module
276  */
277  //======================================================================================================================================
278  errorCode = oC_ScreenMan_TurnOn();
279 
280  if(oC_ErrorOccur(errorCode))
281  {
282  oC_SaveError("Screen manager error: " , errorCode );
283  }
284 #endif
285 
286  //======================================================================================================================================
287  /*
288  * Turning on drivers from current level and configuration of all possible drivers
289  */
290  //======================================================================================================================================
291  oC_DriverMan_TurnOnAllDrivers();
292  oC_DriverMan_ConfigureAllDrivers();
293 
294 #if CFG_BOOL_GUI_ENABLED
296 #endif
297 
300 }
301 
302 //==========================================================================================================================================
303 //==========================================================================================================================================
304 static void InitializeLevel1(void)
305 {
306  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
307 
308  //======================================================================================================================================
309  /*
310  * Prepare level
311  */
312  //======================================================================================================================================
313  CurrentBootLevel = oC_Boot_Level_1;
314 
315  //======================================================================================================================================
316  /*
317  * Turning on process manager
318  */
319  //======================================================================================================================================
320  errorCode = oC_ProcessMan_TurnOn();
321 
322  if(oC_ErrorOccur(errorCode))
323  {
324  oC_SaveError("Turn on process manager error: " , errorCode);
325  }
326 
327  //======================================================================================================================================
328  /*
329  * Turning on stream manager
330  */
331  //======================================================================================================================================
332  errorCode = oC_StreamMan_TurnOn();
333 
334  if(oC_ErrorOccur(errorCode))
335  {
336  oC_SaveError("Turn on stream manager error: " , errorCode);
337  }
338 
339  //======================================================================================================================================
340  /*
341  * Turning on user manager
342  */
343  //======================================================================================================================================
344  errorCode = oC_UserMan_TurnOn();
345 
346  if(oC_ErrorOccur(errorCode))
347  {
348  oC_SaveError("Turn on user manager error: " , errorCode);
349  }
350 
351  //======================================================================================================================================
352  /*
353  * Turning on kernel time manager
354  */
355  //======================================================================================================================================
356  errorCode = oC_KTime_TurnOn();
357 
358  if(oC_ErrorOccur(errorCode))
359  {
360  oC_SaveError("Turn on kernel time module error: " , errorCode);
361  }
362 
363  //======================================================================================================================================
364  /*
365  * Turning on program manager
366  */
367  //======================================================================================================================================
368  errorCode = oC_ProgramMan_TurnOn();
369 
370  if(oC_ErrorOccur(errorCode))
371  {
372  oC_SaveError("Turn on program manager error: " , errorCode);
373  }
374 
375  //======================================================================================================================================
376  /*
377  * Turning on drivers from current level and configuration of all possible drivers
378  */
379  //======================================================================================================================================
380  oC_DriverMan_TurnOnAllDrivers();
381  oC_DriverMan_ConfigureAllDrivers();
382 
383 #if CFG_BOOL_GUI_ENABLED
385 #endif
386 
389 }
390 
391 //==========================================================================================================================================
392 //==========================================================================================================================================
393 static void InitializeLevel2(void)
394 {
395  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
396 
397  //======================================================================================================================================
398  /*
399  * Prepare level
400  */
401  //======================================================================================================================================
402  CurrentBootLevel = oC_Boot_Level_2;
403 
404  //======================================================================================================================================
405  /*
406  * Turning on kernel print module
407  */
408  //======================================================================================================================================
409  errorCode = oC_KPrint_TurnOn();
410 
411  if(oC_ErrorOccur(errorCode))
412  {
413  oC_SaveError("Turn on kernel print module error: " , errorCode);
414  }
415 
416  //======================================================================================================================================
417  /*
418  * Creating delete daemon
419  */
420  //======================================================================================================================================
421  errorCode = oC_ProcessMan_RunDeleteDaemon();
422 
423  if(oC_ErrorOccur(errorCode))
424  {
425  oC_SaveError("Run delete daemon error: " , errorCode);
426  }
427 
428  //======================================================================================================================================
429  /*
430  * Creating exception daemon
431  */
432  //======================================================================================================================================
433  errorCode = oC_ExcHan_RunDaemon();
434 
435  if(oC_ErrorOccur(errorCode))
436  {
437  oC_SaveError("Run delete daemon error: " , errorCode);
438  }
439 
440  //======================================================================================================================================
441  /*
442  * Turning on drivers from current level and configuration of all possible drivers
443  */
444  //======================================================================================================================================
445  oC_DriverMan_TurnOnAllDrivers();
446  oC_DriverMan_ConfigureAllDrivers();
447 
448 #if CFG_BOOL_GUI_ENABLED
450 #endif
451 
454 }
455 
456 static void InitializeLevel3(void)
457 {
458  oC_ErrorCode_t errorCode = oC_ErrorCode_ImplementError;
459 
460  //======================================================================================================================================
461  /*
462  * Prepare level
463  */
464  //======================================================================================================================================
465  CurrentBootLevel = oC_Boot_Level_3;
466 
467  //======================================================================================================================================
468  /*
469  * Creating delete daemon
470  */
471  //======================================================================================================================================
472  errorCode = oC_VirtualFileSystem_TurnOn();
473 
474  if(oC_ErrorOccur(errorCode))
475  {
476  oC_SaveError("Virtual File System turning on: " , errorCode);
477  }
478 
479  //======================================================================================================================================
480  /*
481  * Turning on drivers from current level and configuration of all possible drivers
482  */
483  //======================================================================================================================================
484  oC_DriverMan_TurnOnAllDrivers();
485  oC_DriverMan_ConfigureAllDrivers();
486 
487 #if CFG_BOOL_GUI_ENABLED
489 #endif
490 
493 }
494 
495 static void InitializeLevel4(void)
496 {
497  //======================================================================================================================================
498  /*
499  * Prepare level
500  */
501  //======================================================================================================================================
502  CurrentBootLevel = oC_Boot_Level_4;
503 
504  //======================================================================================================================================
505  /*
506  * Starting network manager
507  */
508  //======================================================================================================================================
509 #if CFG_BOOL_NETWORK_ENABLED == true
510  oC_SaveIfErrorOccur("NetifMan turning on: " , oC_NetifMan_TurnOn() );
511  oC_SaveIfErrorOccur("NetifMan start daemon: " , oC_NetifMan_StartDaemon() );
512  oC_SaveIfErrorOccur("UDP turning on: " , oC_Udp_TurnOn() );
513  oC_SaveIfErrorOccur("ICMP turning on: " , oC_Icmp_TurnOn() );
514  oC_SaveIfErrorOccur("PortMan turning on: " , oC_PortMan_TurnOn() );
515  oC_SaveIfErrorOccur("TCP turning on: " , oC_Tcp_TurnOn( s(1) ) );
516 #endif
517 
518  //======================================================================================================================================
519  /*
520  * Turning on drivers from current level and configuration of all possible drivers
521  */
522  //======================================================================================================================================
523  oC_DriverMan_TurnOnAllDrivers();
524  oC_DriverMan_ConfigureAllDrivers();
525 
526 #if CFG_BOOL_GUI_ENABLED
528 #endif
529 
530 #if CFG_BOOL_NETWORK_ENABLED
532 #endif
533 
536 }
537 
538 static void InitializeLevel5(void)
539 {
540  //======================================================================================================================================
541  /*
542  * Prepare level
543  */
544  //======================================================================================================================================
545  CurrentBootLevel = oC_Boot_Level_5;
546 
547  //======================================================================================================================================
548  /*
549  * Turning on drivers from current level and configuration of all possible drivers
550  */
551  //======================================================================================================================================
552  oC_DriverMan_TurnOnAllDrivers();
553  oC_DriverMan_ConfigureAllDrivers();
554 
555 #if CFG_BOOL_GUI_ENABLED
557 #endif
558 
559 #if CFG_BOOL_NETWORK_ENABLED
561 #endif
562 
565 }
566 
567 static void InitializeLevel6(void)
568 {
569  //======================================================================================================================================
570  /*
571  * Prepare level
572  */
573  //======================================================================================================================================
574  CurrentBootLevel = oC_Boot_Level_6;
575 
576  //======================================================================================================================================
577  /*
578  * Turning on drivers from current level and configuration of all possible drivers
579  */
580  //======================================================================================================================================
581  oC_DriverMan_TurnOnAllDrivers();
582  oC_DriverMan_ConfigureAllDrivers();
583 
584 #if CFG_BOOL_GUI_ENABLED
586 #endif
587 
588 #if CFG_BOOL_NETWORK_ENABLED
590 #endif
591 
594 }
595 
596 #undef _________________________________________LOCAL_FUNCTIONS_SECTION____________________________________________________________________
597 
oC_Boot_Level_t oC_Boot_GetCurrentBootLevel(void)
returns current boot level
Definition: oc_boot.c:131
Interface of Service Manager.
#define s(time)
Number of s.
Definition: oc_cfg.h:133
void oC_ScreenMan_ConfigureAll(void)
configures all screens
Definition: oc_screenman.c:164
void oC_ExcHan_PrintLoggedEvents(void)
prints logged events in the STD out
Definition: oc_exchan.c:206
oC_ErrorCode_t oC_ExcHan_RunDaemon(void)
starts daemon of the Exception Handler
Definition: oc_exchan.c:362
oC_ErrorCode_t oC_NetifMan_StartDaemon(void)
starts the NetifMan daemon
Definition: oc_netifman.c:905
The file with LLD interface for the TIMER driver.
The file with interface for the timer driver.
double oC_Frequency_t
type to store frequency
Definition: oc_frequency.h:76
void oC_NetifMan_ConfigureAll(void)
configures all network interface
Definition: oc_netifman.c:335
oC_Timestamp_t oC_Boot_GetStartupTimestamp(void)
returns timestamp of startup
Definition: oc_boot.c:138
The file with interface for process manager.
oC_ErrorCode_t oC_ScreenMan_TurnOn(void)
turns on the screen manager module
Definition: oc_screenman.c:80
oC_ErrorCode_t oC_Tcp_TurnOn(oC_Time_t Timeout)
turns on TCP module
Definition: oc_tcp.c:118
File with interface for user system manager.
Stores interface of netif manager module.
Module for managing port reservations.
oC_Frequency_t oC_CLOCK_LLD_GetMaximumClockFrequency(void)
returns maximum frequency permissible for the machine
Definition: oc_clock_lld.c:259
oC_ErrorCode_t oC_CLOCK_LLD_ConfigureInternalClock(oC_Frequency_t TargetFrequency, oC_Frequency_t PermissibleDifference)
configures system clock in internal mode
Definition: oc_clock_lld.c:312
The file with interface of the Screen Manager module.
void oC_ModuleMan_TurnOnAllPossible(void)
turns on all modules that turning on is possible
Definition: oc_moduleman.c:71
oC_ErrorCode_t oC_PortMan_TurnOn(void)
turns on the module
Definition: oc_portman.c:126
The file with LLD interface for the GPIO driver.
oC_ErrorCode_t oC_MemMan_TurnOn(void)
turns on memory manager
Definition: oc_memman.c:251
Definition: oc_user.c:43
The file with interface for bootloader.
void oC_Boot_Main(void)
main function of the system
Definition: oc_boot.c:111
oC_ErrorCode_t oC_Udp_TurnOn(void)
turns on UDP module
Definition: oc_udp.c:132
The file with interface for stream manager.
void oC_Boot_Restart(oC_Boot_Reason_t Reason, oC_User_t User)
restarts the system
Definition: oc_boot.c:145
oC_ErrorCode_t oC_CLOCK_LLD_TurnOnDriver(void)
initializes the driver to work
Definition: oc_clock_lld.c:160
The file with LLD interface for the CLOCK driver.
The file with interface for Virtual File System.
The file with interface for kernel print operations.
The file with interface for interrupt manager.
void oC_MemMan_CheckMemoryLeak(void)
checks if memory is not leaking
Definition: oc_memman.c:425
oC_ErrorCode_t oC_ExcHan_TurnOn(void)
turns on exception handler
Definition: oc_exchan.c:140
Stores UDP interface.
oC_ErrorCode_t oC_CLOCK_LLD_ConfigureExternalClock(oC_Frequency_t TargetFrequency, oC_Frequency_t PermissibleDifference, oC_Frequency_t OscillatorFrequency)
configures system clock to work in external mode
Definition: oc_clock_lld.c:405
The file with drivers manager interface.
The file with interface for program manager.
The file with memory manager interface.
void oC_SYS_LLD_Reset(void)
software reset of the machine
Definition: oc_sys_lld.c:496
oC_ErrorCode_t oC_Icmp_TurnOn(void)
turns on ICMP module
Definition: oc_icmp.c:109
File with interface of Exception Handler.
File with interface for ICMP.
The file with LLD interface for the SYS driver.
The file with interface for semaphores.
void oC_ServiceMan_StartAllPossible(void)
starts all services
void oC_MemMan_CheckMemoryExhausted(void)
checks if memory exhausted event not occurs.
Definition: oc_memman.c:385
The file with interface for Thread Manager.
void oC_MemMan_CheckOverflow(void)
scan each block to check if the overflow event not occurs.
Definition: oc_memman.c:355
The file with LLD interface for the DMA driver.
Manages modules in the system.
The file with standard input/output operations.