PD Buddy Sink Firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

chconf.h 17KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. /*
  2. * PD Buddy Sink Firmware - Smart power jack for USB Power Delivery
  3. * Copyright (C) 2017-2018 Clayton G. Hobbs <clay@lakeserv.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /*
  19. ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio
  20. Licensed under the Apache License, Version 2.0 (the "License");
  21. you may not use this file except in compliance with the License.
  22. You may obtain a copy of the License at
  23. http://www.apache.org/licenses/LICENSE-2.0
  24. Unless required by applicable law or agreed to in writing, software
  25. distributed under the License is distributed on an "AS IS" BASIS,
  26. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  27. See the License for the specific language governing permissions and
  28. limitations under the License.
  29. */
  30. /**
  31. * @file templates/chconf.h
  32. * @brief Configuration file template.
  33. * @details A copy of this file must be placed in each project directory, it
  34. * contains the application specific kernel settings.
  35. *
  36. * @addtogroup config
  37. * @details Kernel related settings and hooks.
  38. * @{
  39. */
  40. #ifndef CHCONF_H
  41. #define CHCONF_H
  42. #define _CHIBIOS_RT_CONF_
  43. /*===========================================================================*/
  44. /**
  45. * @name System timers settings
  46. * @{
  47. */
  48. /*===========================================================================*/
  49. /**
  50. * @brief System time counter resolution.
  51. * @note Allowed values are 16 or 32 bits.
  52. */
  53. #define CH_CFG_ST_RESOLUTION 32
  54. /**
  55. * @brief System tick frequency.
  56. * @details Frequency of the system timer that drives the system ticks. This
  57. * setting also defines the system tick time unit.
  58. */
  59. #define CH_CFG_ST_FREQUENCY 10000
  60. /**
  61. * @brief Time delta constant for the tick-less mode.
  62. * @note If this value is zero then the system uses the classic
  63. * periodic tick. This value represents the minimum number
  64. * of ticks that is safe to specify in a timeout directive.
  65. * The value one is not valid, timeouts are rounded up to
  66. * this value.
  67. */
  68. #define CH_CFG_ST_TIMEDELTA 2
  69. /** @} */
  70. /*===========================================================================*/
  71. /**
  72. * @name Kernel parameters and options
  73. * @{
  74. */
  75. /*===========================================================================*/
  76. /**
  77. * @brief Round robin interval.
  78. * @details This constant is the number of system ticks allowed for the
  79. * threads before preemption occurs. Setting this value to zero
  80. * disables the preemption for threads with equal priority and the
  81. * round robin becomes cooperative. Note that higher priority
  82. * threads can still preempt, the kernel is always preemptive.
  83. * @note Disabling the round robin preemption makes the kernel more compact
  84. * and generally faster.
  85. * @note The round robin preemption is not supported in tickless mode and
  86. * must be set to zero in that case.
  87. */
  88. #define CH_CFG_TIME_QUANTUM 0
  89. /**
  90. * @brief Managed RAM size.
  91. * @details Size of the RAM area to be managed by the OS. If set to zero
  92. * then the whole available RAM is used. The core memory is made
  93. * available to the heap allocator and/or can be used directly through
  94. * the simplified core memory allocator.
  95. *
  96. * @note In order to let the OS manage the whole RAM the linker script must
  97. * provide the @p __heap_base__ and @p __heap_end__ symbols.
  98. * @note Requires @p CH_CFG_USE_MEMCORE.
  99. */
  100. #define CH_CFG_MEMCORE_SIZE 0
  101. /**
  102. * @brief Idle thread automatic spawn suppression.
  103. * @details When this option is activated the function @p chSysInit()
  104. * does not spawn the idle thread. The application @p main()
  105. * function becomes the idle thread and must implement an
  106. * infinite loop.
  107. */
  108. #define CH_CFG_NO_IDLE_THREAD FALSE
  109. /** @} */
  110. /*===========================================================================*/
  111. /**
  112. * @name Performance options
  113. * @{
  114. */
  115. /*===========================================================================*/
  116. /**
  117. * @brief OS optimization.
  118. * @details If enabled then time efficient rather than space efficient code
  119. * is used when two possible implementations exist.
  120. *
  121. * @note This is not related to the compiler optimization options.
  122. * @note The default is @p TRUE.
  123. */
  124. #define CH_CFG_OPTIMIZE_SPEED TRUE
  125. /** @} */
  126. /*===========================================================================*/
  127. /**
  128. * @name Subsystem options
  129. * @{
  130. */
  131. /*===========================================================================*/
  132. /**
  133. * @brief Time Measurement APIs.
  134. * @details If enabled then the time measurement APIs are included in
  135. * the kernel.
  136. *
  137. * @note The default is @p TRUE.
  138. */
  139. #define CH_CFG_USE_TM FALSE
  140. /**
  141. * @brief Threads registry APIs.
  142. * @details If enabled then the registry APIs are included in the kernel.
  143. *
  144. * @note The default is @p TRUE.
  145. */
  146. #define CH_CFG_USE_REGISTRY TRUE
  147. /**
  148. * @brief Threads synchronization APIs.
  149. * @details If enabled then the @p chThdWait() function is included in
  150. * the kernel.
  151. *
  152. * @note The default is @p TRUE.
  153. */
  154. #define CH_CFG_USE_WAITEXIT TRUE
  155. /**
  156. * @brief Semaphores APIs.
  157. * @details If enabled then the Semaphores APIs are included in the kernel.
  158. *
  159. * @note The default is @p TRUE.
  160. */
  161. #define CH_CFG_USE_SEMAPHORES TRUE
  162. /**
  163. * @brief Semaphores queuing mode.
  164. * @details If enabled then the threads are enqueued on semaphores by
  165. * priority rather than in FIFO order.
  166. *
  167. * @note The default is @p FALSE. Enable this if you have special
  168. * requirements.
  169. * @note Requires @p CH_CFG_USE_SEMAPHORES.
  170. */
  171. #define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
  172. /**
  173. * @brief Mutexes APIs.
  174. * @details If enabled then the mutexes APIs are included in the kernel.
  175. *
  176. * @note The default is @p TRUE.
  177. */
  178. #define CH_CFG_USE_MUTEXES TRUE
  179. /**
  180. * @brief Enables recursive behavior on mutexes.
  181. * @note Recursive mutexes are heavier and have an increased
  182. * memory footprint.
  183. *
  184. * @note The default is @p FALSE.
  185. * @note Requires @p CH_CFG_USE_MUTEXES.
  186. */
  187. #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
  188. /**
  189. * @brief Conditional Variables APIs.
  190. * @details If enabled then the conditional variables APIs are included
  191. * in the kernel.
  192. *
  193. * @note The default is @p TRUE.
  194. * @note Requires @p CH_CFG_USE_MUTEXES.
  195. */
  196. #define CH_CFG_USE_CONDVARS TRUE
  197. /**
  198. * @brief Conditional Variables APIs with timeout.
  199. * @details If enabled then the conditional variables APIs with timeout
  200. * specification are included in the kernel.
  201. *
  202. * @note The default is @p TRUE.
  203. * @note Requires @p CH_CFG_USE_CONDVARS.
  204. */
  205. #define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
  206. /**
  207. * @brief Events Flags APIs.
  208. * @details If enabled then the event flags APIs are included in the kernel.
  209. *
  210. * @note The default is @p TRUE.
  211. */
  212. #define CH_CFG_USE_EVENTS TRUE
  213. /**
  214. * @brief Events Flags APIs with timeout.
  215. * @details If enabled then the events APIs with timeout specification
  216. * are included in the kernel.
  217. *
  218. * @note The default is @p TRUE.
  219. * @note Requires @p CH_CFG_USE_EVENTS.
  220. */
  221. #define CH_CFG_USE_EVENTS_TIMEOUT TRUE
  222. /**
  223. * @brief Synchronous Messages APIs.
  224. * @details If enabled then the synchronous messages APIs are included
  225. * in the kernel.
  226. *
  227. * @note The default is @p TRUE.
  228. */
  229. #define CH_CFG_USE_MESSAGES TRUE
  230. /**
  231. * @brief Synchronous Messages queuing mode.
  232. * @details If enabled then messages are served by priority rather than in
  233. * FIFO order.
  234. *
  235. * @note The default is @p FALSE. Enable this if you have special
  236. * requirements.
  237. * @note Requires @p CH_CFG_USE_MESSAGES.
  238. */
  239. #define CH_CFG_USE_MESSAGES_PRIORITY FALSE
  240. /**
  241. * @brief Mailboxes APIs.
  242. * @details If enabled then the asynchronous messages (mailboxes) APIs are
  243. * included in the kernel.
  244. *
  245. * @note The default is @p TRUE.
  246. * @note Requires @p CH_CFG_USE_SEMAPHORES.
  247. */
  248. #define CH_CFG_USE_MAILBOXES TRUE
  249. /**
  250. * @brief Core Memory Manager APIs.
  251. * @details If enabled then the core memory manager APIs are included
  252. * in the kernel.
  253. *
  254. * @note The default is @p TRUE.
  255. */
  256. #define CH_CFG_USE_MEMCORE TRUE
  257. /**
  258. * @brief Heap Allocator APIs.
  259. * @details If enabled then the memory heap allocator APIs are included
  260. * in the kernel.
  261. *
  262. * @note The default is @p TRUE.
  263. * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
  264. * @p CH_CFG_USE_SEMAPHORES.
  265. * @note Mutexes are recommended.
  266. */
  267. #define CH_CFG_USE_HEAP TRUE
  268. /**
  269. * @brief Memory Pools Allocator APIs.
  270. * @details If enabled then the memory pools allocator APIs are included
  271. * in the kernel.
  272. *
  273. * @note The default is @p TRUE.
  274. */
  275. #define CH_CFG_USE_MEMPOOLS TRUE
  276. /**
  277. * @brief Dynamic Threads APIs.
  278. * @details If enabled then the dynamic threads creation APIs are included
  279. * in the kernel.
  280. *
  281. * @note The default is @p TRUE.
  282. * @note Requires @p CH_CFG_USE_WAITEXIT.
  283. * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
  284. */
  285. #define CH_CFG_USE_DYNAMIC TRUE
  286. /** @} */
  287. /*===========================================================================*/
  288. /**
  289. * @name Debug options
  290. * @{
  291. */
  292. /*===========================================================================*/
  293. /**
  294. * @brief Debug option, kernel statistics.
  295. *
  296. * @note The default is @p FALSE.
  297. */
  298. #define CH_DBG_STATISTICS FALSE
  299. /**
  300. * @brief Debug option, system state check.
  301. * @details If enabled the correct call protocol for system APIs is checked
  302. * at runtime.
  303. *
  304. * @note The default is @p FALSE.
  305. */
  306. #define CH_DBG_SYSTEM_STATE_CHECK FALSE
  307. /**
  308. * @brief Debug option, parameters checks.
  309. * @details If enabled then the checks on the API functions input
  310. * parameters are activated.
  311. *
  312. * @note The default is @p FALSE.
  313. */
  314. #define CH_DBG_ENABLE_CHECKS FALSE
  315. /**
  316. * @brief Debug option, consistency checks.
  317. * @details If enabled then all the assertions in the kernel code are
  318. * activated. This includes consistency checks inside the kernel,
  319. * runtime anomalies and port-defined checks.
  320. *
  321. * @note The default is @p FALSE.
  322. */
  323. #define CH_DBG_ENABLE_ASSERTS FALSE
  324. /**
  325. * @brief Debug option, trace buffer.
  326. * @details If enabled then the trace buffer is activated.
  327. *
  328. * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
  329. */
  330. #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
  331. /**
  332. * @brief Trace buffer entries.
  333. * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
  334. * different from @p CH_DBG_TRACE_MASK_DISABLED.
  335. */
  336. #define CH_DBG_TRACE_BUFFER_SIZE 128
  337. /**
  338. * @brief Debug option, stack checks.
  339. * @details If enabled then a runtime stack check is performed.
  340. *
  341. * @note The default is @p FALSE.
  342. * @note The stack check is performed in a architecture/port dependent way.
  343. * It may not be implemented or some ports.
  344. * @note The default failure mode is to halt the system with the global
  345. * @p panic_msg variable set to @p NULL.
  346. */
  347. #define CH_DBG_ENABLE_STACK_CHECK FALSE
  348. /**
  349. * @brief Debug option, stacks initialization.
  350. * @details If enabled then the threads working area is filled with a byte
  351. * value when a thread is created. This can be useful for the
  352. * runtime measurement of the used stack.
  353. *
  354. * @note The default is @p FALSE.
  355. */
  356. #define CH_DBG_FILL_THREADS FALSE
  357. /**
  358. * @brief Debug option, threads profiling.
  359. * @details If enabled then a field is added to the @p thread_t structure that
  360. * counts the system ticks occurred while executing the thread.
  361. *
  362. * @note The default is @p FALSE.
  363. * @note This debug option is not currently compatible with the
  364. * tickless mode.
  365. */
  366. #define CH_DBG_THREADS_PROFILING FALSE
  367. /** @} */
  368. /*===========================================================================*/
  369. /**
  370. * @name Kernel hooks
  371. * @{
  372. */
  373. /*===========================================================================*/
  374. /**
  375. * @brief Threads descriptor structure extension.
  376. * @details User fields added to the end of the @p thread_t structure.
  377. */
  378. #define CH_CFG_THREAD_EXTRA_FIELDS \
  379. /* Add threads custom fields here.*/
  380. /**
  381. * @brief Threads initialization hook.
  382. * @details User initialization code added to the @p chThdInit() API.
  383. *
  384. * @note It is invoked from within @p chThdInit() and implicitly from all
  385. * the threads creation APIs.
  386. */
  387. #define CH_CFG_THREAD_INIT_HOOK(tp) { \
  388. /* Add threads initialization code here.*/ \
  389. }
  390. /**
  391. * @brief Threads finalization hook.
  392. * @details User finalization code added to the @p chThdExit() API.
  393. */
  394. #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
  395. /* Add threads finalization code here.*/ \
  396. }
  397. /**
  398. * @brief Context switch hook.
  399. * @details This hook is invoked just before switching between threads.
  400. */
  401. #define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
  402. /* Context switch code here.*/ \
  403. }
  404. /**
  405. * @brief ISR enter hook.
  406. */
  407. #define CH_CFG_IRQ_PROLOGUE_HOOK() { \
  408. /* IRQ prologue code here.*/ \
  409. }
  410. /**
  411. * @brief ISR exit hook.
  412. */
  413. #define CH_CFG_IRQ_EPILOGUE_HOOK() { \
  414. /* IRQ epilogue code here.*/ \
  415. }
  416. /**
  417. * @brief Idle thread enter hook.
  418. * @note This hook is invoked within a critical zone, no OS functions
  419. * should be invoked from here.
  420. * @note This macro can be used to activate a power saving mode.
  421. */
  422. #define CH_CFG_IDLE_ENTER_HOOK() { \
  423. /* Idle-enter code here.*/ \
  424. }
  425. /**
  426. * @brief Idle thread leave hook.
  427. * @note This hook is invoked within a critical zone, no OS functions
  428. * should be invoked from here.
  429. * @note This macro can be used to deactivate a power saving mode.
  430. */
  431. #define CH_CFG_IDLE_LEAVE_HOOK() { \
  432. /* Idle-leave code here.*/ \
  433. }
  434. /**
  435. * @brief Idle Loop hook.
  436. * @details This hook is continuously invoked by the idle thread loop.
  437. */
  438. #define CH_CFG_IDLE_LOOP_HOOK() { \
  439. /* Idle loop code here.*/ \
  440. }
  441. /**
  442. * @brief System tick event hook.
  443. * @details This hook is invoked in the system tick handler immediately
  444. * after processing the virtual timers queue.
  445. */
  446. #define CH_CFG_SYSTEM_TICK_HOOK() { \
  447. /* System tick event code here.*/ \
  448. }
  449. /**
  450. * @brief System halt hook.
  451. * @details This hook is invoked in case to a system halting error before
  452. * the system is halted.
  453. */
  454. #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
  455. /* System halt code here.*/ \
  456. }
  457. /**
  458. * @brief Trace hook.
  459. * @details This hook is invoked each time a new record is written in the
  460. * trace buffer.
  461. */
  462. #define CH_CFG_TRACE_HOOK(tep) { \
  463. /* Trace code here.*/ \
  464. }
  465. /** @} */
  466. /*===========================================================================*/
  467. /* Port-specific settings (override port settings defaulted in chcore.h). */
  468. /*===========================================================================*/
  469. #endif /* CHCONF_H */
  470. /** @} */