æçš¿è ïŒNikolai KhabarovãEmbedded Expert DataArtãã¹ããŒãããŒã ãã¯ãããžãŒãšãã³ãžã§ãªã¹ã
ãã®èšäºã§ã¯ãææ°ã®Linux ARM ARMããã»ããµçšã®éåžžã®PythonãŠãŒã¶ãŒç©ºéã¢ããªã±ãŒã·ã§ã³ãäœæããŠãããŒãã®çµè«ã«åºã¥ããŠè€éãªãã«ã¹ã·ãŒã±ã³ã¹ãçæããæ¹æ³ã説æããŸãã ã¢ã€ãã¢ã®æ¬è³ªã¯ãããã»ããµã®DMAã¢ãžã¥ãŒã«ã䜿çšããŠãGPIOã®ã¡ã¢ãªå ã®äºåã«æºåããããããã¡ããæéå ã«é«ã粟床ã§ã³ããŒããããšã§ãã
ã¹ãããã³ã°ã¢ãŒã¿ãŒãªã©ã®è€éãªãã«ã¹ã·ãŒã±ã³ã¹ãçæããå¿ èŠãããå Žåãéåžžãç¹å¥ãªãªã¢ã«ã¿ã€ã ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ãã€ã³ã¹ããŒã«ãããŠãããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ããŸã£ãããªããå€ãè¯ãã·ã³ãã«ãªãã€ã¯ãã³ã³ãããŒã©ãŒã䜿çšããŸãã ãã®å Žåã®å®è£ ã¯ãããããC ++ã§æžãããŠããŸãã çŸåšãããã»ããµã¯ã¯ããã«é²æ©ããŠãããããã©ãŒãã³ã¹ããã¹ãŠã®ã€ã³ãã©ã¹ãã©ã¯ãã£ããã³ãœãããŠã§ã¢ã§Linuxãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã䜿çšã§ããããšãPythonãªã©ã®é«ã¬ãã«ããã°ã©ãã³ã°èšèªãªã©ãå€ãã®å©ç¹ããããŸãã ããã§ããææ°ã®ãã€ã¯ãã³ã³ãããŒã©ãŒã¯ãååãšããŠãè€éãªãã€ã¯ãã³ã³ãããŒã©ãŒã䜿çšããŠGPIOãã³ãçæããŸããã
Pythonã§å®å šã«èšè¿°ãããRaspberry PiããŒãäžã®ææ°ã®ARMããã»ããµã§å®è¡ãããCNCãã·ã³ãå·¥äœæ©æ¢°ã3Dããªã³ã¿ãŒã®ã³ã³ãããŒã©ãŒã®ãããžã§ã¯ãã§ããPyCNCãããžã§ã¯ãã®ã¹ãããã³ã°ã¢ãŒã¿ãŒãå¶åŸ¡ããããã®ãã«ã¹çæãå®è£ ããŸããã
ãã®èšäºã¯ãä»ã®ããã»ããµã®DMAã¢ãžã¥ãŒã«ã䜿çšããŠãä»ã®é«ã¬ãã«ããã°ã©ãã³ã°èšèªã®1ã€ãŸãã¯è€æ°ã®GPIOã®åºåã«èšå®ã¬ãã«ã®è€éãªã·ãŒã±ã³ã¹ã®çæãå®è£ ããå Žåã«åœ¹ç«ã¡ãŸãã
GPIO
æ±çšå ¥ååºåïŒGPIOïŒã¯ãç©çåºåã®è«çã¬ãã«ãèšå®ããããã»ããµã¢ãžã¥ãŒã«ã§ãã ãåç¥ã®ããã«ãããžã¿ã«ã®äžçã§ã¯ãåºåã¯ã0ããã€ãŸããèããã°ã©ã³ããã«åŒã£åŒµãããããã1ããã€ãŸãèãé»æºã«åŒã£åŒµãããå¯èœæ§ããããŸãã
ãã£ãšããªãã®å€ããLEDãç¹ç¯ããŠããã€ã¯ãã³ã³ãããŒã©ãŒã®èã®1ã€ãå¶åŸ¡ããŸãã ããšãã°ãAVRãã€ã¯ãã³ã³ãããŒã©ãŒã®å Žåãããã¯å€æ°ã®å¯Ÿå¿ãããããããŸãã¯ããåŒã°ããããã«PORTxã¬ãžã¹ã¿ãèšå®ããããšã§è¡ãããŸããã ãã®å€æ°ã¯äœã§ããïŒ ããããŒãã¡ã€ã«ãèŠããšã次ã®ãããªãã®ããããŸãã
#define PORT (*(volatile uint8_t *)(0x12345678))
ã€ãŸããåºåç¶æ ã¬ã³ãŒãã¯ãæ¢ç¥ã®ã¢ãã¬ã¹ã§ã®ãã®å€ã®ã¬ã³ãŒãã§ãã ããã¯RAMã®ã¢ãã¬ã¹ã§ã¯ãªããããã»ã¹ã®ä»®æ³ã¡ã¢ãªã®ã¢ãã¬ã¹ã§ã¯ãªããããã»ããµèªäœã®ã¢ãã¬ã¹ç©ºéã®ã¢ãã¬ã¹ã§ããããšã«æ³šæããŠãã ããã ç©ççã§ããããå ã®ã©ããã«ãå®éã®GPIOã¢ãžã¥ãŒã«ããã®ã¢ãã¬ã¹ã«æ¥ç¶ãããããã»ããµã³ã¢ãä»ããŠãã®ã¢ãã¬ã¹ã§ã¢ã¯ã»ã¹ããæ å ±ã®ãã€ããæž¡ããŠåºåã¹ããŒã¿ã¹ãèšå®ããŸãã ãããŠãã»ãšãã©ãã¹ãŠã®ããã»ããµã«ãã®ãããªã¢ãžã¥ãŒã«ããããŸãã Raspberry Pi ARMããã»ããµãäŸå€ã§ã¯ãããŸããã åã¢ãžã¥ãŒã«ãã¢ãã¬ã¹ç©ºéã®ã©ãã«ããããæ£ç¢ºã«ç¥ãã«ã¯ãé¢å¿ã®ããããã»ããµã®ããã¥ã¡ã³ãã調ã¹ãå¿ èŠããããŸãã
Raspberry Piã®å Žåããã®ããã¥ã¡ã³ãã¯ãã¡ãã§ãã
ãã®äžã§ãGPIOã¬ãžã¹ã¿ã¯ãã¹ã¢ãã¬ã¹0x7E200000ã«ãããŸããã€ãŸãã察å¿ããã¢ãã¬ã¹ã«ããŒã¿ãæžã蟌ãããšã§ããã³ã®ç¶æ ãå¶åŸ¡ã§ããŸãã ããã«ãRaspberry Pi 1ã2ãããã³3ããã»ããµã®åšèŸºå šäœãåãã§ãããã¢ãã¬ã¹0x7E000000ããå§ãŸãåšèŸºãã¹ã¢ãã¬ã¹ããããã³ã°ãããç©çã¢ãã¬ã¹ã®ã¿ãç°ãªãããšã«æ³šæããŠãã ããã Raspberry Piã®ããŒãžã§ã³1ã®å Žåãããã¯0x20000000ã«ãªããããŒãžã§ã³2ããã³3ã®å Žåã¯0x3F000000ã«ãªããŸãã ã€ãŸããRPi3ããã»ããµã®å Žåããã¹ã¢ãã¬ã¹0x7E200000ã«ã¢ã¯ã»ã¹ããã«ã¯ãç©çââã¢ãã¬ã¹0x3F200000ã«æžã蟌ãå¿ èŠããããŸãã äžèšã®ãªã³ã¯ã®ããã¥ã¡ã³ãã§ã¯ããã¹ãŠã®ã¢ãã¬ã¹ã¯ãã¹ã¢ãã¬ã¹ã§ãã
ã»ãšãã©ã®å ŽåãLinuxã¯ARMããã»ããµã«ã€ã³ã¹ããŒã«ãããŸãã ç©çã¡ã¢ãªã«ã¢ã¯ã»ã¹ããæ¹æ³ã«ã€ããŠã®è³ªåãããã«çºçããŸãã ãããžã®ã¢ã¯ã»ã¹ã¯OSã®äžæ žã§ãã ä»®æ³ã¢ãã¬ã¹ç©ºéã§å®è¡ããéåžžã®ã¢ããªã±ãŒã·ã§ã³ãäœæããŸãã 幞ããªããšã«ãLinuxã«ãŒãã«ã¯ä»®æ³ããã€ã¹ã/ dev / memããä»ããŠç©çã¡ã¢ãªãžã®ã¢ã¯ã»ã¹ãæäŸããŸãããããéããšïŒã¹ãŒããŒãŠãŒã¶ãŒæš©éãå¿ èŠã§ãïŒãç©çã¡ã¢ãªã«æžã蟌ãããšãã§ããŸãã å ¬å¹³ã«èšããšãå ¬åŒã®Raspberry Pi OSã§ã¯ãRaspbianã«ã¯ãã©ã€ã㌠'bcm2835_gpiomem'ã«ãã£ãŠæäŸãããããã€ã¹ '/ dev / gpiomem'ããããã¹ãŒããŒãŠãŒã¶ãŒæš©éããªããŠãã¢ã¯ã»ã¹ã§ããŸã-æåã®GPIOã¬ãžã¹ã¿ãžã®ã¢ã¯ã»ã¹ã¯ããã«ãŒãã§ã€ã³ãã³ããããŸãã
å°ãç·Žç¿ããŠã¿ãŸããããäžèšã®ãã¹ãŠãç解ããæ¹ãç°¡åã ãšæããŸãã Raspberry Pi 2ããã³3ã§å®è¡ãããŠããGPIO21ãã³ã«æ¥ç¶ãããLEDãç¹ç¯ããåçŽãªPythonã¢ããªã±ãŒã·ã§ã³ãäœæããŠã¿ãŸãããïŒRPi1ã®å Žåããªã¹ãã®ã¢ãã¬ã¹ãä¿®æ£ããŸãïŒã Pythonã®ä»£ããã«ãlibc.soããã·ã¹ãã é¢æ°ãåŒã³åºãããšãã§ããä»ã®ããã°ã©ãã³ã°èšèªã䜿çšã§ããŸãã ã³ãŒãã¯æ¬¡ã®ãšããã§ãã
ã³ãŒãã«ããžãã¯ãã³ããŒãæå³çã«æ®ããŸãã-説æããããã§ãããã ã³ãŒããè¡ããšã«è§£æããŸãããã
äžäœ5è¡ã¯ãå¿ èŠãªæšæºPythonã¢ãžã¥ãŒã«ã®ã€ã³ããŒãã§ãã
7è¡ç®ã§ã¯ããã¡ã€ã« '/ dev / mem'ãçŽæ¥éããŠã¡ã¢ãªã«ã¢ã¯ã»ã¹ããŸãã
8è¡ç®ã§ã memmapã·ã¹ãã é¢æ°ãåŒã³åºããŸãããã®é¢æ°ã¯ãä»®æ³ã§ã¯ãããŸãããããã»ã¹ã®ä»®æ³ã¢ãã¬ã¹ç©ºéã«ãã¡ã€ã«ãæ圱ããŸãã ã€ãŸããããã»ã¹ã®ä»®æ³ã¡ã¢ãªã«æžã蟌ããšãå®éã«ç©çã¡ã¢ãªã«æžã蟌ã¿ãŸãã ãŸããã³ãŒãã¯ãã¡ã¢ãªãæ圱ããã¢ãã¬ã¹ããå§ãŸãã€ã³ãã³ããšé·ãïŒmmap.PAGESIZEïŒã瀺ããŸãã æåã®GPIOã¬ãžã¹ã¿ã®ã¢ãã¬ã¹ãšã¡ã¢ãªã®1ããŒãžã®é·ãã瀺ããŸãã äžèŠãã/ dev / memããéããŠç®çã®ã¢ãã¬ã¹ã«æ»ãããã¡ã€ã«ã®æžã蟌ã¿ãéå§ããããã«èŠãããããããŸããããæ®å¿µãªãããããã¯ããŸããããŸããã
9è¡ç®ã§ã¯ããã³ãã«ãéãããŸãŸã«ããå¿ èŠããªãããããã¡ã€ã«ãéããŸãããããã³ã°ã¯ã©ãã«ãæ¶ããŸããã
11ã14è¡ç®ã§ã¯ã0x08ã€ã³ãã³ããããã¬ãžã¹ã¿ãèªã¿æžãããŸãã ããã¥ã¡ã³ããèŠããšãããã¯ã¬ãžã¹ã¿GPFSEL2 GPIOæ©èœéžæ2ã§ãããããã®ã¬ãžã¹ã¿ã䜿çšããŠããããã¬ãã°ãå®è¡ããæ©èœãéžæããŸãã ãã®å ŽåãåºåãåºåãšããŠæ©èœããããã«ã001ã§3çªç®ããå§ãŸã3ããããèšå®ïŒæåã«ã¯ãªã¢ãã次ã«ORæŒç®ã䜿çšããŠèšå®ïŒããŸãã å®éã«ã¯ãç°ãªãã¢ãŒããèšå®ããçµè«ã¯éåžžã«å€ãã1ã€ã®ã¬ãžã¹ã¿ãŒã§ã¯ååã§ã¯ãªããããã¬ãžã¹ã¿ãŒã¯ãããã10ã®çµè«ã®ã°ã«ãŒãã«åå²ãããŸãã
16è¡ç®ãš22è¡ç®ã«ã¯ãããŒããŒãã®Ctrl + Cãããã°ã©ã ãçµäºããã®ãåŸ ã€ãã³ãã©ãŒãã€ã³ã¹ããŒã«ããŸãã
17è¡ç®ã§ãç¡éã«ãŒããéå§ããŸãã
18è¡ç®ã§ã¯ãããããã¹ã¯ãGPSET0ã¬ãžã¹ã¿ã«æžã蟌ãããšã«ãããåºåãHighã«èšå®ããŸãã
19è¡ç®ãš21è¡ç®ã§ã¯ã0.5ç§ã®é 延ãå®çŸããŠããŸãã
20è¡ç®ã§ã¯ãGPCLR0ããããã¹ã¯ãæžã蟌ãããšã§åºåãäžããŠããŸãã
25è¡ç®ãš26è¡ç®ã§ããã³ãåæå解é€ããããã©ã«ãç¶æ ïŒå ¥åïŒã«å€æããŠãã¡ã¢ãªãããã³ã°ãéããŸãã
çãã¡ã¢ïŒBCM2835ã«ã¯ãAVRã®ãããªPORTAã«äŒŒãã¬ãžã¹ã¿ããããŸãããã€ãŸãããã¹ãŠã®ãã³ã®ç¶æ ïŒãã€ãŸãã¯ããŒïŒãããã«èšé²ããããšã¯ã§ããŸããã ãŠããããããããã¹ã¯ã§ç€ºãããŠãããã¹ãŠã®ãã³ã«è«çãŠããããèšå®ã§ããSETã¬ãžã¹ã¿ãšããŠããããããããã¹ã¯ã§æå®ãããŠãããã¹ãŠã®ãã³ã«è«çãŒããèšå®ã§ããCLEARã¬ãžã¹ã¿ã®ã¿ããããŸãã
ããšãã°ãã³ãã³ã 'sudo python gpio.py'ã䜿çšããŠRaspberry Pi 2ãŸãã¯3ã§ã¹ãŒããŒãŠãŒã¶ãŒæš©éã§ãã®ã³ãŒããå®è¡ããLEDããã³21ã«æ¥ç¶ãããšãç¹æ» ããããšãããããŸãã
GPIOãã³ã管çããæ¢è£œã®å®è£ ãå¿ èŠãªå Žåã¯ããã®ãã¡ã€ã«ããGPIOã¯ã©ã¹ã䜿çšã§ããŸã ã
ã¹ãããã³ã°ã¢ãŒã¿ãŒ
ã¹ãããã³ã°ã¢ãŒã¿ãŒã®å¶åŸ¡ã¯ãäžèŠãããšåçŽãªããã«åçŽã§ã¯ãããŸããã åé¡ã®æ¬è³ªãç°¡åã«èª¬æãããã®ãããªã·ãŒã±ã³ã¹ãçæããå¿ èŠãããçç±ãèŠãŠã¿ãŸãããã ã¹ãããã³ã°ã¢ãŒã¿ãŒããã€ã¹ã®çè«ã®è©³çŽ°ã«ã€ããŠã¯èª¬æããŸããããåžæã®æ¹ã¯ããã§èªãããšãã§ããŸã ã
代ããã«ãããã«çŸå®ã«æ»ããã¹ãããã³ã°ã¢ãŒã¿ãŒã«ã¯4ã€ã®å·»ç·ãã4ã€ãŸãã¯5ã€ã®åºåããããŸãã ãšã³ãžã³ãå転ãããã®ã«å¿ èŠãªé»æµã¯éåžžã«é«ããåäžã®ãã€ã¯ãã³ã³ãããŒã©ãŒãŸãã¯ããã»ããµãŒããããæäŸããããšã¯ã§ããŸããã ãŸãããã®ãããªé»æµãçæããã«ã¯ãååãšããŠãããã»ããµããžãã¯ã®é»å§ãè¶ ããé»å§ãå¿ èŠã§ãã ãã®ãããã¹ãããã³ã°ã¢ãŒã¿ãŒã§ã¯ããã©ã€ããŒãå Žåã«ãã£ãŠã¯ã¢ãŒã¿ãŒããŠãžã³ã°ã«çµã¿èŸŒãŸããç¹æ®ãªãã€ã¯ãåè·¯ã䜿çšãããŸãã æãåçŽãªãã©ã€ãïŒULN2003ãªã©ïŒã¯ãæšæºã®ãã€ã¯ãã³ã³ãããŒã©ããžãã¯é»å§ãšäºææ§ã®ããäœé»æµå·»ç·å¶åŸ¡å ¥åãæäŸããã ãã§ãã ãã®ãããªãã©ã€ãã§ã¯ãå·»ç·ããšã«ãã«ã¹ã·ãŒã±ã³ã¹ãçæããå¿ èŠããããŸãã æã人æ°ã®ããA4988ãDRV8825ãå«ãã»ãšãã©ã®ãã©ã€ããŒã¯ãã¢ãŒã¿ãŒå·»ç·ãæ±ãéã®é çã®çš®ã«ãªããŸãã ãããã¯ã2ã€ã®äœé»æµåºåSTEPããã³DIRã®ã·ã³ãã«ãªã€ã³ã¿ãŒãã§ã€ã¹ãæäŸããŸãã ååããæšæž¬ã§ããããã«ãSTEPã«ãã«ã¹ãå°å ãããšããã©ã€ããŒã¯ãšã³ãžã³ã1ã¹ããã移åããŸãïŒãã©ã€ããŒã¯ãããããã€ã¯ãã¹ããããã€ãŸã1 / 2ã1 / 4ãªã©ã®ã¹ãããã®ç§»åçšã«æ§æããããšãã§ããŸã-ããã¯éæãããŸãå·»ç·æè¡ïŒã DIRãã³ã¯ãäœã¬ãã«ãšé«ã¬ãã«ã®ã©ã¡ããé©çšããããã«å¿ããŠããšã³ãžã³ã®å転æ¹åãéžæããããã«äœ¿çšãããŸãã
å žåçãªA4988æ¥ç¶å³ã¯æ¬¡ã®ããã«ãªããŸãïŒã€ã³ã¿ãŒãããã§åçãåããŸããïŒã
æãåçŽãªã±ãŒã¹ã§ã¯ãSTEP端åã«ãã«ã¹ãå°å ããããšã«ãããç¹å®ã®åšæ³¢æ°ã§ãšã³ãžã³ãå転ãããããšãã§ããŸãã 圌ãšéã¶ã ãã§ååã§ãã ããããç©çæ³åã¯å®éã®ããã€ã¹ã«äœçšãããããæ©æ§ãå£ããããªãå Žåã¯ãåºå®åšæ³¢æ°ã®ãã«ã¹ãå°å ããã ãã§ã¯ããšã³ãžã³ãå¿ èŠãªé床ã«ããã«å éããããšã¯ã§ããŸããã äžå®ã®å é床ã§ãšã³ãžã³ãå転ãããŠåžæã®é床ã«ãããã®åŸå®å šã«åæ¢ãããŸã§ãšã³ãžã³ãæžéãããå¿ èŠããããŸãã ãããã£ãŠããã«ã¹ç¹°ãè¿ãçã¯å éããã³å éäžã«å€åããã¯ãã§ãããå¿ èŠãªä¿¡å·ã¯ãã¯ãåšæçã§ã¯ãªããªããŸãã
ãã®æ¥ç¶ã«ããããã€ã¯ãã³ã³ãããŒã©èªäœã«ã»ãšãã©ãã¹ãŠã®æ©èœãå®è£ ã§ãããããSTEPããã³DIRåºåã§ã¢ãŒã¿ãŒãå¶åŸ¡ãããã®ã¢ãããŒãã¯æãäžè¬çã§ãã ããšãã°ãèªè ã質åããå ŽåããããŸã-I2CãŸãã¯UARTã€ã³ã¿ãŒãã§ã€ã¹ãåãããã©ã€ããŒã¯ãããŸããïŒ çè«çã«ã¯ããã®ãããªãã©ã€ããŒãäœæã§ããŸãããåã3Dããªã³ã¿ãŒãå¶åŸ¡ããã«ã¯ãããã€ãã®ã¹ãããã³ã°ã¢ãŒã¿ãŒãåæå¶åŸ¡ããå¿ èŠããããŸãã ããã«ãããããã«ç°ãªãå éãã©ã¡ãŒã¿ãŒã1ããªã¡ãŒãã«ãããã®ã¹ãããæ°ãããã³æ倧é床ãèšå®ã§ããŸãã ãã®çµæããã®ãããªè€éãã®ãã©ã€ããŒã¯ãCNCã³ã³ãããŒã©ãŒã®ã¢ããã°ã«ãªããŸãã
ãæ³åã®ãšãããäžèšã®GPIOå¶åŸ¡æ¹æ³ã§ã¯ããã³äžã®ãã«ã¹ãæ£ãã圢æã§ããŸããã Pythonã³ãŒãã®å®è¡ã®é 延ãäºæž¬ã§ããªããšããã ãã§ã¯ãããŸããã Cã§ãã¹ãŠãLinux Linuxã®ã«ãŒãã«ã¢ãžã¥ãŒã«ã®åœ¢åŒã§å®è£ ããŠããLinuxã¯ãªã¢ã«ã¿ã€ã ãªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã§ã¯ãªããããè¯ãçµæã¯åŸãããŸããã ãã€ã§ããããã»ããµã³ã¢ã¯ä»ã®ã¿ã¹ã¯ã®å®è¡ã«åãæ¿ããããšãã§ããæéå ã«è¡åãäžããŸããã ãããããã®ãããªäºçŽ°ãªããšã§ç§ãã¡ã¯èšç»ãžã®éãé»ãŸããŸããïŒ
DMA
ãã€ã¬ã¯ãã¡ã¢ãªã¢ã¯ã»ã¹ã¯ãã³ã¢ããã»ããµèªäœã®ãµãŒãã¹ã«é Œããã«ãããå Žæããå¥ã®å Žæã«ã¡ã¢ãªãã³ããŒã§ããå°çšã®ããã»ããµããŒããŠã§ã¢ã¢ãžã¥ãŒã«ã§ãã ãã®ãããªã¢ãžã¥ãŒã«ã¯åçŽãªãã€ã¯ãã³ã³ãããŒã©ãŒã§ãååšããŸãããå®è£ ã¯ããã»ããµãŒã¢ãã«ããšã«å€§ããç°ãªããŸãã Raspberry Piã®å®è£ ã¯ããªãå¹³å¡ã§ããå¿ èŠãªãã®ã¯ãã¹ãŠæã£ãŠããŸããã食ãæ°ã¯ãããŸããã ãŸããããšãã°ãRockchip RK3399 DMAã¢ãžã¥ãŒã«ã¯ãå°ãããªãããäžé£ã®åœä»€ãåããããã³ã¢ããã»ããµã«äŒŒãŠããŸãã
ç§ã¯ãªãªãžãã«ã®ããã¥ã¡ã³ãã®å®å šãªç¿»èš³ãæžãä»äºãèªåèªèº«ã«èšå®ããŠããŸããã ãããŠãGPIOã¢ãžã¥ãŒã«ã«ããŒã¿ãã³ããŒããã¢ãŒãã§DMAã¢ãžã¥ãŒã«ãå®è¡ã§ããããã«ããã¡ã€ã³ã¬ãžã¹ã¿ã«ã€ããŠèª¬æããŸãã
ãæ³åã®ãšãããã¡ã¢ãªå ã«ãããã¡ãçæããGPIOã¢ãžã¥ãŒã«ã®ãã±ãŒã·ã§ã³ã¢ãã¬ã¹ã«ã³ããŒããŸãã ããããDMAã¢ãžã¥ãŒã«ãæ©èœããããã«ã¯ããã®ãããã¡ãç©çã¡ã¢ãªã®ã©ããã«ããããšãå¿ èŠã§ãã åœç¶ãã¹ã¯ããã«è©²åœããªãã£ãä»®æ³ã¡ã¢ãªãç©çã¡ââã¢ãªã«æ ŒçŽãããŸãã ã/ proc / self / pagemapãã䜿çšãããšãç¬èªã®ããã»ã¹ã®ã¡ã¢ãªã®ãããã³ã°ããŒãã«ãç©çã¡ã¢ãªã«ååŸã§ããŸããã€ãŸãããããã¡ãå²ãåœãŠãŠããã®ç©çã¢ãã¬ã¹ãèŠã€ããŸãã
ããããããã¯DMAã§è¡ã䟡å€ã¯ãããŸãããããã¯ãã¡ã¢ãªãã¹ã¯ããã«å ¥ãå¯èœæ§ãšããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®ã¡ã¢ãªãããŒãžã£ãå²ãåœãŠãããã¡ã¢ãªãå¥ã®å Žæã«è»¢éã§ããããã§ãã ããŒãæã«Linuxã«ãŒãã«kmallocïŒïŒããã¡ãœãããåŒã³åºãåçŽãªã«ãŒãã«ã¢ãžã¥ãŒã«ãäœæã§ããŸãããã®ã¡ãœããã¯ãå¯èœãªè»¢éããã¡ã¢ãªãå²ãåœãŠããããã¯ããŸãã 次ã«ãããšãã°ä»®æ³ããã€ã¹ãä»ããŠãå²ãåœãŠãããã¡ã¢ãªã®ã¢ãã¬ã¹ãã¢ããªã±ãŒã·ã§ã³ã«æž¡ããŸãã ãã®ã¢ãã¬ã¹ã䜿çšãããšãã¢ããªã±ãŒã·ã§ã³ã¯GPIOã»ã¯ã·ã§ã³ã§èª¬æããæ¹æ³ãšãŸã£ããåãæ¹æ³ã§ã¡ã¢ãªã«ã¢ã¯ã»ã¹ã§ããŸãã å²ãåœãŠãã¢ãã¬ã¹ãŸãã¯ãããã¡ã¯ãDMAã¢ãžã¥ãŒã«ã§äœ¿çšã§ããŸãã
ãã ããéåžžã«åçŽã§ã¯ãããŸããã匷åãªã¢ãžã¥ãŒã«ãäœæããå¿ èŠã¯ãªãã§ãããã
ããŠãæ¢è£œã®ãœãªã¥ãŒã·ã§ã³-ä»®æ³ããã€ã¹ '/ dev / vcio'ããããŸãã Raspberry Piã°ã©ãã£ãã¯ã«ãŒããã©ã€ããŒã«ãã£ãŠäœæãããŸãã éä¿¡ã®ããã«ãVideoCoreãšCPUã¯ããããã¡ãŒã«ããã¯ã¹ã䜿çšããŸããããã¯ãæ¬è³ªçã«ããããªã«ãŒãã«å²ãåœãŠãããã¡ã¢ãªã«å²ãåœãŠãããéšåã§ãã ããã©ã«ãã§ã¯ããããªã«ãŒãã«ã¯64 MBãå²ãåœãŠãããŠãããå¿ èŠã«å¿ããŠãã®å€ãå€æŽã§ããŸãã å¿ èŠã«å¿ããŠãããªã¡ã¢ãªããããã€ãã®ãªãœãŒã¹ãå²ãåœãŠããšããäºå®ã¯ããããªã«ãŒãã®åäœã«åœ±é¿ãäžããããšã¯ãããŸãããäž»ãªããšã¯ãããŸãå€ãããšããªãããšã§ãã å®éã«ã¯ãRaspbian OSãã¹ã¯ããããæ£åžžã«æ©èœããã«ã¯30ã35 MBã®ã¡ã¢ãªã§ååã§ãïŒçŽååïŒã ã€ãŸããOpenGLã䜿çšããŠã¢ããªã±ãŒã·ã§ã³ãèµ·åããäºå®ããªãå ŽåãåŸåã¯å®å šã«ã¢ã¯ã»ã¹å¯èœã§ãã ããã«ãGPUèªäœã«è»¢éããããã®ã¡ã¢ãªã®äžéšã®å²ãåœãŠã¯ãéåžžã®æé ã§ãã ãŸããã¡ã¢ãªãå²ãåœãŠãŠãããããªããã»ããµã«å²ãåœãŠãªãå Žåãåé¡ã¯çºçããŸããã ãã®ãããªã¡ã¢ãªå²ãåœãŠã䜿çšããå ¬åŒã®äŸã次ã«ç€ºããŸãã
ãã®ããã»ã¹ã¯éåžžã«ç°¡åã§ãããã³ãŒãã®ããžãã¯ãã³ããŒã®åŸãã«é ããŠããŸãã / dev / vcioãéããioctlïŒïŒã¡ãœããã䜿çšããŠããªã¯ãšã¹ãã§æ§é äœãæž¡ããçããååŸããŸãã ã¡ã¢ãªãããŒãžã£ãå²ãåœãŠãéšåãã©ãã«ã䜿çšããªãããã«ãã¡ã¢ãªãå²ãåœãŠãŠããã¯ããå¿ èŠããããŸãã äžèšã®ãªã³ã¯ããå®è£ ã確èªã§ããŸããmem_allocïŒïŒãmem_lockïŒïŒã¡ãœããããããŠãã¡ãããmem_unlockïŒïŒãmem_freeïŒïŒãã¯ãªãŒã³ã¢ããã§ããã¡ãœããã«èå³ããããŸãã Cã®å®è£ ã«æ··ä¹±ããŠããå Žåã¯ããããã®ã¡ãœãããä»ã®èšèªã§æžãæããããšãã§ããŸãã
ãŸãã ãããã¡ãå²ãåœãŠãå Žæã ããã§ãã©ãã«ãããŠDMAãããã°ã©ã ããå¿ èŠãªããšãè¡ãå¿ èŠããããŸãã DMAã¢ãžã¥ãŒã«ã¯ç©çã¡ã¢ãªå ã®ã»ãã®æ°åã®ã¬ãžã¹ã¿ã§ããããšã«æ³šæããŠãã ããã æ§é ãç®çã®ã¢ãã¬ã¹ã«æžã蟌ãããšã«ãããåãæ¹æ³ã§ç®¡çãããŸãã åèšã§ãRaspberry Piã«ã¯16åã®DMAãã£ãã«ããããŸãã æåã®8ã€ã¯å®å šã«æ©èœããæ®ãã®8ã€ã¯æ©èœããããã«å¶éãããŠããŸãã åãã£ãã«ã«ã¯ãç¬èªã®ã¬ãžã¹ã¿ã»ããããããŸãã DMAã¢ãžã¥ãŒã«ãã¹ã®ããŒã¹ã¢ãã¬ã¹ã¯0x7E007000ã§ããã€ãŸããRaspberry Pi 2ãŸãã¯3ã®å Žåã0x3F007000ã§æžã蟌ãå¿ èŠããããŸãã æåã®DMAãã£ãã«ã®æåã®ã¬ãžã¹ã¿ã¯æ¬¡ã®ãšããã§ãã åŸç¶ã®åãªãã»ããã¯0x100ã§ãïŒ15ãé€ãã0x7EE05000ã«ãããŸãïŒã
䜿çšãããã£ãã«ã¯ïŒ ãã£ãã«ãã«ãŒãã«ã§äœ¿çšã§ãããããéžæã¯éåžžã«è€éã§ãã ã³ãã³ããcat / sys / class / dma / dma0chan * / in_useãã䜿çšããŠãsysfsãä»ããŠã«ãŒãã«èªäœã§äœ¿çšãããŠãããã£ãã«ãæ£ç¢ºã«èŠã€ããããšãã§ããŸãã ååãšããŠã0ã1ã2ã3ã6ã7ãã£ã³ãã«ã¯microSDã«ãŒããªãŒããŒãšãããªã«ãŒããã©ã€ããŒã䜿çšããããã䜿çšããªãã§ãã ããã
DMAã¢ãžã¥ãŒã«ãå¶åŸ¡ããããã®ã¡ã€ã³ã¬ãžã¹ã¿ã¯ãCSããã³CONBLK_ADã§ãã DMAãèµ·åããã®ã¯ããããåããããšã§ãã æåã®ã¬ãžã¹ã¿ã¯CSã§ããããã®äžã®ãã£ãŒã«ãã«èå³ããããŸãã
ããã
æ° | ãã£ãŒã«ã | 説æ | ã¢ã¯ã»ã¹ |
---|---|---|---|
31 | ãªã»ãã | ãŠããããæžã蟌ããšãDMAã¢ãžã¥ãŒã«ããªã»ãããããŸãã | W |
1 | çµäº | ãŠããããæžã蟌ãŸãããšãéä¿¡çµäºãã©ã°ããªã»ãããããŸãã | W |
0 | ACTIVE | ãŠããããæžã蟌ããšããDMAã¯åäœãéå§ããŸãã ãã®ãã£ãŒã«ãã䜿çšãã
DMAãäžæåæ¢ã§ããŸãã 転éãå®äºãããšããã£ãŒã«ã èªåçã«å€0ãåããŸãã | Rw |
ã¬ãžã¹ã¿ã«ã¯ããã«å€ãã®ãã£ãŒã«ãããããŸãã奜å¥å¿itiveçãªèªè ã¯ã äžèšã§åºäŒã£ããªã³ã¯ ïŒ47ããŒãžïŒ ã䜿çšããŠãå ¬åŒææžã§åãã£ãŒã«ãã®èª¬æãèŠã€ããããšãã§ããŸãã
ããããã³ã³ãããŒã«ãŠããããDMAã¢ãžã¥ãŒã«ã®åŠçå 容ãèšè¿°ããã¢ãã¬ã¹ã¯ãCONBLK_ADã¬ãžã¹ã¿ã«æžã蟌ãŸããŸãã åæã«ãå¶åŸ¡ãããã¯ã¯ãªã³ã¯ãªã¹ãã§ããã€ãŸããè€æ°ã®å¶åŸ¡ãããã¯ã䜿çšããŠãããŸããŸãªã¿ã¹ã¯ã®ãã§ãŒã³ãæ§ç¯ã§ããŸãã ã¿ã¹ã¯ãå®äºãããšãDMAã¢ãžã¥ãŒã«ã¯èªåçã«ãã¹ãŠã®å¶åŸ¡ãããã¯ãééããŸãã CONBLK_ADã®ã¢ãã¬ã¹ãããCSã¬ãžã¹ã¿ã«ACTIVEããããèšå®ããããšãDMAã¢ãžã¥ãŒã«ãã³ããŒãéå§ããŸãã
ã³ã³ãããŒã«ãŠãããã¯ã32ãã€ãã®ã¢ã©ã€ã¡ã³ãã§ã¡ã¢ãªã«æ ŒçŽããå¿ èŠããããŸãïŒã¢ãã¬ã¹ã®æäžäœ5ãããã¯ãŒãã§ãªããã°ãªããŸããïŒã 次ã«ãå¶åŸ¡ãããã¯ã®æ§é ãèŠãŠã¿ãŸãããã
ã€ã³ãã³ããã€ã | ãã£ãŒã«ã | 説æ |
---|---|---|
0 | Ti | ããŒã¿ã³ããŒèšå®ãæå®ããããŸããŸãªãã©ã°ã®ã»ããã |
4 | SOURCE_AD | ã³ããŒãéå§ãããœãŒã¹ã¢ãã¬ã¹ã |
8 | DEST_AD | ã³ããŒå ã®å®å ã¢ãã¬ã¹ã |
12 | TXFR_LEN | ã³ããŒãããã€ãæ°ã
ç¹å¥ãª2Dã¢ãŒãã§ã¯ãæé«16ããããèšå®ãããŸã ã³ããŒãµã€ã¯ã«æ°ãäžäœ16ããã- ãµã€ã¯ã«ããšã«ã³ããŒããããã€ãæ°ã |
16 | ã¹ãã©ã€ã | 2Dã¢ãŒãã§ã®ã¿äœ¿çšãããŸãã äžäœ16ãã€ã
ã·ããéãæå®ãã笊å·ä»ãæ°å€ãä¿åããŸã 次ã®ãµã€ã¯ã«ã®éå§åã®éä¿¡å ã¢ãã¬ã¹ã äžäœ16ãã€ãã«ã¯ãå¿ èŠãªç¬Šå·ä»ãçªå·ãæ ŒçŽãããŸã 次ã®ãµã€ã¯ã«ãéå§ããåã«å®å ã¢ãã¬ã¹ãã·ããããŸãã |
20 | NEXTCONBK | 次ã®å¶åŸ¡ãããã¯ãžã®ãã€ã³ã¿ãŒã |
ãã£ãã«0ã7ã¯ã2Dã¢ãŒãïŒå¶åŸ¡ãããã¯ã®TIãã£ãŒã«ãã®TDMODEãã©ã°ïŒããã1ïŒã§èšå®ïŒããµããŒãããŸããããã«ãããYãã€ãã®Xã³ããŒãæŽçã§ããŸãã ãã®å Žåãåã³ããŒã®åã®å®å ããã³/ãŸãã¯éä¿¡å ã¢ãã¬ã¹ã¯ãå¶åŸ¡ãããã¯ã®STRIDEãã£ãŒã«ãã«åŸã£ãŠãç¹å®ã®éã ãå¢æžã§ããŸãã
åDMAãã£ãã«ã«ã¯ãTIãSOURCE_ADãDEST_ADãTXFR_LENãSTRIDEãNEXTCONBKã®ã¬ãžã¹ã¿ã»ãããããããããã¯èªã¿åãå°çšã§ãã ãããã¯çŸåšã®å¶åŸ¡ãããã¯ããããŒããããŸãã
ããŠãPythonã®DMAããã³GPIOã¢ãžã¥ãŒã«ã䜿ã£ãŠç°¡åãªããšãè©ŠããŠã¿ãŸãããã ããã°ã©ã ã®ãªã¹ããããã»ã©é·ããªããäœåãªããžãã¯ãã³ããŒãå«ãŸããªãããã«ããã®ãã¡ã€ã«ããããã€ãã®æ¢è£œã®ã³ãŒããåããŸãããã
ãããããå®æ°ãšã¯ã©ã¹ãPhysicalMemoryãïŒGPIOã®äŸã§è¡ã£ãããã«ç©çã¡ã¢ãªãžã®ã¢ã¯ã»ã¹ïŒãšãCMAPhysicalMemoryãïŒããã¯äžã§æžãããããªãã©ã€ã/ dev / vcioã䜿çšããŠç©çã¡ã¢ãªãå²ãåœãŠãå®è£ ã§ãïŒã䜿çšããŸãã
ãã®ããã°ã©ã ãå®è¡ãããšïŒã¹ãŒããŒãŠãŒã¶ãŒæš©éã§å®è¡ããããšãå¿ããªãã§ãã ããïŒããã³21ã«æ¥ç¶ãããLEDãæ倧èŒåºŠã§0.5ç§éç¹ç¯ãïŒéããé¡èã«ãªãããã«ïŒãEnterããŒãæŒããŸã§åèŒåºŠã§ç¹ç¯ããŸãã è¡ããšã«è§£æããŸãããã
2-3è¡-ã¢ãžã¥ãŒã«ã®ã€ã³ããŒãã
5çªç®ãš6çªç®ã¯ã䜿çšããDMAãã£ãã«ãšGPIOåºåã瀺ãå€æ°ã§ãã
8-15th-瀺ãããGPIOåºåãåºåãšããŠåæåãã0.5ç§éç¹ç¯ããŸãïŒãã®ãããDMAããªã³ã«ãªã£ããšãã«éããã¯ã£ãããšèŠããããã«ãªããŸãïŒã å®éãããã¯æåã®ããã°ã©ã ã§è¡ã£ããã®ãšåãã§ãããå°ãé«ãã¬ãã«ã§æžãããŠããŸãã
17è¡ç®-ãããªãã©ã€ããŒã«64ãã€ãã®ã¡ã¢ãªãå²ãåœãŠãããã«äŸé ŒããŸãã CMAPhysicalMemoryã¯ã©ã¹ã§ã¯ãã¡ã¢ãªã¯ããŒãžãµã€ãºãã€ãŸã4096ãã€ãã«çããã¢ã©ã€ã¡ã³ãã§å²ãåœãŠãããããããã®ã¡ã¢ãªã䜿çšããå Žåãå²ãåœãŠãããã¡ã¢ãªã®å é ã¯åžžã«DMAã¢ãžã¥ãŒã«ãå¿ èŠãšãã32ãã€ãã«ã¢ã©ã€ã¡ã³ããããŸãã
18è¡ç®-å¶åŸ¡ãããã¯ã®æåã®æ§é ãåããŸãã ããã«ã€ããŠããã«è©³ãã説æããŸãã
19è¡ç®-æåã®4ãã€ã-TIïŒè»¢éæ å ±ïŒãã©ã°ã DMA_TI_NO_WIDE_BURSTS â burst- â â , , .
DMA_TI_WAIT_RESP â DMA- .
DMA_TI_SRC_INC DMA_TI_DST_INC â , DMA- 4 . , DMA-, / . .
20- â , . , , () ( get_bus_address()). , , , . .
21- â GPIO- SET, . . , .
22- â â 4 .
23- â stride, , 0.
24- â next control block, 32 .
25- â , , 21- 4 , , â , GPIO.
26 â .
28â37- â , . CLEAR GPIO, . , .
38â39- â .
41- â DMA- .
42-43- â DMA-.
44- â .
45- â DMA-.
47- â Enter.
49â52- â . DMA- ().
, :
Raspberry Pi 2. , 1.5 â ( ~2 ) , , .
DMA
, , â DMA- GPIO-. DMA â , , ⊠, .
DMA 1 . , STEP, , , 2 . , 2 , . . 500 000 . 4 , . : 1 ( 200 200 / â ), 114 . â 228 . , ? , , . 114 .
DMA- â . DMA- â . , , , , , , 16 4 . , . . - , . , , .
GPIO DMA , - . , 3D-. . ?
.
:
, GPIO, DMA ( ). « 1» , « 2» â . . 200 200 /. « 2», . , , . . , . CNC- .
(200 400 â 80 000 ) 128 ( 32 ), DMA ~9.8 . . , , . 3D- , . . 39.2 , , ( - ), .
, ? , , , . . GPIO . DMA- â . PWM (, , , ). PWM , , DMA FIFO- PMW. PWM- . , PWM , FIFO.
DMA- PWM-, PERMAP TI , , 5, PWM- .
, , DMAGPIO. rpgpio, , ( 1, 2, 3, 4 5 ). :
, , , .
import rpgpio PIN=21 PINMASK = 1 << PIN PULSE_LENGTH_US = 1000 PULSE_DELAY_US = 1000 DELAY_US = 2000 g = rpgpio.GPIO() g.init(PIN, rpgpio.GPIO.MODE_OUTPUT) dma = rpgpio.DMAGPIO() for i in range(1, 6): for i in range(0, i): dma.add_pulse(PINMASK, PULSE_LENGTH_US) dma.add_delay(PULSE_DELAY_US) dma.add_delay(DELAY_US) dma.run(True) raw_input("Press Enter to stop") dma.stop() g.init(PIN, rpgpio.GPIO.MODE_INPUT_NOPULL)
DMA-
DMA-, , FM- Raspberry Pi â .
DMA-, 250 . , DMA- . . PWM ( PWM , PWM- ), . , , . , DMA-, PWM-, , .
PRU
BeagleBone PRU (programmable real-time unit), 200 32- , AM3358. . . â .
ãããã«
DMA- , , .
, , . , . Raspberry Pi Zero, , .
â , , :