rusEFI
The most advanced open source ECU
chconf.h
Go to the documentation of this file.
1 /*
2  ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
3 
4  Licensed under the Apache License, Version 2.0 (the "License");
5  you may not use this file except in compliance with the License.
6  You may obtain a copy of the License at
7 
8  http://www.apache.org/licenses/LICENSE-2.0
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 */
16 
17 /**
18  * @file templates/chconf.h
19  * @brief Configuration file template.
20  * @details A copy of this file must be placed in each project directory, it
21  * contains the application specific kernel settings.
22  *
23  * @addtogroup config
24  * @details Kernel related settings and hooks.
25  * @{
26  */
27 
28 #ifndef CHCONF_H
29 #define CHCONF_H
30 
31 // todo: access some existing configuration field
32 #define STM32_SYSCLK 168000000
33 
34 #include "chconf_common.h"
35 
36 /*===========================================================================*/
37 /**
38  * @name System timers settings
39  * @{
40  */
41 /*===========================================================================*/
42 
43 /**
44  * @brief System time counter resolution.
45  * @note Allowed values are 16 or 32 bits.
46  */
47 #if !defined(CH_CFG_ST_RESOLUTION)
48 #define CH_CFG_ST_RESOLUTION 32
49 #endif
50 
51 /**
52  * @brief System tick frequency.
53  * @details Frequency of the system timer that drives the system ticks. This
54  * setting also defines the system tick time unit.
55  */
56 #if !defined(CH_CFG_ST_FREQUENCY)
57 #define CH_CFG_ST_FREQUENCY 1000
58 #endif
59 
60 /**
61  * @brief Time intervals data size.
62  * @note Allowed values are 16, 32 or 64 bits.
63  */
64 #if !defined(CH_CFG_INTERVALS_SIZE)
65 #define CH_CFG_INTERVALS_SIZE 32
66 #endif
67 
68 /**
69  * @brief Time types data size.
70  * @note Allowed values are 16 or 32 bits.
71  */
72 #if !defined(CH_CFG_TIME_TYPES_SIZE)
73 #define CH_CFG_TIME_TYPES_SIZE 32
74 #endif
75 
76 /**
77  * @brief Time delta constant for the tick-less mode.
78  * @note If this value is zero then the system uses the classic
79  * periodic tick. This value represents the minimum number
80  * of ticks that is safe to specify in a timeout directive.
81  * The value one is not valid, timeouts are rounded up to
82  * this value.
83  */
84 // rusEfi currently uses tick mode, see CH_CFG_ST_FREQUENCY
85 // ST requires TIM2 or another 32 bit timer and we currently use it for ICU
86 // but! there is no reason to use it for ICU as we've recently realized
87 // so todo: migrate trigger to EXTI and try tick-less mode
88 // see also CH_CFG_TIME_QUANTUM
89 #if !defined(CH_CFG_ST_TIMEDELTA)
90 #define CH_CFG_ST_TIMEDELTA 0
91 #endif
92 
93 /** @} */
94 
95 /*===========================================================================*/
96 /**
97  * @name Kernel parameters and options
98  * @{
99  */
100 /*===========================================================================*/
101 
102 /**
103  * @brief Round robin interval.
104  * @details This constant is the number of system ticks allowed for the
105  * threads before preemption occurs. Setting this value to zero
106  * disables the preemption for threads with equal priority and the
107  * round robin becomes cooperative. Note that higher priority
108  * threads can still preempt, the kernel is always preemptive.
109  * @note Disabling the round robin preemption makes the kernel more compact
110  * and generally faster.
111  * @note The round robin preemption is not supported in tickless mode and
112  * must be set to zero in that case.
113  */
114 #if !defined(CH_CFG_TIME_QUANTUM)
115 #define CH_CFG_TIME_QUANTUM 20
116 #endif
117 
118 /**
119  * @brief Idle thread automatic spawn suppression.
120  * @details When this option is activated the function @p chSysInit()
121  * does not spawn the idle thread. The application @p main()
122  * function becomes the idle thread and must implement an
123  * infinite loop.
124  */
125 #if !defined(CH_CFG_NO_IDLE_THREAD)
126 #define CH_CFG_NO_IDLE_THREAD FALSE
127 #endif
128 
129 /** @} */
130 
131 /*===========================================================================*/
132 /**
133  * @name Performance options
134  * @{
135  */
136 /*===========================================================================*/
137 
138 /**
139  * @brief OS optimization.
140  * @details If enabled then time efficient rather than space efficient code
141  * is used when two possible implementations exist.
142  *
143  * @note This is not related to the compiler optimization options.
144  * @note The default is @p TRUE.
145  */
146 #if !defined(CH_CFG_OPTIMIZE_SPEED)
147 #define CH_CFG_OPTIMIZE_SPEED TRUE
148 #endif
149 
150 /** @} */
151 
152 /*===========================================================================*/
153 /**
154  * @name Subsystem options
155  * @{
156  */
157 /*===========================================================================*/
158 
159 /**
160  * @brief Time Measurement APIs.
161  * @details If enabled then the time measurement APIs are included in
162  * the kernel.
163  *
164  * @note The default is @p TRUE.
165  */
166 #if !defined(CH_CFG_USE_TM)
167 #define CH_CFG_USE_TM TRUE
168 #endif
169 
170 /**
171  * @brief Threads registry APIs.
172  * @details If enabled then the registry APIs are included in the kernel.
173  *
174  * @note The default is @p TRUE.
175  */
176 #if !defined(CH_CFG_USE_REGISTRY)
177 #define CH_CFG_USE_REGISTRY TRUE
178 #endif
179 
180 /**
181  * @brief Threads synchronization APIs.
182  * @details If enabled then the @p chThdWait() function is included in
183  * the kernel.
184  *
185  * @note The default is @p TRUE.
186  */
187 #if !defined(CH_CFG_USE_WAITEXIT)
188 #define CH_CFG_USE_WAITEXIT TRUE
189 #endif
190 
191 /**
192  * @brief Semaphores APIs.
193  * @details If enabled then the Semaphores APIs are included in the kernel.
194  *
195  * @note The default is @p TRUE.
196  */
197 #if !defined(CH_CFG_USE_SEMAPHORES)
198 #define CH_CFG_USE_SEMAPHORES TRUE
199 #endif
200 
201 /**
202  * @brief Semaphores queuing mode.
203  * @details If enabled then the threads are enqueued on semaphores by
204  * priority rather than in FIFO order.
205  *
206  * @note The default is @p FALSE. Enable this if you have special
207  * requirements.
208  * @note Requires @p CH_CFG_USE_SEMAPHORES.
209  */
210 #if !defined(CH_CFG_USE_SEMAPHORES_PRIORITY)
211 #define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
212 #endif
213 
214 /**
215  * @brief Mutexes APIs.
216  * @details If enabled then the mutexes APIs are included in the kernel.
217  *
218  * @note The default is @p TRUE.
219  */
220 #if !defined(CH_CFG_USE_MUTEXES)
221 #define CH_CFG_USE_MUTEXES TRUE
222 #endif
223 
224 /**
225  * @brief Enables recursive behavior on mutexes.
226  * @note Recursive mutexes are heavier and have an increased
227  * memory footprint.
228  *
229  * @note The default is @p FALSE.
230  * @note Requires @p CH_CFG_USE_MUTEXES.
231  */
232 #if !defined(CH_CFG_USE_MUTEXES_RECURSIVE)
233 #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
234 #endif
235 
236 /**
237  * @brief Conditional Variables APIs.
238  * @details If enabled then the conditional variables APIs are included
239  * in the kernel.
240  *
241  * @note The default is @p TRUE.
242  * @note Requires @p CH_CFG_USE_MUTEXES.
243  */
244 #if !defined(CH_CFG_USE_CONDVARS)
245 #define CH_CFG_USE_CONDVARS TRUE
246 #endif
247 
248 /**
249  * @brief Conditional Variables APIs with timeout.
250  * @details If enabled then the conditional variables APIs with timeout
251  * specification are included in the kernel.
252  *
253  * @note The default is @p TRUE.
254  * @note Requires @p CH_CFG_USE_CONDVARS.
255  */
256 #if !defined(CH_CFG_USE_CONDVARS_TIMEOUT)
257 #define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
258 #endif
259 
260 /**
261  * @brief Events Flags APIs.
262  * @details If enabled then the event flags APIs are included in the kernel.
263  *
264  * @note The default is @p TRUE.
265  */
266 #if !defined(CH_CFG_USE_EVENTS)
267 #define CH_CFG_USE_EVENTS TRUE
268 #endif
269 
270 /**
271  * @brief Events Flags APIs with timeout.
272  * @details If enabled then the events APIs with timeout specification
273  * are included in the kernel.
274  *
275  * @note The default is @p TRUE.
276  * @note Requires @p CH_CFG_USE_EVENTS.
277  */
278 #if !defined(CH_CFG_USE_EVENTS_TIMEOUT)
279 #define CH_CFG_USE_EVENTS_TIMEOUT TRUE
280 #endif
281 
282 /**
283  * @brief Synchronous Messages APIs.
284  * @details If enabled then the synchronous messages APIs are included
285  * in the kernel.
286  *
287  * @note The default is @p TRUE.
288  */
289 #if !defined(CH_CFG_USE_MESSAGES)
290 #define CH_CFG_USE_MESSAGES TRUE
291 #endif
292 
293 /**
294  * @brief Synchronous Messages queuing mode.
295  * @details If enabled then messages are served by priority rather than in
296  * FIFO order.
297  *
298  * @note The default is @p FALSE. Enable this if you have special
299  * requirements.
300  * @note Requires @p CH_CFG_USE_MESSAGES.
301  */
302 #if !defined(CH_CFG_USE_MESSAGES_PRIORITY)
303 #define CH_CFG_USE_MESSAGES_PRIORITY FALSE
304 #endif
305 
306 /**
307  * @brief Dynamic Threads APIs.
308  * @details If enabled then the dynamic threads creation APIs are included
309  * in the kernel.
310  *
311  * @note The default is @p TRUE.
312  * @note Requires @p CH_CFG_USE_WAITEXIT.
313  * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
314  */
315 #if !defined(CH_CFG_USE_DYNAMIC)
316 #define CH_CFG_USE_DYNAMIC FALSE
317 #endif
318 
319 /**
320  * @brief Mailboxes APIs.
321  * @details If enabled then the asynchronous messages (mailboxes) APIs are
322  * included in the kernel.
323  *
324  * @note The default is @p TRUE.
325  * @note Requires @p CH_CFG_USE_SEMAPHORES.
326  */
327 #if !defined(CH_CFG_USE_MAILBOXES)
328 #define CH_CFG_USE_MAILBOXES TRUE
329 #endif
330 
331 /**
332  * @brief I/O Queues APIs.
333  * @details If enabled then the I/O queues APIs are included in the kernel.
334  *
335  * @note The default is @p TRUE.
336  */
337 #define CH_CFG_USE_QUEUES FALSE
338 
339 /**
340  * @brief Core Memory Manager APIs.
341  * @details If enabled then the core memory manager APIs are included
342  * in the kernel.
343  *
344  * @note The default is @p TRUE.
345  */
346 #if !defined(CH_CFG_USE_MEMCORE)
347 #define CH_CFG_USE_MEMCORE TRUE
348 #endif
349 
350 /**
351  * @brief Managed RAM size.
352  * @details Size of the RAM area to be managed by the OS. If set to zero
353  * then the whole available RAM is used. The core memory is made
354  * available to the heap allocator and/or can be used directly through
355  * the simplified core memory allocator.
356  *
357  * @note In order to let the OS manage the whole RAM the linker script must
358  * provide the @p __heap_base__ and @p __heap_end__ symbols.
359  * @note Requires @p CH_CFG_USE_MEMCORE.
360  */
361 #if !defined(CH_CFG_MEMCORE_SIZE)
362 #define CH_CFG_MEMCORE_SIZE 0
363 #endif
364 
365 /**
366  * @brief Heap Allocator APIs.
367  * @details If enabled then the memory heap allocator APIs are included
368  * in the kernel.
369  *
370  * @note The default is @p TRUE.
371  * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
372  * @p CH_CFG_USE_SEMAPHORES.
373  * @note Mutexes are recommended.
374  */
375 #if !defined(CH_CFG_USE_HEAP)
376 #define CH_CFG_USE_HEAP TRUE
377 #endif
378 
379 /**
380  * @brief Memory Pools Allocator APIs.
381  * @details If enabled then the memory pools allocator APIs are included
382  * in the kernel.
383  *
384  * @note The default is @p TRUE.
385  */
386 #if !defined(CH_CFG_USE_MEMPOOLS)
387 #define CH_CFG_USE_MEMPOOLS FALSE
388 #endif
389 
390 /**
391  * @brief Objects FIFOs APIs.
392  * @details If enabled then the objects FIFOs APIs are included
393  * in the kernel.
394  *
395  * @note The default is @p TRUE.
396  */
397 #if !defined(CH_CFG_USE_OBJ_FIFOS)
398 #define CH_CFG_USE_OBJ_FIFOS FALSE
399 #endif
400 
401 /**
402  * @brief Pipes APIs.
403  * @details If enabled then the pipes APIs are included
404  * in the kernel.
405  *
406  * @note The default is @p TRUE.
407  */
408 #if !defined(CH_CFG_USE_PIPES)
409 #define CH_CFG_USE_PIPES FALSE
410 #endif
411 
412 /**
413  * @brief Objects Caches APIs.
414  * @details If enabled then the objects caches APIs are included
415  * in the kernel.
416  *
417  * @note The default is @p TRUE.
418  */
419 #if !defined(CH_CFG_USE_OBJ_CACHES)
420 #define CH_CFG_USE_OBJ_CACHES FALSE
421 #endif
422 
423 /**
424  * @brief Delegate threads APIs.
425  * @details If enabled then the delegate threads APIs are included
426  * in the kernel.
427  *
428  * @note The default is @p TRUE.
429  */
430 #if !defined(CH_CFG_USE_DELEGATES)
431 #define CH_CFG_USE_DELEGATES FALSE
432 #endif
433 
434 /**
435  * @brief Jobs Queues APIs.
436  * @details If enabled then the jobs queues APIs are included
437  * in the kernel.
438  *
439  * @note The default is @p TRUE.
440  */
441 #if !defined(CH_CFG_USE_JOBS)
442 #define CH_CFG_USE_JOBS FALSE
443 #endif
444 
445 /** @} */
446 
447 /*===========================================================================*/
448 /**
449  * @name Objects factory options
450  * @{
451  */
452 /*===========================================================================*/
453 
454 /**
455  * @brief Objects Factory APIs.
456  * @details If enabled then the objects factory APIs are included in the
457  * kernel.
458  *
459  * @note The default is @p FALSE.
460  */
461 #if !defined(CH_CFG_USE_FACTORY)
462 #define CH_CFG_USE_FACTORY FALSE
463 #endif
464 
465 /**
466  * @brief Maximum length for object names.
467  * @details If the specified length is zero then the name is stored by
468  * pointer but this could have unintended side effects.
469  */
470 #if !defined(CH_CFG_FACTORY_MAX_NAMES_LENGTH)
471 #define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8
472 #endif
473 
474 /**
475  * @brief Enables the registry of generic objects.
476  */
477 #if !defined(CH_CFG_FACTORY_OBJECTS_REGISTRY)
478 #define CH_CFG_FACTORY_OBJECTS_REGISTRY FALSE
479 #endif
480 
481 /**
482  * @brief Enables factory for generic buffers.
483  */
484 #if !defined(CH_CFG_FACTORY_GENERIC_BUFFERS)
485 #define CH_CFG_FACTORY_GENERIC_BUFFERS FALSE
486 #endif
487 
488 /**
489  * @brief Enables factory for semaphores.
490  */
491 #if !defined(CH_CFG_FACTORY_SEMAPHORES)
492 #define CH_CFG_FACTORY_SEMAPHORES FALSE
493 #endif
494 
495 /**
496  * @brief Enables factory for mailboxes.
497  */
498 #if !defined(CH_CFG_FACTORY_MAILBOXES)
499 #define CH_CFG_FACTORY_MAILBOXES FALSE
500 #endif
501 
502 /**
503  * @brief Enables factory for objects FIFOs.
504  */
505 #if !defined(CH_CFG_FACTORY_OBJ_FIFOS)
506 #define CH_CFG_FACTORY_OBJ_FIFOS FALSE
507 #endif
508 
509 /** @} */
510 
511 /*===========================================================================*/
512 /**
513  * @name Debug options
514  * @{
515  */
516 /*===========================================================================*/
517 
518 /**
519  * @brief Debug option, kernel statistics.
520  *
521  * @note The default is @p FALSE.
522  */
523 #if !defined(CH_DBG_STATISTICS)
524 #define CH_DBG_STATISTICS FALSE
525 #endif
526 
527 /**
528  * @brief Debug option, system state check.
529  * @details If enabled the correct call protocol for system APIs is checked
530  * at runtime.
531  *
532  * @note The default is @p FALSE.
533  */
534 #if !defined(CH_DBG_SYSTEM_STATE_CHECK)
535 #define CH_DBG_SYSTEM_STATE_CHECK TRUE
536 #endif
537 
538 /**
539  * @brief Debug option, parameters checks.
540  * @details If enabled then the checks on the API functions input
541  * parameters are activated.
542  *
543  * @note The default is @p FALSE.
544  */
545 #if !defined(CH_DBG_ENABLE_CHECKS)
546 #define CH_DBG_ENABLE_CHECKS TRUE
547 #endif
548 
549 /**
550  * @brief Debug option, consistency checks.
551  * @details If enabled then all the assertions in the kernel code are
552  * activated. This includes consistency checks inside the kernel,
553  * runtime anomalies and port-defined checks.
554  *
555  * @note The default is @p FALSE.
556  */
557 #if !defined(CH_DBG_ENABLE_ASSERTS)
558 #define CH_DBG_ENABLE_ASSERTS TRUE
559 #endif
560 
561 /**
562  * @brief Debug option, trace buffer.
563  * @details If enabled then the trace buffer is activated.
564  *
565  * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
566  */
567 #if !defined(CH_DBG_TRACE_MASK)
568 #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
569 #endif
570 
571 /**
572  * @brief Trace buffer entries.
573  * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
574  * different from @p CH_DBG_TRACE_MASK_DISABLED.
575  */
576 #if !defined(CH_DBG_TRACE_BUFFER_SIZE)
577 #define CH_DBG_TRACE_BUFFER_SIZE 128
578 #endif
579 
580 /**
581  * @brief Debug option, stack checks.
582  * @details If enabled then a runtime stack check is performed.
583  *
584  * @note The default is @p FALSE.
585  * @note The stack check is performed in a architecture/port dependent way.
586  * It may not be implemented or some ports.
587  * @note The default failure mode is to halt the system with the global
588  * @p panic_msg variable set to @p NULL.
589  */
590 #if !defined(CH_DBG_ENABLE_STACK_CHECK)
591 #define CH_DBG_ENABLE_STACK_CHECK TRUE
592 #endif
593 
594 /**
595  * @brief Debug option, stacks initialization.
596  * @details If enabled then the threads working area is filled with a byte
597  * value when a thread is created. This can be useful for the
598  * runtime measurement of the used stack.
599  *
600  * @note The default is @p FALSE.
601  */
602 // see also CH_DBG_STACK_FILL_VALUE
603 #if !defined(CH_DBG_FILL_THREADS)
604 #define CH_DBG_FILL_THREADS TRUE
605 #endif
606 
607 /**
608  * @brief Debug option, threads profiling.
609  * @details If enabled then a field is added to the @p thread_t structure that
610  * counts the system ticks occurred while executing the thread.
611  *
612  * @note The default is @p FALSE.
613  * @note This debug option is not currently compatible with the
614  * tickless mode.
615  */
616 #if !defined(CH_DBG_THREADS_PROFILING)
617 #define CH_DBG_THREADS_PROFILING FALSE
618 #endif
619 
620 /** @} */
621 
622 /*===========================================================================*/
623 /**
624  * @name Kernel hooks
625  * @{
626  */
627 /*===========================================================================*/
628 
629 /**
630  * @brief System structure extension.
631  * @details User fields added to the end of the @p ch_system_t structure.
632  */
633 #define CH_CFG_SYSTEM_EXTRA_FIELDS \
634  /* Add threads custom fields here.*/
635 
636 /**
637  * @brief System initialization hook.
638  * @details User initialization code added to the @p chSysInit() function
639  * just before interrupts are enabled globally.
640  */
641 #define CH_CFG_SYSTEM_INIT_HOOK() { \
642  /* Add threads initialization code here.*/ \
643 }
644 
645 /**
646  * @brief Threads finalization hook.
647  * @details User finalization code added to the @p chThdExit() API.
648  *
649  * @note It is inserted into lock zone.
650  * @note It is also invoked when the threads simply return in order to
651  * terminate.
652  */
653 #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
654  /* Add threads finalization code here.*/ \
655 }
656 
657 /**
658  * @brief Idle thread enter hook.
659  * @note This hook is invoked within a critical zone, no OS functions
660  * should be invoked from here.
661  * @note This macro can be used to activate a power saving mode.
662  */
663 #define CH_CFG_IDLE_ENTER_HOOK() { \
664  /* Idle-enter code here.*/ \
665 }
666 
667 /**
668  * @brief Idle thread leave hook.
669  * @note This hook is invoked within a critical zone, no OS functions
670  * should be invoked from here.
671  * @note This macro can be used to deactivate a power saving mode.
672  */
673 #define CH_CFG_IDLE_LEAVE_HOOK() { \
674  /* Idle-leave code here.*/ \
675 }
676 
677 /**
678  * @brief Idle Loop hook.
679  * @details This hook is continuously invoked by the idle thread loop.
680  */
681 #define CH_CFG_IDLE_LOOP_HOOK() { \
682  /* Idle loop code here.*/ \
683 }
684 
685 /**
686  * @brief System tick event hook.
687  * @details This hook is invoked in the system tick handler immediately
688  * after processing the virtual timers queue.
689  */
690 #define CH_CFG_SYSTEM_TICK_HOOK() { \
691  /* System tick event code here.*/ \
692 }
693 
694 /**
695  * @brief System halt hook.
696  * @details This hook is invoked in case to a system halting error before
697  * the system is halted.
698  */
699 #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
700  /* System halt code here.*/ \
701  chDbgPanic3(reason, __FILE__, __LINE__); \
702 }
703 
704 /**
705  * @brief Trace hook.
706  * @details This hook is invoked each time a new record is written in the
707  * trace buffer.
708  */
709 #define CH_CFG_TRACE_HOOK(tep) { \
710  /* Trace code here.*/ \
711 }
712 
713 /** @} */
714 
715 /*===========================================================================*/
716 /* Port-specific settings (override port settings defaulted in chcore.h). */
717 /*===========================================================================*/
718 
719 #endif /* CHCONF_H */
720 
721 /** @} */