├── .gitattributes ├── .gitignore ├── README.md ├── doc ├── ChRt.html ├── Doxyfile ├── MainPage │ └── ChRtMainPage.h ├── clean_html.bat ├── del_htm.bat └── html │ ├── _ch_rt_8h.html │ ├── _ch_rt_8h_source.html │ ├── _ch_rt_main_page_8h_source.html │ ├── bc_s.png │ ├── bdwn.png │ ├── closed.png │ ├── dir_68267d1309a1af8e8297ef4c3efbcdba.html │ ├── dir_f1e74b9d244c08400ce0f6c55d14c7e5.html │ ├── doc.png │ ├── doxygen.css │ ├── doxygen.svg │ ├── dynsections.js │ ├── files.html │ ├── folderclosed.png │ ├── folderopen.png │ ├── globals.html │ ├── globals_defs.html │ ├── globals_func.html │ ├── index.html │ ├── jquery.js │ ├── menu.js │ ├── menudata.js │ ├── nav_f.png │ ├── nav_g.png │ ├── nav_h.png │ ├── open.png │ ├── search │ ├── all_0.html │ ├── all_0.js │ ├── all_1.html │ ├── all_1.js │ ├── all_2.html │ ├── all_2.js │ ├── close.svg │ ├── defines_0.html │ ├── defines_0.js │ ├── files_0.html │ ├── files_0.js │ ├── functions_0.html │ ├── functions_0.js │ ├── functions_1.html │ ├── functions_1.js │ ├── functions_2.html │ ├── functions_2.js │ ├── mag_sel.svg │ ├── nomatches.html │ ├── pages_0.html │ ├── pages_0.js │ ├── search.css │ ├── search.js │ ├── search_l.png │ ├── search_m.png │ ├── search_r.png │ └── searchdata.js │ ├── splitbar.png │ ├── sync_off.png │ ├── sync_on.png │ ├── tab_a.png │ ├── tab_b.png │ ├── tab_h.png │ ├── tab_s.png │ └── tabs.css ├── examples ├── chBlink │ └── chBlink.ino ├── chBlinkPrint │ └── chBlinkPrint.ino ├── chContextTime │ └── chContextTime.ino ├── chCoop │ └── chCoop.ino ├── chDataSharing │ └── chDataSharing.ino ├── chEvent │ └── chEvent.ino ├── chFifoDataLogger │ └── chFifoDataLogger.ino ├── chIsrSemaphore │ └── chIsrSemaphore.ino ├── chJitter │ └── chJitter.ino ├── chMailbox │ └── chMailbox.ino ├── chMemPool │ └── chMemPool.ino ├── chMutex │ └── chMutex.ino ├── chRoundRobin │ └── chRoundRobin.ino └── chSemaphore │ └── chSemaphore.ino ├── extra ├── src_org │ ├── CMSIS │ │ ├── cachel1_armv7.h │ │ ├── cmsis_armcc.h │ │ ├── cmsis_armclang.h │ │ ├── cmsis_armclang_ltm.h │ │ ├── cmsis_compiler.h │ │ ├── cmsis_gcc.h │ │ ├── cmsis_iccarm.h │ │ ├── cmsis_version.h │ │ ├── core_armv81mml.h │ │ ├── core_armv8mbl.h │ │ ├── core_armv8mml.h │ │ ├── core_cm0.h │ │ ├── core_cm0plus.h │ │ ├── core_cm1.h │ │ ├── core_cm23.h │ │ ├── core_cm3.h │ │ ├── core_cm33.h │ │ ├── core_cm35p.h │ │ ├── core_cm4.h │ │ ├── core_cm55.h │ │ ├── core_cm7.h │ │ ├── core_sc000.h │ │ ├── core_sc300.h │ │ ├── mpu_armv7.h │ │ ├── mpu_armv8.h │ │ ├── pmu_armv8.h │ │ └── tz_context.h │ ├── arm │ │ ├── chcore.h │ │ ├── chcore_timer.h │ │ ├── chcore_v6m.c │ │ ├── chcore_v6m.h │ │ ├── chcore_v7m.c │ │ ├── chcore_v7m.h │ │ ├── chcoreasm_v6m.S │ │ ├── chcoreasm_v7m.S │ │ ├── chtypes.h │ │ └── mpu.h │ ├── avr │ │ ├── chcore.c │ │ ├── chcore.h │ │ ├── chcore_timer.h │ │ └── chtypes.h │ ├── hal │ │ ├── hal_st.c │ │ ├── hal_st.h │ │ └── osal.h │ ├── license │ │ ├── chcustomer.h │ │ ├── chlicense.h │ │ ├── chversion.h │ │ ├── license.dox │ │ └── license.mk │ ├── oslib │ │ ├── dox │ │ │ └── lib.dox │ │ ├── include │ │ │ ├── chbsem.h │ │ │ ├── chdelegates.h │ │ │ ├── chfactory.h │ │ │ ├── chjobs.h │ │ │ ├── chlib.h │ │ │ ├── chmboxes.h │ │ │ ├── chmemcore.h │ │ │ ├── chmemheaps.h │ │ │ ├── chmempools.h │ │ │ ├── chobjcaches.h │ │ │ ├── chobjfifos.h │ │ │ └── chpipes.h │ │ ├── oslib.mk │ │ ├── readme.txt │ │ └── src │ │ │ ├── chdelegates.c │ │ │ ├── chfactory.c │ │ │ ├── chmboxes.c │ │ │ ├── chmemcore.c │ │ │ ├── chmemheaps.c │ │ │ ├── chmempools.c │ │ │ ├── chobjcaches.c │ │ │ └── chpipes.c │ ├── readme.txt │ └── rt │ │ ├── include │ │ ├── ch.h │ │ ├── chalign.h │ │ ├── chchecks.h │ │ ├── chcond.h │ │ ├── chdebug.h │ │ ├── chdynamic.h │ │ ├── chevents.h │ │ ├── chlists.h │ │ ├── chmsg.h │ │ ├── chmtx.h │ │ ├── chregistry.h │ │ ├── chrestrictions.h │ │ ├── chschd.h │ │ ├── chsem.h │ │ ├── chstats.h │ │ ├── chsys.h │ │ ├── chsystypes.h │ │ ├── chthreads.h │ │ ├── chtime.h │ │ ├── chtm.h │ │ ├── chtrace.h │ │ └── chvt.h │ │ ├── src │ │ ├── chcond.c │ │ ├── chdebug.c │ │ ├── chdynamic.c │ │ ├── chevents.c │ │ ├── chmsg.c │ │ ├── chmtx.c │ │ ├── chregistry.c │ │ ├── chschd.c │ │ ├── chsem.c │ │ ├── chstats.c │ │ ├── chsys.c │ │ ├── chthreads.c │ │ ├── chtm.c │ │ ├── chtrace.c │ │ └── chvt.c │ │ └── templates │ │ ├── chconf.h │ │ └── meta │ │ ├── module.c │ │ └── module.h ├── srcdiff.bat └── srcdiff.txt ├── library.properties └── src ├── CMSIS ├── cachel1_armv7.h ├── cmsis_armcc.h ├── cmsis_armclang.h ├── cmsis_armclang_ltm.h ├── cmsis_compiler.h ├── cmsis_gcc.h ├── cmsis_iccarm.h ├── cmsis_version.h ├── core_armv81mml.h ├── core_armv8mbl.h ├── core_armv8mml.h ├── core_cm0.h ├── core_cm0plus.h ├── core_cm1.h ├── core_cm23.h ├── core_cm3.h ├── core_cm33.h ├── core_cm35p.h ├── core_cm4.h ├── core_cm55.h ├── core_cm7.h ├── core_sc000.h ├── core_sc300.h ├── mpu_armv7.h ├── mpu_armv8.h ├── pmu_armv8.h └── tz_context.h ├── ChRt.c ├── ChRt.cpp ├── ChRt.h ├── arm ├── chcore.h ├── chcore_timer.h ├── chcore_v6m.c ├── chcore_v6m.h ├── chcore_v7m.c ├── chcore_v7m.h ├── chcoreasm_v6m.S ├── chcoreasm_v7m.S ├── chtypes.h └── mpu.h ├── avr ├── chconf_avr.h ├── chcore.c ├── chcore.h ├── chcore_timer.h ├── chtypes.h ├── st_lld_avr.c └── st_lld_avr.h ├── ch.h ├── chconf.h ├── chcore.h ├── chlib.h ├── chlicense.h ├── chtypes.h ├── cmparams.h ├── hal ├── hal.h ├── hal_st.c ├── hal_st.h └── osal.h ├── hal_st.h ├── hal_st_lld.h ├── license ├── chcustomer.h ├── chlicense.h ├── chversion.h ├── license.dox └── license.mk ├── oslib ├── dox │ └── lib.dox ├── include │ ├── chbsem.h │ ├── chdelegates.h │ ├── chfactory.h │ ├── chjobs.h │ ├── chlib.h │ ├── chmboxes.h │ ├── chmemcore.h │ ├── chmemheaps.h │ ├── chmempools.h │ ├── chobjcaches.h │ ├── chobjfifos.h │ └── chpipes.h ├── oslib.mk ├── readme.txt └── src │ ├── chdelegates.c │ ├── chfactory.c │ ├── chmboxes.c │ ├── chmemcore.c │ ├── chmemheaps.c │ ├── chmempools.c │ ├── chobjcaches.c │ └── chpipes.c ├── rt ├── include │ ├── ch.h │ ├── chalign.h │ ├── chchecks.h │ ├── chcond.h │ ├── chdebug.h │ ├── chdynamic.h │ ├── chevents.h │ ├── chlists.h │ ├── chmsg.h │ ├── chmtx.h │ ├── chregistry.h │ ├── chrestrictions.h │ ├── chschd.h │ ├── chsem.h │ ├── chstats.h │ ├── chsys.h │ ├── chsystypes.h │ ├── chthreads.h │ ├── chtime.h │ ├── chtm.h │ ├── chtrace.h │ └── chvt.h ├── src │ ├── chcond.c │ ├── chdebug.c │ ├── chdynamic.c │ ├── chevents.c │ ├── chmsg.c │ ├── chmtx.c │ ├── chregistry.c │ ├── chschd.c │ ├── chsem.c │ ├── chstats.c │ ├── chsys.c │ ├── chthreads.c │ ├── chtm.c │ ├── chtrace.c │ └── chvt.c └── templates │ ├── chconf.h │ └── meta │ ├── module.c │ └── module.h ├── sam3x ├── chconf_sam3x.h ├── cmparams_sam3x.h └── st_lld_sam3x.c ├── samd ├── chconf_samd.h ├── cmparams_samd.h └── st_lld_samd.c ├── teensy3 ├── chconf_teensy3.h ├── cmparams_teensy3.h └── st_lld_teensy3.cpp └── teensy4 ├── chconf_teensy4.h ├── cmparams_teensy4.h ├── st_lld_teensy4.cpp └── st_lld_teensy4.h /.gitattributes: -------------------------------------------------------------------------------- 1 | # Auto detect text files and perform LF normalization 2 | * text=auto 3 | 4 | # Custom for Visual Studio 5 | *.cs diff=csharp 6 | 7 | # Standard to msysgit 8 | *.doc diff=astextplain 9 | *.DOC diff=astextplain 10 | *.docx diff=astextplain 11 | *.DOCX diff=astextplain 12 | *.dot diff=astextplain 13 | *.DOT diff=astextplain 14 | *.pdf diff=astextplain 15 | *.PDF diff=astextplain 16 | *.rtf diff=astextplain 17 | *.RTF diff=astextplain 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Windows image file caches 2 | Thumbs.db 3 | ehthumbs.db 4 | 5 | # Folder config file 6 | Desktop.ini 7 | 8 | # Recycle Bin used on file shares 9 | $RECYCLE.BIN/ 10 | 11 | # Windows Installer files 12 | *.cab 13 | *.msi 14 | *.msm 15 | *.msp 16 | 17 | # Windows shortcuts 18 | *.lnk 19 | 20 | # ========================= 21 | # Operating System Files 22 | # ========================= 23 | 24 | # OSX 25 | # ========================= 26 | 27 | .DS_Store 28 | .AppleDouble 29 | .LSOverride 30 | 31 | # Thumbnails 32 | ._* 33 | 34 | # Files that might appear in the root of a volume 35 | .DocumentRevisions-V100 36 | .fseventsd 37 | .Spotlight-V100 38 | .TemporaryItems 39 | .Trashes 40 | .VolumeIcon.icns 41 | 42 | # Directories potentially created on remote AFP share 43 | .AppleDB 44 | .AppleDesktop 45 | Network Trash Folder 46 | Temporary Items 47 | .apdisk 48 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #### ChRt - ChibiOS/RT Arduino Library 2 | 3 | This is a version of ChibiOS for Arduino. 4 | I am starting a new repository since this version is not backward 5 | compatible with the previous libraries. Both AVR and ARM are now in 6 | a single library. 7 | 8 | Teensy 4.0 has support for free running tick-less mode and periodic mode. 9 | The default for Teensy 4.0 is tick-less mode. Edit 10 | libraries/ChRt/src/teensy4/chconf_teensy4.h to select periodic mode 11 | or change parameters for Teensy 4. 12 | 13 | See this article about ChibiOS tick-less mode: 14 | 15 | http://www.chibios.org/dokuwiki/doku.php?id=chibios:articles:tickless 16 | 17 | AVR also supports tick-less mode. The default is periodic mode. Edit 18 | libraries/ChRt/src/avr/chconf_avr.h to select tick-less mode. 19 | 20 | 21 | Due, SAMD, and Teensy 3.x are supported in periodic mode. 22 | 23 | The base code for ChRt was written by Giovanni Di Sirio, the author 24 | of ChibiOS/Nil and ChibiOS/RT. 25 | 26 | See this site for detailed documentation of ChibiOS/RT. 27 | 28 | http://www.chibios.org/dokuwiki/doku.php 29 | 30 | The kernel is version 6.1.3 of ChibiOS/RT from ChibiOS release 20.3.3. 31 | 32 | https://osdn.net/projects/chibios/releases 33 | 34 | If you are installing from the GitHub repo zips, rename the folder ChRt 35 | before copying it to your Arduino/libraries folder. 36 | 37 | Please read libraries/ChRt/doc/ChRt.html for more information. See the 38 | Examples section of the html documentation. 39 | 40 | Start with the ChBlink example which is traditional for almost every RTOS. 41 | 42 | -------------------------------------------------------------------------------- /doc/ChRt.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | A web page that points a browser to a different page 4 | 5 | 6 | 7 | 8 | Your browser didn't automatically redirect. Open html/index.html manually. 9 | 10 | 11 | -------------------------------------------------------------------------------- /doc/clean_html.bat: -------------------------------------------------------------------------------- 1 | del html\*.md5 2 | del html\*.map 3 | pause -------------------------------------------------------------------------------- /doc/del_htm.bat: -------------------------------------------------------------------------------- 1 | rm html/*.* html/*/*.* 2 | pause -------------------------------------------------------------------------------- /doc/html/_ch_rt_main_page_8h_source.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: MainPage/ChRtMainPage.h Source File 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 | 50 |
54 |
55 | 56 | 57 |
58 | 61 |
62 | 63 | 67 |
68 |
69 |
70 |
ChRtMainPage.h
71 |
72 |
73 |
1 
74 |
75 | 76 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /doc/html/bc_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/bc_s.png -------------------------------------------------------------------------------- /doc/html/bdwn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/bdwn.png -------------------------------------------------------------------------------- /doc/html/closed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/closed.png -------------------------------------------------------------------------------- /doc/html/dir_68267d1309a1af8e8297ef4c3efbcdba.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: C:/Users/bill/Documents/ArduinoChRt/libraries/ChRt/src Directory Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 | 50 |
54 |
55 | 56 | 57 |
58 | 61 |
62 | 63 | 67 |
68 |
69 |
70 |
src Directory Reference
71 |
72 |
73 | 74 | 76 | 77 | 78 | 79 |

75 | Files

file  ChRt.h [code]
 main ChRt include file.
 
80 |
81 | 82 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /doc/html/dir_f1e74b9d244c08400ce0f6c55d14c7e5.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: MainPage Directory Reference 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 | 50 |
54 |
55 | 56 | 57 |
58 | 61 |
62 | 63 | 67 |
68 |
69 |
70 |
MainPage Directory Reference
71 |
72 |
73 |
74 | 75 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /doc/html/doc.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/doc.png -------------------------------------------------------------------------------- /doc/html/folderclosed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/folderclosed.png -------------------------------------------------------------------------------- /doc/html/folderopen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/folderopen.png -------------------------------------------------------------------------------- /doc/html/globals.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: File Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 |
50 | 51 |
55 |
56 | 57 | 58 |
59 | 62 |
63 | 64 |
65 |
Here is a list of all documented file members with links to the documentation:
88 |
89 | 90 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /doc/html/globals_defs.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: File Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 |
50 | 51 |
55 |
56 | 57 | 58 |
59 | 62 |
63 | 64 |
65 |   70 |
71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /doc/html/globals_func.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | ChRt: File Members 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 |
20 | 21 | 22 | 23 | 28 | 29 | 30 |
24 |
ChRt 25 |
26 |
ChibiOS/RT Arduino
27 |
31 |
32 | 33 | 34 | 39 | 40 | 41 | 48 | 49 |
50 | 51 |
55 |
56 | 57 | 58 |
59 | 62 |
63 | 64 |
65 |   85 |
86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /doc/html/menu.js: -------------------------------------------------------------------------------- 1 | /* 2 | @licstart The following is the entire license notice for the JavaScript code in this file. 3 | 4 | The MIT License (MIT) 5 | 6 | Copyright (C) 1997-2020 by Dimitri van Heesch 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 9 | and associated documentation files (the "Software"), to deal in the Software without restriction, 10 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 11 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all copies or 15 | substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 18 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | @licend The above is the entire license notice for the JavaScript code in this file 24 | */ 25 | function initMenu(relPath,searchEnabled,serverSide,searchPage,search) { 26 | function makeTree(data,relPath) { 27 | var result=''; 28 | if ('children' in data) { 29 | result+=''; 36 | } 37 | return result; 38 | } 39 | 40 | $('#main-nav').append(makeTree(menudata,relPath)); 41 | $('#main-nav').children(':first').addClass('sm sm-dox').attr('id','main-menu'); 42 | if (searchEnabled) { 43 | if (serverSide) { 44 | $('#main-menu').append('
  • '); 45 | } else { 46 | $('#main-menu').append('
  • '); 47 | } 48 | } 49 | $('#main-menu').smartmenus(); 50 | } 51 | /* @license-end */ 52 | -------------------------------------------------------------------------------- /doc/html/menudata.js: -------------------------------------------------------------------------------- 1 | /* 2 | @licstart The following is the entire license notice for the JavaScript code in this file. 3 | 4 | The MIT License (MIT) 5 | 6 | Copyright (C) 1997-2020 by Dimitri van Heesch 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software 9 | and associated documentation files (the "Software"), to deal in the Software without restriction, 10 | including without limitation the rights to use, copy, modify, merge, publish, distribute, 11 | sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in all copies or 15 | substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING 18 | BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 20 | DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 | 23 | @licend The above is the entire license notice for the JavaScript code in this file 24 | */ 25 | var menudata={children:[ 26 | {text:"Main Page",url:"index.html"}, 27 | {text:"Files",url:"files.html",children:[ 28 | {text:"File List",url:"files.html"}, 29 | {text:"File Members",url:"globals.html",children:[ 30 | {text:"All",url:"globals.html"}, 31 | {text:"Functions",url:"globals_func.html"}, 32 | {text:"Macros",url:"globals_defs.html"}]}]}]} 33 | -------------------------------------------------------------------------------- /doc/html/nav_f.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/nav_f.png -------------------------------------------------------------------------------- /doc/html/nav_g.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/nav_g.png -------------------------------------------------------------------------------- /doc/html/nav_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/nav_h.png -------------------------------------------------------------------------------- /doc/html/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/open.png -------------------------------------------------------------------------------- /doc/html/search/all_0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/all_0.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['chbegin_0',['chBegin',['../_ch_rt_8h.html#a745e6a77bbc187994fb79c2eb5450769',1,'ChRt.cpp']]], 4 | ['chrt_2eh_1',['ChRt.h',['../_ch_rt_8h.html',1,'']]], 5 | ['chunusedhandlerstack_2',['chUnusedHandlerStack',['../_ch_rt_8h.html#a0e513af394d20a21b12570380bb56773',1,'ChRt.cpp']]], 6 | ['chunusedmainstack_3',['chUnusedMainStack',['../_ch_rt_8h.html#a2b867b2762d19663f32931a3fa4ae94c',1,'ChRt.cpp']]], 7 | ['chunusedthreadstack_4',['chUnusedThreadStack',['../_ch_rt_8h.html#a9ae19ba1b487fdb8ea7d1608e64a2125',1,'ChRt.cpp']]], 8 | ['chibios_20rtos_20library_5',['ChibiOS RTOS library',['../index.html',1,'']]] 9 | ]; 10 | -------------------------------------------------------------------------------- /doc/html/search/all_1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/all_1.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['errorblink_6',['errorBlink',['../_ch_rt_8h.html#a8a5009aeaddf095fe34fee2fd029171c',1,'ChRt.h']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/all_2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/all_2.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['handler_5fstack_5fsize_7',['HANDLER_STACK_SIZE',['../_ch_rt_8h.html#acdb3e86f36ba7ea83d508e406d29dca1',1,'ChRt.h']]], 4 | ['heapend_8',['heapEnd',['../_ch_rt_8h.html#a9a1425ec66529dd4aec14702b02451d2',1,'ChRt.cpp']]] 5 | ]; 6 | -------------------------------------------------------------------------------- /doc/html/search/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 13 | 15 | 16 | 18 | image/svg+xml 19 | 21 | 22 | 23 | 24 | 25 | 27 | 31 | 32 | -------------------------------------------------------------------------------- /doc/html/search/defines_0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/defines_0.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['handler_5fstack_5fsize_16',['HANDLER_STACK_SIZE',['../_ch_rt_8h.html#acdb3e86f36ba7ea83d508e406d29dca1',1,'ChRt.h']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/files_0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/files_0.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['chrt_2eh_9',['ChRt.h',['../_ch_rt_8h.html',1,'']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/functions_0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/functions_0.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['chbegin_10',['chBegin',['../_ch_rt_8h.html#a745e6a77bbc187994fb79c2eb5450769',1,'ChRt.cpp']]], 4 | ['chunusedhandlerstack_11',['chUnusedHandlerStack',['../_ch_rt_8h.html#a0e513af394d20a21b12570380bb56773',1,'ChRt.cpp']]], 5 | ['chunusedmainstack_12',['chUnusedMainStack',['../_ch_rt_8h.html#a2b867b2762d19663f32931a3fa4ae94c',1,'ChRt.cpp']]], 6 | ['chunusedthreadstack_13',['chUnusedThreadStack',['../_ch_rt_8h.html#a9ae19ba1b487fdb8ea7d1608e64a2125',1,'ChRt.cpp']]] 7 | ]; 8 | -------------------------------------------------------------------------------- /doc/html/search/functions_1.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/functions_1.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['errorblink_14',['errorBlink',['../_ch_rt_8h.html#a8a5009aeaddf095fe34fee2fd029171c',1,'ChRt.h']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/functions_2.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/functions_2.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['heapend_15',['heapEnd',['../_ch_rt_8h.html#a9a1425ec66529dd4aec14702b02451d2',1,'ChRt.cpp']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/mag_sel.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 19 | 21 | 22 | 24 | image/svg+xml 25 | 27 | 28 | 29 | 30 | 31 | 33 | 57 | 63 | 69 | 74 | 75 | -------------------------------------------------------------------------------- /doc/html/search/nomatches.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
    9 |
    No Matches
    10 |
    11 | 12 | 13 | -------------------------------------------------------------------------------- /doc/html/search/pages_0.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
    11 |
    Loading...
    12 |
    13 | 18 |
    Searching...
    19 |
    No Matches
    20 | 34 |
    35 | 36 | 37 | -------------------------------------------------------------------------------- /doc/html/search/pages_0.js: -------------------------------------------------------------------------------- 1 | var searchData= 2 | [ 3 | ['chibios_20rtos_20library_17',['ChibiOS RTOS library',['../index.html',1,'']]] 4 | ]; 5 | -------------------------------------------------------------------------------- /doc/html/search/search_l.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/search/search_l.png -------------------------------------------------------------------------------- /doc/html/search/search_m.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/search/search_m.png -------------------------------------------------------------------------------- /doc/html/search/search_r.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/search/search_r.png -------------------------------------------------------------------------------- /doc/html/search/searchdata.js: -------------------------------------------------------------------------------- 1 | var indexSectionsWithContent = 2 | { 3 | 0: "ceh", 4 | 1: "c", 5 | 2: "ceh", 6 | 3: "h", 7 | 4: "c" 8 | }; 9 | 10 | var indexSectionNames = 11 | { 12 | 0: "all", 13 | 1: "files", 14 | 2: "functions", 15 | 3: "defines", 16 | 4: "pages" 17 | }; 18 | 19 | var indexSectionLabels = 20 | { 21 | 0: "All", 22 | 1: "Files", 23 | 2: "Functions", 24 | 3: "Macros", 25 | 4: "Pages" 26 | }; 27 | 28 | -------------------------------------------------------------------------------- /doc/html/splitbar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/splitbar.png -------------------------------------------------------------------------------- /doc/html/sync_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/sync_off.png -------------------------------------------------------------------------------- /doc/html/sync_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/sync_on.png -------------------------------------------------------------------------------- /doc/html/tab_a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/tab_a.png -------------------------------------------------------------------------------- /doc/html/tab_b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/tab_b.png -------------------------------------------------------------------------------- /doc/html/tab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/tab_h.png -------------------------------------------------------------------------------- /doc/html/tab_s.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/greiman/ChRt/96df06298cb5719ffe060747b78093c08b2b1e8a/doc/html/tab_s.png -------------------------------------------------------------------------------- /examples/chBlink/chBlink.ino: -------------------------------------------------------------------------------- 1 | // Example to demonstrate thread definition, semaphores, and thread sleep. 2 | #include "ChRt.h" 3 | 4 | // LED_BUILTIN pin on Arduino is usually pin 13. 5 | 6 | // Declare a semaphore with an inital counter value of zero. 7 | SEMAPHORE_DECL(sem, 0); 8 | //------------------------------------------------------------------------------ 9 | // Thread 1, turn the LED off when signalled by thread 2. 10 | // 11 | // 64 byte stack beyond task switch and interrupt needs. 12 | static THD_WORKING_AREA(waThread1, 64); 13 | 14 | static THD_FUNCTION(Thread1, arg) { 15 | (void)arg; 16 | while (!chThdShouldTerminateX()) { 17 | // Wait for signal from thread 2. 18 | chSemWait(&sem); 19 | 20 | // Turn LED off. 21 | digitalWrite(LED_BUILTIN, LOW); 22 | } 23 | } 24 | //------------------------------------------------------------------------------ 25 | // Thread 2, turn the LED on and signal thread 1 to turn the LED off. 26 | // 27 | // 64 byte stack beyond task switch and interrupt needs. 28 | static THD_WORKING_AREA(waThread2, 64); 29 | 30 | static THD_FUNCTION(Thread2, arg) { 31 | (void)arg; 32 | pinMode(LED_BUILTIN, OUTPUT); 33 | while (true) { 34 | digitalWrite(LED_BUILTIN, HIGH); 35 | 36 | // Sleep for 200 milliseconds. 37 | chThdSleepMilliseconds(200); 38 | 39 | // Signal thread 1 to turn LED off. 40 | chSemSignal(&sem); 41 | 42 | // Sleep for 200 milliseconds. 43 | chThdSleepMilliseconds(200); 44 | } 45 | } 46 | //------------------------------------------------------------------------------ 47 | // continue setup() after chBegin(). 48 | void chSetup() { 49 | // Start threads. 50 | chThdCreateStatic(waThread1, sizeof(waThread1), 51 | NORMALPRIO + 2, Thread1, NULL); 52 | 53 | chThdCreateStatic(waThread2, sizeof(waThread2), 54 | NORMALPRIO + 1, Thread2, NULL); 55 | } 56 | //------------------------------------------------------------------------------ 57 | void setup() { 58 | // Initialize OS and then call chSetup. 59 | chBegin(chSetup); 60 | // chBegin() resets stacks and should never return. 61 | while (true) {} 62 | } 63 | //------------------------------------------------------------------------------ 64 | // loop() is the main thread. Not used in this example. 65 | void loop() { 66 | } -------------------------------------------------------------------------------- /examples/chBlinkPrint/chBlinkPrint.ino: -------------------------------------------------------------------------------- 1 | // Simple demo of three threads. 2 | // LED blink thread, count thread, and main thread. 3 | #include "ChRt.h" 4 | 5 | // LED_BUILTIN pin on Arduino is usually pin 13. 6 | 7 | volatile uint32_t count = 0; 8 | //------------------------------------------------------------------------------ 9 | // thread 1 - high priority for blinking LED. 10 | // 64 byte stack beyond task switch and interrupt needs. 11 | static THD_WORKING_AREA(waThread1, 64); 12 | 13 | static THD_FUNCTION(Thread1 , arg) { 14 | (void)arg; 15 | 16 | pinMode(LED_BUILTIN, OUTPUT); 17 | 18 | // Flash led every 200 ms. 19 | while (true) { 20 | // Turn LED on. 21 | digitalWrite(LED_BUILTIN, HIGH); 22 | 23 | // Sleep for 50 milliseconds. 24 | chThdSleepMilliseconds(50); 25 | 26 | // Turn LED off. 27 | digitalWrite(LED_BUILTIN, LOW); 28 | 29 | // Sleep for 150 milliseconds. 30 | chThdSleepMilliseconds(150); 31 | } 32 | } 33 | //------------------------------------------------------------------------------ 34 | // thread 2 - count when higher priority threads sleep. 35 | // 64 byte stack beyond task switch and interrupt needs. 36 | static THD_WORKING_AREA(waThread2, 64); 37 | 38 | static THD_FUNCTION(Thread2, arg) { 39 | (void)arg; 40 | 41 | while (true) { 42 | noInterrupts(); 43 | count++; 44 | interrupts(); 45 | } 46 | } 47 | //------------------------------------------------------------------------------ 48 | // Name chSetup is not special - must be same as used in chBegin() call. 49 | void chSetup() { 50 | // Start blink thread. Priority one more than loop(). 51 | chThdCreateStatic(waThread1, sizeof(waThread1), 52 | NORMALPRIO + 1, Thread1, NULL); 53 | // Start count thread. Priority one less than loop(). 54 | chThdCreateStatic(waThread2, sizeof(waThread2), 55 | NORMALPRIO - 1, Thread2, NULL); 56 | } 57 | //------------------------------------------------------------------------------ 58 | void setup() { 59 | Serial.begin(9600); 60 | // Wait for USB Serial. 61 | while (!Serial) {} 62 | 63 | chBegin(chSetup); 64 | // chBegin() resets stacks and should never return. 65 | while (true) {} 66 | } 67 | //------------------------------------------------------------------------------ 68 | // Runs at NORMALPRIO. 69 | void loop() { 70 | // Sleep for one second. 71 | chThdSleepMilliseconds(1000); 72 | 73 | // Print count for previous second. 74 | Serial.print(F("Count: ")); 75 | Serial.print(count); 76 | 77 | // Zero count. 78 | count = 0; 79 | 80 | // Print unused stack space in bytes. 81 | Serial.print(F(", Unused Stack: ")); 82 | Serial.print(chUnusedThreadStack(waThread1, sizeof(waThread1))); 83 | Serial.print(' '); 84 | Serial.print(chUnusedThreadStack(waThread2, sizeof(waThread2))); 85 | Serial.print(' '); 86 | Serial.print(chUnusedMainStack()); 87 | #ifdef __arm__ 88 | // ARM has separate stack for ISR interrupts. 89 | Serial.print(' '); 90 | Serial.print(chUnusedHandlerStack()); 91 | #endif // __arm__ 92 | Serial.println(); 93 | } 94 | -------------------------------------------------------------------------------- /examples/chContextTime/chContextTime.ino: -------------------------------------------------------------------------------- 1 | // Connect a scope to pin 13 2 | // Measure difference in time between first pulse with no context switch 3 | // and second pulse started in thread 2 and ended in thread 1. 4 | // Difference should be about 15-16 usec on a 16 MHz 328 Arduino. 5 | // Under a microsecond on a Teensy 3.6. 6 | // About 200 ns on Teensy 4.0 7 | #include "ChRt.h" 8 | 9 | // LED_BUILTIN pin on Arduino is usually pin 13. 10 | 11 | // Semaphore to trigger context switch 12 | SEMAPHORE_DECL(sem, 0); 13 | //------------------------------------------------------------------------------ 14 | // thread 1 - high priority thread to set pin low. 15 | // 64 byte stack beyond task switch and interrupt needs. 16 | static THD_WORKING_AREA(waThread1, 64); 17 | 18 | static THD_FUNCTION(Thread1, arg) { 19 | (void)arg; 20 | while (true) { 21 | chSemWait(&sem); 22 | digitalWrite(LED_BUILTIN, LOW); 23 | } 24 | } 25 | //------------------------------------------------------------------------------ 26 | // thread 2 - lower priority thread to toggle LED and trigger thread 1. 27 | // 64 byte stack beyond task switch and interrupt needs. 28 | static THD_WORKING_AREA(waThread2, 64); 29 | 30 | static THD_FUNCTION(Thread2, arg) { 31 | (void)arg; 32 | pinMode(LED_BUILTIN, OUTPUT); 33 | while (true) { 34 | // First pulse to get time with no context switch. 35 | digitalWrite(LED_BUILTIN, HIGH); 36 | digitalWrite(LED_BUILTIN, LOW); 37 | // Start second pulse. 38 | digitalWrite(LED_BUILTIN, HIGH); 39 | // Trigger context switch for task that ends pulse. 40 | chSemSignal(&sem); 41 | // Sleep until next tick. 42 | chThdSleep(1); 43 | } 44 | } 45 | //------------------------------------------------------------------------------ 46 | void chSetup() { 47 | // Start high priority thread. 48 | chThdCreateStatic(waThread1, sizeof(waThread1), 49 | NORMALPRIO + 2, Thread1, NULL); 50 | 51 | // Start lower priority thread. 52 | chThdCreateStatic(waThread2, sizeof(waThread2), 53 | NORMALPRIO+1, Thread2, NULL); 54 | } 55 | //------------------------------------------------------------------------------ 56 | void setup() { 57 | chBegin(&chSetup); 58 | // chBegin() resets stacks and should never return. 59 | while (true) {} 60 | } 61 | //------------------------------------------------------------------------------ 62 | void loop() { 63 | // Not used. 64 | } -------------------------------------------------------------------------------- /examples/chCoop/chCoop.ino: -------------------------------------------------------------------------------- 1 | // This example illustrates cooperative scheduling. Cooperative scheduling 2 | // simplifies multitasking since no preemptive context switches occur. 3 | // 4 | // You must call chYield() or other ChibiOS functions such as chThdSleep 5 | // to force a context switch to other threads. 6 | // 7 | // Insert a delay(100) in loop() to see the effect of not 8 | // using chThdSleep with cooperative scheduling. 9 | // 10 | // Setting CH_TIME_QUANTUM to zero disables the preemption for threads 11 | // with equal priority and the round robin becomes cooperative. 12 | // Note that higher priority threads can still preempt, the kernel 13 | // is always preemptive. 14 | // 15 | #include "ChRt.h" 16 | // LED_BUILTIN pin on Arduino is usually pin 13. 17 | 18 | volatile uint32_t count = 0; 19 | volatile uint32_t maxDelay = 0; 20 | //------------------------------------------------------------------------------ 21 | // thread 1 blink LED 22 | // 64 byte stack beyond task switch and interrupt needs. 23 | static THD_WORKING_AREA(waThread1, 64); 24 | 25 | static THD_FUNCTION(Thread1, arg) { 26 | (void)arg; 27 | pinMode(LED_BUILTIN, OUTPUT); 28 | while (true) { 29 | digitalWrite(LED_BUILTIN, HIGH); 30 | chThdSleepMilliseconds(50); 31 | digitalWrite(LED_BUILTIN, LOW); 32 | chThdSleepMilliseconds(150); 33 | } 34 | } 35 | //------------------------------------------------------------------------------ 36 | // thread 2 increment a counter and records max delay. 37 | // 64 byte stack beyond task switch and interrupt needs. 38 | static THD_WORKING_AREA(waThread2, 64); 39 | 40 | static THD_FUNCTION(Thread2, arg) { 41 | (void)arg; 42 | while (true) { 43 | count++; 44 | uint32_t t = micros(); 45 | // Yield so other threads can run. 46 | chThdYield(); 47 | t = micros() - t; 48 | if (t > maxDelay) maxDelay = t; 49 | } 50 | } 51 | //------------------------------------------------------------------------------ 52 | // Continue setup() after chBegin(). 53 | void chSetup() { 54 | if (CH_CFG_TIME_QUANTUM) { 55 | Serial.println("You must set CH_CFG_TIME_QUANTUM zero in"); 56 | #if defined(__arm__) 57 | Serial.print("src//chconfig.h"); 58 | #elif defined(__AVR__) 59 | Serial.print(F("src/avr/chconfig_avr.h")); 60 | #endif 61 | Serial.println(F(" to enable cooperative scheduling.")); 62 | while (true) {} 63 | } 64 | chThdCreateStatic(waThread1, sizeof(waThread1), 65 | NORMALPRIO, Thread1, NULL); 66 | 67 | chThdCreateStatic(waThread2, sizeof(waThread2), 68 | NORMALPRIO, Thread2, NULL); 69 | } 70 | //------------------------------------------------------------------------------ 71 | void setup() { 72 | Serial.begin(9600); 73 | // Wait for USB Serial. 74 | while (!Serial) {} 75 | 76 | // Start ChibiOS. 77 | chBegin(chSetup); 78 | // chBegin() resets stacks and should never return. 79 | while (true) {} 80 | } 81 | //------------------------------------------------------------------------------ 82 | void loop() { 83 | Serial.println("Count, MaxDelay micros"); 84 | while (true) { 85 | Serial.print(count); 86 | Serial.write(','); 87 | Serial.println(maxDelay); 88 | count = 0; 89 | maxDelay = 0; 90 | // Enable next line to see blocking of above threads. 91 | // delay(100); 92 | // Allow other threads to run for 1 sec. 93 | chThdSleepMilliseconds(1000); 94 | } 95 | } -------------------------------------------------------------------------------- /examples/chDataSharing/chDataSharing.ino: -------------------------------------------------------------------------------- 1 | // Simple demo using a mutex for data sharing. 2 | #include "ChRt.h" 3 | 4 | const uint8_t X_PIN = 0; 5 | const uint8_t Y_PIN = 1; 6 | const uint8_t Z_PIN = 2; 7 | 8 | //------------------------------------------------------------------------------ 9 | // Shared data, use volatile to insure correct access. 10 | 11 | // Mutex for atomic access to data. 12 | MUTEX_DECL(dataMutex); 13 | 14 | // Time data was read. 15 | volatile uint32_t dataT; 16 | 17 | // Data X value. 18 | volatile int dataX; 19 | 20 | // Data Y value. 21 | volatile int dataY; 22 | 23 | // Data Z value. 24 | volatile int dataZ; 25 | //------------------------------------------------------------------------------ 26 | // Thread 1, high priority to read sensor. 27 | // 64 byte stack beyond task switch and interrupt needs. 28 | static THD_WORKING_AREA(waThread1, 64); 29 | 30 | static THD_FUNCTION(Thread1, arg) { 31 | (void)arg; 32 | 33 | // Read data every 13 ms. 34 | // Use 13 ms so print interval is not a multiple of sensor interval. 35 | // Try 10 ms to see synchronous effect. 36 | 37 | while (true) { 38 | // Use 13 so 1000 is not a multiple of interval. 39 | chThdSleepMilliseconds(13); 40 | 41 | // Use temp variables to acquire data. 42 | uint32_t tmpT = millis(); 43 | int tmpX = analogRead(X_PIN); 44 | int tmpY = analogRead(Y_PIN); 45 | int tmpZ = analogRead(Z_PIN); 46 | 47 | // Lock access to data. 48 | chMtxLock(&dataMutex); 49 | 50 | // Copy tmp variables to shared data. 51 | dataT = tmpT; 52 | dataX = tmpX; 53 | dataY = tmpY; 54 | dataZ = tmpZ; 55 | 56 | // Unlock data access. 57 | chMtxUnlock(&dataMutex); 58 | } 59 | } 60 | //------------------------------------------------------------------------------ 61 | // thread 2 - print data every second. 62 | // 200 byte stack beyond task switch and interrupt needs. 63 | static THD_WORKING_AREA(waThread2, 200); 64 | 65 | static THD_FUNCTION(Thread2, arg) { 66 | (void)arg; 67 | 68 | // Print count every second. 69 | systime_t wakeTime = chVTGetSystemTime(); 70 | while (true) { 71 | // Sleep until next second. 72 | wakeTime += TIME_MS2I(1000); 73 | chThdSleepUntil(wakeTime); 74 | 75 | // Lock access to data. 76 | chMtxLock(&dataMutex); 77 | 78 | // Copy shared data to tmp variables. 79 | uint32_t tmpT = dataT; 80 | int tmpX = dataX; 81 | int tmpY = dataY; 82 | int tmpZ = dataZ; 83 | 84 | // Unlock data access. 85 | chMtxUnlock(&dataMutex); 86 | 87 | // Print shared data. 88 | Serial.print(F("dataAge: ")); 89 | Serial.print(millis() - tmpT); 90 | Serial.print(F(" ms, dataX: ")); 91 | Serial.print(tmpX); 92 | Serial.print(F(", dataY: ")); 93 | Serial.print(tmpY); 94 | Serial.print(F(", dataZ: ")); 95 | Serial.print(tmpZ); 96 | 97 | // Print unused stack for threads. 98 | Serial.print(F(", Unused Stack: ")); 99 | Serial.print(chUnusedThreadStack(waThread1, sizeof(waThread1))); 100 | Serial.print(' '); 101 | Serial.print(chUnusedThreadStack(waThread2, sizeof(waThread2))); 102 | Serial.print(' '); 103 | Serial.println(chUnusedMainStack()); 104 | } 105 | } 106 | //------------------------------------------------------------------------------ 107 | // 108 | void chSetup() { 109 | // Start analgRead() thread. 110 | chThdCreateStatic(waThread1, sizeof(waThread1), 111 | NORMALPRIO + 2, Thread1, NULL); 112 | 113 | // Start print thread. 114 | chThdCreateStatic(waThread2, sizeof(waThread2), 115 | NORMALPRIO + 1, Thread2, NULL); 116 | } 117 | //------------------------------------------------------------------------------ 118 | void setup() { 119 | Serial.begin(9600); 120 | // Wait for USB Serial. 121 | while (!Serial) {} 122 | 123 | chBegin(chSetup); 124 | // chBegin() resets stacks and should never return. 125 | while (true) {} 126 | } 127 | //------------------------------------------------------------------------------ 128 | void loop() { 129 | // Not used. 130 | } -------------------------------------------------------------------------------- /examples/chIsrSemaphore/chIsrSemaphore.ino: -------------------------------------------------------------------------------- 1 | // Example of how a handler task can be triggered from an ISR 2 | // by using a binary semaphore. 3 | #include 4 | 5 | // Pins to generate interrupts - these pins must be connected with a wire. 6 | const uint8_t INPUT_PIN = 2; 7 | const uint8_t OUTPUT_PIN = 3; 8 | 9 | // Initialize semaphore as taken. 10 | BSEMAPHORE_DECL(isrSem, true); 11 | 12 | // ISR entry time 13 | volatile uint32_t tIsr = 0; 14 | //------------------------------------------------------------------------------ 15 | // Fake ISR, normally 16 | // void isrFcn() { 17 | // would be replaced by something like 18 | // CH_IRQ_HANDLER(INT0_vect) { 19 | // 20 | void isrFcn() { 21 | 22 | // On ARM CH_IRQ_PROLOGUE is void. 23 | CH_IRQ_PROLOGUE(); 24 | // IRQ handling code, preemptable if the architecture supports it. 25 | 26 | // Only ISR processing is to save time. 27 | tIsr = micros(); 28 | 29 | chSysLockFromISR(); 30 | // Invocation of some I-Class system APIs, never preemptable. 31 | 32 | // Signal handler task. 33 | chBSemSignalI(&isrSem); 34 | chSysUnlockFromISR(); 35 | 36 | // More IRQ handling code, again preemptable. 37 | 38 | // Perform rescheduling if required. 39 | CH_IRQ_EPILOGUE(); 40 | } 41 | //------------------------------------------------------------------------------ 42 | // Handler task for interrupt. 43 | static THD_WORKING_AREA(waThd1, 200); 44 | 45 | static THD_FUNCTION(handler, arg) { 46 | (void)arg; 47 | while (true) { 48 | // wait for event 49 | chBSemWait(&isrSem); 50 | 51 | // print elapsed time 52 | uint32_t t = micros(); 53 | Serial.print("Handler: "); 54 | Serial.println(t - tIsr); 55 | } 56 | } 57 | //------------------------------------------------------------------------------ 58 | void setup() { 59 | Serial.begin(9600); 60 | // Wait for USB Serial. 61 | while (!Serial) {} 62 | 63 | chBegin(mainThread); 64 | // chBegin() resets stacks and should never return. 65 | while (true) {} 66 | } 67 | //------------------------------------------------------------------------------ 68 | void mainThread() { 69 | // Setup and check pins. 70 | pinMode(INPUT_PIN, INPUT_PULLUP); 71 | pinMode(OUTPUT_PIN, OUTPUT); 72 | 73 | for (int i = 0; i < 10; i++) { 74 | bool level = i & 1; 75 | digitalWrite(OUTPUT_PIN, level); 76 | if (level != digitalRead(INPUT_PIN)) { 77 | Serial.print("pin "); 78 | Serial.print(INPUT_PIN); 79 | Serial.print(" must be connected to pin "); 80 | Serial.println(OUTPUT_PIN); 81 | while (true) {} 82 | } 83 | } 84 | // Start handler task. 85 | chThdCreateStatic(waThd1, sizeof(waThd1), NORMALPRIO + 1, handler, NULL); 86 | 87 | // Attach interrupt function. 88 | attachInterrupt(digitalPinToInterrupt(INPUT_PIN), isrFcn, RISING); 89 | while (true) { 90 | // Cause an interrupt - normally done by external event. 91 | Serial.println("High"); 92 | digitalWrite(OUTPUT_PIN, HIGH); 93 | Serial.println("Low"); 94 | digitalWrite(OUTPUT_PIN, LOW); 95 | Serial.println(); 96 | chThdSleepMilliseconds(1000); 97 | } 98 | } 99 | //------------------------------------------------------------------------------ 100 | void loop() { 101 | // Not used. 102 | } -------------------------------------------------------------------------------- /examples/chJitter/chJitter.ino: -------------------------------------------------------------------------------- 1 | // Test of jitter in sleep for one tick. 2 | // 3 | // Idle main thread prints min and max time between sleep calls. 4 | // 5 | // Note: access to shared variables tmin and tmax is not atomic 6 | // so glitches are possible if context switch happens during main loop 7 | // access to these variables. 8 | // 9 | #include "ChRt.h" 10 | 11 | volatile uint16_t tmax = 0; 12 | volatile uint16_t tmin = 0XFFFF; 13 | //------------------------------------------------------------------------------ 14 | // Thread for sleep interval. 15 | static THD_WORKING_AREA(waThread1, 64); 16 | 17 | static THD_FUNCTION(Thread1, arg) { 18 | (void)arg; 19 | // Initialize tlast. 20 | chThdSleep(1); 21 | uint32_t tlast = micros(); 22 | 23 | while (true) { 24 | 25 | // Sleep until next tick. 26 | chThdSleep(1); 27 | 28 | // Get wake time. 29 | uint32_t tmp = micros(); 30 | 31 | // Calculate min and max interval between wake times. 32 | uint16_t diff = tmp - tlast; 33 | if (diff < tmin) tmin = diff; 34 | if (diff > tmax) tmax = diff; 35 | tlast = tmp; 36 | } 37 | } 38 | //------------------------------------------------------------------------------ 39 | void chStatup() { 40 | // Start higher priority thread. 41 | chThdCreateStatic(waThread1, sizeof(waThread1), 42 | NORMALPRIO + 1, Thread1, NULL); 43 | } 44 | //------------------------------------------------------------------------------ 45 | void setup() { 46 | Serial.begin(9600); 47 | // Wait for USB Serial. 48 | while (!Serial) {} 49 | 50 | // Start ChibiOS. 51 | chBegin(chStatup); 52 | // chBegin() resets stacks and should never return. 53 | while (true) {} 54 | } 55 | //------------------------------------------------------------------------------ 56 | void loop() { 57 | int np = 10; 58 | 59 | while (true) { 60 | chThdSleepMilliseconds(1000); 61 | Serial.print(tmin); 62 | Serial.write(','); 63 | Serial.println(tmax); 64 | if (np++ == 10) { 65 | np = 0; 66 | tmin = 0XFFFF; 67 | tmax = 0; 68 | Serial.println("clear"); 69 | } 70 | } 71 | } -------------------------------------------------------------------------------- /examples/chMailbox/chMailbox.ino: -------------------------------------------------------------------------------- 1 | // Example use of mailboxes. Use mailbox to return free slots. 2 | #include "ChRt.h" 3 | 4 | #define NUM_BUFFERS 4 5 | #define BUFFERS_SIZE 32 6 | 7 | static char buffers[NUM_BUFFERS][BUFFERS_SIZE]; 8 | 9 | // Slots for free buffer pointers. 10 | static msg_t free_buffers_queue[NUM_BUFFERS]; 11 | // Free queue mailbox structure. 12 | MAILBOX_DECL(free_buffers, &free_buffers_queue, NUM_BUFFERS); 13 | 14 | // Slots for filled buffer pointers. 15 | static msg_t filled_buffers_queue[NUM_BUFFERS]; 16 | // Filled queue mailbox structure. 17 | MAILBOX_DECL(filled_buffers, &filled_buffers_queue, NUM_BUFFERS); 18 | //------------------------------------------------------------------------------ 19 | // Declare a stack with 300 bytes beyond context switch and interrupt needs. 20 | THD_WORKING_AREA(waThread1, 300); 21 | 22 | // Declare the thread function for thread 1. 23 | THD_FUNCTION(Thread1, arg) { 24 | (void)arg; 25 | int n = 0; 26 | while (true) { 27 | void *pbuf = nullptr; 28 | 29 | // Waiting for a free buffer. 30 | msg_t msg = chMBFetchTimeout(&free_buffers, (msg_t *)&pbuf, TIME_INFINITE); 31 | if (msg != MSG_OK) { 32 | Serial.println("fetch free failed"); 33 | chThdSleep(TIME_INFINITE); 34 | } 35 | sprintf((char*)pbuf, "message %d", n++); 36 | (void)chMBPostTimeout(&filled_buffers, (msg_t)pbuf, TIME_INFINITE); 37 | chThdSleepMilliseconds(1000); 38 | } 39 | } 40 | //------------------------------------------------------------------------------ 41 | // Declare a stack with 200 bytes beyond context switch and interrupt needs. 42 | THD_WORKING_AREA(waThread2, 200); 43 | 44 | // Declare the thread function for thread 2. 45 | THD_FUNCTION(Thread2, arg) { 46 | (void)arg; 47 | while (true) { 48 | void *pbuf = nullptr; 49 | // Waiting for a filled buffer. 50 | msg_t msg = chMBFetchTimeout(&filled_buffers, (msg_t *)&pbuf, TIME_INFINITE); 51 | if (msg != MSG_OK) { 52 | Serial.println("fetch filled failed"); 53 | chThdSleep(TIME_INFINITE); 54 | } 55 | Serial.println((char*)pbuf); 56 | 57 | (void)chMBPostTimeout(&free_buffers, (msg_t)pbuf, TIME_INFINITE); 58 | } 59 | } 60 | //------------------------------------------------------------------------------ 61 | // Continue setup() after chBegin(). 62 | void chSetup() { 63 | 64 | //Put all buffers in free queue. 65 | for (int i = 0; i < NUM_BUFFERS; i++) { 66 | (void)chMBPostTimeout(&free_buffers, (msg_t)&buffers[i], TIME_INFINITE); 67 | } 68 | 69 | chThdCreateStatic(waThread1, sizeof(waThread1), 70 | NORMALPRIO + 1, Thread1, NULL); 71 | 72 | chThdCreateStatic(waThread2, sizeof(waThread2), 73 | NORMALPRIO + 1, Thread2, NULL); 74 | } 75 | //------------------------------------------------------------------------------ 76 | void setup() { 77 | Serial.begin(9600); 78 | // Wait for USB Serial. 79 | while (!Serial) {} 80 | 81 | chBegin(chSetup); 82 | // chBegin() resets stacks and should never return. 83 | while (true) {} 84 | } 85 | void loop() { 86 | } -------------------------------------------------------------------------------- /examples/chMemPool/chMemPool.ino: -------------------------------------------------------------------------------- 1 | // Example of memory pool and mailboxes with two senders and one receiver. 2 | #include "ChRt.h" 3 | //------------------------------------------------------------------------------ 4 | // Mailbox/memory pool object count. 5 | const size_t MB_COUNT = 6; 6 | 7 | // Type for a memory pool object. 8 | struct PoolObject_t { 9 | char* name; 10 | int msg; 11 | }; 12 | // Array of memory pool objects. 13 | PoolObject_t PoolObject[MB_COUNT]; 14 | 15 | // Memory pool structure. 16 | MEMORYPOOL_DECL(memPool, sizeof(PoolObject_t),PORT_NATURAL_ALIGN, NULL); 17 | //------------------------------------------------------------------------------ 18 | // Slots for mailbox messages. Will hold pointers to pool objects. 19 | msg_t letter[MB_COUNT]; 20 | 21 | // Mailbox queue structure. 22 | MAILBOX_DECL(mail, &letter, MB_COUNT); 23 | //------------------------------------------------------------------------------ 24 | // Data structures and stack for thread 2. 25 | static THD_WORKING_AREA(waTh2, 200); 26 | 27 | // Data structures and stack for thread 3. 28 | static THD_WORKING_AREA(waTh3, 200); 29 | //------------------------------------------------------------------------------ 30 | // Send message every 1000 ms. 31 | static THD_FUNCTION(thdFcn, name) { 32 | int msg = 0; 33 | 34 | while (true) { 35 | 36 | // Get object from memory pool. 37 | PoolObject_t* p = (PoolObject_t*)chPoolAlloc(&memPool); 38 | if (!p) { 39 | Serial.println("chPoolAlloc failed"); 40 | while (true); 41 | } 42 | // Form message. 43 | p->name = (char*)name; 44 | p->msg = msg++; 45 | 46 | // Send message. 47 | msg_t s = chMBPostTimeout(&mail, (msg_t)p, TIME_IMMEDIATE); 48 | if (s != MSG_OK) { 49 | Serial.println("chMBPost failed"); 50 | while (true); 51 | } 52 | chThdSleepMilliseconds(1000); 53 | } 54 | } 55 | //------------------------------------------------------------------------------ 56 | void chSetup() { 57 | // Fill pool with PoolObject array. 58 | chPoolLoadArray(&memPool, PoolObject, MB_COUNT); 59 | 60 | // Schedule thread 2. 61 | chThdCreateStatic(waTh2, sizeof(waTh2), NORMALPRIO, thdFcn, (void*)"Th 2"); 62 | 63 | // Schedule thread 3. 64 | chThdCreateStatic(waTh3, sizeof(waTh2), NORMALPRIO, thdFcn, (void*)"Th 3"); 65 | } 66 | //------------------------------------------------------------------------------ 67 | void setup() { 68 | Serial.begin(9600); 69 | // Wait for USB Serial. 70 | while (!Serial) {} 71 | 72 | chBegin(chSetup); 73 | // chBegin() resets stacks and should never return. 74 | while (true) {} 75 | } 76 | //------------------------------------------------------------------------------ 77 | // loop() is receiver thread. 78 | void loop() { 79 | PoolObject_t *p = 0;; 80 | 81 | // Get mail. 82 | chMBFetchTimeout(&mail, (msg_t*)&p, TIME_INFINITE); 83 | 84 | Serial.print(p->name); 85 | Serial.write(' '); 86 | Serial.println(p->msg); 87 | 88 | // Put memory back into pool. 89 | chPoolFree(&memPool, p); 90 | } -------------------------------------------------------------------------------- /examples/chMutex/chMutex.ino: -------------------------------------------------------------------------------- 1 | // Example of mutex to prevent print calls from being scrambled. 2 | #include "ChRt.h" 3 | 4 | // Set USE_MUTEX to zero for scrambled print. 5 | #define USE_MUTEX 1 6 | 7 | // Declare and initialize a mutex for limiting access to threads. 8 | MUTEX_DECL(demoMutex); 9 | 10 | // Data structures and stack for thread 2. 11 | static THD_WORKING_AREA(waTh2, 200); 12 | 13 | // Data structures and stack for thread 3. 14 | static THD_WORKING_AREA(waTh3, 200); 15 | //------------------------------------------------------------------------------ 16 | void notify(const char* name, int state) { 17 | 18 | #if USE_MUTEX 19 | // Wait to enter print region. 20 | chMtxLock(&demoMutex); 21 | #endif // USE_MUTEX 22 | 23 | // Only one thread in this region while doing prints. 24 | Serial.print(name); 25 | chThdSleep(100); 26 | Serial.write(": "); 27 | Serial.println(state); 28 | 29 | #if USE_MUTEX 30 | // Exit protected region. 31 | chMtxUnlock(&demoMutex); 32 | #endif // USE_MUTEX 33 | } 34 | //------------------------------------------------------------------------------ 35 | static THD_FUNCTION(thdFcn, arg) { 36 | while (true) { 37 | notify((const char*)arg, 0); 38 | chThdSleepMilliseconds(1000); 39 | notify((const char*)arg, 1); 40 | chThdSleepMilliseconds(1000); 41 | } 42 | } 43 | //------------------------------------------------------------------------------ 44 | void chStartup() { 45 | // Schedule thread 2. 46 | chThdCreateStatic(waTh2, sizeof(waTh2), NORMALPRIO, thdFcn, (void*)"Th 2"); 47 | 48 | // Schedule thread 3. 49 | chThdCreateStatic(waTh3, sizeof(waTh3), NORMALPRIO, thdFcn, (void*)"Th 3"); 50 | 51 | // Main thread is thread 1 at NORMALPRIO. 52 | thdFcn((void*)"Th 1"); 53 | } 54 | //------------------------------------------------------------------------------ 55 | void setup() { 56 | Serial.begin(9600); 57 | // Wait for USB Serial. 58 | while (!Serial) {} 59 | 60 | // Initialize and start ChibiOS. 61 | chBegin(chStartup); 62 | // chBegin() resets stacks and should never return. 63 | while (true) {} 64 | } 65 | //------------------------------------------------------------------------------ 66 | void loop() {/* Not used. */} -------------------------------------------------------------------------------- /examples/chRoundRobin/chRoundRobin.ino: -------------------------------------------------------------------------------- 1 | // Demo runing two threads round-robin. 2 | // 3 | // Warning, this example uses wait loops to illustrate round-robin. 4 | // Use chThdSleep in normal applications. 5 | // 6 | // Both threads use wait loops. Each thread will execute 7 | // for one quantum then be preempted. 8 | // 9 | // Run with the blink thread at NORMALPRIO + 1 and NORMALPRIO - 1 to 10 | // See blockage due to use of wait loops. 11 | // 12 | #include "ChRt.h" 13 | //------------------------------------------------------------------------------ 14 | // 32 byte stack beyond task switch and interrupt needs. 15 | static THD_WORKING_AREA(waBlink, 64); 16 | 17 | static THD_FUNCTION(blink, arg) { 18 | (void)arg; 19 | // blink twice per second 20 | pinMode(LED_BUILTIN, OUTPUT); 21 | uint32_t next = millis(); 22 | while (true) { 23 | digitalWrite(LED_BUILTIN, HIGH); 24 | next += 100; 25 | while ((int32_t)(millis() - next) < 0) {} 26 | digitalWrite(LED_BUILTIN, LOW); 27 | next += 400; 28 | while ((int32_t)(millis() - next) < 0) {} 29 | } 30 | } 31 | //------------------------------------------------------------------------------ 32 | void chStartup() { 33 | if (CH_CFG_TIME_QUANTUM == 0) { 34 | Serial.println("CH_CFG_TIME_QUANTUM must be nonzero for round-robin."); 35 | while (true) {} 36 | } 37 | // Start blink thread. 38 | chThdCreateStatic(waBlink, sizeof(waBlink), NORMALPRIO, blink, NULL); 39 | } 40 | //------------------------------------------------------------------------------ 41 | void setup() { 42 | Serial.begin(9600); 43 | // Wait for USB Serial. 44 | while (!Serial) {} 45 | 46 | // Initialize and start ChibiOS. 47 | chBegin(chStartup); 48 | // chBegin() resets stacks and should never return. 49 | while (true) {} 50 | } 51 | //------------------------------------------------------------------------------ 52 | void loop() { 53 | uint32_t next = 0; 54 | while (true) { 55 | next += 1000; 56 | while ((int32_t)(millis() - next) < 0) {} 57 | Serial.println(millis()); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /examples/chSemaphore/chSemaphore.ino: -------------------------------------------------------------------------------- 1 | // Example of counting semaphore. 2 | // Note, one thread may get an unfair share time in the critical section. 3 | #include "ChRt.h" 4 | 5 | // Declare and initialize a semaphore for limiting access. 6 | // 7 | // Initialize semSlots to one slot to see sequential behavior. 8 | SEMAPHORE_DECL(semSlots, 2); 9 | 10 | // Data structures and stack for thread 2. 11 | static THD_WORKING_AREA(waTh2, 200); 12 | 13 | // Data structures and stack for thread 3. 14 | static THD_WORKING_AREA(waTh3, 200); 15 | //------------------------------------------------------------------------------ 16 | static THD_FUNCTION(thdFcn, name) { 17 | while (true) { 18 | 19 | // Wait for slot. 20 | chSemWait(&semSlots); 21 | 22 | // Only two threads can be in this region at a time. 23 | Serial.println((char*)name); 24 | 25 | chThdSleepMilliseconds(1000); 26 | 27 | // Exit region. 28 | chSemSignal(&semSlots); 29 | } 30 | } 31 | //------------------------------------------------------------------------------ 32 | void chStartup() { 33 | // Schedule thread 2. 34 | chThdCreateStatic(waTh2, sizeof(waTh2), NORMALPRIO, thdFcn, (void*)"Th 2"); 35 | 36 | // Schedule thread 3. 37 | chThdCreateStatic(waTh3, sizeof(waTh3), NORMALPRIO, thdFcn, (void*)"Th 3"); 38 | 39 | // Main thread is thread 1 at NORMALPRIO. 40 | thdFcn((void*)"Th 1"); 41 | } 42 | //------------------------------------------------------------------------------ 43 | void setup() { 44 | Serial.begin(9600); 45 | // Wait for USB Serial. 46 | while (!Serial) {} 47 | 48 | // Initialize and start ChibiOS. 49 | chBegin(chStartup); 50 | // chBegin() resets stacks and should never return. 51 | while (true) {} 52 | } 53 | //------------------------------------------------------------------------------ 54 | void loop() {/* not used */} 55 | -------------------------------------------------------------------------------- /extra/src_org/CMSIS/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.4 5 | * @date 23. July 2019 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 4U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /extra/src_org/CMSIS/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /extra/src_org/arm/chtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file ARMCMx/compilers/GCC/chtypes.h 22 | * @brief ARM Cortex-Mx port system types. 23 | * 24 | * @addtogroup ARMCMx_GCC_CORE 25 | * @{ 26 | */ 27 | 28 | #ifndef CHTYPES_H 29 | #define CHTYPES_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** 36 | * @name Kernel types 37 | * @{ 38 | */ 39 | typedef uint32_t rtcnt_t; /**< Realtime counter. */ 40 | typedef uint64_t rttime_t; /**< Realtime accumulator. */ 41 | typedef uint32_t syssts_t; /**< System status word. */ 42 | typedef uint8_t tmode_t; /**< Thread flags. */ 43 | typedef uint8_t tstate_t; /**< Thread state. */ 44 | typedef uint8_t trefs_t; /**< Thread references counter. */ 45 | typedef uint8_t tslices_t; /**< Thread time slices counter.*/ 46 | typedef uint32_t tprio_t; /**< Thread priority. */ 47 | typedef int32_t msg_t; /**< Inter-thread message. */ 48 | typedef int32_t eventid_t; /**< Numeric event identifier. */ 49 | typedef uint32_t eventmask_t; /**< Mask of event identifiers. */ 50 | typedef uint32_t eventflags_t; /**< Mask of event flags. */ 51 | typedef int32_t cnt_t; /**< Generic signed counter. */ 52 | typedef uint32_t ucnt_t; /**< Generic unsigned counter. */ 53 | /** @} */ 54 | 55 | /** 56 | * @brief ROM constant modifier. 57 | * @note It is set to use the "const" keyword in this port. 58 | */ 59 | #define ROMCONST const 60 | 61 | /** 62 | * @brief Makes functions not inlineable. 63 | * @note If the compiler does not support such attribute then some 64 | * time-dependent services could be degraded. 65 | */ 66 | #define NOINLINE __attribute__((noinline)) 67 | 68 | /** 69 | * @brief Optimized thread function declaration macro. 70 | */ 71 | #define PORT_THD_FUNCTION(tname, arg) void tname(void *arg) 72 | 73 | /** 74 | * @brief Packed variable specifier. 75 | */ 76 | #define PACKED_VAR __attribute__((packed)) 77 | 78 | /** 79 | * @brief Memory alignment enforcement for variables. 80 | */ 81 | #define ALIGNED_VAR(n) __attribute__((aligned(n))) 82 | 83 | /** 84 | * @brief Size of a pointer. 85 | * @note To be used where the sizeof operator cannot be used, preprocessor 86 | * expressions for example. 87 | */ 88 | #define SIZEOF_PTR 4 89 | 90 | /** 91 | * @brief True if alignment is low-high in current architecture. 92 | */ 93 | #define REVERSE_ORDER 1 94 | 95 | #endif /* CHTYPES_H */ 96 | 97 | /** @} */ 98 | -------------------------------------------------------------------------------- /extra/src_org/avr/chcore_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file AVR/chcore_timer.h 22 | * @brief System timer header file. 23 | * 24 | * @addtogroup AVR_TIMER 25 | * @{ 26 | */ 27 | 28 | #ifndef CHCORE_TIMER_H 29 | #define CHCORE_TIMER_H 30 | 31 | /*===========================================================================*/ 32 | /* Module constants. */ 33 | /*===========================================================================*/ 34 | 35 | /*===========================================================================*/ 36 | /* Module pre-compile time settings. */ 37 | /*===========================================================================*/ 38 | 39 | /*===========================================================================*/ 40 | /* Derived constants and error checks. */ 41 | /*===========================================================================*/ 42 | 43 | /*===========================================================================*/ 44 | /* Module data structures and types. */ 45 | /*===========================================================================*/ 46 | 47 | /*===========================================================================*/ 48 | /* Module macros. */ 49 | /*===========================================================================*/ 50 | 51 | /*===========================================================================*/ 52 | /* External declarations. */ 53 | /*===========================================================================*/ 54 | 55 | /*===========================================================================*/ 56 | /* Module inline functions. */ 57 | /*===========================================================================*/ 58 | 59 | /** 60 | * @brief Starts the alarm. 61 | * @note Makes sure that no spurious alarms are triggered after 62 | * this call. 63 | * 64 | * @param[in] time the time to be set for the first alarm 65 | * 66 | * @notapi 67 | */ 68 | static inline void port_timer_start_alarm(systime_t time) { 69 | void stStartAlarm(systime_t time); 70 | 71 | stStartAlarm(time); 72 | } 73 | 74 | /** 75 | * @brief Stops the alarm interrupt. 76 | * 77 | * @notapi 78 | */ 79 | static inline void port_timer_stop_alarm(void) { 80 | void stStopAlarm(void); 81 | 82 | stStopAlarm(); 83 | } 84 | 85 | /** 86 | * @brief Sets the alarm time. 87 | * 88 | * @param[in] time the time to be set for the next alarm 89 | * 90 | * @notapi 91 | */ 92 | static inline void port_timer_set_alarm(systime_t time) { 93 | void stSetAlarm(systime_t time); 94 | 95 | stSetAlarm(time); 96 | } 97 | 98 | /** 99 | * @brief Returns the system time. 100 | * 101 | * @return The system time. 102 | * 103 | * @notapi 104 | */ 105 | static inline systime_t port_timer_get_time(void) { 106 | systime_t stGetCounter(void); 107 | 108 | return stGetCounter(); 109 | } 110 | 111 | /** 112 | * @brief Returns the current alarm time. 113 | * 114 | * @return The currently set alarm time. 115 | * 116 | * @notapi 117 | */ 118 | static inline systime_t port_timer_get_alarm(void) { 119 | systime_t stGetAlarm(void); 120 | 121 | return stGetAlarm(); 122 | } 123 | 124 | #endif /* CHCORE_TIMER_H */ 125 | 126 | /** @} */ 127 | -------------------------------------------------------------------------------- /extra/src_org/avr/chtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file AVR/compilers/GCC/chtypes.h 22 | * @brief AVR architecture port system types. 23 | * 24 | * @addtogroup AVR_CORE 25 | * @{ 26 | */ 27 | 28 | #ifndef CHTYPES_H 29 | #define CHTYPES_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** 36 | * @name Kernel types 37 | * @{ 38 | */ 39 | typedef uint32_t rtcnt_t; /**< Realtime counter. */ 40 | typedef uint64_t rttime_t; /**< Realtime accumulator. */ 41 | typedef uint8_t syssts_t; /**< System status word. */ 42 | typedef uint8_t tmode_t; /**< Thread flags. */ 43 | typedef uint8_t tstate_t; /**< Thread state. */ 44 | typedef uint8_t trefs_t; /**< Thread references counter. */ 45 | typedef uint8_t tslices_t; /**< Thread time slices counter.*/ 46 | typedef uint8_t tprio_t; /**< Thread priority. */ 47 | typedef int16_t msg_t; /**< Inter-thread message. */ 48 | typedef int32_t eventid_t; /**< Numeric event identifier. */ 49 | typedef uint8_t eventmask_t; /**< Mask of event identifiers. */ 50 | typedef uint8_t eventflags_t; /**< Mask of event flags. */ 51 | typedef int8_t cnt_t; /**< Generic signed counter. */ 52 | typedef uint8_t ucnt_t; /**< Generic unsigned counter. */ 53 | typedef bool bool_t; /**< Fast boolean type. */ 54 | /** @} */ 55 | 56 | /** 57 | * @brief ROM constant modifier. 58 | * @note It is set to use the "const" keyword in this port. 59 | */ 60 | #define ROMCONST const 61 | 62 | /** 63 | * @brief Makes functions not inlineable. 64 | * @note If the compiler does not support such attribute then the 65 | * realtime counter precision could be degraded. 66 | */ 67 | #define NOINLINE __attribute__((noinline)) 68 | 69 | /** 70 | * @brief Optimized thread function declaration macro. 71 | */ 72 | #define PORT_THD_FUNCTION(tname, arg) void tname(void *arg) 73 | 74 | /** 75 | * @brief Packed variable specifier. 76 | */ 77 | #define PACKED_VAR __attribute__((packed)) 78 | 79 | /** 80 | * @brief Memory alignment enforcement for variables. 81 | */ 82 | #define ALIGNED_VAR(n) __attribute__((aligned(n))) 83 | 84 | /** 85 | * @brief Size of a pointer. 86 | * @note To be used where the sizeof operator cannot be used, preprocessor 87 | * expressions for example. 88 | */ 89 | #define SIZEOF_PTR 2 90 | 91 | /** 92 | * @brief True if alignment is low-high in current architecture. 93 | */ 94 | #define REVERSE_ORDER 1 95 | 96 | #endif /* CHTYPES_H */ 97 | 98 | /** @} */ 99 | -------------------------------------------------------------------------------- /extra/src_org/hal/hal_st.h: -------------------------------------------------------------------------------- 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 hal_st.h 19 | * @brief ST Driver macros and structures. 20 | * @details This header is designed to be include-able without having to 21 | * include other files from the HAL. 22 | * 23 | * @addtogroup ST 24 | * @{ 25 | */ 26 | 27 | #ifndef HAL_ST_H 28 | #define HAL_ST_H 29 | 30 | #include "hal_st_lld.h" 31 | 32 | /*===========================================================================*/ 33 | /* Driver constants. */ 34 | /*===========================================================================*/ 35 | 36 | /*===========================================================================*/ 37 | /* Driver pre-compile time settings. */ 38 | /*===========================================================================*/ 39 | 40 | /*===========================================================================*/ 41 | /* Derived constants and error checks. */ 42 | /*===========================================================================*/ 43 | 44 | /* Compatibility with old LLDS.*/ 45 | #if !defined(ST_LLD_NUM_ALARMS) 46 | #define ST_LLD_NUM_ALARMS 1 47 | #endif 48 | 49 | /*===========================================================================*/ 50 | /* Driver data structures and types. */ 51 | /*===========================================================================*/ 52 | 53 | typedef void (*st_callback_t)(unsigned alarm); 54 | 55 | /*===========================================================================*/ 56 | /* Driver macros. */ 57 | /*===========================================================================*/ 58 | 59 | /*===========================================================================*/ 60 | /* External declarations. */ 61 | /*===========================================================================*/ 62 | 63 | #if (ST_LLD_NUM_ALARMS > 1) && !defined(__DOXYGEN__) 64 | extern st_callback_t st_callbacks[ST_LLD_NUM_ALARMS - 1]; 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | extern "C" { 69 | #endif 70 | void stInit(void); 71 | void stStartAlarm(systime_t abstime); 72 | void stStopAlarm(void); 73 | void stSetAlarm(systime_t abstime); 74 | systime_t stGetAlarm(void); 75 | systime_t stGetCounter(void); 76 | bool stIsAlarmActive(void); 77 | #if ST_LLD_NUM_ALARMS > 1 78 | bool stIsAlarmActiveN(unsigned alarm); 79 | void stStartAlarmN(unsigned alarm, systime_t abstime, st_callback_t cb); 80 | void stStopAlarmN(unsigned alarm); 81 | void stSetAlarmN(unsigned alarm, systime_t abstime); 82 | systime_t stGetAlarmN(unsigned alarm); 83 | #endif 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* HAL_ST_H */ 89 | 90 | /** @} */ 91 | -------------------------------------------------------------------------------- /extra/src_org/license/chversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chversion.h 22 | * @brief Version Module macros and structures. 23 | * 24 | * @addtogroup chibios_version 25 | * @details This module contains information about the ChibiOS release, it 26 | * is common to all subsystems. 27 | * @{ 28 | */ 29 | 30 | #ifndef CHVERSION_H 31 | #define CHVERSION_H 32 | 33 | /*===========================================================================*/ 34 | /* Module constants. */ 35 | /*===========================================================================*/ 36 | 37 | /** 38 | * @brief ChibiOS product identification macro. 39 | */ 40 | #define _CHIBIOS_ 41 | 42 | /** 43 | * @brief Stable release flag. 44 | */ 45 | #define CH_VERSION_STABLE 1 46 | 47 | /** 48 | * @name ChibiOS version identification 49 | * @{ 50 | */ 51 | /** 52 | * @brief ChibiOS version string. 53 | */ 54 | #define CH_VERSION "20.3.3" 55 | 56 | /** 57 | * @brief ChibiOS version release year. 58 | */ 59 | #define CH_VERSION_YEAR 20 60 | 61 | /** 62 | * @brief ChibiOS version release month. 63 | */ 64 | #define CH_VERSION_MONTH 3 65 | 66 | /** 67 | * @brief ChibiOS version patch number. 68 | */ 69 | #define CH_VERSION_PATCH 3 70 | 71 | /** 72 | * @brief ChibiOS version nickname. 73 | */ 74 | #define CH_VERSION_NICKNAME "Dragonea" 75 | /** @} */ 76 | 77 | /*===========================================================================*/ 78 | /* Module pre-compile time settings. */ 79 | /*===========================================================================*/ 80 | 81 | /*===========================================================================*/ 82 | /* Derived constants and error checks. */ 83 | /*===========================================================================*/ 84 | 85 | /*===========================================================================*/ 86 | /* Module data structures and types. */ 87 | /*===========================================================================*/ 88 | 89 | /*===========================================================================*/ 90 | /* Module macros. */ 91 | /*===========================================================================*/ 92 | 93 | /*===========================================================================*/ 94 | /* External declarations. */ 95 | /*===========================================================================*/ 96 | 97 | /*===========================================================================*/ 98 | /* Module inline functions. */ 99 | /*===========================================================================*/ 100 | 101 | #endif /* CHVERSION_H */ 102 | 103 | /** @} */ 104 | -------------------------------------------------------------------------------- /extra/src_org/license/license.dox: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @defgroup licensing Release and Licensing 22 | */ 23 | 24 | /** 25 | * @defgroup chibios_version Release Information 26 | * @ingroup licensing 27 | */ 28 | 29 | /** 30 | * @defgroup chibios_customer Customer Information 31 | * @ingroup licensing 32 | */ 33 | 34 | /** 35 | * @defgroup chibios_license License Settings 36 | * @ingroup licensing 37 | */ 38 | -------------------------------------------------------------------------------- /extra/src_org/license/license.mk: -------------------------------------------------------------------------------- 1 | # List of all the licensing subsystem files. 2 | LICSRC := 3 | 4 | # Required include directories 5 | LICINC := $(CHIBIOS)/os/license 6 | 7 | # Shared variables 8 | ALLCSRC += $(LICSRC) 9 | ALLINC += $(LICINC) 10 | -------------------------------------------------------------------------------- /extra/src_org/oslib/dox/lib.dox: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * @defgroup oslib OS Library 21 | * @details The OS Library is a set of RTOS extensions compatible with both 22 | * the RT and NIL RTOSes. 23 | */ 24 | 25 | /** 26 | * @defgroup oslib_info Version Numbers and Identification 27 | * @ingroup oslib 28 | */ 29 | 30 | /** 31 | * @defgroup oslib_synchronization Synchronization 32 | * @details Synchronization services. 33 | * @ingroup oslib 34 | */ 35 | 36 | /** 37 | * @defgroup oslib_binary_semaphores Binary Semaphores 38 | * @ingroup oslib_synchronization 39 | */ 40 | 41 | /** 42 | * @defgroup oslib_mailboxes Mailboxes 43 | * @ingroup oslib_synchronization 44 | */ 45 | 46 | /** 47 | * @defgroup oslib_pipes Pipes 48 | * @ingroup oslib_synchronization 49 | */ 50 | 51 | /** 52 | * @defgroup oslib_delegates Delegate Threads 53 | * @ingroup oslib_synchronization 54 | */ 55 | 56 | /** 57 | * @defgroup oslib_jobs_queues Jobs Queues 58 | * @ingroup oslib_synchronization 59 | */ 60 | 61 | /** 62 | * @defgroup oslib_memory Memory Management 63 | * @details Memory Management services. 64 | * @ingroup oslib 65 | */ 66 | 67 | /** 68 | * @defgroup oslib_memcore Core Memory Manager 69 | * @ingroup oslib_memory 70 | */ 71 | 72 | /** 73 | * @defgroup oslib_memheaps Memory Heaps 74 | * @ingroup oslib_memory 75 | */ 76 | 77 | /** 78 | * @defgroup oslib_mempools Memory Pools 79 | * @ingroup oslib_memory 80 | */ 81 | 82 | /** 83 | * @defgroup oslib_complex Complex Services 84 | * @ingroup oslib 85 | */ 86 | 87 | /** 88 | * @defgroup oslib_objects_fifos Objects FIFOs 89 | * @ingroup oslib_complex 90 | */ 91 | 92 | /** 93 | * @defgroup oslib_objchaches Objects Caches 94 | * @ingroup oslib_complex 95 | */ 96 | 97 | /** 98 | * @defgroup oslib_objects_factory Dynamic Objects Factory 99 | * @ingroup oslib_complex 100 | */ 101 | -------------------------------------------------------------------------------- /extra/src_org/oslib/oslib.mk: -------------------------------------------------------------------------------- 1 | # List of all the ChibiOS/LIB files, there is no need to remove the files 2 | # from this list, you can disable parts of the kernel by editing chlibconf.h. 3 | ifeq ($(USE_SMART_BUILD),yes) 4 | 5 | # Configuration files directory 6 | ifeq ($(CHCONFDIR),) 7 | ifeq ($(CONFDIR),) 8 | CHCONFDIR = . 9 | else 10 | CHCONFDIR := $(CONFDIR) 11 | endif 12 | endif 13 | 14 | CHLIBCONF := $(strip $(shell cat $(CHCONFDIR)/chconf.h | egrep -e "\#define")) 15 | 16 | LIBSRC := 17 | ifneq ($(findstring CH_CFG_USE_MAILBOXES TRUE,$(CHLIBCONF)),) 18 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmboxes.c 19 | endif 20 | ifneq ($(findstring CH_CFG_USE_MEMCORE TRUE,$(CHLIBCONF)),) 21 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmemcore.c 22 | endif 23 | ifneq ($(findstring CH_CFG_USE_HEAP TRUE,$(CHLIBCONF)),) 24 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmemheaps.c 25 | endif 26 | ifneq ($(findstring CH_CFG_USE_MEMPOOLS TRUE,$(CHLIBCONF)),) 27 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmempools.c 28 | endif 29 | ifneq ($(findstring CH_CFG_USE_PIPES TRUE,$(CHLIBCONF)),) 30 | LIBSRC += $(CHIBIOS)/os/oslib/src/chpipes.c 31 | endif 32 | ifneq ($(findstring CH_CFG_USE_OBJ_CACHES TRUE,$(CHLIBCONF)),) 33 | LIBSRC += $(CHIBIOS)/os/oslib/src/chobjcaches.c 34 | endif 35 | ifneq ($(findstring CH_CFG_USE_DELEGATES TRUE,$(CHLIBCONF)),) 36 | LIBSRC += $(CHIBIOS)/os/oslib/src/chdelegates.c 37 | endif 38 | ifneq ($(findstring CH_CFG_USE_FACTORY TRUE,$(CHLIBCONF)),) 39 | LIBSRC += $(CHIBIOS)/os/oslib/src/chfactory.c 40 | endif 41 | else 42 | LIBSRC := $(CHIBIOS)/os/oslib/src/chmboxes.c \ 43 | $(CHIBIOS)/os/oslib/src/chmemcore.c \ 44 | $(CHIBIOS)/os/oslib/src/chmemheaps.c \ 45 | $(CHIBIOS)/os/oslib/src/chmempools.c \ 46 | $(CHIBIOS)/os/oslib/src/chpipes.c \ 47 | $(CHIBIOS)/os/oslib/src/chobjcaches.c \ 48 | $(CHIBIOS)/os/oslib/src/chdelegates.c \ 49 | $(CHIBIOS)/os/oslib/src/chfactory.c 50 | endif 51 | 52 | # Required include directories 53 | LIBINC := $(CHIBIOS)/os/oslib/include 54 | 55 | # Shared variables 56 | ALLCSRC += $(LIBSRC) 57 | ALLINC += $(LIBINC) 58 | -------------------------------------------------------------------------------- /extra/src_org/oslib/readme.txt: -------------------------------------------------------------------------------- 1 | All the code contained under ./os/lib are high level RTOS extension modules 2 | compatible with both RT and NIL. -------------------------------------------------------------------------------- /extra/src_org/readme.txt: -------------------------------------------------------------------------------- 1 | unmodified source: 2 | CMSIS version 5.7.0 from https://github.com/ARM-software/CMSIS_5 3 | ChibiOS version 20.3.3 from https://osdn.net/projects/chibios/releases -------------------------------------------------------------------------------- /extra/src_org/rt/include/ch.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/include/ch.h 22 | * @brief ChibiOS/RT main include file. 23 | * 24 | * @addtogroup kernel_info 25 | * @details This header includes all the required kernel headers so it is the 26 | * only kernel header you usually want to include in your application. 27 | * @details Kernel related info. 28 | * @{ 29 | */ 30 | 31 | #ifndef CH_H 32 | #define CH_H 33 | 34 | /** 35 | * @brief ChibiOS/RT identification macro. 36 | */ 37 | #define _CHIBIOS_RT_ 38 | 39 | /** 40 | * @brief Stable release flag. 41 | */ 42 | #define CH_KERNEL_STABLE 1 43 | 44 | /** 45 | * @name ChibiOS/RT version identification 46 | * @{ 47 | */ 48 | /** 49 | * @brief Kernel version string. 50 | */ 51 | #define CH_KERNEL_VERSION "6.1.3" 52 | 53 | /** 54 | * @brief Kernel version major number. 55 | */ 56 | #define CH_KERNEL_MAJOR 6 57 | 58 | /** 59 | * @brief Kernel version minor number. 60 | */ 61 | #define CH_KERNEL_MINOR 1 62 | 63 | /** 64 | * @brief Kernel version patch number. 65 | */ 66 | #define CH_KERNEL_PATCH 3 67 | /** @} */ 68 | 69 | /** 70 | * @name Constants for configuration options 71 | * @{ 72 | */ 73 | /** 74 | * @brief Generic 'false' preprocessor boolean constant. 75 | * @note It is meant to be used in configuration files as switch. 76 | */ 77 | #if !defined(FALSE) || defined(__DOXYGEN__) 78 | #define FALSE 0 79 | #endif 80 | 81 | /** 82 | * @brief Generic 'true' preprocessor boolean constant. 83 | * @note It is meant to be used in configuration files as switch. 84 | */ 85 | #if !defined(TRUE) || defined(__DOXYGEN__) 86 | #define TRUE 1 87 | #endif 88 | /** @} */ 89 | 90 | /* Configuration headers, checks and licensing restrictions.*/ 91 | #include "chconf.h" 92 | #include "chchecks.h" 93 | #include "chlicense.h" 94 | #include "chrestrictions.h" 95 | 96 | /* Early function prototype required by the following headers.*/ 97 | #ifdef __cplusplus 98 | extern "C" { 99 | #endif 100 | void chSysHalt(const char *reason); 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | /* Base kernel headers.*/ 106 | #include "chtypes.h" /* CHTODO: Rename and rework.*/ 107 | #include "chsystypes.h" 108 | #include "chlists.h" 109 | #include "chdebug.h" 110 | #include "chtime.h" 111 | #include "chalign.h" 112 | #include "chcore.h" 113 | #include "chtrace.h" 114 | #include "chtm.h" 115 | #include "chstats.h" 116 | #include "chschd.h" 117 | #include "chsys.h" 118 | #include "chvt.h" 119 | #include "chthreads.h" 120 | 121 | /* Optional subsystems headers.*/ 122 | #include "chregistry.h" 123 | #include "chsem.h" 124 | #include "chmtx.h" 125 | #include "chcond.h" 126 | #include "chevents.h" 127 | #include "chmsg.h" 128 | 129 | /* OSLIB.*/ 130 | #include "chlib.h" 131 | 132 | /* Headers dependent on the OSLIB.*/ 133 | #include "chdynamic.h" 134 | 135 | #endif /* CH_H */ 136 | 137 | /** @} */ 138 | -------------------------------------------------------------------------------- /extra/src_org/rt/include/chdynamic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/include/chdynamic.h 22 | * @brief Dynamic threads macros and structures. 23 | * 24 | * @addtogroup dynamic_threads 25 | * @{ 26 | */ 27 | 28 | #ifndef CHDYNAMIC_H 29 | #define CHDYNAMIC_H 30 | 31 | #if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__) 32 | 33 | /*===========================================================================*/ 34 | /* Module constants. */ 35 | /*===========================================================================*/ 36 | 37 | /*===========================================================================*/ 38 | /* Module pre-compile time settings. */ 39 | /*===========================================================================*/ 40 | 41 | /*===========================================================================*/ 42 | /* Derived constants and error checks. */ 43 | /*===========================================================================*/ 44 | 45 | /* 46 | * Module dependencies check. 47 | */ 48 | #if CH_CFG_USE_WAITEXIT == FALSE 49 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_WAITEXIT" 50 | #endif 51 | 52 | #if CH_CFG_USE_REGISTRY == FALSE 53 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_REGISTRY" 54 | #endif 55 | 56 | #if (CH_CFG_USE_HEAP == FALSE) && (CH_CFG_USE_MEMPOOLS == FALSE) 57 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_HEAP and/or CH_CFG_USE_MEMPOOLS" 58 | #endif 59 | 60 | /*===========================================================================*/ 61 | /* Module data structures and types. */ 62 | /*===========================================================================*/ 63 | 64 | /*===========================================================================*/ 65 | /* Module macros. */ 66 | /*===========================================================================*/ 67 | 68 | /*===========================================================================*/ 69 | /* External declarations. */ 70 | /*===========================================================================*/ 71 | 72 | /* 73 | * Dynamic threads APIs. 74 | */ 75 | #ifdef __cplusplus 76 | extern "C" { 77 | #endif 78 | #if CH_CFG_USE_HEAP == TRUE 79 | thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, 80 | const char *name, tprio_t prio, 81 | tfunc_t pf, void *arg); 82 | #endif 83 | #if CH_CFG_USE_MEMPOOLS == TRUE 84 | thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name, 85 | tprio_t prio, tfunc_t pf, void *arg); 86 | #endif 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | /*===========================================================================*/ 92 | /* Module inline functions. */ 93 | /*===========================================================================*/ 94 | 95 | #endif /* CH_CFG_USE_DYNAMIC == TRUE */ 96 | 97 | #endif /* CHDYNAMIC_H */ 98 | 99 | /** @} */ 100 | -------------------------------------------------------------------------------- /extra/src_org/rt/src/chstats.c: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/src/chstats.c 22 | * @brief Statistics module code. 23 | * 24 | * @addtogroup statistics 25 | * @details Statistics services. 26 | * @{ 27 | */ 28 | 29 | #include "ch.h" 30 | 31 | #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__) 32 | 33 | /*===========================================================================*/ 34 | /* Module local definitions. */ 35 | /*===========================================================================*/ 36 | 37 | /*===========================================================================*/ 38 | /* Module exported variables. */ 39 | /*===========================================================================*/ 40 | 41 | /*===========================================================================*/ 42 | /* Module local types. */ 43 | /*===========================================================================*/ 44 | 45 | /*===========================================================================*/ 46 | /* Module local variables. */ 47 | /*===========================================================================*/ 48 | 49 | /*===========================================================================*/ 50 | /* Module local functions. */ 51 | /*===========================================================================*/ 52 | 53 | /*===========================================================================*/ 54 | /* Module exported functions. */ 55 | /*===========================================================================*/ 56 | 57 | /** 58 | * @brief Initializes the statistics module. 59 | * 60 | * @init 61 | */ 62 | void _stats_init(void) { 63 | 64 | ch.kernel_stats.n_irq = (ucnt_t)0; 65 | ch.kernel_stats.n_ctxswc = (ucnt_t)0; 66 | chTMObjectInit(&ch.kernel_stats.m_crit_thd); 67 | chTMObjectInit(&ch.kernel_stats.m_crit_isr); 68 | } 69 | 70 | /** 71 | * @brief Increases the IRQ counter. 72 | */ 73 | void _stats_increase_irq(void) { 74 | 75 | port_lock_from_isr(); 76 | ch.kernel_stats.n_irq++; 77 | port_unlock_from_isr(); 78 | } 79 | 80 | /** 81 | * @brief Updates context switch related statistics. 82 | * 83 | * @param[in] ntp the thread to be switched in 84 | * @param[in] otp the thread to be switched out 85 | */ 86 | void _stats_ctxswc(thread_t *ntp, thread_t *otp) { 87 | 88 | ch.kernel_stats.n_ctxswc++; 89 | chTMChainMeasurementToX(&otp->stats, &ntp->stats); 90 | } 91 | 92 | /** 93 | * @brief Starts the measurement of a thread critical zone. 94 | */ 95 | void _stats_start_measure_crit_thd(void) { 96 | 97 | chTMStartMeasurementX(&ch.kernel_stats.m_crit_thd); 98 | } 99 | 100 | /** 101 | * @brief Stops the measurement of a thread critical zone. 102 | */ 103 | void _stats_stop_measure_crit_thd(void) { 104 | 105 | chTMStopMeasurementX(&ch.kernel_stats.m_crit_thd); 106 | } 107 | 108 | /** 109 | * @brief Starts the measurement of an ISR critical zone. 110 | */ 111 | void _stats_start_measure_crit_isr(void) { 112 | 113 | chTMStartMeasurementX(&ch.kernel_stats.m_crit_isr); 114 | } 115 | 116 | /** 117 | * @brief Stops the measurement of an ISR critical zone. 118 | */ 119 | void _stats_stop_measure_crit_isr(void) { 120 | 121 | chTMStopMeasurementX(&ch.kernel_stats.m_crit_isr); 122 | } 123 | 124 | #endif /* CH_DBG_STATISTICS == TRUE */ 125 | 126 | /** @} */ 127 | -------------------------------------------------------------------------------- /extra/src_org/rt/templates/meta/module.c: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chXxx.c 22 | * @brief XXX module code. 23 | * 24 | * @addtogroup XXX 25 | * @{ 26 | */ 27 | 28 | #include "ch.h" 29 | 30 | #if CH_CFG_USE_XXX || defined(__DOXYGEN__) 31 | 32 | /*===========================================================================*/ 33 | /* Module local definitions. */ 34 | /*===========================================================================*/ 35 | 36 | /*===========================================================================*/ 37 | /* Module exported variables. */ 38 | /*===========================================================================*/ 39 | 40 | /*===========================================================================*/ 41 | /* Module local types. */ 42 | /*===========================================================================*/ 43 | 44 | /*===========================================================================*/ 45 | /* Module local variables. */ 46 | /*===========================================================================*/ 47 | 48 | /*===========================================================================*/ 49 | /* Module local functions. */ 50 | /*===========================================================================*/ 51 | 52 | /*===========================================================================*/ 53 | /* Module exported functions. */ 54 | /*===========================================================================*/ 55 | 56 | /** 57 | * @brief XXX Module initialization. 58 | * @note This function is implicitly invoked on system initialization, 59 | * there is no need to explicitly initialize the module. 60 | * 61 | * @notapi 62 | */ 63 | void _xxx_init(void) { 64 | 65 | } 66 | 67 | /** 68 | * @brief Initializes a @p xxx_t object. 69 | * 70 | * @param[out] xxxp pointer to the @p xxx_t object 71 | * 72 | * @init 73 | */ 74 | void chXxxObjectInit(xxx_t *xxxp) { 75 | 76 | } 77 | 78 | #endif /* CH_CFG_USE_XXX */ 79 | 80 | /** @} */ 81 | -------------------------------------------------------------------------------- /extra/src_org/rt/templates/meta/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chXxx.h 22 | * @brief XXX Module macros and structures. 23 | * 24 | * @addtogroup XXX 25 | * @{ 26 | */ 27 | 28 | #ifndef CHXXX_H 29 | #define CHXXX_H 30 | 31 | #include "ch.h" 32 | 33 | #if CH_CFG_USE_XXX || defined(__DOXYGEN__) 34 | 35 | /*===========================================================================*/ 36 | /* Module constants. */ 37 | /*===========================================================================*/ 38 | 39 | /*===========================================================================*/ 40 | /* Module pre-compile time settings. */ 41 | /*===========================================================================*/ 42 | 43 | /*===========================================================================*/ 44 | /* Derived constants and error checks. */ 45 | /*===========================================================================*/ 46 | 47 | /*===========================================================================*/ 48 | /* Module data structures and types. */ 49 | /*===========================================================================*/ 50 | 51 | /*===========================================================================*/ 52 | /* Module macros. */ 53 | /*===========================================================================*/ 54 | 55 | /*===========================================================================*/ 56 | /* External declarations. */ 57 | /*===========================================================================*/ 58 | 59 | #ifdef __cplusplus 60 | extern "C" { 61 | #endif 62 | void chXxxInit(void); 63 | void chXxxObjectInit(xxx_t *xxxp); 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | /*===========================================================================*/ 69 | /* Module inline functions. */ 70 | /*===========================================================================*/ 71 | 72 | #endif /* CH_CFG_USE_XXX */ 73 | 74 | #endif /* CHXXX_H */ 75 | 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /extra/srcdiff.bat: -------------------------------------------------------------------------------- 1 | diff -rb src_org ..\src >srcdiff.txt 2 | pause 3 | -------------------------------------------------------------------------------- /extra/srcdiff.txt: -------------------------------------------------------------------------------- 1 | Only in ..\src: ChRt.c 2 | Only in ..\src: ChRt.cpp 3 | Only in ..\src: ChRt.h 4 | diff -rb src_org/arm/chcore_v6m.c "..\\src/arm/chcore_v6m.c" 5 | 27c27 6 | < 7 | --- 8 | > #ifdef __arm__ // WHG 9 | 29c29 10 | < 11 | --- 12 | > #if (CORTEX_MODEL == 0) || (CORTEX_MODEL == 1) // WHG 13 | 154c154,155 14 | < 15 | --- 16 | > #endif // (CORTEX_MODEL == 0) || (CORTEX_MODEL == 1) WHG 17 | > #endif // __arm__ WHG 18 | diff -rb src_org/arm/chcore_v7m.c "..\\src/arm/chcore_v7m.c" 19 | 29c29 20 | < 21 | --- 22 | > #ifdef __arm__ // WHG 23 | 31c31 24 | < 25 | --- 26 | > #if (CORTEX_MODEL == 3) || (CORTEX_MODEL == 4) || (CORTEX_MODEL == 7) // WHG 27 | 390c390,391 28 | < 29 | --- 30 | > #endif // (CORTEX_MODEL == 3) || (CORTEX_MODEL == 4) || (CORTEX_MODEL == 7) WHG 31 | > #endif // __arm__ WHG 32 | diff -rb src_org/arm/chcoreasm_v6m.S "..\\src/arm/chcoreasm_v6m.S" 33 | 35c35 34 | < 35 | --- 36 | > #ifdef __arm__ //WHG 37 | 36a37,38 38 | > #include "cmparams.h" // WHG 39 | > #if (CORTEX_MODEL == 0) || (CORTEX_MODEL == 1) // WHG 40 | 153c155,156 41 | < 42 | --- 43 | > #endif // (CORTEX_MODEL == 0) || (CORTEX_MODEL == 1) WHG 44 | > #endif // __arm__ WHG 45 | diff -rb src_org/arm/chcoreasm_v7m.S "..\\src/arm/chcoreasm_v7m.S" 46 | 35c35 47 | < 48 | --- 49 | > #ifdef __arm__ // WHG 50 | 36a37,41 51 | > #include "cmparams.h" // WHG 52 | > #if (CORTEX_MODEL == 0) // WHG 53 | > /* prevent Conflicting CPU architectures error WHG */ 54 | > .cpu cortex-m0 // WHG 55 | > #elif (CORTEX_MODEL == 3) || (CORTEX_MODEL == 4) || (CORTEX_MODEL == 7) // WHG 56 | 241c246,247 57 | < 58 | --- 59 | > #endif // (CORTEX_MODEL == 3) || (CORTEX_MODEL == 4) || (CORTEX_MODEL == 7) WHG 60 | > #endif // __arm__ WHG 61 | diff -rb src_org/arm/chtypes.h "..\\src/arm/chtypes.h" 62 | 32a33 63 | > #include "Arduino.h" // WHG 64 | Only in ..\src/avr: chconf_avr.h 65 | diff -rb src_org/avr/chcore.c "..\\src/avr/chcore.c" 66 | 27c27 67 | < 68 | --- 69 | > #ifdef __AVR__ // WHG 70 | 158c158 71 | < 72 | --- 73 | > #endif // _AVR_ WHG 74 | Only in ..\src/avr: st_lld_avr.c 75 | Only in ..\src/avr: st_lld_avr.h 76 | Only in ..\src: ch.h 77 | Only in ..\src: chconf.h 78 | Only in ..\src: chcore.h 79 | Only in ..\src: chlib.h 80 | Only in ..\src: chlicense.h 81 | Only in ..\src: chtypes.h 82 | Only in ..\src: cmparams.h 83 | Only in ..\src/hal: hal.h 84 | Only in ..\src: hal_st.h 85 | Only in ..\src: hal_st_lld.h 86 | Only in src_org: readme.txt 87 | diff -rb src_org/rt/src/chthreads.c "..\\src/rt/src/chthreads.c" 88 | 476a477 89 | > void chThdExit(msg_t msg) __attribute__((used)); // WHG 90 | Only in ..\src: sam3x 91 | Only in ..\src: samd 92 | Only in ..\src: teensy3 93 | Only in ..\src: teensy4 94 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ChRt 2 | version=1.3.0 3 | author=Bill Greiman 4 | maintainer=Bill Greiman 5 | sentence=ChibiOS/RT for Arduino AVR, SAMD, Due, Teensy 3.x, Teensy 4.0. 6 | paragraph=ChibiOS/RT for Arduino AVR, SAMD, Due, Teensy 3.x, Teensy 4.0 7 | category=Uncategorized 8 | url= 9 | architectures=* 10 | -------------------------------------------------------------------------------- /src/CMSIS/cmsis_version.h: -------------------------------------------------------------------------------- 1 | /**************************************************************************//** 2 | * @file cmsis_version.h 3 | * @brief CMSIS Core(M) Version definitions 4 | * @version V5.0.4 5 | * @date 23. July 2019 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2009-2019 ARM Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef __CMSIS_VERSION_H 32 | #define __CMSIS_VERSION_H 33 | 34 | /* CMSIS Version definitions */ 35 | #define __CM_CMSIS_VERSION_MAIN ( 5U) /*!< [31:16] CMSIS Core(M) main version */ 36 | #define __CM_CMSIS_VERSION_SUB ( 4U) /*!< [15:0] CMSIS Core(M) sub version */ 37 | #define __CM_CMSIS_VERSION ((__CM_CMSIS_VERSION_MAIN << 16U) | \ 38 | __CM_CMSIS_VERSION_SUB ) /*!< CMSIS Core(M) version number */ 39 | #endif 40 | -------------------------------------------------------------------------------- /src/CMSIS/tz_context.h: -------------------------------------------------------------------------------- 1 | /****************************************************************************** 2 | * @file tz_context.h 3 | * @brief Context Management for Armv8-M TrustZone 4 | * @version V1.0.1 5 | * @date 10. January 2018 6 | ******************************************************************************/ 7 | /* 8 | * Copyright (c) 2017-2018 Arm Limited. All rights reserved. 9 | * 10 | * SPDX-License-Identifier: Apache-2.0 11 | * 12 | * Licensed under the Apache License, Version 2.0 (the License); you may 13 | * not use this file except in compliance with the License. 14 | * You may obtain a copy of the License at 15 | * 16 | * www.apache.org/licenses/LICENSE-2.0 17 | * 18 | * Unless required by applicable law or agreed to in writing, software 19 | * distributed under the License is distributed on an AS IS BASIS, WITHOUT 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 21 | * See the License for the specific language governing permissions and 22 | * limitations under the License. 23 | */ 24 | 25 | #if defined ( __ICCARM__ ) 26 | #pragma system_include /* treat file as system include file for MISRA check */ 27 | #elif defined (__clang__) 28 | #pragma clang system_header /* treat file as system include file */ 29 | #endif 30 | 31 | #ifndef TZ_CONTEXT_H 32 | #define TZ_CONTEXT_H 33 | 34 | #include 35 | 36 | #ifndef TZ_MODULEID_T 37 | #define TZ_MODULEID_T 38 | /// \details Data type that identifies secure software modules called by a process. 39 | typedef uint32_t TZ_ModuleId_t; 40 | #endif 41 | 42 | /// \details TZ Memory ID identifies an allocated memory slot. 43 | typedef uint32_t TZ_MemoryId_t; 44 | 45 | /// Initialize secure context memory system 46 | /// \return execution status (1: success, 0: error) 47 | uint32_t TZ_InitContextSystem_S (void); 48 | 49 | /// Allocate context memory for calling secure software modules in TrustZone 50 | /// \param[in] module identifies software modules called from non-secure mode 51 | /// \return value != 0 id TrustZone memory slot identifier 52 | /// \return value 0 no memory available or internal error 53 | TZ_MemoryId_t TZ_AllocModuleContext_S (TZ_ModuleId_t module); 54 | 55 | /// Free context memory that was previously allocated with \ref TZ_AllocModuleContext_S 56 | /// \param[in] id TrustZone memory slot identifier 57 | /// \return execution status (1: success, 0: error) 58 | uint32_t TZ_FreeModuleContext_S (TZ_MemoryId_t id); 59 | 60 | /// Load secure context (called on RTOS thread context switch) 61 | /// \param[in] id TrustZone memory slot identifier 62 | /// \return execution status (1: success, 0: error) 63 | uint32_t TZ_LoadContext_S (TZ_MemoryId_t id); 64 | 65 | /// Store secure context (called on RTOS thread context switch) 66 | /// \param[in] id TrustZone memory slot identifier 67 | /// \return execution status (1: success, 0: error) 68 | uint32_t TZ_StoreContext_S (TZ_MemoryId_t id); 69 | 70 | #endif // TZ_CONTEXT_H 71 | -------------------------------------------------------------------------------- /src/ChRt.c: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #include "ChRt.h" 3 | 4 | //------------------------------------------------------------------------------ 5 | /** calibration factor for delayMS */ 6 | #if defined(__IMXRT1062__) 7 | #define CAL_FACTOR (F_CPU/3500) 8 | #else // defined(__IMXRT1062__) 9 | #define CAL_FACTOR (F_CPU/7000) 10 | #endif // defined(__IMXRT1062__) 11 | /** delay between led error flashes 12 | * \param[in] millis milliseconds to delay 13 | */ 14 | static void delayMS(uint32_t millis) { 15 | uint32_t i; 16 | uint32_t iterations = millis*CAL_FACTOR; 17 | for(i = 0; i < iterations; ++i) { 18 | asm volatile("nop\n\t"); 19 | } 20 | } 21 | //------------------------------------------------------------------------------ 22 | void errorBlink(int n) { 23 | noInterrupts(); 24 | pinMode(13, OUTPUT); 25 | for (;;) { 26 | int i; 27 | for (i = 0; i < n; i++) { 28 | digitalWrite(13, 1); 29 | delayMS(300); 30 | digitalWrite(13, 0); 31 | delayMS(300); 32 | } 33 | delayMS(2000); 34 | } 35 | } 36 | // catch Teensy and Due exceptions 37 | /** Hard fault - blink one short flash every two seconds */ 38 | void hard_fault_isr() {errorBlink(1);} 39 | 40 | /** Hard fault - blink one short flash every two seconds */ 41 | void HardFault_Handler() {errorBlink(1);} 42 | 43 | /** Bus fault - blink two short flashes every two seconds */ 44 | void bus_fault_isr() {errorBlink(2);} 45 | 46 | /** Bus fault - blink two short flashes every two seconds */ 47 | void BusFault_Handler() {errorBlink(2);} 48 | 49 | /** Usage fault - blink three short flashes every two seconds */ 50 | void usage_fault_isr() {errorBlink(3);} 51 | 52 | /** Usage fault - blink three short flashes every two seconds */ 53 | void UsageFault_Handler() {errorBlink(3);} 54 | 55 | /** Memory management fault - blink four short flashes every two seconds */ 56 | void memmanage_fault_isr() {errorBlink(4);} 57 | 58 | /** Memory management fault - blink four short flashes every two seconds */ 59 | void MemManage_Handler() {errorBlink(4);} -------------------------------------------------------------------------------- /src/ChRt.h: -------------------------------------------------------------------------------- 1 | #ifndef ChRt_h 2 | #define ChRt_h 3 | /** 4 | * \file 5 | * \brief main ChRt include file. 6 | */ 7 | #include "rt/include/ch.h" 8 | #include "hal_st.h" 9 | 10 | /** Size of handler stack. */ 11 | #define HANDLER_STACK_SIZE 400 12 | /** 13 | * Starts ChibiOS/RT - does not return. 14 | * \param[in] mainThread Function to be called before repeated calls 15 | * to loop(). 16 | */ 17 | void chBegin(void (*mainThread)()); 18 | /** 19 | * Determine unused bytes in the handler stack. 20 | * 21 | * \return number of unused bytes 22 | */ 23 | size_t chUnusedHandlerStack(); 24 | /** 25 | * Determine unused bytes in the main() thread stack. 26 | * 27 | * \return number of unused bytes 28 | */ 29 | size_t chUnusedMainStack(); 30 | /** 31 | * Determine number unused bytes in a thread's stack. 32 | * 33 | * \param[in] wsp pointer to working space for thread 34 | * \param[in] size working space size 35 | * 36 | * \return Unused byte count. 37 | * Most accurate if called from the main thread. Some versions of sbrk() 38 | * don't work correctly when called from another thread. 39 | */ 40 | size_t chUnusedThreadStack(void *wsp, size_t size); 41 | 42 | /** \return Heap end address. Best if called from the main thread. */ 43 | uint8_t* heapEnd(); 44 | #ifdef __cplusplus 45 | extern "C" { 46 | #endif 47 | /** Blink an error pattern 48 | * 49 | * \param[in] n number of short pulses 50 | */ 51 | void errorBlink(int n); 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | #endif // ChRt_h -------------------------------------------------------------------------------- /src/arm/chcore_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chcore_timer.h 22 | * @brief System timer header file. 23 | * 24 | * @addtogroup ARMCMx_TIMER 25 | * @{ 26 | */ 27 | 28 | #ifndef CHCORE_TIMER_H 29 | #define CHCORE_TIMER_H 30 | 31 | /*===========================================================================*/ 32 | /* Module constants. */ 33 | /*===========================================================================*/ 34 | 35 | /*===========================================================================*/ 36 | /* Module pre-compile time settings. */ 37 | /*===========================================================================*/ 38 | 39 | /*===========================================================================*/ 40 | /* Derived constants and error checks. */ 41 | /*===========================================================================*/ 42 | 43 | /*===========================================================================*/ 44 | /* Module data structures and types. */ 45 | /*===========================================================================*/ 46 | 47 | /*===========================================================================*/ 48 | /* Module macros. */ 49 | /*===========================================================================*/ 50 | 51 | /*===========================================================================*/ 52 | /* External declarations. */ 53 | /*===========================================================================*/ 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | void stStartAlarm(systime_t time); 59 | void stStopAlarm(void); 60 | void stSetAlarm(systime_t time); 61 | systime_t stGetCounter(void); 62 | systime_t stGetAlarm(void); 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | /*===========================================================================*/ 68 | /* Module inline functions. */ 69 | /*===========================================================================*/ 70 | 71 | /** 72 | * @brief Starts the alarm. 73 | * @note Makes sure that no spurious alarms are triggered after 74 | * this call. 75 | * 76 | * @param[in] time the time to be set for the first alarm 77 | * 78 | * @notapi 79 | */ 80 | static inline void port_timer_start_alarm(systime_t time) { 81 | 82 | stStartAlarm(time); 83 | } 84 | 85 | /** 86 | * @brief Stops the alarm interrupt. 87 | * 88 | * @notapi 89 | */ 90 | static inline void port_timer_stop_alarm(void) { 91 | 92 | stStopAlarm(); 93 | } 94 | 95 | /** 96 | * @brief Sets the alarm time. 97 | * 98 | * @param[in] time the time to be set for the next alarm 99 | * 100 | * @notapi 101 | */ 102 | static inline void port_timer_set_alarm(systime_t time) { 103 | 104 | stSetAlarm(time); 105 | } 106 | 107 | /** 108 | * @brief Returns the system time. 109 | * 110 | * @return The system time. 111 | * 112 | * @notapi 113 | */ 114 | static inline systime_t port_timer_get_time(void) { 115 | 116 | return stGetCounter(); 117 | } 118 | 119 | /** 120 | * @brief Returns the current alarm time. 121 | * 122 | * @return The currently set alarm time. 123 | * 124 | * @notapi 125 | */ 126 | static inline systime_t port_timer_get_alarm(void) { 127 | 128 | return stGetAlarm(); 129 | } 130 | 131 | #endif /* CHCORE_TIMER_H */ 132 | 133 | /** @} */ 134 | -------------------------------------------------------------------------------- /src/arm/chtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file ARMCMx/compilers/GCC/chtypes.h 22 | * @brief ARM Cortex-Mx port system types. 23 | * 24 | * @addtogroup ARMCMx_GCC_CORE 25 | * @{ 26 | */ 27 | 28 | #ifndef CHTYPES_H 29 | #define CHTYPES_H 30 | 31 | #include 32 | #include 33 | #include "Arduino.h" // WHG 34 | #include 35 | 36 | /** 37 | * @name Kernel types 38 | * @{ 39 | */ 40 | typedef uint32_t rtcnt_t; /**< Realtime counter. */ 41 | typedef uint64_t rttime_t; /**< Realtime accumulator. */ 42 | typedef uint32_t syssts_t; /**< System status word. */ 43 | typedef uint8_t tmode_t; /**< Thread flags. */ 44 | typedef uint8_t tstate_t; /**< Thread state. */ 45 | typedef uint8_t trefs_t; /**< Thread references counter. */ 46 | typedef uint8_t tslices_t; /**< Thread time slices counter.*/ 47 | typedef uint32_t tprio_t; /**< Thread priority. */ 48 | typedef int32_t msg_t; /**< Inter-thread message. */ 49 | typedef int32_t eventid_t; /**< Numeric event identifier. */ 50 | typedef uint32_t eventmask_t; /**< Mask of event identifiers. */ 51 | typedef uint32_t eventflags_t; /**< Mask of event flags. */ 52 | typedef int32_t cnt_t; /**< Generic signed counter. */ 53 | typedef uint32_t ucnt_t; /**< Generic unsigned counter. */ 54 | /** @} */ 55 | 56 | /** 57 | * @brief ROM constant modifier. 58 | * @note It is set to use the "const" keyword in this port. 59 | */ 60 | #define ROMCONST const 61 | 62 | /** 63 | * @brief Makes functions not inlineable. 64 | * @note If the compiler does not support such attribute then some 65 | * time-dependent services could be degraded. 66 | */ 67 | #define NOINLINE __attribute__((noinline)) 68 | 69 | /** 70 | * @brief Optimized thread function declaration macro. 71 | */ 72 | #define PORT_THD_FUNCTION(tname, arg) void tname(void *arg) 73 | 74 | /** 75 | * @brief Packed variable specifier. 76 | */ 77 | #define PACKED_VAR __attribute__((packed)) 78 | 79 | /** 80 | * @brief Memory alignment enforcement for variables. 81 | */ 82 | #define ALIGNED_VAR(n) __attribute__((aligned(n))) 83 | 84 | /** 85 | * @brief Size of a pointer. 86 | * @note To be used where the sizeof operator cannot be used, preprocessor 87 | * expressions for example. 88 | */ 89 | #define SIZEOF_PTR 4 90 | 91 | /** 92 | * @brief True if alignment is low-high in current architecture. 93 | */ 94 | #define REVERSE_ORDER 1 95 | 96 | #endif /* CHTYPES_H */ 97 | 98 | /** @} */ 99 | -------------------------------------------------------------------------------- /src/avr/chcore_timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file AVR/chcore_timer.h 22 | * @brief System timer header file. 23 | * 24 | * @addtogroup AVR_TIMER 25 | * @{ 26 | */ 27 | 28 | #ifndef CHCORE_TIMER_H 29 | #define CHCORE_TIMER_H 30 | 31 | /*===========================================================================*/ 32 | /* Module constants. */ 33 | /*===========================================================================*/ 34 | 35 | /*===========================================================================*/ 36 | /* Module pre-compile time settings. */ 37 | /*===========================================================================*/ 38 | 39 | /*===========================================================================*/ 40 | /* Derived constants and error checks. */ 41 | /*===========================================================================*/ 42 | 43 | /*===========================================================================*/ 44 | /* Module data structures and types. */ 45 | /*===========================================================================*/ 46 | 47 | /*===========================================================================*/ 48 | /* Module macros. */ 49 | /*===========================================================================*/ 50 | 51 | /*===========================================================================*/ 52 | /* External declarations. */ 53 | /*===========================================================================*/ 54 | 55 | /*===========================================================================*/ 56 | /* Module inline functions. */ 57 | /*===========================================================================*/ 58 | 59 | /** 60 | * @brief Starts the alarm. 61 | * @note Makes sure that no spurious alarms are triggered after 62 | * this call. 63 | * 64 | * @param[in] time the time to be set for the first alarm 65 | * 66 | * @notapi 67 | */ 68 | static inline void port_timer_start_alarm(systime_t time) { 69 | void stStartAlarm(systime_t time); 70 | 71 | stStartAlarm(time); 72 | } 73 | 74 | /** 75 | * @brief Stops the alarm interrupt. 76 | * 77 | * @notapi 78 | */ 79 | static inline void port_timer_stop_alarm(void) { 80 | void stStopAlarm(void); 81 | 82 | stStopAlarm(); 83 | } 84 | 85 | /** 86 | * @brief Sets the alarm time. 87 | * 88 | * @param[in] time the time to be set for the next alarm 89 | * 90 | * @notapi 91 | */ 92 | static inline void port_timer_set_alarm(systime_t time) { 93 | void stSetAlarm(systime_t time); 94 | 95 | stSetAlarm(time); 96 | } 97 | 98 | /** 99 | * @brief Returns the system time. 100 | * 101 | * @return The system time. 102 | * 103 | * @notapi 104 | */ 105 | static inline systime_t port_timer_get_time(void) { 106 | systime_t stGetCounter(void); 107 | 108 | return stGetCounter(); 109 | } 110 | 111 | /** 112 | * @brief Returns the current alarm time. 113 | * 114 | * @return The currently set alarm time. 115 | * 116 | * @notapi 117 | */ 118 | static inline systime_t port_timer_get_alarm(void) { 119 | systime_t stGetAlarm(void); 120 | 121 | return stGetAlarm(); 122 | } 123 | 124 | #endif /* CHCORE_TIMER_H */ 125 | 126 | /** @} */ 127 | -------------------------------------------------------------------------------- /src/avr/chtypes.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file AVR/compilers/GCC/chtypes.h 22 | * @brief AVR architecture port system types. 23 | * 24 | * @addtogroup AVR_CORE 25 | * @{ 26 | */ 27 | 28 | #ifndef CHTYPES_H 29 | #define CHTYPES_H 30 | 31 | #include 32 | #include 33 | #include 34 | 35 | /** 36 | * @name Kernel types 37 | * @{ 38 | */ 39 | typedef uint32_t rtcnt_t; /**< Realtime counter. */ 40 | typedef uint64_t rttime_t; /**< Realtime accumulator. */ 41 | typedef uint8_t syssts_t; /**< System status word. */ 42 | typedef uint8_t tmode_t; /**< Thread flags. */ 43 | typedef uint8_t tstate_t; /**< Thread state. */ 44 | typedef uint8_t trefs_t; /**< Thread references counter. */ 45 | typedef uint8_t tslices_t; /**< Thread time slices counter.*/ 46 | typedef uint8_t tprio_t; /**< Thread priority. */ 47 | typedef int16_t msg_t; /**< Inter-thread message. */ 48 | typedef int32_t eventid_t; /**< Numeric event identifier. */ 49 | typedef uint8_t eventmask_t; /**< Mask of event identifiers. */ 50 | typedef uint8_t eventflags_t; /**< Mask of event flags. */ 51 | typedef int8_t cnt_t; /**< Generic signed counter. */ 52 | typedef uint8_t ucnt_t; /**< Generic unsigned counter. */ 53 | typedef bool bool_t; /**< Fast boolean type. */ 54 | /** @} */ 55 | 56 | /** 57 | * @brief ROM constant modifier. 58 | * @note It is set to use the "const" keyword in this port. 59 | */ 60 | #define ROMCONST const 61 | 62 | /** 63 | * @brief Makes functions not inlineable. 64 | * @note If the compiler does not support such attribute then the 65 | * realtime counter precision could be degraded. 66 | */ 67 | #define NOINLINE __attribute__((noinline)) 68 | 69 | /** 70 | * @brief Optimized thread function declaration macro. 71 | */ 72 | #define PORT_THD_FUNCTION(tname, arg) void tname(void *arg) 73 | 74 | /** 75 | * @brief Packed variable specifier. 76 | */ 77 | #define PACKED_VAR __attribute__((packed)) 78 | 79 | /** 80 | * @brief Memory alignment enforcement for variables. 81 | */ 82 | #define ALIGNED_VAR(n) __attribute__((aligned(n))) 83 | 84 | /** 85 | * @brief Size of a pointer. 86 | * @note To be used where the sizeof operator cannot be used, preprocessor 87 | * expressions for example. 88 | */ 89 | #define SIZEOF_PTR 2 90 | 91 | /** 92 | * @brief True if alignment is low-high in current architecture. 93 | */ 94 | #define REVERSE_ORDER 1 95 | 96 | #endif /* CHTYPES_H */ 97 | 98 | /** @} */ 99 | -------------------------------------------------------------------------------- /src/avr/st_lld_avr.c: -------------------------------------------------------------------------------- 1 | #ifdef __AVR__ 2 | #include "../hal/osal.h" 3 | #if (OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC) || defined(__DOXYGEN__) 4 | #if OSAL_ST_FREQUENCY != (1000000UL/1024) 5 | #error "AVR only supports CH_CFG_ST_FREQUENCY == (1000000UL/1024)" 6 | #endif 7 | /** 8 | * @brief Timer handler for periodic mode. 9 | */ 10 | CH_IRQ_HANDLER(TIMER0_COMPA_vect) { 11 | CH_IRQ_PROLOGUE(); 12 | 13 | chSysLockFromISR(); 14 | chSysTimerHandlerI(); 15 | chSysUnlockFromISR(); 16 | 17 | CH_IRQ_EPILOGUE(); 18 | } 19 | /* 20 | * Timer 0 setup. 21 | */ 22 | 23 | void st_lld_init(void) { 24 | OCR0A = 128; 25 | TIMSK0 |= (1 << OCIE0A); 26 | } 27 | 28 | #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ 29 | //------------------------------------------------------------------------------ 30 | #if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) || defined(__DOXYGEN__) 31 | #if OSAL_ST_FREQUENCY != (F_CPU/1024) 32 | #error "AVR only supports CH_CFG_ST_FREQUENCY == (F_CPU/1024)" 33 | #endif 34 | #define PRESCALER (_BV(CS12) | _BV(CS10)) 35 | /** 36 | * @brief Timer handler for free running mode. 37 | */ 38 | OSAL_IRQ_HANDLER(TIMER1_COMPA_vect) { 39 | 40 | OSAL_IRQ_PROLOGUE(); 41 | 42 | /* TODO: reset status if required. */ 43 | 44 | osalSysLockFromISR(); 45 | osalOsTimerHandlerI(); 46 | osalSysUnlockFromISR(); 47 | 48 | OSAL_IRQ_EPILOGUE(); 49 | } 50 | /** 51 | * @brief Low level ST driver initialization. 52 | * 53 | * @notapi 54 | */ 55 | void st_lld_init(void) { 56 | /* 57 | * Periodic mode uses Timer 1 (16 bit). 58 | */ 59 | 60 | /* CTC mode, no clock source. */ 61 | TCCR1A = 0; 62 | TCCR1B = _BV(WGM12); 63 | 64 | /* start disabled. */ 65 | TCCR1C = 0; 66 | OCR1A = 0; 67 | TCNT1 = 0; 68 | TIFR_REG = _BV(OCF1A); /* Reset pending. */ 69 | TIMSK_REG = 0; 70 | TCCR1B = PRESCALER; 71 | } 72 | #endif /* OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC */ 73 | #endif // __AVR__ 74 | -------------------------------------------------------------------------------- /src/ch.h: -------------------------------------------------------------------------------- 1 | #include "rt/include/ch.h" -------------------------------------------------------------------------------- /src/chconf.h: -------------------------------------------------------------------------------- 1 | #ifndef chconf_rt_h 2 | #define chconf_rt_h 3 | #define _CHIBIOS_RT_CONF_ 4 | #ifdef __AVR__ 5 | #include "avr/chconf_avr.h" 6 | #elif defined(__SAM3X8E__) || defined(__SAM3X8H__) 7 | #include "sam3x/chconf_sam3x.h" 8 | #elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) 9 | #include "samd/chconf_samd.h" 10 | #elif defined(__MK20DX256__) || defined(__MK20DX128__)\ 11 | || defined(__MK64FX512__) || defined(__MK66FX1M0__) 12 | #include "teensy3/chconf_teensy3.h" 13 | #elif defined(__IMXRT1062__) 14 | #include "teensy4/chconf_teensy4.h" 15 | #else 16 | #error "unknown processor type" 17 | #endif // __AVR__ 18 | #include "rt/templates/chconf.h" 19 | #endif // chconf_rt_h 20 | -------------------------------------------------------------------------------- /src/chcore.h: -------------------------------------------------------------------------------- 1 | #ifndef chcore_rt_h 2 | #define chcore_rt_h 3 | #ifdef __AVR__ 4 | #include "avr/chcore.h" 5 | #else // __AVR__ 6 | #include "arm/chcore.h" 7 | #endif // __AVR__ 8 | #endif // chcore_rt_h 9 | -------------------------------------------------------------------------------- /src/chlib.h: -------------------------------------------------------------------------------- 1 | #include "oslib/include/chlib.h" -------------------------------------------------------------------------------- /src/chlicense.h: -------------------------------------------------------------------------------- 1 | #include "license/chlicense.h" -------------------------------------------------------------------------------- /src/chtypes.h: -------------------------------------------------------------------------------- 1 | #ifndef chtypes_rt_h 2 | #define chtypes_rt_h 3 | #ifdef __AVR__ 4 | #include "avr/chtypes.h" 5 | #elif defined(__arm__) 6 | #include "arm/chtypes.h" 7 | #else 8 | #error "unknown processor type" 9 | #endif // __AVR__ 10 | #endif // chtypes_rt_h -------------------------------------------------------------------------------- /src/cmparams.h: -------------------------------------------------------------------------------- 1 | #ifndef chparams_h 2 | #define chparams_h 3 | #if defined(__IMXRT1062__) 4 | #include "teensy4/cmparams_teensy4.h" 5 | #elif defined(__MK20DX256__) || defined(__MK20DX128__) || \ 6 | defined(__MK64FX512__) || defined(__MK66FX1M0__) 7 | #include "teensy3/cmparams_teensy3.h" 8 | #elif defined(__SAMD21G18A__) || defined(__SAMD21J18A__) 9 | #include "samd/cmparams_samd.h" 10 | #elif defined(__SAM3X8E__) || defined(__SAM3X8H__) 11 | #include "sam3x/cmparams_sam3x.h" 12 | #else 13 | #error unknown ARM processor 14 | #endif 15 | 16 | #endif // chparams_h -------------------------------------------------------------------------------- /src/hal/hal.h: -------------------------------------------------------------------------------- 1 | #include "ch.h" //WHG 2 | #include "osal.h" // WHG 3 | #include "hal_st.h" -------------------------------------------------------------------------------- /src/hal/hal_st.h: -------------------------------------------------------------------------------- 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 hal_st.h 19 | * @brief ST Driver macros and structures. 20 | * @details This header is designed to be include-able without having to 21 | * include other files from the HAL. 22 | * 23 | * @addtogroup ST 24 | * @{ 25 | */ 26 | 27 | #ifndef HAL_ST_H 28 | #define HAL_ST_H 29 | 30 | #include "hal_st_lld.h" 31 | 32 | /*===========================================================================*/ 33 | /* Driver constants. */ 34 | /*===========================================================================*/ 35 | 36 | /*===========================================================================*/ 37 | /* Driver pre-compile time settings. */ 38 | /*===========================================================================*/ 39 | 40 | /*===========================================================================*/ 41 | /* Derived constants and error checks. */ 42 | /*===========================================================================*/ 43 | 44 | /* Compatibility with old LLDS.*/ 45 | #if !defined(ST_LLD_NUM_ALARMS) 46 | #define ST_LLD_NUM_ALARMS 1 47 | #endif 48 | 49 | /*===========================================================================*/ 50 | /* Driver data structures and types. */ 51 | /*===========================================================================*/ 52 | 53 | typedef void (*st_callback_t)(unsigned alarm); 54 | 55 | /*===========================================================================*/ 56 | /* Driver macros. */ 57 | /*===========================================================================*/ 58 | 59 | /*===========================================================================*/ 60 | /* External declarations. */ 61 | /*===========================================================================*/ 62 | 63 | #if (ST_LLD_NUM_ALARMS > 1) && !defined(__DOXYGEN__) 64 | extern st_callback_t st_callbacks[ST_LLD_NUM_ALARMS - 1]; 65 | #endif 66 | 67 | #ifdef __cplusplus 68 | extern "C" { 69 | #endif 70 | void stInit(void); 71 | void stStartAlarm(systime_t abstime); 72 | void stStopAlarm(void); 73 | void stSetAlarm(systime_t abstime); 74 | systime_t stGetAlarm(void); 75 | systime_t stGetCounter(void); 76 | bool stIsAlarmActive(void); 77 | #if ST_LLD_NUM_ALARMS > 1 78 | bool stIsAlarmActiveN(unsigned alarm); 79 | void stStartAlarmN(unsigned alarm, systime_t abstime, st_callback_t cb); 80 | void stStopAlarmN(unsigned alarm); 81 | void stSetAlarmN(unsigned alarm, systime_t abstime); 82 | systime_t stGetAlarmN(unsigned alarm); 83 | #endif 84 | #ifdef __cplusplus 85 | } 86 | #endif 87 | 88 | #endif /* HAL_ST_H */ 89 | 90 | /** @} */ 91 | -------------------------------------------------------------------------------- /src/hal_st.h: -------------------------------------------------------------------------------- 1 | #include "hal/hal_st.h" -------------------------------------------------------------------------------- /src/hal_st_lld.h: -------------------------------------------------------------------------------- 1 | #include "rt/include/ch.h" 2 | #if defined(__IMXRT1062__) 3 | #include "teensy4/st_lld_teensy4.h" 4 | #elif defined(__AVR__) 5 | #include "avr/st_lld_avr.h" 6 | #else // defined(__IMXRT1062__) 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | void st_lld_init(void); 11 | #ifdef __cplusplus 12 | } 13 | #endif 14 | #endif // defined(__IMXRT1062__) -------------------------------------------------------------------------------- /src/license/chversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chversion.h 22 | * @brief Version Module macros and structures. 23 | * 24 | * @addtogroup chibios_version 25 | * @details This module contains information about the ChibiOS release, it 26 | * is common to all subsystems. 27 | * @{ 28 | */ 29 | 30 | #ifndef CHVERSION_H 31 | #define CHVERSION_H 32 | 33 | /*===========================================================================*/ 34 | /* Module constants. */ 35 | /*===========================================================================*/ 36 | 37 | /** 38 | * @brief ChibiOS product identification macro. 39 | */ 40 | #define _CHIBIOS_ 41 | 42 | /** 43 | * @brief Stable release flag. 44 | */ 45 | #define CH_VERSION_STABLE 1 46 | 47 | /** 48 | * @name ChibiOS version identification 49 | * @{ 50 | */ 51 | /** 52 | * @brief ChibiOS version string. 53 | */ 54 | #define CH_VERSION "20.3.3" 55 | 56 | /** 57 | * @brief ChibiOS version release year. 58 | */ 59 | #define CH_VERSION_YEAR 20 60 | 61 | /** 62 | * @brief ChibiOS version release month. 63 | */ 64 | #define CH_VERSION_MONTH 3 65 | 66 | /** 67 | * @brief ChibiOS version patch number. 68 | */ 69 | #define CH_VERSION_PATCH 3 70 | 71 | /** 72 | * @brief ChibiOS version nickname. 73 | */ 74 | #define CH_VERSION_NICKNAME "Dragonea" 75 | /** @} */ 76 | 77 | /*===========================================================================*/ 78 | /* Module pre-compile time settings. */ 79 | /*===========================================================================*/ 80 | 81 | /*===========================================================================*/ 82 | /* Derived constants and error checks. */ 83 | /*===========================================================================*/ 84 | 85 | /*===========================================================================*/ 86 | /* Module data structures and types. */ 87 | /*===========================================================================*/ 88 | 89 | /*===========================================================================*/ 90 | /* Module macros. */ 91 | /*===========================================================================*/ 92 | 93 | /*===========================================================================*/ 94 | /* External declarations. */ 95 | /*===========================================================================*/ 96 | 97 | /*===========================================================================*/ 98 | /* Module inline functions. */ 99 | /*===========================================================================*/ 100 | 101 | #endif /* CHVERSION_H */ 102 | 103 | /** @} */ 104 | -------------------------------------------------------------------------------- /src/license/license.dox: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @defgroup licensing Release and Licensing 22 | */ 23 | 24 | /** 25 | * @defgroup chibios_version Release Information 26 | * @ingroup licensing 27 | */ 28 | 29 | /** 30 | * @defgroup chibios_customer Customer Information 31 | * @ingroup licensing 32 | */ 33 | 34 | /** 35 | * @defgroup chibios_license License Settings 36 | * @ingroup licensing 37 | */ 38 | -------------------------------------------------------------------------------- /src/license/license.mk: -------------------------------------------------------------------------------- 1 | # List of all the licensing subsystem files. 2 | LICSRC := 3 | 4 | # Required include directories 5 | LICINC := $(CHIBIOS)/os/license 6 | 7 | # Shared variables 8 | ALLCSRC += $(LICSRC) 9 | ALLINC += $(LICINC) 10 | -------------------------------------------------------------------------------- /src/oslib/dox/lib.dox: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | /** 20 | * @defgroup oslib OS Library 21 | * @details The OS Library is a set of RTOS extensions compatible with both 22 | * the RT and NIL RTOSes. 23 | */ 24 | 25 | /** 26 | * @defgroup oslib_info Version Numbers and Identification 27 | * @ingroup oslib 28 | */ 29 | 30 | /** 31 | * @defgroup oslib_synchronization Synchronization 32 | * @details Synchronization services. 33 | * @ingroup oslib 34 | */ 35 | 36 | /** 37 | * @defgroup oslib_binary_semaphores Binary Semaphores 38 | * @ingroup oslib_synchronization 39 | */ 40 | 41 | /** 42 | * @defgroup oslib_mailboxes Mailboxes 43 | * @ingroup oslib_synchronization 44 | */ 45 | 46 | /** 47 | * @defgroup oslib_pipes Pipes 48 | * @ingroup oslib_synchronization 49 | */ 50 | 51 | /** 52 | * @defgroup oslib_delegates Delegate Threads 53 | * @ingroup oslib_synchronization 54 | */ 55 | 56 | /** 57 | * @defgroup oslib_jobs_queues Jobs Queues 58 | * @ingroup oslib_synchronization 59 | */ 60 | 61 | /** 62 | * @defgroup oslib_memory Memory Management 63 | * @details Memory Management services. 64 | * @ingroup oslib 65 | */ 66 | 67 | /** 68 | * @defgroup oslib_memcore Core Memory Manager 69 | * @ingroup oslib_memory 70 | */ 71 | 72 | /** 73 | * @defgroup oslib_memheaps Memory Heaps 74 | * @ingroup oslib_memory 75 | */ 76 | 77 | /** 78 | * @defgroup oslib_mempools Memory Pools 79 | * @ingroup oslib_memory 80 | */ 81 | 82 | /** 83 | * @defgroup oslib_complex Complex Services 84 | * @ingroup oslib 85 | */ 86 | 87 | /** 88 | * @defgroup oslib_objects_fifos Objects FIFOs 89 | * @ingroup oslib_complex 90 | */ 91 | 92 | /** 93 | * @defgroup oslib_objchaches Objects Caches 94 | * @ingroup oslib_complex 95 | */ 96 | 97 | /** 98 | * @defgroup oslib_objects_factory Dynamic Objects Factory 99 | * @ingroup oslib_complex 100 | */ 101 | -------------------------------------------------------------------------------- /src/oslib/oslib.mk: -------------------------------------------------------------------------------- 1 | # List of all the ChibiOS/LIB files, there is no need to remove the files 2 | # from this list, you can disable parts of the kernel by editing chlibconf.h. 3 | ifeq ($(USE_SMART_BUILD),yes) 4 | 5 | # Configuration files directory 6 | ifeq ($(CHCONFDIR),) 7 | ifeq ($(CONFDIR),) 8 | CHCONFDIR = . 9 | else 10 | CHCONFDIR := $(CONFDIR) 11 | endif 12 | endif 13 | 14 | CHLIBCONF := $(strip $(shell cat $(CHCONFDIR)/chconf.h | egrep -e "\#define")) 15 | 16 | LIBSRC := 17 | ifneq ($(findstring CH_CFG_USE_MAILBOXES TRUE,$(CHLIBCONF)),) 18 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmboxes.c 19 | endif 20 | ifneq ($(findstring CH_CFG_USE_MEMCORE TRUE,$(CHLIBCONF)),) 21 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmemcore.c 22 | endif 23 | ifneq ($(findstring CH_CFG_USE_HEAP TRUE,$(CHLIBCONF)),) 24 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmemheaps.c 25 | endif 26 | ifneq ($(findstring CH_CFG_USE_MEMPOOLS TRUE,$(CHLIBCONF)),) 27 | LIBSRC += $(CHIBIOS)/os/oslib/src/chmempools.c 28 | endif 29 | ifneq ($(findstring CH_CFG_USE_PIPES TRUE,$(CHLIBCONF)),) 30 | LIBSRC += $(CHIBIOS)/os/oslib/src/chpipes.c 31 | endif 32 | ifneq ($(findstring CH_CFG_USE_OBJ_CACHES TRUE,$(CHLIBCONF)),) 33 | LIBSRC += $(CHIBIOS)/os/oslib/src/chobjcaches.c 34 | endif 35 | ifneq ($(findstring CH_CFG_USE_DELEGATES TRUE,$(CHLIBCONF)),) 36 | LIBSRC += $(CHIBIOS)/os/oslib/src/chdelegates.c 37 | endif 38 | ifneq ($(findstring CH_CFG_USE_FACTORY TRUE,$(CHLIBCONF)),) 39 | LIBSRC += $(CHIBIOS)/os/oslib/src/chfactory.c 40 | endif 41 | else 42 | LIBSRC := $(CHIBIOS)/os/oslib/src/chmboxes.c \ 43 | $(CHIBIOS)/os/oslib/src/chmemcore.c \ 44 | $(CHIBIOS)/os/oslib/src/chmemheaps.c \ 45 | $(CHIBIOS)/os/oslib/src/chmempools.c \ 46 | $(CHIBIOS)/os/oslib/src/chpipes.c \ 47 | $(CHIBIOS)/os/oslib/src/chobjcaches.c \ 48 | $(CHIBIOS)/os/oslib/src/chdelegates.c \ 49 | $(CHIBIOS)/os/oslib/src/chfactory.c 50 | endif 51 | 52 | # Required include directories 53 | LIBINC := $(CHIBIOS)/os/oslib/include 54 | 55 | # Shared variables 56 | ALLCSRC += $(LIBSRC) 57 | ALLINC += $(LIBINC) 58 | -------------------------------------------------------------------------------- /src/oslib/readme.txt: -------------------------------------------------------------------------------- 1 | All the code contained under ./os/lib are high level RTOS extension modules 2 | compatible with both RT and NIL. -------------------------------------------------------------------------------- /src/rt/include/ch.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/include/ch.h 22 | * @brief ChibiOS/RT main include file. 23 | * 24 | * @addtogroup kernel_info 25 | * @details This header includes all the required kernel headers so it is the 26 | * only kernel header you usually want to include in your application. 27 | * @details Kernel related info. 28 | * @{ 29 | */ 30 | 31 | #ifndef CH_H 32 | #define CH_H 33 | 34 | /** 35 | * @brief ChibiOS/RT identification macro. 36 | */ 37 | #define _CHIBIOS_RT_ 38 | 39 | /** 40 | * @brief Stable release flag. 41 | */ 42 | #define CH_KERNEL_STABLE 1 43 | 44 | /** 45 | * @name ChibiOS/RT version identification 46 | * @{ 47 | */ 48 | /** 49 | * @brief Kernel version string. 50 | */ 51 | #define CH_KERNEL_VERSION "6.1.3" 52 | 53 | /** 54 | * @brief Kernel version major number. 55 | */ 56 | #define CH_KERNEL_MAJOR 6 57 | 58 | /** 59 | * @brief Kernel version minor number. 60 | */ 61 | #define CH_KERNEL_MINOR 1 62 | 63 | /** 64 | * @brief Kernel version patch number. 65 | */ 66 | #define CH_KERNEL_PATCH 3 67 | /** @} */ 68 | 69 | /** 70 | * @name Constants for configuration options 71 | * @{ 72 | */ 73 | /** 74 | * @brief Generic 'false' preprocessor boolean constant. 75 | * @note It is meant to be used in configuration files as switch. 76 | */ 77 | #if !defined(FALSE) || defined(__DOXYGEN__) 78 | #define FALSE 0 79 | #endif 80 | 81 | /** 82 | * @brief Generic 'true' preprocessor boolean constant. 83 | * @note It is meant to be used in configuration files as switch. 84 | */ 85 | #if !defined(TRUE) || defined(__DOXYGEN__) 86 | #define TRUE 1 87 | #endif 88 | /** @} */ 89 | 90 | /* Configuration headers, checks and licensing restrictions.*/ 91 | #include "chconf.h" 92 | #include "chchecks.h" 93 | #include "chlicense.h" 94 | #include "chrestrictions.h" 95 | 96 | /* Early function prototype required by the following headers.*/ 97 | #ifdef __cplusplus 98 | extern "C" { 99 | #endif 100 | void chSysHalt(const char *reason); 101 | #ifdef __cplusplus 102 | } 103 | #endif 104 | 105 | /* Base kernel headers.*/ 106 | #include "chtypes.h" /* CHTODO: Rename and rework.*/ 107 | #include "chsystypes.h" 108 | #include "chlists.h" 109 | #include "chdebug.h" 110 | #include "chtime.h" 111 | #include "chalign.h" 112 | #include "chcore.h" 113 | #include "chtrace.h" 114 | #include "chtm.h" 115 | #include "chstats.h" 116 | #include "chschd.h" 117 | #include "chsys.h" 118 | #include "chvt.h" 119 | #include "chthreads.h" 120 | 121 | /* Optional subsystems headers.*/ 122 | #include "chregistry.h" 123 | #include "chsem.h" 124 | #include "chmtx.h" 125 | #include "chcond.h" 126 | #include "chevents.h" 127 | #include "chmsg.h" 128 | 129 | /* OSLIB.*/ 130 | #include "chlib.h" 131 | 132 | /* Headers dependent on the OSLIB.*/ 133 | #include "chdynamic.h" 134 | 135 | #endif /* CH_H */ 136 | 137 | /** @} */ 138 | -------------------------------------------------------------------------------- /src/rt/include/chdynamic.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/include/chdynamic.h 22 | * @brief Dynamic threads macros and structures. 23 | * 24 | * @addtogroup dynamic_threads 25 | * @{ 26 | */ 27 | 28 | #ifndef CHDYNAMIC_H 29 | #define CHDYNAMIC_H 30 | 31 | #if (CH_CFG_USE_DYNAMIC == TRUE) || defined(__DOXYGEN__) 32 | 33 | /*===========================================================================*/ 34 | /* Module constants. */ 35 | /*===========================================================================*/ 36 | 37 | /*===========================================================================*/ 38 | /* Module pre-compile time settings. */ 39 | /*===========================================================================*/ 40 | 41 | /*===========================================================================*/ 42 | /* Derived constants and error checks. */ 43 | /*===========================================================================*/ 44 | 45 | /* 46 | * Module dependencies check. 47 | */ 48 | #if CH_CFG_USE_WAITEXIT == FALSE 49 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_WAITEXIT" 50 | #endif 51 | 52 | #if CH_CFG_USE_REGISTRY == FALSE 53 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_REGISTRY" 54 | #endif 55 | 56 | #if (CH_CFG_USE_HEAP == FALSE) && (CH_CFG_USE_MEMPOOLS == FALSE) 57 | #error "CH_CFG_USE_DYNAMIC requires CH_CFG_USE_HEAP and/or CH_CFG_USE_MEMPOOLS" 58 | #endif 59 | 60 | /*===========================================================================*/ 61 | /* Module data structures and types. */ 62 | /*===========================================================================*/ 63 | 64 | /*===========================================================================*/ 65 | /* Module macros. */ 66 | /*===========================================================================*/ 67 | 68 | /*===========================================================================*/ 69 | /* External declarations. */ 70 | /*===========================================================================*/ 71 | 72 | /* 73 | * Dynamic threads APIs. 74 | */ 75 | #ifdef __cplusplus 76 | extern "C" { 77 | #endif 78 | #if CH_CFG_USE_HEAP == TRUE 79 | thread_t *chThdCreateFromHeap(memory_heap_t *heapp, size_t size, 80 | const char *name, tprio_t prio, 81 | tfunc_t pf, void *arg); 82 | #endif 83 | #if CH_CFG_USE_MEMPOOLS == TRUE 84 | thread_t *chThdCreateFromMemoryPool(memory_pool_t *mp, const char *name, 85 | tprio_t prio, tfunc_t pf, void *arg); 86 | #endif 87 | #ifdef __cplusplus 88 | } 89 | #endif 90 | 91 | /*===========================================================================*/ 92 | /* Module inline functions. */ 93 | /*===========================================================================*/ 94 | 95 | #endif /* CH_CFG_USE_DYNAMIC == TRUE */ 96 | 97 | #endif /* CHDYNAMIC_H */ 98 | 99 | /** @} */ 100 | -------------------------------------------------------------------------------- /src/rt/src/chstats.c: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file rt/src/chstats.c 22 | * @brief Statistics module code. 23 | * 24 | * @addtogroup statistics 25 | * @details Statistics services. 26 | * @{ 27 | */ 28 | 29 | #include "ch.h" 30 | 31 | #if (CH_DBG_STATISTICS == TRUE) || defined(__DOXYGEN__) 32 | 33 | /*===========================================================================*/ 34 | /* Module local definitions. */ 35 | /*===========================================================================*/ 36 | 37 | /*===========================================================================*/ 38 | /* Module exported variables. */ 39 | /*===========================================================================*/ 40 | 41 | /*===========================================================================*/ 42 | /* Module local types. */ 43 | /*===========================================================================*/ 44 | 45 | /*===========================================================================*/ 46 | /* Module local variables. */ 47 | /*===========================================================================*/ 48 | 49 | /*===========================================================================*/ 50 | /* Module local functions. */ 51 | /*===========================================================================*/ 52 | 53 | /*===========================================================================*/ 54 | /* Module exported functions. */ 55 | /*===========================================================================*/ 56 | 57 | /** 58 | * @brief Initializes the statistics module. 59 | * 60 | * @init 61 | */ 62 | void _stats_init(void) { 63 | 64 | ch.kernel_stats.n_irq = (ucnt_t)0; 65 | ch.kernel_stats.n_ctxswc = (ucnt_t)0; 66 | chTMObjectInit(&ch.kernel_stats.m_crit_thd); 67 | chTMObjectInit(&ch.kernel_stats.m_crit_isr); 68 | } 69 | 70 | /** 71 | * @brief Increases the IRQ counter. 72 | */ 73 | void _stats_increase_irq(void) { 74 | 75 | port_lock_from_isr(); 76 | ch.kernel_stats.n_irq++; 77 | port_unlock_from_isr(); 78 | } 79 | 80 | /** 81 | * @brief Updates context switch related statistics. 82 | * 83 | * @param[in] ntp the thread to be switched in 84 | * @param[in] otp the thread to be switched out 85 | */ 86 | void _stats_ctxswc(thread_t *ntp, thread_t *otp) { 87 | 88 | ch.kernel_stats.n_ctxswc++; 89 | chTMChainMeasurementToX(&otp->stats, &ntp->stats); 90 | } 91 | 92 | /** 93 | * @brief Starts the measurement of a thread critical zone. 94 | */ 95 | void _stats_start_measure_crit_thd(void) { 96 | 97 | chTMStartMeasurementX(&ch.kernel_stats.m_crit_thd); 98 | } 99 | 100 | /** 101 | * @brief Stops the measurement of a thread critical zone. 102 | */ 103 | void _stats_stop_measure_crit_thd(void) { 104 | 105 | chTMStopMeasurementX(&ch.kernel_stats.m_crit_thd); 106 | } 107 | 108 | /** 109 | * @brief Starts the measurement of an ISR critical zone. 110 | */ 111 | void _stats_start_measure_crit_isr(void) { 112 | 113 | chTMStartMeasurementX(&ch.kernel_stats.m_crit_isr); 114 | } 115 | 116 | /** 117 | * @brief Stops the measurement of an ISR critical zone. 118 | */ 119 | void _stats_stop_measure_crit_isr(void) { 120 | 121 | chTMStopMeasurementX(&ch.kernel_stats.m_crit_isr); 122 | } 123 | 124 | #endif /* CH_DBG_STATISTICS == TRUE */ 125 | 126 | /** @} */ 127 | -------------------------------------------------------------------------------- /src/rt/templates/meta/module.c: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chXxx.c 22 | * @brief XXX module code. 23 | * 24 | * @addtogroup XXX 25 | * @{ 26 | */ 27 | 28 | #include "ch.h" 29 | 30 | #if CH_CFG_USE_XXX || defined(__DOXYGEN__) 31 | 32 | /*===========================================================================*/ 33 | /* Module local definitions. */ 34 | /*===========================================================================*/ 35 | 36 | /*===========================================================================*/ 37 | /* Module exported variables. */ 38 | /*===========================================================================*/ 39 | 40 | /*===========================================================================*/ 41 | /* Module local types. */ 42 | /*===========================================================================*/ 43 | 44 | /*===========================================================================*/ 45 | /* Module local variables. */ 46 | /*===========================================================================*/ 47 | 48 | /*===========================================================================*/ 49 | /* Module local functions. */ 50 | /*===========================================================================*/ 51 | 52 | /*===========================================================================*/ 53 | /* Module exported functions. */ 54 | /*===========================================================================*/ 55 | 56 | /** 57 | * @brief XXX Module initialization. 58 | * @note This function is implicitly invoked on system initialization, 59 | * there is no need to explicitly initialize the module. 60 | * 61 | * @notapi 62 | */ 63 | void _xxx_init(void) { 64 | 65 | } 66 | 67 | /** 68 | * @brief Initializes a @p xxx_t object. 69 | * 70 | * @param[out] xxxp pointer to the @p xxx_t object 71 | * 72 | * @init 73 | */ 74 | void chXxxObjectInit(xxx_t *xxxp) { 75 | 76 | } 77 | 78 | #endif /* CH_CFG_USE_XXX */ 79 | 80 | /** @} */ 81 | -------------------------------------------------------------------------------- /src/rt/templates/meta/module.h: -------------------------------------------------------------------------------- 1 | /* 2 | ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio. 3 | 4 | This file is part of ChibiOS. 5 | 6 | ChibiOS is free software; you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | ChibiOS is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program. If not, see . 18 | */ 19 | 20 | /** 21 | * @file chXxx.h 22 | * @brief XXX Module macros and structures. 23 | * 24 | * @addtogroup XXX 25 | * @{ 26 | */ 27 | 28 | #ifndef CHXXX_H 29 | #define CHXXX_H 30 | 31 | #include "ch.h" 32 | 33 | #if CH_CFG_USE_XXX || defined(__DOXYGEN__) 34 | 35 | /*===========================================================================*/ 36 | /* Module constants. */ 37 | /*===========================================================================*/ 38 | 39 | /*===========================================================================*/ 40 | /* Module pre-compile time settings. */ 41 | /*===========================================================================*/ 42 | 43 | /*===========================================================================*/ 44 | /* Derived constants and error checks. */ 45 | /*===========================================================================*/ 46 | 47 | /*===========================================================================*/ 48 | /* Module data structures and types. */ 49 | /*===========================================================================*/ 50 | 51 | /*===========================================================================*/ 52 | /* Module macros. */ 53 | /*===========================================================================*/ 54 | 55 | /*===========================================================================*/ 56 | /* External declarations. */ 57 | /*===========================================================================*/ 58 | 59 | #ifdef __cplusplus 60 | extern "C" { 61 | #endif 62 | void chXxxInit(void); 63 | void chXxxObjectInit(xxx_t *xxxp); 64 | #ifdef __cplusplus 65 | } 66 | #endif 67 | 68 | /*===========================================================================*/ 69 | /* Module inline functions. */ 70 | /*===========================================================================*/ 71 | 72 | #endif /* CH_CFG_USE_XXX */ 73 | 74 | #endif /* CHXXX_H */ 75 | 76 | /** @} */ 77 | -------------------------------------------------------------------------------- /src/sam3x/cmparams_sam3x.h: -------------------------------------------------------------------------------- 1 | #ifndef cmparams_sam3x_h 2 | #define cmparams_sam3x_h 3 | 4 | /** 5 | * @brief Cortex core model. 6 | */ 7 | #define CORTEX_MODEL 3 8 | 9 | /** 10 | * @brief Floating Point unit presence. 11 | */ 12 | #define CORTEX_HAS_FPU 0 13 | 14 | /** 15 | * @brief Number of bits in priority masks. 16 | */ 17 | #define CORTEX_PRIORITY_BITS 4 18 | 19 | #if !defined(_FROM_ASM_) 20 | #include "Arduino.h" 21 | #define SVC_Handler svcHook 22 | #define PendSV_Handler pendSVHook 23 | 24 | /** \brief Structure type to access the Data Watchpoint and Trace Register (DWT). 25 | */ 26 | #ifndef DWT 27 | typedef struct 28 | { 29 | __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) Control Register */ 30 | __IO uint32_t CYCCNT; /*!< Offset: 0x004 (R/W) Cycle Count Register */ 31 | __IO uint32_t CPICNT; /*!< Offset: 0x008 (R/W) CPI Count Register */ 32 | __IO uint32_t EXCCNT; /*!< Offset: 0x00C (R/W) Exception Overhead Count Register */ 33 | __IO uint32_t SLEEPCNT; /*!< Offset: 0x010 (R/W) Sleep Count Register */ 34 | __IO uint32_t LSUCNT; /*!< Offset: 0x014 (R/W) LSU Count Register */ 35 | __IO uint32_t FOLDCNT; /*!< Offset: 0x018 (R/W) Folded-instruction Count Register */ 36 | __I uint32_t PCSR; /*!< Offset: 0x01C (R/ ) Program Counter Sample Register */ 37 | __IO uint32_t COMP0; /*!< Offset: 0x020 (R/W) Comparator Register 0 */ 38 | __IO uint32_t MASK0; /*!< Offset: 0x024 (R/W) Mask Register 0 */ 39 | __IO uint32_t FUNCTION0; /*!< Offset: 0x028 (R/W) Function Register 0 */ 40 | uint32_t RESERVED0[1]; 41 | __IO uint32_t COMP1; /*!< Offset: 0x030 (R/W) Comparator Register 1 */ 42 | __IO uint32_t MASK1; /*!< Offset: 0x034 (R/W) Mask Register 1 */ 43 | __IO uint32_t FUNCTION1; /*!< Offset: 0x038 (R/W) Function Register 1 */ 44 | uint32_t RESERVED1[1]; 45 | __IO uint32_t COMP2; /*!< Offset: 0x040 (R/W) Comparator Register 2 */ 46 | __IO uint32_t MASK2; /*!< Offset: 0x044 (R/W) Mask Register 2 */ 47 | __IO uint32_t FUNCTION2; /*!< Offset: 0x048 (R/W) Function Register 2 */ 48 | uint32_t RESERVED2[1]; 49 | __IO uint32_t COMP3; /*!< Offset: 0x050 (R/W) Comparator Register 3 */ 50 | __IO uint32_t MASK3; /*!< Offset: 0x054 (R/W) Mask Register 3 */ 51 | __IO uint32_t FUNCTION3; /*!< Offset: 0x058 (R/W) Function Register 3 */ 52 | } DWT_Type; 53 | #define DWT_CTRL_CYCCNTENA_Pos 0 /*!< DWT CTRL: CYCCNTENA Position */ 54 | #define DWT_CTRL_CYCCNTENA_Msk (0x1UL /*<< DWT_CTRL_CYCCNTENA_Pos*/) /*!< DWT CTRL: CYCCNTENA Mask */ 55 | 56 | #define DWT_BASE (0xE0001000UL) /*!< DWT Base Address */ 57 | #define DWT ((DWT_Type *) DWT_BASE ) /*!< DWT configuration struct */ 58 | #endif // DWT 59 | 60 | #ifndef __STATIC_FORCEINLINE 61 | #define __STATIC_FORCEINLINE __attribute__((always_inline)) static inline 62 | #endif 63 | 64 | #include "../CMSIS/core_cm3.h" 65 | #endif // _FROM_ASM_ 66 | 67 | #endif /* cmparams_sam3x_h */ 68 | 69 | /** @} */ 70 | -------------------------------------------------------------------------------- /src/sam3x/st_lld_sam3x.c: -------------------------------------------------------------------------------- 1 | #if defined(__SAM3X8E__) || defined(__SAM3X8H__) 2 | #include "../hal/osal.h" 3 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 4 | #if OSAL_ST_FREQUENCY != 1000 5 | #error "Due only supports CH_CFG_ST_FREQUENCY == 1000" 6 | #endif 7 | 8 | static int sysTickEnabled = 0; 9 | 10 | int sysTickHook(void) { 11 | if (sysTickEnabled) { 12 | CH_IRQ_PROLOGUE(); 13 | 14 | chSysLockFromISR(); 15 | chSysTimerHandlerI(); 16 | chSysUnlockFromISR(); 17 | 18 | CH_IRQ_EPILOGUE(); 19 | } 20 | return 0; 21 | } 22 | void st_lld_init(void) { 23 | sysTickEnabled = 1; 24 | } 25 | #endif // OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 26 | #endif // defined(__SAM3X8E__) || defined(__SAM3X8H__) -------------------------------------------------------------------------------- /src/samd/cmparams_samd.h: -------------------------------------------------------------------------------- 1 | #ifndef cmparams_samd_h 2 | #define cmparams_samd_h 3 | 4 | /** 5 | * @brief Cortex core model. 6 | */ 7 | #define CORTEX_MODEL 0 8 | 9 | /** 10 | * @brief Floating Point unit presence. 11 | */ 12 | #define CORTEX_HAS_FPU 0 13 | 14 | /** 15 | * @brief Number of bits in priority masks. 16 | */ 17 | #define CORTEX_PRIORITY_BITS 2 18 | 19 | #if !defined(_FROM_ASM_) 20 | #include "Arduino.h" 21 | #endif // _FROM_ASM_ 22 | 23 | #endif /* cmparams_samd_h */ 24 | 25 | /** @} */ 26 | -------------------------------------------------------------------------------- /src/samd/st_lld_samd.c: -------------------------------------------------------------------------------- 1 | #if defined(__SAMD21G18A__) || defined(__SAMD21J18A__) 2 | #include "../hal/osal.h" 3 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 4 | #if OSAL_ST_FREQUENCY != 1000 5 | #error "SAMD only supports CH_CFG_ST_FREQUENCY == 1000" 6 | #endif 7 | 8 | static int sysTickEnabled = 0; 9 | 10 | int sysTickHook(void) { 11 | if (sysTickEnabled) { 12 | CH_IRQ_PROLOGUE(); 13 | 14 | chSysLockFromISR(); 15 | chSysTimerHandlerI(); 16 | chSysUnlockFromISR(); 17 | 18 | CH_IRQ_EPILOGUE(); 19 | } 20 | return 0; 21 | } 22 | void st_lld_init(void) { 23 | sysTickEnabled = 1; 24 | } 25 | #endif // OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 26 | #endif // #if defined(__SAMD21G18A__) || defined(__SAMD21J18A__) -------------------------------------------------------------------------------- /src/teensy3/cmparams_teensy3.h: -------------------------------------------------------------------------------- 1 | #ifndef chparams_teensy3_h 2 | #define chparams_teensy3_h 3 | 4 | /** 5 | * @brief Cortex core model. 6 | */ 7 | #define CORTEX_MODEL 4 8 | 9 | /** 10 | * @brief Floating Point unit presence. 11 | */ 12 | #if defined(__MK20DX256__) || defined(__MK20DX128__) 13 | #define CORTEX_HAS_FPU 0 14 | #elif defined(__MK64FX512__) || defined(__MK66FX1M0__) 15 | #define CORTEX_HAS_FPU 1 16 | #else // CORTEX_HAS_FPU 17 | #error unknown Teensy 3 model 18 | #endif // CORTEX_HAS_FPU 19 | 20 | #define __FPU_PRESENT CORTEX_HAS_FPU 21 | 22 | /** 23 | * @brief Number of bits in priority masks. 24 | */ 25 | #define CORTEX_PRIORITY_BITS 4 26 | #define __NVIC_PRIO_BITS 4 27 | #if !defined(_FROM_ASM_) 28 | #define SVC_Handler svcall_isr 29 | #define PendSV_Handler pendablesrvreq_isr 30 | #undef __disable_irq 31 | #undef __enable_irq 32 | typedef enum IRQn { 33 | SVCall_IRQn = -5, /* 11 SV Call Interrupt */ 34 | DebugMonitor_IRQn = -4, /* 12 Debug Monitor Interrupt */ 35 | PendSV_IRQn = -2, /* 14 Pend SV Interrupt */ 36 | SysTick_IRQn = -1, /* 15 System Tick Interrupt */ 37 | } IRQn_Type; 38 | 39 | #include "../CMSIS/core_cm4.h" 40 | #endif // _FROM_ASM_ 41 | #endif // chparams_teensy3_h 42 | 43 | -------------------------------------------------------------------------------- /src/teensy3/st_lld_teensy3.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #if defined(__MK20DX256__) || defined(__MK20DX128__)\ 4 | || defined(__MK64FX512__) || defined(__MK66FX1M0__) 5 | 6 | #include "../hal/osal.h" 7 | 8 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 9 | #if 1000000 % OSAL_ST_FREQUENCY != 0 10 | #error "CH_CFG_ST_FREQUENCY is not obtainable due to integer rounding" 11 | #endif 12 | #if OSAL_ST_FREQUENCY > 10000 13 | #error "CH_CFG_ST_FREQUENCY is too high" 14 | #endif 15 | //------------------------------------------------------------------------------ 16 | static void tick() { 17 | CH_IRQ_PROLOGUE(); 18 | chSysLockFromISR(); 19 | chSysTimerHandlerI(); 20 | chSysUnlockFromISR(); 21 | CH_IRQ_EPILOGUE(); 22 | } 23 | //------------------------------------------------------------------------------ 24 | IntervalTimer chTimer; 25 | extern "C" void st_lld_init(void) { 26 | chTimer.begin(tick, 1000000/OSAL_ST_FREQUENCY); 27 | } 28 | #endif // OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 29 | #endif // defined(__MK20DX256__) || defined(__MK20DX128__) ... -------------------------------------------------------------------------------- /src/teensy4/cmparams_teensy4.h: -------------------------------------------------------------------------------- 1 | #ifndef chparams_teensy4_h 2 | #define chparams_teensy4_h 3 | 4 | /** 5 | * @brief Cortex core model. 6 | */ 7 | #define CORTEX_MODEL 7 8 | 9 | /** 10 | * @brief Floating Point unit presence. 11 | */ 12 | #if defined(__IMXRT1062__) 13 | #define CORTEX_HAS_FPU 1 14 | #else // CORTEX_HAS_FPU 15 | #error unknown Teensy 4 model 16 | #endif // CORTEX_HAS_FPU 17 | 18 | #define __FPU_PRESENT CORTEX_HAS_FPU 19 | 20 | /** 21 | * @brief Number of bits in priority masks. 22 | */ 23 | #define CORTEX_PRIORITY_BITS 4 24 | #define __NVIC_PRIO_BITS 4 25 | #if !defined(_FROM_ASM_) 26 | //#define SVC_Handler svcall_isr 27 | #define PendSV_Handler pendablesrvreq_isr 28 | #undef __disable_irq 29 | #undef __enable_irq 30 | typedef enum IRQn { 31 | SVCall_IRQn = -5, /* 11 SV Call Interrupt */ 32 | DebugMonitor_IRQn = -4, /* 12 Debug Monitor Interrupt */ 33 | PendSV_IRQn = -2, /* 14 Pend SV Interrupt */ 34 | SysTick_IRQn = -1, /* 15 System Tick Interrupt */ 35 | } IRQn_Type; 36 | 37 | #include "../CMSIS/core_cm7.h" 38 | #endif // !defined(_FROM_ASM_) 39 | #endif // chparams_teensy4_h 40 | 41 | -------------------------------------------------------------------------------- /src/teensy4/st_lld_teensy4.cpp: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | #if defined(__IMXRT1062__) 3 | #include "../hal/osal.h" 4 | //------------------------------------------------------------------------------ 5 | extern "C" void HardFault_Handler(void); 6 | extern "C" void BusFault_Handler(void); 7 | extern "C" void UsageFault_Handler(void); 8 | extern "C" void MemManage_Handler(void); 9 | extern "C" void SVC_Handler(void); 10 | static void setVectors() { 11 | _VectorsRam[11] = SVC_Handler; 12 | _VectorsRam[3] = HardFault_Handler; 13 | _VectorsRam[4] = BusFault_Handler; 14 | _VectorsRam[5] = UsageFault_Handler; 15 | _VectorsRam[6] = MemManage_Handler; 16 | } 17 | //------------------------------------------------------------------------------ 18 | #if OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 19 | #if 1000000 % OSAL_ST_FREQUENCY != 0 20 | #error "CH_CFG_ST_FREQUENCY is not obtainable due to integer rounding" 21 | #endif 22 | #if OSAL_ST_FREQUENCY > 10000 23 | #error "CH_CFG_ST_FREQUENCY is too high" 24 | #endif 25 | //------------------------------------------------------------------------------ 26 | static void tick() { 27 | CH_IRQ_PROLOGUE(); 28 | chSysLockFromISR(); 29 | chSysTimerHandlerI(); 30 | chSysUnlockFromISR(); 31 | CH_IRQ_EPILOGUE(); 32 | } 33 | //------------------------------------------------------------------------------ 34 | IntervalTimer chTimer; 35 | extern "C" void st_lld_init(void) { 36 | setVectors(); 37 | chTimer.begin(tick, 1000000/OSAL_ST_FREQUENCY); 38 | } 39 | #endif // OSAL_ST_MODE == OSAL_ST_MODE_PERIODIC 40 | //------------------------------------------------------------------------------ 41 | #if (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) 42 | #if 2000000 % OSAL_ST_FREQUENCY != 0 43 | #error "CH_CFG_ST_FREQUENCY is not obtainable due to integer rounding" 44 | #endif 45 | #if OSAL_ST_FREQUENCY > 1000000 46 | #error "CH_CFG_ST_FREQUENCY is too high" 47 | #endif 48 | #if (2000000/OSAL_ST_FREQUENCY) - 1 > 0xFFF 49 | #error "CH_CFG_ST_FREQUENCY is too low due to prescaler limit" 50 | #endif 51 | //------------------------------------------------------------------------------ 52 | static void tick() { 53 | CH_IRQ_PROLOGUE(); 54 | GPT2_SR |= GPT_SR_OF1; 55 | __DSB(); // DSB fix for ARM errata 838869 56 | chSysLockFromISR(); 57 | chSysTimerHandlerI(); 58 | chSysUnlockFromISR(); 59 | CH_IRQ_EPILOGUE(); 60 | } 61 | //------------------------------------------------------------------------------ 62 | // To ensure proper operations of GPT, the external clock input frequency 63 | // should be less than 1/4 of frequency of the peripheral clock (ipg_clk). 64 | // This means GPT_PR_PRESCALER24M must be greater than 4. 65 | extern "C" void st_lld_init(void) { 66 | setVectors(); 67 | CCM_CCGR0 |= CCM_CCGR0_GPT2_BUS(CCM_CCGR_ON) ; // enable GPT2 module 68 | GPT2_CR = 0; 69 | // Reduce input frequency to 2000000 MHz. 24 Mhz crystal prescale by 12. 70 | GPT2_PR = GPT_PR_PRESCALER24M(11) | ((2000000/OSAL_ST_FREQUENCY) - 1); 71 | GPT2_OCR1 = 0; 72 | GPT2_SR = 0x3F; // clear all prior status 73 | GPT2_IR = 0; 74 | // GPT Enable, Free-Run mode, enable 24MHz crystal, source 24MHz crystal. 75 | GPT2_CR = GPT_CR_EN | GPT_CR_FRR | GPT_CR_EN_24M | GPT_CR_CLKSRC(5); 76 | attachInterruptVector(IRQ_GPT2, tick); 77 | NVIC_ENABLE_IRQ(IRQ_GPT2); 78 | } 79 | #endif // (OSAL_ST_MODE == OSAL_ST_MODE_FREERUNNING) 80 | #endif // defined(__IMXRT1062__) -------------------------------------------------------------------------------- /src/teensy4/st_lld_teensy4.h: -------------------------------------------------------------------------------- 1 | #ifndef st_lld_teensy4_h 2 | #define st_lld_teensy4_h 3 | #include "Arduino.h" 4 | #include "ch.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | void st_lld_init(void); 10 | #ifdef __cplusplus 11 | } 12 | #endif 13 | /*===========================================================================*/ 14 | /* Driver inline functions. */ 15 | /*===========================================================================*/ 16 | 17 | /** 18 | * @brief Returns the time counter value. 19 | * 20 | * @return The counter value. 21 | * 22 | * @notapi 23 | */ 24 | static inline systime_t st_lld_get_counter(void) { 25 | return (systime_t)GPT2_CNT; 26 | } 27 | 28 | /** 29 | * @brief Starts the alarm. 30 | * @note Makes sure that no spurious alarms are triggered after 31 | * this call. 32 | * 33 | * @param[in] time the time to be set for the first alarm 34 | * 35 | * @notapi 36 | */ 37 | static inline void st_lld_start_alarm(systime_t time) { 38 | GPT2_OCR1 = (uint32_t)time; 39 | GPT2_SR |= GPT_SR_OF1; 40 | GPT2_IR = GPT_IR_OF1IE; 41 | } 42 | 43 | /** 44 | * @brief Stops the alarm interrupt. 45 | * 46 | * @notapi 47 | */ 48 | static inline void st_lld_stop_alarm(void) { 49 | GPT2_IR = 0; 50 | } 51 | 52 | /** 53 | * @brief Sets the alarm time. 54 | * 55 | * @param[in] time the time to be set for the next alarm 56 | * 57 | * @notapi 58 | */ 59 | static inline void st_lld_set_alarm(systime_t time) { 60 | GPT2_OCR1 = (uint32_t)time; 61 | } 62 | 63 | /** 64 | * @brief Returns the current alarm time. 65 | * 66 | * @return The currently set alarm time. 67 | * 68 | * @notapi 69 | */ 70 | static inline systime_t st_lld_get_alarm(void) { 71 | return (systime_t)GPT2_OCR1; 72 | } 73 | 74 | /** 75 | * @brief Determines if the alarm is active. 76 | * 77 | * @return The alarm status. 78 | * @retval false if the alarm is not active. 79 | * @retval true is the alarm is active 80 | * 81 | * @notapi 82 | */ 83 | static inline bool st_lld_is_alarm_active(void) { 84 | return (GPT2_IR & GPT_SR_OF1) != 0; 85 | } 86 | #endif /* st_lld_teensy4_h */ 87 | 88 | /** @} */ 89 | --------------------------------------------------------------------------------