ãããã人çã¯ã©ããªèšç»ã«å¯ŸããŠãç¬èªã®èª¿æŽãè¡ããé·ãéãã®æ¹åã«åãçµãããšã¯äžå¯èœã§ããã ãããã質åã¯æªè§£æ±ºã®ãŸãŸã§ãããä»ãããªãã®æéã®åŸãç§ã¯äž»é¡ã«æ»ããŸãã
ãããã«ããã1ã€ã®éèŠãªè³ªåãæªè§£æ±ºã®ãŸãŸã§ããã ç§ãã¡ã¯çãç°ãªãIDEãšããŸããŸãªããŒã«ãã§ãŒã³ã䜿çšããŠããŸãã 移æ€ããã»ã¹ã¯éåžžã«è€éã§ãã¿ã³ããªã³ãšã®ç¹å®ã®ãã³ã¹ãå¿ èŠã§ãã ããšãã°ã GCCã®ã¢ã»ã³ãã©ãŒã¯x86æ§æïŒ ATïŒTããããŸã ïŒããµããŒãããŠããªããããããã°ã©ããŒãããã§æåã«çŽé¢ããæãåºæ¬çãªåé¡ã¯ãArm mbedãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ãœãŒã¹ã³ãŒãã§ã®ã¢ã»ã³ãã©ãŒæ¿å ¥ã«å¯ŸããåãGCCã³ã³ãã€ã©ãŒã®ä¹±çšã§ãã
誰ããIARã䜿çšãã誰ããuVisionã䜿çšãã誰ããSublime Textã§æžã蟌ã¿ããããŠèª°ãïŒç§ã®ãããªïŒãCode :: Blocksã䜿çšããŸã ã 誰ããWindowsã䜿çšãã誰ããLinuxã䜿çšããŸãã åºå€§ããææ¡ããç解ã§ããªããã®ãåãå ¥ããããšã¯ã§ããŸãããåæã«ããªãã·ã§ã³ãèæ ®ããã«æ®ãããšã¯ã芳客ã®äžéšãæ®ãããšã§ãã
解決çã¯çªç¶çŸããéåžžã«ã·ã³ãã«ã§æ®éçãªãã®ã«ãªããŸããã
PlatformIO IDEã
PlatformIOã¯ãPythonã§èšè¿°ãããã¯ãã¹ãã©ãããã©ãŒã ããŒã«ãã§ãŒã³ã§ããããŠãŒã¶ãŒã®ãã·ã³ã«ååšããããšãããããå¯äžã®åææ¡ä»¶ã§ãïŒããŒãžã§ã³2.7以äžïŒã
ãã®ããã©ãŒãã³ã¹ãšäœ¿çšããããŒã«ã«ãããšã PlatformIO㯠ãæ°å¹Žåã«ãªãªãŒã¹ãããIDE MicroEJ StudioãæãåºããŸããããã®ãªãªãŒã¹ã§ã¯ãJavaã§ãã€ã¯ãã³ã³ãããŒã©ãŒã®ã³ãŒããæžãããšãã§ããŸããã ãã®åŸãMicroJVMïŒCã§èšè¿°ïŒãMKã«æ³šããããã®äžã§ã³ãŒããå®è¡ãããŸããã ããããåªäœã¯åºãé åžãããã倧è¡ã«è¡ããŸããã§ããã
PlatformIOã¯ãå€ãã®åºç¯ãªIDEããã³ã³ãŒããšãã£ã¿ãŒã®äžéšãšããŠäœ¿çšã§ããŸãã
- ã¢ãã
- ã¯ã©ã€ãªã³
- æ¥é£
- Emacs
- NetBeans
- Qt Creator ;
- åŽé«ãªããã¹ã
- VIM
- Visual Studio
- VSCodeãªã©
PlatformIOã®äž»ãªæ©èœã¯ãæ§æãã¡ã€ã«ãplatformio.iniãã®äœ¿çšã§ããããã¯ããããžã§ã¯ãã®ã¿ãŒã²ãããã©ãããã©ãŒã ã決å®ãããã®æ§æãã¡ã€ã«ã«ããèšè¿°ã«åŸã£ãŠã©ã€ãã©ãªãããŒãããäŸåé¢ä¿ãæ§ç¯ããããã«äœ¿çšãããŸãã
äž»ãªèŠçŽ ã¯PlatformIO IDEãšPlatformIO Coreã§ãã
2016幎ã PlatformIOã¯2016 IoT Awardsã§ãBest IoT SoftwareïŒToolsãã«ããããŒããããŸããã
ããã¯äžè¬çãªæŠèŠã§ãã 詳现ãªããã¥ã¡ã³ãã¯ãplatformio.orgãããžã§ã¯ãã®Webãµã€ããšããã¥ã¡ã³ãã®ã»ã¯ã·ã§ã³ã«ãããŸãã
ç§ãã¡ã®ã¿ã¹ã¯ã¯ãå¿ èŠãªéçºããŒã«ã確ç«ãããããžã§ã¯ããäœæãããã®äžã§äœããããããšã§ãã
ã¢ãã vs. VSã³ãŒã
ããŒã ããŒãžã«ã¯ã AtomãšVS Codeã® 2ã€ã®ãšãã£ã¿ãŒãããŠã³ããŒãçšã«æäŸãããŠããŸãã äž¡æ¹è©ŠããŠã¿ãŸããããããã«èšããŸããVSCodeã®æ¹ã䟿å©ã§ãã ã³ãŒãã«åºæ¬çãªé·ç§»ãããããã ãã®å Žåã ä»åŸã®å±æãè¿°ã¹ãŸããã©ã€ãã©ãªãšãœãŒã¹ã³ãŒãã®ãããžã§ã¯ãã§ã¯ã衚瀺ãããªãarm mbed osã¯ãã¹ãŠããŒã«ã«ãªããžããªã«ããããã main.cppãšããããžã§ã¯ãããªãŒã§äœæããä»ã®ãã¹ãŠã®ãã®ã®ã¿ã§ãã ãããã£ãŠãããã€ãã®å®£èšãã¯ã©ã¹ãšãã®ãªããžã§ã¯ããã¯ã©ã¹ã€ã³ã¿ãŒãã§ã€ã¹ã100ïŒ ç£èŠããå¿ èŠããããŸãã ãããã Atomã¯ãã®ãããªæ©äŒãæäŸããŸããïŒ ãŸãã Atomã䜿çšããå Žåã¯ãmbed osããã¥ã¡ã³ãã«æºè¶³ããã ãã§æžã¿ãŸãã åæããŸããããã¯äžäŸ¿ã§ãã
ãã®ããã VS Codeã«é©çšãããããã»ã¹ãããã«èª¿ã¹ãŸã ã 次ã®æé ãå®è¡ããå¿ èŠããããŸãã
- VS Codeãã€ã³ã¹ããŒã«ããŸãã
- PlatformIO IDEãã€ã³ã¹ããŒã«ããŸãã
- udevã«ãŒã«ãèšå®ããŸãïŒLinuxãŠãŒã¶ãŒã®å ŽåïŒ-å¿ èŠã§ã¯ãªããããããŸããããåŸã§æ€ åã«ããŠã³ã¹ããªãããã«ãäºé²çãªã¹ãã©ã€ããè¡ããŸãã
- ãããžã§ã¯ããäœæãããã®äžã«æå°éã®æ©èœãå«ããŸãã ããŒãäžã§ã¢ã»ã³ãã«ãããŒãããããã°ãããŠããããšã確èªããŠãã ããïŒOCD / GDBããµãŒããŒãšããŠäœ¿çšãããŸãïŒã
ãªã³ã¯ãã¯ãªãã¯ããç®çã®ã·ã¹ãã ã®ã€ã³ã¹ããŒã©ãŒãããŠã³ããŒãããåŸã VS Codeãã€ã³ã¹ããŒã«ããŸãã
ã€ã³ã¹ããŒã«åŸããšãã£ã¿ãŒãèµ·åããæ¡åŒµæ©èœããã«ãéããæ€çŽ¢ã«ãplatformioããšå ¥åããŸãã æåã®ãªãã·ã§ã³ã¯ã PlatformIO IDE ãããããã¢ããããŸãã ãã€ã³ã¹ããŒã«ããã¯ãªãã¯ããã€ã³ã¹ããŒã«ãå®äºããã®ãåŸ ã£ãŠããšãã£ã¿ãŒãåèµ·åããŸãã
LinuxãŠãŒã¶ãŒã¯ããããã¬ãŒãæ£åžžã«åäœããããã®udevã«ãŒã«ãããã«ã€ã³ã¹ããŒã«ã§ããŸãã ååãšããŠããããã¬ãŒã®éå§æã«ãã¿ãŒããã«ãã ãªã¢ãŒãéä¿¡ãšã©ãŒã ã¿ãŒã²ãããåæãããŸããããã¢ã«ãã£ãŠæ¥ç¶ããªã»ãããããŸããã ã
ã¿ãŒããã«ãéããŠæžã蟌ã¿ãŸãïŒ
sudo curl -fsSL https://raw.githubusercontent.com/platformio/platformio-core/develop/scripts/99-platformio-udev.rules > /etc/udev/rules.d/99-platformio-udev.rules
端æ«ã«ãPermission deniedããšè¡šç€ºããããã ãªã³ã¯ãããã¡ã€ã«ã99-platformio-udev.rulesããããŠã³ããŒããããã¡ã€ã«ãetc / udevã«åŒ·å¶çã«ã³ããŒããŸãã
sudo cp 99-platformio-udev.rules /etc/udev/rules.d/99-platformio-udev.rules
cpã³ãã³ãã®åŸã«ãã¡ã€ã«ãžã®ãã«ãã¹ãæå®ããå¿ èŠãããããšã«æ³šæããŠãã ããã .rulesãã¡ã€ã«ããã©ã«ããŒã«ããå ŽåïŒãããŠã³ããŒãããªã©ïŒãã¿ãŒããã«ã³ãã³ãã¯æ¬¡ã®ããã«ãªããŸãã
sudo cp ~/Downloads/99-platformio-udev.rules /etc/udev/rules.d/99-platformio-udev.rules
次ã«è¡ãããšïŒ
sudo usermod -a -G dialout $USER sudo usermod -a -G plugdev $USER
ããã§ã $ USERã¯ãŠãŒã¶ãŒåã§ãã ããšãã°ããã®ãµããã£ã¢ããããŸãã
ãã®åŸãçºçããå¯èœæ§ãããå Žåããããã¬ãŒã®ãã¹ãŠã®åé¡ã解決ããå¿ èŠããããŸãã
ç°å¢ããã³ããŒã«ã«ãªããžããªarm mbed os
ç°å¢ãã€ã³ã¹ããŒã«ããåŸãããŒã«ã«arm mbed osãªããžããªã®å ŽæïŒæ¢ã«è¿°ã¹ãããã«ããããžã§ã¯ãããªãŒã«ã¯è¡šç€ºãããŸããïŒããã¹ãŠã®mbed osãœãŒã¹ã®å Žæãããã³ã³ã³ãã€ã«ããããããžã§ã¯ãã®ä¿åå Žæãç解ããããšã¯äžèŠã§ãã
ã€ã³ã¹ããŒã«ããã»ã¹äžã«ã platformIOã¯ããã¹$ HOME / .platformio / packagesã«æ²¿ã£ãŠããŒã«ã«arm mbedãªããžããªãŒïŒããã³ããã ãã§ã¯ãªãïŒããããã€ããŸãã ããã§ã¯ãããšãã°ãarm mbedã
ãã¡ãŒã ãŠã§ã¢ãã¡ã€ã«ãšããªã³ã³ãã€ã«ããããœãŒã¹ã¯ããããžã§ã¯ããã©ã«ããŒã«çŽæ¥é 眮ãããŸãã
ãããä¿åãããŠããå Žæã«ã€ããŠç¥ãå¿ èŠãããã®ã¯ããã ãã§ãã ãããžã§ã¯ãã®äœæã«çŽæ¥é²ã¿ãŸãã
ãããžã§ã¯ããäœæããŸãã
äœæäžã®ãããžã§ã¯ãã«ã€ããŠç°¡åã«èª¬æããŸãã æãããªçç±ããããµããŒããããŠããARMãªã³ã©ã€ã³IDEã«å«ãŸããŠããªãããŒããã€ãŸãSTM32F4DISCOVERYã®ãããžã§ã¯ããäœæããããšã«ããŸããã
çµã¿èŸŒã¿ã·ã¹ãã ã®äžçã§ã¯ãç¹æ» ããLEDã䜿çšãããã¢ã³ã¹ãã¬ãŒã·ã§ã³ãããžã§ã¯ããäœæããã®ãäžè¬çã§ãã ç§ãã¡ã¯ãããããŸãã-ããã¯ãã§ã«åçŽã§é¢çœããªãã§ãã PlatformIO㯠ã cmsis ã hal ã rtosãªã©ã®ããã€ãã®ã¿ã€ãã®ãããžã§ã¯ããæå³ããŸãã çŸåšarm mbed osãã€ãŸããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«ã€ããŠè©±ããŠããã®ã§ã rtoså°çšã®ãããžã§ã¯ããäœæããŸãã
ãããžã§ã¯ãã§ã¯ã3ã€ã®ã¿ã¹ã¯ïŒã¿ã¹ã¯ïŒãäœæããŠå®è¡ããŸãïŒæåã¯floatåã®é åãä¹ç®ãïŒCortex-M4Fããã»ããµããããããFPUã䜿çšããŸãïŒã2çªç®ã®ã¿ã¹ã¯ã¯... LEDãç¹æ» ïŒ=ïŒãã3çªç®ã¯æ±ºå®ããŸãCPU䜿çšç
è¡ããŸãããã
VS CodeãéããŸã ã æåã®ã¹ãããã¯ã PIOããŒã ãŠã£ã³ããŠãéãããšã§ãã ã æ°èŠãããžã§ã¯ã ããéžæããŸãã
ã ãããžã§ã¯ããŠã£ã¶ãŒã ããŠã£ã³ããŠã§ããããžã§ã¯ãã®ååãæå®ãïŒãarmmbed_F407_CPU_usageãã«ããŠãã ããïŒãã ããŒã ãããããããŠã³ãªã¹ãã§ããŒããéžæããŸãã èäœæš©ããŒãçšã®ãœãããŠã§ã¢ãäœæãããšãã«çŽ æã䜿çšããããšãèšç»ããŠããèªè ã®å ŽåïŒã¯ããç¹å®ã®ããŒãã«ãã€ã³ãããŸããããã¹ãŠã®èãšåšèŸºæ©åšãåæ§æã§ããŸãã 次ã«ãç§ã¯ããã«ã€ããŠããã€ãã®èšèãèšããŸãããæ¥ãã§æã£ãŠã¯ãããŸããã ã ããã ããŒã ã
STM32F4DISCOVERYãéžæããã ãã¬ãŒã ã¯ãŒã¯ ããŠã£ã³ããŠã«ç§»åããŸãã ããã«ã¯ããã€ãã®ãªãã·ã§ã³ããããŸãã
arm mbed osã®äœ¿çšã«åæãããããããã§ã¯ã mbed ããªãã·ã§ã³ãéžæããããšã¯æããã§ãã ã çµäº ããã¯ãªãã¯ããŸã-å®äºã ãŠã£ã¶ãŒãã¯å°ãèããŠãæ°ããäœæãããããžã§ã¯ãã®ç©ºçœãéããŸãã ãããèŠãŠãã ããã
åè¿°ããããã«ããããžã§ã¯ãã«ã¯ããã©ã«ãã®ãã©ã«ããŒã2ã€ãããããŸãããlib ïŒç©ºïŒãšsrcã§ãåäžã®main.cppãã¡ã€ã«ãå«ãŸããŠããŸãã ããã§ã¯ãœãŒã¹ã³ãŒãå šäœã衚瀺ãããªãããšãæãåºããŠãã ããã ããã§ããarm mbed osã®ãã¹ãŠã®æ©èœã䜿çšã§ããŸãã rtosã䜿çšããã«ã¯ãã platformio.ini ããã¡ã€ã«ã«ãã«ããã©ã°ãè¿œå ããå¿ èŠããããŸãã
build_flags =-DPIO_FRAMEWORK_MBED_RTOS_PRESENT
äžè¬ã«ãæ§æãã¡ã€ã«ã¯åå¥ã«èæ ®ããå¿ èŠããããŸãã ãã®ã¢ãããŒãã¯ã .cfgæ§æãã¡ã€ã«ã§Texas Instrumentsã® TIRTOS / SYSBIOSãæãåºããŸããããã¢ãŒã mbedã§ã¯ãã¹ãŠãã¯ããã«ç°¡åã§ãã æ§æãã¡ã€ã«ã§ã¯ãããŒããŠã§ã¢ãªãœãŒã¹ãããã©ã°ã®äœæãšãããã°ãŸã§ãå€ãã宣èšã§ããŸãã ããšãã°ãæãåçŽãªæ§æãã¡ã€ã«ã®æ§æã¯æ¬¡ã®ãšããã§ãã
[env:disco_f407vg] platform = ststm32 framework = mbed board = disco_f407vg
ãããŠãããã¯æçµåœ¢åŒã®äŸã®èšå®ãã¡ã€ã«ã§ãïŒ
[env:disco_f407vg] platform = ststm32 board = disco_f407vg framework = mbed build_flags = -DPIO_FRAMEWORK_MBED_RTOS_PRESENT -O1 -Wl,-u_printf_float -D std=gnu99 -fno-builtin-printf -fexceptions -fpermissive debug_flags = -D DEBUG=1 -DDEBUG_LEVEL=DEBUG_NONE monitor_baud = 115200
ã§ããããããªãã®äœæã«åŠã¶ã¹ãããšããããŸãã
ãã®ãããå¿ èŠãªåœ¢åŒã§ãããžã§ã¯ããå°å ¥ãå§ããŸãã
ã³ãŒãããããã¯åäœã§æäŸããã³ãŒãã§äœãèµ·ãã£ãŠããã®ãã説æããŸãã éå§ããã«ã¯ããœãŒã¹ã«ããããŒãã¡ã€ã«ã mbed.h ããšã rtos.h ããå«ããå¿ èŠããããŸãã çç±ã¯æããã ãšæããŸãã
ã¡ã€ã³é¢æ°ã¯æ¬¡ã®åœ¢åŒãåããŸãã
/**************************************************************************/ int main (void) { Thread thread0; Thread thread1; Thread thread2; Thread::attach_idle_hook (&sleeping_sun); thread0.start (&ledblink); thread1.start (&cpu_usage); thread2.start (&math_thread); while (true) { } } /**************************************************************************/
æåã«ãã Thread ãã¯ã©ã¹ã®ãªããžã§ã¯ããã€ãŸãæ¬è³ªçã«ãç¹å®ã®æ©èœãæäŸããã¿ã¹ã¯ïŒTaskãThreadïŒãäœæããŸãã
誰ããæ°ä»ããå Žåã次ã®è¡ã衚瀺ãããŸã
Thread::attach_idle_hook (&sleeping_sun);
ããã¯ã ã¢ã€ãã« ãã¿ã¹ã¯ã§ããã€ãŸããåªå 床ã®äœãã¿ã¹ã¯ã§ããéåžžã®åªå 床ã®é«ãã¿ã¹ã¯ãå®äºããåŸãããã»ããµãæ®ã£ãŠããæéã ãå²ãåœãŠãããŸãã ããŠãç§ãã¡ã®å Žåããã®ã¿ã¹ã¯ã¯ããã»ããµã«æéããªãããç©ºè ¹ã®ãŸãŸã§ãã ã»ãã®äžäŸãšããŠããã«æã£ãŠããŸããã
次ã«ãã start ãã¡ãœããã䜿çšããŠã¿ã¹ã¯ãé çªã«éå§ããã¿ã¹ã¯ã®æ©èœãã€ãŸãããã»ã¹ã§å®è¡ããããã®ãžã®åç §ãæž¡ããŸãã ããã¯ã ledblink ã-shmorgalkaãã cpu_usage ã -CPUè² è·ã®èšç®ãããã³æãé£ãã-ã math_thread ããé åã®ä¹ç®ãå®è¡ããŸãã
åã¿ã¹ã¯ãèŠãŠã¿ãŸãããã ã ledblink ãã§ã¯ããã¹ãŠãç°¡åã§ãã
/**************************************************************************/ void ledblink (void) { while (true) { myled1 = !myled1; Thread::wait (500); } } /**************************************************************************/
LEDã®åºåç¶æ ãå察ã«äº€äºã«å€æŽãã500ããªç§ã®é 延ãçºçãããŸãã ãšããã§ã宣èšã myled1 ãã¯æ¬¡ã®ããã«ãªããŸãã
DigitalOut myled1(LED1);
ããã§cpu_usageã¿ã¹ã¯ã«æ³šç®ããŸãããã
/**************************************************************************/ void cpu_usage (void) { Timer tim; CPU_Usage cpu(tim, 1); cpu.working(); uint8_t value = 0; while (true) { cpu.delay(0.25); value = cpu.update(); pc.printf("CPU %i", value); } } /**************************************************************************/
ããã®ãã¹ãŠã¯ãããå°ãè€éã§ãã äžè¬ã«ãèªè»¢è»ãçºæããªãããã«ãç§ã¯2014幎ã«ã¢ãŒã mbedã®ããã«CPU_UsageãšåŒã°ããé¢çœãç·ãæžããæ¢è£œã®ã©ã€ãã©ãªã䜿çšããŸããã ããªãã¯ãããåç §ããããšãã§ããŸããããã®ç°¡åãªèª¬æããããŸãã ã©ã€ãã©ãªã¯ã¿ã€ããŒã䜿çšããŸãïŒ Timer timã¯ã©ã¹ã®ãªããžã§ã¯ãã衚瀺ãããŸãïŒã æåã«ã cpu ãã¯ã©ã¹ã®ã³ã³ã¹ãã©ã¯ã¿ãŒãåŒã³åºããã次ã«ã working ãïŒ äœæ¥ã®éå§ïŒã¡ãœãããããã³ã update ãã¡ãœãããããã»ããµãŒè² è·ã®å²åãèšç®ããŸãã
ããããä»ããããã¢ã³ã¹ãã¬ãŒã·ã§ã³ããã®ã«æé©ãªææã§ãã ãããã°ã¢ãŒãããç»é¢ã衚瀺ããŸãã
å·Šäžã®å€ã value ã= 95ã衚瀺ãããŸããããã¯ããã®æç¹ã§ããã»ããµã®95ïŒ ãããŒããããããšãæå³ããŸãã äžè¬ã«ãå®éšã®çµæã«ãããšãåãã¿ã¹ã¯ãå®è¡ãããšãã®ãã®å€ã¯ã87ã98ïŒ ã§å€åããŸããã
ãšããã§ã端æ«ããã§ã¯ãªããããã¬ããã®ã¹ã¯ãªãŒã³ã·ã§ããã衚瀺ããŠããã®ã¯ãªãã§ããïŒ ç°¡åã§ããæå ã«UART-USBã¢ããã¿ãŒããªããããUARTã¿ãŒããã«ã䜿çšã§ããŸããïŒãã®é¢æ°ã pc.printfïŒïŒ ãã¯åãªãUARTåºåã§ãããpcã¯Serialã¯ã©ã¹ã®ãªããžã§ã¯ãã§ãïŒã
ãããŠãããã»ããµã«ãšã£ãŠæåŸã§æãé£ãããåãªã®ã¯math_threadã¿ã¹ã¯ã§ãã ãããèŠãŠã¿ãŸããã-æåã«ãããåºãã®ã圢ã§ã次ã«ã¢ãŒã mbedãã³ã§ããå°ãã
/**************************************************************************/ void math_thread(void) { volatile uint16_t rand_num_dmassi1 = 0; volatile uint16_t rand_num_dmassi2 = 0; float result; while (true) { rand_num_dmassi1 = RandomMassIndex(); rand_num_dmassi2 = RandomMassIndex(); result = (DigMas1[rand_num_dmassi1]*DigMas2[rand_num_dmassi2]); } } /**************************************************************************/
ããã»ããµã®ããŒãæ¹æ³ãæãã€ãããšããé åã®ä¹ç®ãããã«æãæµ®ãã³ãŸããã ãããŠãç§ããªã¢ãŒãã§äœããããŠããïŒãããŠäžçäžã®ååã§ãªã¢ãŒãã§ãããã°ããŠããïŒé¡§å®¢ãSkypeã§ç§ã«å«ãã ãšãã®ç¶æ³ãæãåºããŸããïŒã ããªãã¯ããã°ã©ãã§ããããã»ããµãããŒãããŠãã ããïŒ åœŒã¯ãšãŠãå¯ãã§ããæããããŠãã ããïŒ ã MCUãå ç±ããŸãã =ïŒ
ãããŠãé åãé çªã«ä¹ç®ããã®ã§ã¯ãªããä¹±æ°ãžã§ãã¬ãŒã¿ã䜿çšããŠã€ã³ããã¯ã¹ãçæããããšã«ããŸããã ãããŠãããã§ããçŽ æŽãããæ°åŠã©ã€ãã©ãªãŒalglibã圹ç«ã¡ãŸãã ã ããã¯æ°åŠçæ©èœã®å·šå€§ãªå±€ãã«ããŒããŠãããããªãã¯ããã§ãããåãããšãã§ããŸã ã ãã¡ãããæ©èœã®å·šå€§ãªå±€å šäœã䜿çšããããã§ã¯ãããŸããããå°ããªéšåã䜿çšããŸãã
補åã®ã¿ã¹ã¯èšç®æ©ãèŠããšãããã«ã RandomMassIndexïŒïŒ ããšãã2ã€ã®åŒã³åºãããããŸãã ããã¯ãç¯å²å ã®å€ãè¿ãåãªãé¢æ°ã§ãïŒç¯å²ã¯é åèŠçŽ ã®æ°ã«ãã£ãŠå¶éãããŸãïŒã
/**************************************************************************/ uint16_t RandomMassIndex (void){ uint16_t randval; alglib_impl::ae_state mystate; randval = alglib_impl::ae_randominteger(18, &mystate); return randval; } /******************************END_OF_FILE*********************************/
ããã§ç§ãã¡ã¯äœãããŠããŸããã ãŸããã ae_state ãæ§é ãåæåãïŒå éšã®ããŒãºã«äœ¿çšãããŸãïŒã次ã«ã ae_randominteger ãã¡ãœãããåŒã³åºããŸãããã®ã¡ãœããã«æ§é ãžã®ãªã³ã¯ãæž¡ããçæãããä¹±æ°ãååŸããç¯å²ãååŸããŸãïŒ0..18ããããŸãïŒ ïŒ ãã®æ°ã¯ãçæãããæ倧å€ãããå°ããããå¿ èŠããããŸãã é åèŠçŽ ã®æ°ã¯20ïŒ0..19ïŒã§ãæ倧æ°ã¯19ã§ãããããã£ãŠãå¢çåŒæ°ãšããŠã®18ã¯ãç§ãã¡ã«ãŽã£ããã§ãã
ãšããã§ããã®é¢æ°ãåŒã³åºããçµæãèŠãããšãã§ããŸãã
å·Šäžã¯ãã©ã³ãã ã«çæãããé åã®ã€ã³ããã¯ã¹rand_num_dmassi1ãšrand_num_dmassi2ã§ãã 13ããã³12ã
å¥ã®ãµã€ã¯ã«ãé²ããŠãå€åãããã©ããã確èªããŸãããã
11ããã³17ãå€æŽã ã ãããã¹ãŠãåäœããŸãã
ãªãœãŒã¹åæïŒç¹ã«ãããã»ããµæéã®äœ¿çšïŒã«ã€ããŠè©±ãå§ããã®ã§ãå°ãã¡ã¢ãªæéãšã¿ã¹ã¯ã®åªå é äœããšããŸãã Arm mbed osã¯ããããã®ããŒãºã«åãããŠrtos :: Threadã¯ã©ã¹å šäœãå®è£ ããŸãã
次ã®è¡ãmath_threadã¿ã¹ã¯ã«çŽæ¥è¿œå ããŸãã
osThreadId_t this_thread_id; volatile uint32_t this_thread_stacksize; volatile osPriority_t this_thread_priority; this_thread_id = osThreadGetId(); this_thread_stacksize = osThreadGetStackSize(this_thread_id); this_thread_priority = osThreadGetPriority(this_thread_id);
ããïŒããã³äžèšïŒã§ã¯ãå€æ°ã远跡ã§ããããã«volatileããŒã¯ãŒãã䜿çšããŸããã
ãã®ãããæåã«å°æ¥ã®äœ¿çšã®ããã«ã¿ã¹ã¯IDãååŸããŸãã 次ã«ãã¡ãœãããåŒã³åºããŠã¿ã¹ã¯ã¹ã¿ãã¯ãšãã®åªå 床ã決å®ããŸãã åªå 床ã¯å€åºå ã§å€æŽã§ããŸã-äžéšã®ã¢ããªã±ãŒã·ã§ã³ã§ã¯ãããå¿ èŠã§ãã
èŠãŸãã
ã¿ã¹ã¯ã¹ã¿ãã¯ã®ãµã€ãºã¯4096ãã€ãã§ãããåªå 床ã¯osPriorityNormalã§ããããšãããããŸãã éåžžã®åªå 床ã
ããã«ããŠãŒã¶ããªãã£ã®çšåºŠãæªäœ¿çšããã³äœ¿çšæžã¿ã¹ã¿ãã¯ã®ãµã€ãºãè©äŸ¡ã§ããŸãã ã¡ã€ã³ã«çŽæ¥è¿œå ïŒ
volatile uint32_t threads_stack; volatile uint32_t threads_max_stack; volatile uint32_t free_stack; volatile uint32_t used_stack;
ãããŠãã¿ã¹ã¯ãéå§ããåŸïŒ
threads_stack = thread0.stack_size(); threads_stack = thread1.stack_size(); threads_stack = thread2.stack_size(); threads_max_stack = thread0.max_stack(); threads_max_stack = thread1.max_stack(); threads_max_stack = thread2.max_stack(); free_stack = thread0.free_stack(); free_stack = thread1.free_stack(); free_stack = thread2.free_stack(); used_stack = thread0.used_stack(); used_stack = thread1.used_stack(); used_stack = thread2.used_stack();
ããã§ã¯4ã€ã®ã¡ãœãããåŒã³åºãããŸãã ã Stack_sizeïŒïŒ ãã¯ã¿ã¹ã¯ã¹ã¿ãã¯ã®ãµã€ãºãè¿ããŸãïŒå°ãåã«æšå®ãããã®ãšåæ§ïŒãã max_stackïŒïŒ ãã¯å®è¡ããã»ã¹ã§äœ¿çšãããæ倧ãµã€ãºãè¿ããã free_stackïŒïŒ ãã¯ç©ºãé åã®ãµã€ãºãè¿ããã used_stackïŒïŒ ã-䜿çšãµã€ãºã æ»ãå€ã¯ãã€ãåäœã§ãã 3ã€ã®ã¿ã¹ã¯ãã¹ãŠã§ããããã®å€ã¯åãã«ãªããŸãã
ãããã¬ãŒ
ã芧ã®ãšããã4096ãã€ãããããªãé¢ããŠããŸã-64ãã€ãã®ã¿ã§ããŸã 4032ãã€ãã®åšåº«ããããŸãã
ããããç§ãã¡ã¯å®éšãšåæã§çµããã§ããã-ç§ã¯ãã§ã«ãããããŠããŸãã
ã¯ããèäœæš©æ²ç€ºæ¿ã«ã€ããŠä»ã«èšãããããšã¯ãããŸããã ä»ã誰ããèšãããšãã§ããã圌ãã¯èšãã圌ã¯F4Discoveryãåããããã楜ããã§éãã ããç§ã¯äžè¬ã«èªå®¶è£œã®ããŒããæã£ãŠããŸãããããŠLEDã¯äžè¬ã«ä»ã®è¶³ã«æãããŸãããããŠäžè¬ã«ãç§ã¯ããã«SPIãäžãããã§ãã ãã®ããã ã¢ãŒã ä»ããªããžããªã®ã targets ããã©ã«ããŒïŒéåžžã«ç¹å®ã®MCUãããã«éžæããŸã-ãããã¯æãïŒãåãã€ã¯ãã³ã³ãããŒã©ãŒã®ãã£ã¬ã¯ããªã«ã¯ãã PinNames.h ããã PeripheralPins.h ããã PeripheralNames ããšããååã®çŽ æŽããããªãŒããŒãããŸã.h ãã ãããã®ãã¡ã€ã«ãç·šéããããšã«ãããåšèŸºæ©åšãè¿œå /ç·šé/åé€ã§ããŸãã
ããããããããç§ã¯åæ¢ããŸãã arm mbedã®ããŸããŸãªã¢ããªã±ãŒã·ã§ã³ïŒértosãå«ãããã¢ã¡ã¿ã«ã®ã¿ãå«ãïŒã®ãã®ä»ã®äŸã¯ã ãã¡ãã®ã¢ãŒã«ã€ãã§è€è£œãŸãã¯ããŠã³ããŒãã§ããŸã ã
äœæãããµã³ãã«ãå«ãè³æïŒGoogleãã©ã€ãïŒ ãžã®ãªã³ã¯ãæ·»ä»ãããã¿ãã¬ã®äžã«å®å šãªãœãŒã¹ã³ãŒããé 眮ããŠãå šäœåãå®æãããŸãã ã©ã¡ãããšããã°ãsubdia.subdia @ gmail.comãžããããã
main.cpp
#include "mbed.h" #include "rtos.h" #include "CPU_Usage.h" #include "alglibmisc.h" #include "ap.h" DigitalOut myled1(LED1); DigitalOut myled2(LED2); Timer tim; CPU_Usage cpu(tim, 1); Serial pc(USBTX,USBRX,9600); #define PRETTY_ENOUGH 20 float DigMas1[PRETTY_ENOUGH] = {0.1234, 1.1234, 2.1234, 3.1234, 4.1234, 5.1234, 6.1234, 7.1234, 8.1234, 9.1234, 10.1234, 11.1234, 12.1234, 13.1234, 14.1234, 15.1234, 16.1234, 17.1234, 18.1234, 19.1234}; float DigMas2[PRETTY_ENOUGH] = {0.5678, 1.5678, 2.5678, 3.5678, 4.5678, 5.5678, 6.5678, 7.5678, 8.5678, 9.5678, 10.5678, 11.5678, 12.5678, 13.5678, 14.5678, 15.5678, 16.5678, 17.5678, 18.5678, 19.5678}; uint16_t RandomMassIndex (void); /**************************************************************************/ void math_thread(void) { volatile uint16_t rand_num_dmassi1 = 0; volatile uint16_t rand_num_dmassi2 = 0; float result; osThreadId_t this_thread_id; volatile uint32_t this_thread_stacksize; volatile osPriority_t this_thread_priority; while (true) { rand_num_dmassi1 = RandomMassIndex(); rand_num_dmassi2 = RandomMassIndex(); result = (DigMas1[rand_num_dmassi1]*DigMas2[rand_num_dmassi2]); this_thread_id = osThreadGetId(); this_thread_stacksize = osThreadGetStackSize(this_thread_id); this_thread_priority = osThreadGetPriority(this_thread_id); } } /**************************************************************************/ void cpu_usage (void) { uint8_t value = 0; while (true) { cpu.delay(0.25); value = cpu.update(); pc.printf("CPU %i", value); } } /**************************************************************************/ void ledblink (void) { while (true) { myled1 = !myled1; Thread::wait (500); } } /**************************************************************************/ void sleeping_sun(void) { return; } /**************************************************************************/ int main (void) { Thread thread0; Thread thread1; Thread thread2; volatile uint32_t threads_stack; volatile uint32_t threads_max_stack; volatile uint32_t free_stack; volatile uint32_t used_stack; Thread::attach_idle_hook (&sleeping_sun); thread0.start (&ledblink); thread1.start (&cpu_usage); thread2.start (&math_thread); threads_stack = thread0.stack_size(); threads_stack = thread1.stack_size(); threads_stack = thread2.stack_size(); threads_max_stack = thread0.max_stack(); threads_max_stack = thread1.max_stack(); threads_max_stack = thread2.max_stack(); free_stack = thread0.free_stack(); free_stack = thread1.free_stack(); free_stack = thread2.free_stack(); used_stack = thread0.used_stack(); used_stack = thread1.used_stack(); used_stack = thread2.used_stack(); cpu.working(); while (true) { } } /**************************************************************************/ uint16_t RandomMassIndex (void){ uint16_t randval; alglib_impl::ae_state mystate; randval = alglib_impl::ae_randominteger(18, &mystate); return randval; } /******************************END_OF_FILE*********************************/
ãæž èŽããããšãããããŸããããã¹ãŠã®è¯ãäžæ¥ãšè¯ãæ°åã