PD Buddy Sink Firmware
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  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..2017 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. #define _CHIBIOS_RT_CONF_VER_5_0_
  44. /*===========================================================================*/
  45. /**
  46. * @name System timers settings
  47. * @{
  48. */
  49. /*===========================================================================*/
  50. /**
  51. * @brief System time counter resolution.
  52. * @note Allowed values are 16 or 32 bits.
  53. */
  54. #define CH_CFG_ST_RESOLUTION 32
  55. /**
  56. * @brief System tick frequency.
  57. * @details Frequency of the system timer that drives the system ticks. This
  58. * setting also defines the system tick time unit.
  59. */
  60. #define CH_CFG_ST_FREQUENCY 10000
  61. /**
  62. * @brief Time intervals data size.
  63. * @note Allowed values are 16, 32 or 64 bits.
  64. */
  65. #define CH_CFG_INTERVALS_SIZE 32
  66. /**
  67. * @brief Time types data size.
  68. * @note Allowed values are 16 or 32 bits.
  69. */
  70. #define CH_CFG_TIME_TYPES_SIZE 32
  71. /**
  72. * @brief Time delta constant for the tick-less mode.
  73. * @note If this value is zero then the system uses the classic
  74. * periodic tick. This value represents the minimum number
  75. * of ticks that is safe to specify in a timeout directive.
  76. * The value one is not valid, timeouts are rounded up to
  77. * this value.
  78. */
  79. #define CH_CFG_ST_TIMEDELTA 2
  80. /** @} */
  81. /*===========================================================================*/
  82. /**
  83. * @name Kernel parameters and options
  84. * @{
  85. */
  86. /*===========================================================================*/
  87. /**
  88. * @brief Round robin interval.
  89. * @details This constant is the number of system ticks allowed for the
  90. * threads before preemption occurs. Setting this value to zero
  91. * disables the preemption for threads with equal priority and the
  92. * round robin becomes cooperative. Note that higher priority
  93. * threads can still preempt, the kernel is always preemptive.
  94. * @note Disabling the round robin preemption makes the kernel more compact
  95. * and generally faster.
  96. * @note The round robin preemption is not supported in tickless mode and
  97. * must be set to zero in that case.
  98. */
  99. #define CH_CFG_TIME_QUANTUM 0
  100. /**
  101. * @brief Managed RAM size.
  102. * @details Size of the RAM area to be managed by the OS. If set to zero
  103. * then the whole available RAM is used. The core memory is made
  104. * available to the heap allocator and/or can be used directly through
  105. * the simplified core memory allocator.
  106. *
  107. * @note In order to let the OS manage the whole RAM the linker script must
  108. * provide the @p __heap_base__ and @p __heap_end__ symbols.
  109. * @note Requires @p CH_CFG_USE_MEMCORE.
  110. */
  111. #define CH_CFG_MEMCORE_SIZE 0
  112. /**
  113. * @brief Idle thread automatic spawn suppression.
  114. * @details When this option is activated the function @p chSysInit()
  115. * does not spawn the idle thread. The application @p main()
  116. * function becomes the idle thread and must implement an
  117. * infinite loop.
  118. */
  119. #define CH_CFG_NO_IDLE_THREAD FALSE
  120. /** @} */
  121. /*===========================================================================*/
  122. /**
  123. * @name Performance options
  124. * @{
  125. */
  126. /*===========================================================================*/
  127. /**
  128. * @brief OS optimization.
  129. * @details If enabled then time efficient rather than space efficient code
  130. * is used when two possible implementations exist.
  131. *
  132. * @note This is not related to the compiler optimization options.
  133. * @note The default is @p TRUE.
  134. */
  135. #define CH_CFG_OPTIMIZE_SPEED TRUE
  136. /** @} */
  137. /*===========================================================================*/
  138. /**
  139. * @name Subsystem options
  140. * @{
  141. */
  142. /*===========================================================================*/
  143. /**
  144. * @brief Time Measurement APIs.
  145. * @details If enabled then the time measurement APIs are included in
  146. * the kernel.
  147. *
  148. * @note The default is @p TRUE.
  149. */
  150. #define CH_CFG_USE_TM FALSE
  151. /**
  152. * @brief Threads registry APIs.
  153. * @details If enabled then the registry APIs are included in the kernel.
  154. *
  155. * @note The default is @p TRUE.
  156. */
  157. #define CH_CFG_USE_REGISTRY TRUE
  158. /**
  159. * @brief Threads synchronization APIs.
  160. * @details If enabled then the @p chThdWait() function is included in
  161. * the kernel.
  162. *
  163. * @note The default is @p TRUE.
  164. */
  165. #define CH_CFG_USE_WAITEXIT TRUE
  166. /**
  167. * @brief Semaphores APIs.
  168. * @details If enabled then the Semaphores APIs are included in the kernel.
  169. *
  170. * @note The default is @p TRUE.
  171. */
  172. #define CH_CFG_USE_SEMAPHORES TRUE
  173. /**
  174. * @brief Semaphores queuing mode.
  175. * @details If enabled then the threads are enqueued on semaphores by
  176. * priority rather than in FIFO order.
  177. *
  178. * @note The default is @p FALSE. Enable this if you have special
  179. * requirements.
  180. * @note Requires @p CH_CFG_USE_SEMAPHORES.
  181. */
  182. #define CH_CFG_USE_SEMAPHORES_PRIORITY FALSE
  183. /**
  184. * @brief Mutexes APIs.
  185. * @details If enabled then the mutexes APIs are included in the kernel.
  186. *
  187. * @note The default is @p TRUE.
  188. */
  189. #define CH_CFG_USE_MUTEXES TRUE
  190. /**
  191. * @brief Enables recursive behavior on mutexes.
  192. * @note Recursive mutexes are heavier and have an increased
  193. * memory footprint.
  194. *
  195. * @note The default is @p FALSE.
  196. * @note Requires @p CH_CFG_USE_MUTEXES.
  197. */
  198. #define CH_CFG_USE_MUTEXES_RECURSIVE FALSE
  199. /**
  200. * @brief Conditional Variables APIs.
  201. * @details If enabled then the conditional variables APIs are included
  202. * in the kernel.
  203. *
  204. * @note The default is @p TRUE.
  205. * @note Requires @p CH_CFG_USE_MUTEXES.
  206. */
  207. #define CH_CFG_USE_CONDVARS TRUE
  208. /**
  209. * @brief Conditional Variables APIs with timeout.
  210. * @details If enabled then the conditional variables APIs with timeout
  211. * specification are included in the kernel.
  212. *
  213. * @note The default is @p TRUE.
  214. * @note Requires @p CH_CFG_USE_CONDVARS.
  215. */
  216. #define CH_CFG_USE_CONDVARS_TIMEOUT TRUE
  217. /**
  218. * @brief Events Flags APIs.
  219. * @details If enabled then the event flags APIs are included in the kernel.
  220. *
  221. * @note The default is @p TRUE.
  222. */
  223. #define CH_CFG_USE_EVENTS TRUE
  224. /**
  225. * @brief Events Flags APIs with timeout.
  226. * @details If enabled then the events APIs with timeout specification
  227. * are included in the kernel.
  228. *
  229. * @note The default is @p TRUE.
  230. * @note Requires @p CH_CFG_USE_EVENTS.
  231. */
  232. #define CH_CFG_USE_EVENTS_TIMEOUT TRUE
  233. /**
  234. * @brief Synchronous Messages APIs.
  235. * @details If enabled then the synchronous messages APIs are included
  236. * in the kernel.
  237. *
  238. * @note The default is @p TRUE.
  239. */
  240. #define CH_CFG_USE_MESSAGES TRUE
  241. /**
  242. * @brief Synchronous Messages queuing mode.
  243. * @details If enabled then messages are served by priority rather than in
  244. * FIFO order.
  245. *
  246. * @note The default is @p FALSE. Enable this if you have special
  247. * requirements.
  248. * @note Requires @p CH_CFG_USE_MESSAGES.
  249. */
  250. #define CH_CFG_USE_MESSAGES_PRIORITY FALSE
  251. /**
  252. * @brief Mailboxes APIs.
  253. * @details If enabled then the asynchronous messages (mailboxes) APIs are
  254. * included in the kernel.
  255. *
  256. * @note The default is @p TRUE.
  257. * @note Requires @p CH_CFG_USE_SEMAPHORES.
  258. */
  259. #define CH_CFG_USE_MAILBOXES TRUE
  260. /**
  261. * @brief Core Memory Manager APIs.
  262. * @details If enabled then the core memory manager APIs are included
  263. * in the kernel.
  264. *
  265. * @note The default is @p TRUE.
  266. */
  267. #define CH_CFG_USE_MEMCORE TRUE
  268. /**
  269. * @brief Heap Allocator APIs.
  270. * @details If enabled then the memory heap allocator APIs are included
  271. * in the kernel.
  272. *
  273. * @note The default is @p TRUE.
  274. * @note Requires @p CH_CFG_USE_MEMCORE and either @p CH_CFG_USE_MUTEXES or
  275. * @p CH_CFG_USE_SEMAPHORES.
  276. * @note Mutexes are recommended.
  277. */
  278. #define CH_CFG_USE_HEAP TRUE
  279. /**
  280. * @brief Memory Pools Allocator APIs.
  281. * @details If enabled then the memory pools allocator APIs are included
  282. * in the kernel.
  283. *
  284. * @note The default is @p TRUE.
  285. */
  286. #define CH_CFG_USE_MEMPOOLS TRUE
  287. /**
  288. * @brief Objects FIFOs APIs.
  289. * @details If enabled then the objects FIFOs APIs are included
  290. * in the kernel.
  291. *
  292. * @note The default is @p TRUE.
  293. */
  294. #define CH_CFG_USE_OBJ_FIFOS FALSE
  295. /**
  296. * @brief Dynamic Threads APIs.
  297. * @details If enabled then the dynamic threads creation APIs are included
  298. * in the kernel.
  299. *
  300. * @note The default is @p TRUE.
  301. * @note Requires @p CH_CFG_USE_WAITEXIT.
  302. * @note Requires @p CH_CFG_USE_HEAP and/or @p CH_CFG_USE_MEMPOOLS.
  303. */
  304. #define CH_CFG_USE_DYNAMIC TRUE
  305. /** @} */
  306. /*===========================================================================*/
  307. /**
  308. * @name Objects factory options
  309. * @{
  310. */
  311. /*===========================================================================*/
  312. /**
  313. * @brief Objects Factory APIs.
  314. * @details If enabled then the objects factory APIs are included in the
  315. * kernel.
  316. *
  317. * @note The default is @p FALSE.
  318. */
  319. #define CH_CFG_USE_FACTORY FALSE
  320. /**
  321. * @brief Maximum length for object names.
  322. * @details If the specified length is zero then the name is stored by
  323. * pointer but this could have unintended side effects.
  324. */
  325. #define CH_CFG_FACTORY_MAX_NAMES_LENGTH 8
  326. /**
  327. * @brief Enables the registry of generic objects.
  328. */
  329. #define CH_CFG_FACTORY_OBJECTS_REGISTRY TRUE
  330. /**
  331. * @brief Enables factory for generic buffers.
  332. */
  333. #define CH_CFG_FACTORY_GENERIC_BUFFERS TRUE
  334. /**
  335. * @brief Enables factory for semaphores.
  336. */
  337. #define CH_CFG_FACTORY_SEMAPHORES TRUE
  338. /**
  339. * @brief Enables factory for mailboxes.
  340. */
  341. #define CH_CFG_FACTORY_MAILBOXES TRUE
  342. /**
  343. * @brief Enables factory for objects FIFOs.
  344. */
  345. #define CH_CFG_FACTORY_OBJ_FIFOS TRUE
  346. /** @} */
  347. /*===========================================================================*/
  348. /**
  349. * @name Debug options
  350. * @{
  351. */
  352. /*===========================================================================*/
  353. /**
  354. * @brief Debug option, kernel statistics.
  355. *
  356. * @note The default is @p FALSE.
  357. */
  358. #define CH_DBG_STATISTICS FALSE
  359. /**
  360. * @brief Debug option, system state check.
  361. * @details If enabled the correct call protocol for system APIs is checked
  362. * at runtime.
  363. *
  364. * @note The default is @p FALSE.
  365. */
  366. #define CH_DBG_SYSTEM_STATE_CHECK FALSE
  367. /**
  368. * @brief Debug option, parameters checks.
  369. * @details If enabled then the checks on the API functions input
  370. * parameters are activated.
  371. *
  372. * @note The default is @p FALSE.
  373. */
  374. #define CH_DBG_ENABLE_CHECKS FALSE
  375. /**
  376. * @brief Debug option, consistency checks.
  377. * @details If enabled then all the assertions in the kernel code are
  378. * activated. This includes consistency checks inside the kernel,
  379. * runtime anomalies and port-defined checks.
  380. *
  381. * @note The default is @p FALSE.
  382. */
  383. #define CH_DBG_ENABLE_ASSERTS FALSE
  384. /**
  385. * @brief Debug option, trace buffer.
  386. * @details If enabled then the trace buffer is activated.
  387. *
  388. * @note The default is @p CH_DBG_TRACE_MASK_DISABLED.
  389. */
  390. #define CH_DBG_TRACE_MASK CH_DBG_TRACE_MASK_DISABLED
  391. /**
  392. * @brief Trace buffer entries.
  393. * @note The trace buffer is only allocated if @p CH_DBG_TRACE_MASK is
  394. * different from @p CH_DBG_TRACE_MASK_DISABLED.
  395. */
  396. #define CH_DBG_TRACE_BUFFER_SIZE 128
  397. /**
  398. * @brief Debug option, stack checks.
  399. * @details If enabled then a runtime stack check is performed.
  400. *
  401. * @note The default is @p FALSE.
  402. * @note The stack check is performed in a architecture/port dependent way.
  403. * It may not be implemented or some ports.
  404. * @note The default failure mode is to halt the system with the global
  405. * @p panic_msg variable set to @p NULL.
  406. */
  407. #define CH_DBG_ENABLE_STACK_CHECK FALSE
  408. /**
  409. * @brief Debug option, stacks initialization.
  410. * @details If enabled then the threads working area is filled with a byte
  411. * value when a thread is created. This can be useful for the
  412. * runtime measurement of the used stack.
  413. *
  414. * @note The default is @p FALSE.
  415. */
  416. #define CH_DBG_FILL_THREADS FALSE
  417. /**
  418. * @brief Debug option, threads profiling.
  419. * @details If enabled then a field is added to the @p thread_t structure that
  420. * counts the system ticks occurred while executing the thread.
  421. *
  422. * @note The default is @p FALSE.
  423. * @note This debug option is not currently compatible with the
  424. * tickless mode.
  425. */
  426. #define CH_DBG_THREADS_PROFILING FALSE
  427. /** @} */
  428. /*===========================================================================*/
  429. /**
  430. * @name Kernel hooks
  431. * @{
  432. */
  433. /*===========================================================================*/
  434. /**
  435. * @brief System structure extension.
  436. * @details User fields added to the end of the @p ch_system_t structure.
  437. */
  438. #define CH_CFG_SYSTEM_EXTRA_FIELDS \
  439. /* Add threads custom fields here.*/
  440. /**
  441. * @brief System initialization hook.
  442. * @details User initialization code added to the @p chSysInit() function
  443. * just before interrupts are enabled globally.
  444. */
  445. #define CH_CFG_SYSTEM_INIT_HOOK(tp) { \
  446. /* Add threads initialization code here.*/ \
  447. }
  448. /**
  449. * @brief Threads descriptor structure extension.
  450. * @details User fields added to the end of the @p thread_t structure.
  451. */
  452. #define CH_CFG_THREAD_EXTRA_FIELDS \
  453. /* Add threads custom fields here.*/
  454. /**
  455. * @brief Threads initialization hook.
  456. * @details User initialization code added to the @p _thread_init() function.
  457. *
  458. * @note It is invoked from within @p _thread_init() and implicitly from all
  459. * the threads creation APIs.
  460. */
  461. #define CH_CFG_THREAD_INIT_HOOK(tp) { \
  462. /* Add threads initialization code here.*/ \
  463. }
  464. /**
  465. * @brief Threads finalization hook.
  466. * @details User finalization code added to the @p chThdExit() API.
  467. */
  468. #define CH_CFG_THREAD_EXIT_HOOK(tp) { \
  469. /* Add threads finalization code here.*/ \
  470. }
  471. /**
  472. * @brief Context switch hook.
  473. * @details This hook is invoked just before switching between threads.
  474. */
  475. #define CH_CFG_CONTEXT_SWITCH_HOOK(ntp, otp) { \
  476. /* Context switch code here.*/ \
  477. }
  478. /**
  479. * @brief ISR enter hook.
  480. */
  481. #define CH_CFG_IRQ_PROLOGUE_HOOK() { \
  482. /* IRQ prologue code here.*/ \
  483. }
  484. /**
  485. * @brief ISR exit hook.
  486. */
  487. #define CH_CFG_IRQ_EPILOGUE_HOOK() { \
  488. /* IRQ epilogue code here.*/ \
  489. }
  490. /**
  491. * @brief Idle thread enter hook.
  492. * @note This hook is invoked within a critical zone, no OS functions
  493. * should be invoked from here.
  494. * @note This macro can be used to activate a power saving mode.
  495. */
  496. #define CH_CFG_IDLE_ENTER_HOOK() { \
  497. /* Idle-enter code here.*/ \
  498. }
  499. /**
  500. * @brief Idle thread leave hook.
  501. * @note This hook is invoked within a critical zone, no OS functions
  502. * should be invoked from here.
  503. * @note This macro can be used to deactivate a power saving mode.
  504. */
  505. #define CH_CFG_IDLE_LEAVE_HOOK() { \
  506. /* Idle-leave code here.*/ \
  507. }
  508. /**
  509. * @brief Idle Loop hook.
  510. * @details This hook is continuously invoked by the idle thread loop.
  511. */
  512. #define CH_CFG_IDLE_LOOP_HOOK() { \
  513. /* Idle loop code here.*/ \
  514. }
  515. /**
  516. * @brief System tick event hook.
  517. * @details This hook is invoked in the system tick handler immediately
  518. * after processing the virtual timers queue.
  519. */
  520. #define CH_CFG_SYSTEM_TICK_HOOK() { \
  521. /* System tick event code here.*/ \
  522. }
  523. /**
  524. * @brief System halt hook.
  525. * @details This hook is invoked in case to a system halting error before
  526. * the system is halted.
  527. */
  528. #define CH_CFG_SYSTEM_HALT_HOOK(reason) { \
  529. /* System halt code here.*/ \
  530. }
  531. /**
  532. * @brief Trace hook.
  533. * @details This hook is invoked each time a new record is written in the
  534. * trace buffer.
  535. */
  536. #define CH_CFG_TRACE_HOOK(tep) { \
  537. /* Trace code here.*/ \
  538. }
  539. /** @} */
  540. /*===========================================================================*/
  541. /* Port-specific settings (override port settings defaulted in chcore.h). */
  542. /*===========================================================================*/
  543. #endif /* CHCONF_H */
  544. /** @} */