å³ 1. 1ã€ã®ã³ã³ãããŒã©ãŒå ã§ã®ã¿ã¹ã¯ã®çžäºäœçšã®äŸ
ã³ã³ãããŒã©ãŒéã§ãããã©ã³ã¹ããŒãå±€ãå®å šã«é ããŸãã
å³ 2.ã³ã³ãããŒã©ãŒéã®ã¿ã¹ã¯ã®çžäºäœçšã®äŸ
ããã«ãã¡ã¢ãªãå®å šã«åé¢ãããŠãããããç°ãªãã³ã³ãããŒã©ã¯ç°ãªãããã»ã¹ãšåçã§ãã åœç€Ÿã®ãŠã§ããµã€ãã§å ¬éãããŠããOSããŒãžã§ã³ã§ã¯ãã³ã³ãããŒã©ãŒéã®ç©çãã£ã³ãã«ã¯ãæç·SPIãŸãã¯UARTã€ã³ã¿ãŒãã§ãŒã¹ãããã³RF24ç¡ç·ã¢ãžã¥ãŒã«ãä»ããã¯ã€ã€ã¬ã¹ã€ã³ã¿ãŒãã§ãŒã¹ã«ããããšãã§ããŸãã
SPIããã³UARTãªãã·ã§ã³ã䜿çšããããšã¯æšå¥šãããŸãããçŸåšã®å®è£ ã§ã¯ãããããä»ããŠæ¥ç¶ã§ããã³ã³ãããŒã©ã¯2ã€ãŸã§ã§ãã
ããã«ããã«ã€ããŠããã«èª¬æããŸãããç¥èã®æ¬ãã®ä»ã®ç« ã¯ããã«ãããŸãã
ããŒã1.äžè¬æ å ±
ããŒã2. RTOS MAXã®ã«ãŒãã«
ããŒã3.æãåçŽãªããã°ã©ã ã®æ§é
ããŒã4.æçšãªçè«
ããŒã5.æåã®ã¢ããªã±ãŒã·ã§ã³
ããŒã6.ã¹ã¬ããåæããŒã«
ããŒã7.ã¿ã¹ã¯éã§ããŒã¿ã亀æããæ段ïŒãã®èšäºïŒ
ããŒã8.å²ã蟌ã¿ã®åŠç
1ã€ã®ã³ã³ãããŒã©ãŒå ã§ããŒã¿ã亀æããæ段ïŒã¡ãã»ãŒãžãã¥ãŒïŒ
RTOSã®æäœã«å¯Ÿããå€å žçãªã¢ãããŒãã¯æ¬¡ã®ãšããã§ããã¿ã¹ã¯ã¯ã¡ãã»ãŒãžãã¥ãŒã䜿çšããŠçžäºã«ããŒã¿ã亀æããŸãã å°ãªããšããããã¯ãã¹ãŠã®åŠè¡æç§æžãèŠæ±ãããã®ã§ãã ç§ã¯å®çšçãªããã°ã©ããŒã«å±ããŠãããããç¹å®ã®ã±ãŒã¹ã®ããã«äœæãããçŽæ¥çãªäº€ææ段ã䜿çšããæ¹ãç°¡åãªå ŽåãããããšãèªããŠããŸãã ããšãã°ãã·ã¹ãã ã«é¢é£ä»ããããŠããªãéåžžã®ãªã³ã°ãããã¡ã ããããããã§ããã¡ãã»ãŒãžãã¥ãŒãæé©ãªãªããžã§ã¯ãã§ããå ŽåããããŸãïŒã·ã¹ãã 以å€ã®ãã®ãšã¯ç°ãªããããŒãªã³ã°ããããããã¡ããã£ã±ããŸãã¯ç©ºã®ãšãã«ã¿ã¹ã¯ããããã¯ã§ããããã§ãïŒã
æç§æžã®äŸãèããŠã¿ãŸãããã ã·ãªã¢ã«ããŒãããããŸãã ãã¡ãããåè·¯ã«ãã£ãŠãã·ã¹ãã ãç°¡çŽ åããããã«ããããŒå¶åŸ¡ã©ã€ã³ãªãã§äœãããŠããŸãã ã¯ã€ã€äžã®ããŒã¿ã¯æ¬¡ã ã«éãããŸãã åæã«ãå€ãã®ïŒãã¹ãŠã§ã¯ãããŸãããïŒæšæºã³ã³ãããŒã©ãŒã®æ©åšã¯ã倧ããªããŒããŠã§ã¢ãã¥ãŒãæå³ããŸããã ããŒã¿ãåéããæéããªãå Žåã¯ãåä¿¡ã·ããã¬ãžã¹ã¿ããã®æ°ããéšåã§ããŒã¿ãæ¶å»ãããŸãã
äžæ¹ãããŒã¿ãåŠçããã¿ã¹ã¯ã«æéãããããšããŸãããïŒããšãã°ãäœæ¥ããŒã«ã移åãããªã©ïŒã ããã¯éåžžã«æ£åžžã§ã-CNCãã·ã³ã®Gã³ãŒãã«ã¯äžå®ã®ãªãŒãããããŸãã ããŒã«ã移åããåæã«æ¬¡ã®ç·ãã¯ã€ã€ãéããŸãã
ã³ã³ãããŒã©ã®ãããã¡ã¬ãžã¹ã¿ããªãŒããŒãããŒãããããã°ã©ã å ã®ãã€ããã¡ã€ã³æäœäžã«åä¿¡ãããæéããããããå²ã蟌ã¿ãã³ãã©ã§åä¿¡ããå¿ èŠããããŸãã çã®ãã€ããã¡ã€ã³ã¿ã¹ã¯ã«è»¢éãããå Žåãæãç°¡åãªãªãã·ã§ã³ãå¯èœã§ãã
å³3
ãã ãããã®å Žåããã¥ãŒã®é 眮ãšåãåºãã®æäœãå€ãããããšãããããŸãã ãªãŒããŒããããé«ãããŸãã çã®ãã€ãã§ã¯ãªããååŠçã®çµæããã¥ãŒã«å ¥ããããšããå§ãããŸãïŒè¡ããéå§ããGã³ãŒãã§ãã®äŸã®è¡ã解éããçµæã§çµäºããŸãïŒã ãã ããå²ã蟌ã¿ãã³ãã©ãŒã§ã®ååŠçã¯åãå ¥ããããŸãã ããã®æç¹ã§ãåªå 床èšå®ã«å¿ããŠä»ã®ãã¹ãŠã®å²ã蟌ã¿ããããã¯ãããä»ã®ãµãã·ã¹ãã ã®ããŒã¿ãé 延ããŠåŠçããã補åã®åäœãäžæãããããšãããããã§ãã
ãã®ä»®å®ã¯ãããæ°åç¹°ãè¿ã䟡å€ããããŸãã ãããã©ãŒã©ã ã§ããPDM圢åŒã®ãã€ã¯ãµãŠã³ãçšã«æšæºã®ã¢ã³ããã«ãŒã䜿çšããŸããããæ£åžžã«æ©èœããŸããããšãã質åãèŠãŸããã ãŸãã質åã«äŸãæ·»ä»ãããPDMãã£ã«ã¿ãªã³ã°ãå²ã蟌ã¿ã®ã³ã³ããã¹ãã§å®è¡ãããŸããã 質åã®äœæè ãäžæããã«PDMããPCMã«å€æãå§ãããšãïŒåœŒãããã«ã¢ããã€ã¹ãããããã«ïŒããã¹ãŠã®åé¡ãèªç¶ã«æ¶ããããšã¯èšããŸã§ããªãã ãããã£ãŠã äžææã«ã¯ãååŠçã¯åãå ¥ããããŸããïŒ é»åã¬ã³ãžã§åµã調çããããå²ã蟌ã¿ãã³ãã©ãŒã§äžèŠãªã¢ã¯ã·ã§ã³ãå®è¡ãããããªãã§ãã ãã ïŒ
ååŠçãããå Žåããã¹ãŠã®æç§æžã§æšå¥šãããã¹ããŒã ã¯æ¬¡ã®ãšããã§ãã
å³4
é«åªå 床ã®ååŠçã¿ã¹ã¯ã¯ãã»ãšãã©åžžã«ãããã¯ãããŸãã å²ã蟌ã¿ãã³ãã©ãããŒããŠã§ã¢ãããã€ããåä¿¡ããããªããã»ããµãèµ·åããŠãã®ãã€ããæž¡ãããã®åŸã«å»ããŸããã ãã以éããã¹ãŠã®å²ã蟌ã¿ãåã³æå¹ã«ãªããŸãã
é«åªå 床ã®ããªããã»ããµãèµ·åããå éšãããã¡ã«ããŒã¿ãèç©ããŠããã¹ãªãŒãç¶æ ã«ãªããåã³éåžžã®åªå 床ã§ã¿ã¹ã¯ãåŠçããæ©äŒãäžããããŸãã è¡ãèç©ããããšïŒæ¹è¡æåãå°çããŸãïŒãããã解éããçµæãã¡ãã»ãŒãžãã¥ãŒã«å ¥ããŸãã ããã¯ãã¹ãŠã®åŠè¡åºçç©ãæšå¥šãããªãã·ã§ã³ãªã®ã§ãããã§èªè ã«å€å žçãªã¢ã€ãã¢ãäŒããå¿ èŠããããŸããã ãã ããçè«å®¶ãšããŠã§ã¯ãªããå®è·µè ãšããŠç§èªèº«ãããã«è¿œå ããŸãããã®æ¹æ³ã®åŒ±ç¹ãããããŸãã ãã¥ãŒãžã®ãŸããªåŒã³åºãã§åã¡ãŸãããåªå 床ã®é«ãã¿ã¹ã¯ã«å ¥ãããã®ã³ã³ããã¹ãã¹ã€ããã§è² ããŸãã äžè¬ã«ããã®ã¢ãããŒãã®æ¬ ç¹ã«ã€ããŠèª¬æãããŠããŸãããå®éã®äœæ¥æ¹æ³ã«ã€ããŠã¯æšå¥šäºé ã説æãããŠããŸããããã©ãŒãã³ã¹ãšã·ã³ãã«ãã®æé©ãªæ¯çãéžæããŠã誰ããç¬èªã®æ¹æ³ãèŠã€ããå¿ èŠããããŸãã å®éã®èŠç©ããã䌎ãããã€ãã®æšå¥šäºé ã¯ãäžæã«é¢ãã次ã®èšäºã«èšèŒãããŸãã
ã¡ãã»ãŒãžãã¥ãŒãå®è£ ããã«ã¯ãMessageQueueã¯ã©ã¹ã䜿çšããŸãã ã¡ãã»ãŒãžãã¥ãŒã¯ä»»æã®ã¿ã€ãã®ããŒã¿ã§å¹æçã«æ©èœããå¿ èŠãããããããã³ãã¬ãŒããšããŠèšèšãããŠããŸãïŒåŒæ°ãšããŠããŒã¿ã¿ã€ãã眮ãæããããŸãïŒã
template <typename T> class MessageQueue { ...
ã³ã³ã¹ãã©ã¯ã¿ãŒã®åœ¢åŒã¯æ¬¡ã®ãšããã§ãã
MessageQueueïŒsize_t max_sizeïŒ;
max_sizeãã©ã¡ãŒã¿ãŒã¯ããã¥ãŒã®æ倧ãµã€ãºã決å®ããŸãã 容éããã£ã±ãã«ãªã£ããšãã«èŠçŽ ããã¥ãŒã«å ¥ããããšãããšã空ãã¹ããŒã¹ãã§ãããŸã§ã¿ã¹ã¯ããããã¯ãããŸãïŒäžéšã®ã¿ã¹ã¯ã¯ãæ¢ã«ãã¥ãŒã«ããèŠçŽ ã®1ã€ã䜿çšããŸããïŒã
ããŸãã«ãå€ãã®ããšããã§ã«è¿°ã¹ãããŠããã®ã§ãããã§ã¯ãã¥ãŒã®åæåã®äŸãããã«ã¯ã§ããŸããã ãã¥ãŒèŠçŽ ã®ã¿ã€ããshortã§ããããã¥ãŒã®æ¬¡å ã5èŠçŽ ãè¶ ããªãããšãæãããªãã¹ããã©ã°ã¡ã³ããååŸããŸãã
voidMessageQueueTestApp::Initialize() { mQueue = new MessageQueue<short>(5); Task::Add(new MessageSenderTask("send"), Task::PriorityNormal, 0x50); Task::Add(new MessageReceiverTask("receive"), Task::PriorityNormal, 0x50); }
é¢æ°ã䜿çšããŠã¡ãã»ãŒãžããã¥ãŒã«å ¥ããããšãã§ããŸãïŒ
çµæããã·ã¥ïŒå®æ°Tããã³ã¡ãã»ãŒãžãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ;
ãã¥ãŒããã£ã±ãã®å Žåãtimeout_msãã©ã¡ãŒã¿ãŒãå¿ èŠã§ãã ãã®å Žåãã·ã¹ãã ã¯ç©ºãé åã衚瀺ãããç¬éãåŸ ã¡ãŸãã ãããŠããã®ãã©ã¡ãŒã¿ãŒ-åŸ æ©ãèš±å¯ãããéãäŒããŸãã
å¿ èŠã«å¿ããŠãã¡ãã»ãŒãžããã¥ãŒã®æåŸã§ã¯ãªããæåã«çœ®ãããšãã§ããŸãã ãããè¡ãã«ã¯ã次ã®é¢æ°ã䜿çšããŸãã
çµæPushFrontïŒconst TïŒã¡ãã»ãŒãžãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ;
ãã¥ãŒã®å é ãã次ã®èŠçŽ ãåé€ããã«ã¯ã次ã®é¢æ°ã䜿çšããŸãã
çµæãããïŒTïŒã¡ãã»ãŒãžãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ;
ããã§ãããããã¿ã€ã ã¢ãŠããã©ã¡ãŒã¿ã¯ããã¥ãŒã空ã®å Žåã®åŸ æ©æéãèšå®ããŸãã èšå®ãããæéã®éãã·ã¹ãã ã¯ãä»ã®ã¿ã¹ã¯ã«ãã£ãŠãã¥ãŒã«å ¥ããããã¡ãã»ãŒãžã衚瀺ãããã®ãåŸ ã¡ãŸãã
èŠçŽ ãåé€ããã«ããã¥ãŒã®å é ããèŠçŽ ã®å€ãååŸããããšãã§ããŸãã
çµæã®ããŒã¯ïŒTïŒã¡ãã»ãŒãžãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ;
æåŸã«ããã¥ãŒã«å ¥ã£ãŠããã¡ãã»ãŒãžã®æ°ã調ã¹ãé¢æ°ããããŸãã
size_tã«ãŠã³ãïŒïŒ
ããã³å¯èœãªæ倧ãã¥ãŒãµã€ãºïŒ
size_t GetMaxSizeïŒïŒ
ç°ãªãã³ã³ãããŒã©ãŒéã®éä¿¡æ段
å®éãçŽç²ã«åœ¢åŒçã«ã¯ãã³ã³ãããŒã©ãŒéã§ããŒã¿ã亀æããæ段ã¯ãã©ã€ããŒã§ãã ããããã€ããªãã®ãŒçã«ããããã¯ããŒã¿äº€æã®éåžžã®æ段ã«é¢é£ããŠããŸããããã¯Maxã®äž»ãªæ©èœã®1ã€ã§ãã
OSã®å ¬éããŒãžã§ã³ã§ã¯ãæç·UARTãŸãã¯SPIã€ã³ã¿ãŒãã§ãŒã¹ããŸãã¯RF24ç¡ç·ã¢ãžã¥ãŒã«ïŒSPIã€ã³ã¿ãŒãã§ãŒã¹ã«æ¥ç¶ãããŠããïŒãä»ããŠç©ççãªäº€æãå®è¡ã§ããããšãæãåºããŠãã ããã ãŸããã³ã³ãããŒã©ãŒéã®ããŒã¿äº€æãã¢ã¯ãã£ãã«ããã«ã¯ãMaksConfig.hãã¡ã€ã«ã«æ¬¡ã®è¡ãå ¥åããå¿ èŠãããããšãæãåºããŠãã ããã
#define MAKS_USE_SHARED_MEM 1
å®æ°ã®1ã€ã1ã«èšå®ããŠãç©çãã£ãã«ã®ã¿ã€ãã決å®ããŸãã
MAKS_SHARED_MEM_SPIãMAKS_SHARED_MEM_UARTããŸãã¯MAKS_SHARED_MEM_RADIO
çŸåšã®å®è£ ã®SPIããã³UARTã¡ã«ããºã ã¯2ã€ã®ããã€ã¹ã®ã¿ã®æ¥ç¶ãæäŸãããããç¡ç·ãªãã·ã§ã³ãæšå¥šãããŸã
ããŠããã®ãããªé·åŒããåæã®åŸãSharedMemoryã¯ã©ã¹ã®èª¿æ»ãå§ããŸãããã
ã¯ã©ã¹ãªããžã§ã¯ãã¯ãInitializeïŒïŒé¢æ°ã䜿çšããŠåæåã§ããŸãã ã猶ããšããèšèã¯å¶ç¶äœ¿çšãããŸããã äžè¬ã«ãã©ãžãªãªãã·ã§ã³ã®å Žåãåæåã¯å¿ èŠãããŸããã
ããŒã¿æ§é ã¯ãã®é¢æ°ã«æž¡ãããŸãã ãã®ãã£ãŒã«ãã«ã€ããŠç°¡åã«èããŠã¿ãŸãããã
ãã®æ§é äœãåããŠåæåé¢æ°ãåŒã³åºãäŸãæ€èšããŠãã ããã
SmInitInfo info; info.TransferCore = &SpiTransferCore::GetInstance(); info.NotifyMessageReceived = true; info.AutoSendContextsActivity = true; info.SendActivityDelayMs = 100; info.CheckActivityDelayMs = 200; SpiTransferCore::GetInstance().Initialize(); SharedMemory::GetInstance().Initialize(info);
å¥ã®ãªãã·ã§ã³ïŒ
SmInitInfo info; info.TransferCore = &SpiTransferCore::GetInstance(); info.AutoSendContextsActivity = true; info.SendActivityDelayMs = 100; info.CheckActivityDelayMs = 200; SpiTransferCore::GetInstance().Initialize(); SharedMemory::GetInstance().Initialize(info);
ãã®ã¯ã©ã¹ã¯ãã¿ã¹ã¯ã®çžäºäœçšã®ããã®2ã€ã®ã¡ã«ããºã -ã¡ãã»ãŒãžãšå ±æã¡ã¢ãªïŒããããã³ã°ã®å¯èœæ§ããïŒãæäŸããŸãã
å ±æã¡ã¢ãªãªããžã§ã¯ãã¯åžžã«1ã€ã§ããããããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã®éçºè ã¯ãè€éãªé¢æ°åãã°ããŒãã«ãªååã«å€æããMaksSharedMemoryExtensions.cppãã¡ã€ã«ãäœæããŸããã
ãã®ãã¡ã€ã«ã®ã¹ããããã¯æ¬¡ã®ãšããã§ãã
Result GetContext(uint32_t context_id, void* data) { return SharedMemory::GetInstance().GetContext(context_id, data); } Result GetContext(uint32_t context_id, void* data, size_t data_length) { return SharedMemory::GetInstance().GetContext(context_id, data, data_length); } Result SetContext(uint32_t context_id, const void* data, size_t data_length) { return SharedMemory::GetInstance().SetContext(context_id, data, data_length); }
é ä¿¡ããã±ãŒãžã«å«ãŸãããã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã¯ã°ããŒãã«é¢æ°åã䜿çšããããããã®ããã¥ã¡ã³ãã®äŸã§ã¯ãã®åœåãªãã·ã§ã³ã䜿çšããŸãã
ã¡ãã»ãŒãž
æçš¿ããå§ããŸãããã ããããéä¿¡ããã«ã¯ãSendMessageïŒïŒé¢æ°ã䜿çšããŸãã ãã®é¢æ°ã¯éåžžã«è€éãªã®ã§ã詳现ã«æ€èšããŠãã ããã
çµæSendMessageïŒuint32_t message_idãconst void * dataãsize_t data_lengthïŒ
åŒæ°ïŒ
message_id-ã¡ãã»ãŒãžèå¥åã
data-ã¡ãã»ãŒãžããŒã¿ãžã®ãã€ã³ã¿ãŒã
data_length-ã¡ãã»ãŒãžããŒã¿ã®é·ãã
䜿çšäŸïŒ
const uint32_t APP5_EXPOSE_MESSAGE_ID = 503; ... if (broadcast) { char t = 0; SendMessage(APP5_EXPOSE_MESSAGE_ID, &t, sizeof(t)); } const uint32_t APP5_AIRPLANE_MESSAGE_ID = 504; ... bool AirplaneTask::SendAirplane() { Message msg(_x, _y, _deg, _visibility); return SendMessage(APP5_AIRPLANE_MESSAGE_ID, &msg, sizeof(msg)) == ResultOk; }
é¢æ°ã®çµæã¯ãã¡ãã»ãŒãžã®éä¿¡ã¹ããŒã¿ã¹ãåæ ããŠããŸãã åä¿¡è ãåä¿¡ãããã©ããã«ãããããããã®æ©èœã¯ãµã€ã¬ã³ãã§ãã ããããªããªã£ããã©ããã ããç¥ãããŠããŸãã 確èªããã«ã¯ãåä¿¡è ãè¿ä¿¡ã¡ãã»ãŒãžãéä¿¡ããå¿ èŠããããŸãã
ãããã£ãŠãåä¿¡è åŽã§ã¡ãã»ãŒãžãåŸ æ©ããã«ã¯ã次ã®é¢æ°ã䜿çšãããŸãã
çµæWaitUntilMessageReceivedïŒSmMessageReceiveArgsïŒargsãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ
åŒæ°ïŒ
args-ã¡ãã»ãŒãžãã©ã¡ãŒã¿ãæã€ãªããžã§ã¯ããžã®ãªã³ã¯ã
timeout_ms-ããªç§åäœã®ã¿ã€ã ã¢ãŠãã ã¿ã€ã ã¢ãŠãå€ãINFINITE_TIMEOUTã®å Žåãã¿ã¹ã¯ã¯ã¿ã€ã ã¢ãŠãã«ããããã¯è§£é€ã®å¯èœæ§ãªãã§ãããã¯ãããŸãïŒç¡éåŸ æ©ïŒã
ã¡ãã»ãŒãžãªãã·ã§ã³ã¯ã¯ã©ã¹å šäœã§ãã ãªãŒãã³ã¡ã³ããŒãç°¡åã«æ€èšããŠãã ããã
uint32_t GetMessageIdïŒïŒ
åä¿¡ããã¡ãã»ãŒãžã®èå¥åãè¿ããŸãïŒ
size_t GetDataLengthïŒïŒ
åä¿¡ããã¡ãã»ãŒãžã®ããŒã¿ãµã€ãºããã€ãåäœã§è¿ããŸãã
void CopyDataToïŒvoid *ã¿ãŒã²ããïŒ
ã¡ãã»ãŒãžããŒã¿ãæå®ããããããã¡ã«ã³ããŒããŸãã ãããã¡ã®ã¡ã¢ãªã¯äºåã«å²ãåœãŠãå¿ èŠããããŸãã ãããã¡ãŒã®ãµã€ãºã¯ãã¡ãã»ãŒãžããŒã¿ïŒGetDataLengthã¡ãœãããåŒã³åºããçµæïŒã®ãµã€ãºä»¥äžã§ãªããã°ãªããŸããã
ãããã£ãŠãåã®äŸã§éä¿¡ãããã¡ãã»ãŒãžã®åä¿¡ã«åœ¹ç«ã€äŸã¯æ¬¡ã®ããã«ãªããŸãã
void MessageReceiveTask::Execute() { Message msg; while (true) { SmMessageReceiveArgs args; Result res = WaitUntilMessageReceived(args); if (res == ResultOk) { uint32_t mid = args.GetMessageId(); switch (mid) { .... case APP5_EXPOSE_MESSAGE_ID: #ifdef BOARD_LEFT _gfx->ExposeAirplaneRed(); #else _gfx->ExposeAirplaneBlue(); #endif break; case APP5_AIRPLANE_MESSAGE_ID: { args.CopyDataTo(&msg); #ifdef BOARD_LEFT _gfx->UpdateAirplaneRed(msg.X, msg.Y, msg.Deg); _gfx->SetAirplaneRedVisibility(msg.Visibility); #else _gfx->UpdateAirplaneBlue(msg.X, msg.Y, msg.Deg); _gfx->SetAirplaneBlueVisibility(msg.Visibility); #endif } break; ...
åæãããã³ã³ããã¹ã
ã³ã³ããã¹ãã¯ããã¹ãŠã®ã³ã³ãããŒã©ãŒéã§åæããå¿ èŠãããã¡ã¢ãªã®é åãæããŸãã åæäžã«è¿œæ±ãããç®æšã¯ä»»æã§ãã æãåçŽãªã±ãŒã¹ã¯ã1ã€ã®ããã€ã¹ããããã¹ã¿ã³ãã€ã®å®äºããäœæ¥æ®µéã«ã€ããŠä»ã®ããã€ã¹ã«éç¥ããããšã§ãã 倱æããå Žåãæ®ãã®ããã€ã¹ã«ã¯äœæ¥ãããã¯ã¢ããããæ¹æ³ã«é¢ããæ å ±ããããŸãã äžç·ã«ç®æšãéæããããã€ã¹ã®å Žåãã³ã³ããã¹ããä»ãã亀æã®ã¡ã«ããºã ã¯ãã¡ãã»ãŒãžãä»ãããã®ããã䟿å©ãããããŸããã ã¡ãã»ãŒãžãçæãéä¿¡ãåä¿¡ããã³ãŒãããå¿ èŠããããŸãã ãŸããã³ã³ããã¹ãã®ã¡ã¢ãªã䜿çšãããšãéåžžã®ã¡ã¢ãªãšåãããã«äœæ¥ã§ããŸãã1ã€ã®ããã€ã¹ã®ã¡ã¢ãªãä»ã®ããã€ã¹ã«è€è£œãããããã«ãåæãå¿ããªãããšãéèŠã§ãã
ã·ã¹ãã å ã®åæãããã³ã³ããã¹ãã®æ°ã¯ä»»æã§ãã ãããã£ãŠããã¹ãŠã1ã€ã«åããå¿ èŠã¯ãããŸããã ããŸããŸãªããŒãºã«åãããŠãããŸããŸãªåæã³ã³ããã¹ããäœæã§ããŸãã ã¡ã¢ãªã®ãµã€ãºããã®äžã®ããŒã¿æ§é ãããã³åæãããã³ã³ããã¹ãã®ä»ã®ãã©ã¡ãŒã¿ãŒã¯ãã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã®é¢å¿äºã§ãïŒããèªäœãåæãããã¡ã¢ãªã®éãå€ãã»ã©ãåæãé ããªããŸãããã®ãããç°ãªãããŒãºã«å¯ŸããŠç°ãªãå°ããªã³ã³ããã¹ãã䜿çšããæ¹ãè¯ãã§ãïŒã
ããã«ãåæã»ãã·ã§ã³ã®ç¬éã§ãã-ã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã«ãã£ãŠéžæãããŸãã RTOS MAXã¯ãµããŒãçšã®APIãæäŸããŸãããã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã¯ãã®é¢æ°ãåŒã³åºãå¿ èŠããããŸãã ããã¯ãããŒã¿äº€æã®ããã»ã¹ãæ¯èŒçé ããšããäºå®ã«ãããã®ã§ãã ãã¹ãŠããªãã¬ãŒãã£ã³ã°ã·ã¹ãã ã«å·Šå³ãããå Žåãããã»ããµã³ã¢ãä»ã®ã¿ã¹ã¯ãæ倧åããå¿ èŠããããšãã«é 延ãçºçããå¯èœæ§ããããŸãã ã³ã³ããã¹ããé »ç¹ã«èªååæãããšããªãœãŒã¹ãç¡é§ã«ãªããŸãããŸãã«ãã³ã³ãããŒã©ãŒãåæããåã«ããŒã¿ãå€ããªãå¯èœæ§ããããŸãã ããã«ã¯ãããŒã¿ãããéèŠãªè³ªåïŒããšãã°ã4人ã®ç°ãªããµãã¹ã¯ã©ã€ããŒãããå ŽåïŒãè¿œå ããŸãããã®åŸãã¢ããªã±ãŒã·ã§ã³ããã°ã©ããŒã®ã¿ãåæãéå§ã§ããããšãå®å šã«æããã«ãªããŸãã ãããè¡ãã®ãæé©ãªã¿ã€ãã³ã°ãç¥ã£ãŠããã®ã¯åœŒã§ãããã©ã®ãµãã¹ã¯ã©ã€ããŒãæ®ãã®ããŒã¿ãä»ã®ãµãã¹ã¯ã©ã€ããŒã«é åžãã¹ãããç¥ã£ãŠããŸãã äžæ¹ãOSã¯ã¢ããªã±ãŒã·ã§ã³ã«ééæ§ãæäŸããŸãã
ã³ã³ããã¹ãã«ã¯ãç¬èªã®æ°å€èå¥åããããŸãïŒã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã«ãã£ãŠèšå®ãããŸãïŒã ãã¹ãŠã®ã¢ããªã±ãŒã·ã§ã³ã¯ã1ã€ãŸãã¯è€æ°ã®åæãããã³ã³ããã¹ããæã€ããšãã§ããŸãã çžäºã«äœçšããã³ã³ãããŒã©ãŒå ã§èå¥åãäžè²«ããŠããããšãéèŠã§ãã
åæããŒã¿ã®æãåçŽãªäŸ-æž æããããã¯ãæž æãããŠããªãé åãææ¡ããããã«ãæž æããé åãå®æçã«å°å³äžã«ããŒã¯ããŸãããŸãããäºãã«å¹²æžããªãããã«ãä»ã©ãã«è¡ãã®ããç¥ãããŸãã 1ã€ã®è£œåã§äœæ¥ããŠããã¬ã³ãã¯ããã蟌ã¿ãå®äºããåŸãåãããããã«ããŒã¯ãä»ããŸãã ã¿ããã¹ã¯ãªãŒã³ä»ãã®ããŒãã¯ã¯ãªãã¯ãèšé²ããæ®ãã®ããŒãã«ã€ããŠãã®äºå®ãèšé²ããŸããã ããŠãã¡ã¢ãªãå ±æããå¿ èŠãããä»ã®å€ãã®ã±ãŒã¹ããããŸããããããæ¯ç§æ°åïŒæ倧-æ¯ç§æ°ååïŒè¡ãããšãèš±å¯ãããŠããŸãã
ãããã£ãŠãã³ã³ããã¹ãã¯å³ã«ç€ºãããã«è¡šãããšãã§ããŸãã
å³ 5.ã³ã³ããã¹ã
ãããŠããã®ç®çã¯æ¬¡ã®å³ã§è¡šãããšãã§ããŸãã
å³ 6.ã³ã³ããã¹ãåæã®æ¬è³ª
次ã«ãã³ã³ããã¹ãã®åæã«äœ¿çšãããé¢æ°ãæ€èšããŸãã
çµæGetContextïŒuint32_t context_idãvoid * dataïŒ;
ã³ã³ããã¹ãããŒã¿ãæå®ãããã¡ã¢ãªé åã«ã³ããŒããŸããã¡ã¢ãªã¯äºåã«å²ãåœãŠãããŠããå¿ èŠããããŸãã ããŒã¿é·ãäºåã«ããã£ãŠããå ŽåïŒäŸãã°ãåçŽãªãã£ãŒã«ããæã€æ§é ïŒã«é©ããŠããŸãã
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
data-ã³ã³ããã¹ããä¿åããããã®ãã€ã³ã¿ã¡ã¢ãªé åã
ãã®çµæãæåŸã®åæäžã«ååŸããããæå®ãããèå¥åãæã€ã³ã³ããã¹ãããŒã¿ãè¿ãããŸãã ãããã£ãŠãããŒã¿ã¯ã³ã³ããã¹ãã®ããŒã«ã«ã³ããŒããååŸãããããããã®é¢æ°ã¯ãã°ããåäœããŸãã ãã®é¢æ°ã«ã¯2çªç®ã®ããªã¢ã³ãããããŸãã
çµæGetContextïŒuint32_tcontext_idãvoid *ïŒdataãsize_tïŒdata_lengthïŒ;
ã¡ã¢ãªãå²ãåœãŠãããŒã¿ãšã³ã³ããã¹ãã®é·ããã³ããŒããŸãã ããŒã¿é·ãäºåã«ããããªãå ŽåïŒããšãã°ãä»»æã®é·ãã®é åïŒã«é©ããŠããŸãã
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
data-ã³ã³ããã¹ããä¿åããããã®ãã€ã³ã¿ã¡ã¢ãªé åã
data_length-ã³ã³ããã¹ããæ ŒçŽããã¡ã¢ãªé åã®ãã€ãåäœã®ãµã€ãºã
ååãšããŠãã³ã³ããã¹ããæŽæ°ãããã®ãåŸ ã€ã¿ã¹ã¯ãäœæããŠããããã®æ°ããããŒã¿ãã¢ããªã±ãŒã·ã§ã³ã¡ã¢ãªã«ã³ããŒã§ããŸãã ããã«ã¯æ¬¡ã®é¢æ°ãé©ããŠããŸãã
çµæWaitUntilContextUpdatedïŒuint32_tïŒcontext_idãuint32_t timeout_ms = INFINITE_TIMEOUTïŒ
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
timeout_ms-ããªç§åäœã®ã¿ã€ã ã¢ãŠãã ã¿ã€ã ã¢ãŠãå€ãINFINITE_TIMEOUTã®å Žåãã¿ã¹ã¯ã¯ã¿ã€ã ã¢ãŠãã«ããããã¯è§£é€ã®å¯èœæ§ãªãã§ãããã¯ãããŸãïŒç¡éåŸ æ©ïŒã
æåŸã«ãã¿ã¹ã¯ãã·ã¹ãã å šäœïŒè€æ°ã®ã³ã³ãããŒã©ãŒã§æ§æãããïŒã§ã³ã³ããã¹ããæŽæ°ãããå ŽåãèããŸãã
æåã«ãã³ã³ããã¹ãããã£ããã£ããå¿ èŠããããŸãã ãããè¡ãã«ã¯ã次ã®é¢æ°ã䜿çšããŸãã
çµæLockContextïŒuint32_t context_idïŒ
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
ãã®æ©èœã«ã¯ã³ã³ãããŒã©ãŒéã®äº€æãå¿ èŠã§ãããããæéããããå¯èœæ§ããããŸã
ã³ã³ããã¹ãããã£ããã£ã§ããå ŽåïŒåæã«ãã£ããã£ããããšãããšã1ã€ã ããåã¡ãæ®ãã¯ãšã©ãŒã³ãŒããåãåããŸãïŒã次ã®é¢æ°ã䜿çšããŠã³ã³ããã¹ããèšè¿°ã§ããŸãã
çµæSetContextïŒuint32_t context_idãconst void * dataãsize_t data_lengthïŒ
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
data-ã³ã³ããã¹ããä¿åããããã®ã¡ã¢ãªé åãžã®ãã€ã³ã¿ã
data_length-ã³ã³ããã¹ããæ ŒçŽããã¡ã¢ãªé åã®ãã€ãåäœã®ãµã€ãºã
æåŸã«ãã³ã³ããã¹ããåæããã«ã¯ãé¢æ°ãåŒã³åºãå¿ èŠããããŸãã
çµæUnlockContextïŒuint32_t context_idïŒ
åŒæ°ïŒ
context_id-ã³ã³ããã¹ãèå¥åã
ã³ã³ããã¹ããã·ã¹ãã å šäœã§åæããã®ã¯ãåŒã³åºãåŸã§ãã
ãã®æ©èœã«ã¯ã³ã³ãããŒã©ãŒéã®äº€æãå¿ èŠã§ãããããæéããããå¯èœæ§ããããŸã
äœæ¥äŸ
OSã«ä»å±ããåæã³ã³ããã¹ãã䜿çšããå®éã®äŸãèããŠã¿ãŸãããã ã³ãŒãã¯ãã¡ã€ã«ã«å«ãŸããŠããŸã... \ maksRTOS \ Source \ Applications \ CounterApp.cpp
ãã®äŸã§ã¯ãè€æ°ã®ããã€ã¹ã1ç§ã«1åã«ãŠã³ã¿ãŒãã€ã³ã¯ãªã¡ã³ãããŸãïŒãã®ã¢ããªã±ãŒã·ã§ã³ãç»é¢ã®ããããŒãã§å®è¡ãããšãã«ãŠã³ã¿ãŒå€ãèŠèŠçã«è¡šç€ºãããŸãïŒã ã³ã³ãããŒã©ãŒã®ããããããªãã«ãªã£ãŠãããªã³ã«ãªã£ãå Žåãã«ãŠã³ã¿ãŒã®çŸåšã®å 容ãåãåãããã¹ãŠã®ãŠãŒã¶ãŒãšé£æºããŠåäœããŸãã ãããã£ãŠãã·ã¹ãã ã¯ãå°ãªããšã1ã€ã®ã³ã³ãããŒã©ãŒããã®ã·ã¹ãã å ã§åäœãããŸã§ã«ãŠã³ããç¶ããŸãã
ãã®äŸãå®è¡ããã¢ããªã±ãŒã·ã§ã³ããã°ã©ãã¯ãããªãã§ããïŒããšããååã«åºã¥ããŠã³ã³ããã¹ãèå¥åãéžæããŸããã
static const uint32_t m_context_id = 42;
åæãããã¡ã¢ãªã¯åçŽã«èŠããŸãïŒ
uint32_t m_counter;
é¢å¿ã®ããäž»ãªã¢ã¯ã·ã§ã³ã¯ãé¢æ°ã§çºçããŸãã
void CounterTask ::å®è¡ïŒïŒ
æåã«ãã³ã³ãããŒã©ãŒã¯èŠã€ããããšããŸãïŒã·ã¹ãã ã®æåã§ã¯ãããŸãããïŒ ãããè¡ãããã«ã圌ã¯ã³ã³ããã¹ããååŸããããšããŸãïŒ
Result result = GetContext(m_context_id, & m_counter);
ã³ã³ãããŒã©ãŒãæåã§ã¯ãªãå Žåãã³ã³ããã¹ããåä¿¡ãããéäžã§ã·ã¹ãã ã«ååšããã«ãŠã³ã¿ãŒå€ãåä¿¡ãããŸãã
ã³ã³ãããŒã©ãæåã®å Žåãã³ã³ããã¹ãã¯åä¿¡ãããŸããã ãã®å Žåã次ã®ããã«äœæããå¿ èŠããããŸãïŒåãå Žæã§ãã«ãŠã³ã¿ãŒã¯éäžã§æ¶ããŸãïŒã
if ( result != ResultOk ) { m_counter = 0; result = LockContext(m_context_id); if ( result == ResultOk ) { SetContext(m_context_id, & m_counter, sizeof(m_counter)); UnlockContext(m_context_id); } }
ãã¹ãŠããä»ã§ã¯ç¢ºå®ã«ã³ã³ããã¹ããååšããæ¥ç¶ããã°ããã®ã·ã¹ãã ã§çºèŠãããããäœæãããŸããã ç¡éã«ãŒãã«å ¥ããŸãïŒ
while (true) {
ããã§1ç§éåŸ æ©ããŸãã
Delay(MAKS_TICK_RATE_HZ);
ãããŠãã·ã¹ãã å šäœã«ã«ãŠã³ã¿ãŒãé åžããæš©å©ãããã£ãŠã³ã³ãã¹ãã«åãšããšããŠããŸãã
result = LockContext(m_context_id);
æåããããé åžããŸã
if ( result == ResultOk ) { GetContext(m_context_id, & m_counter); ++ m_counter; SetContext(m_context_id, & m_counter, sizeof(m_counter)); UnlockContext(m_context_id); }
ã©ããããã³ã³ããã¹ããé åžããŸãããåãåããŸããã å®éããã®äŸã§ã¯ãæ°ããæ¥ç¶ãããããã€ã¹ã®ã¿ãã³ã³ããã¹ããååŸããŸãã åä¿¡ããå Žåãããã€ã¹ã¯èªåŸçã«åäœããŸãã ãã¡ããã絶ããé£çµ¡ãåãåãæ¹ãè¯ãã§ããããã®ãããªã·ã¹ãã ã®èª¬æã¯ããå€ãã®çŽãåããŸãããããŠããªãã¯å¿çåŠã«å察ããããšã¯ãããŸãããã»ãšãã©ã®èªè ã¯åã«ããã³ããŠæ¬¡ã®ã»ã¯ã·ã§ã³ã«é²ã¿ãŸãã å ±æã¡ã¢ãªã®åçã¯ãå€ããå°ãªããæ確ã«ãªã£ããšæããŸãã