1 / 30

NesC 프로그래밍 실습 I

NesC 프로그래밍 실습 I. 1. Booting, LED 2. Timer 사용 (Blink) 3. Timer 2 개 이상. Basic : Lesson.1. Requirements : 1) 모든 LED 를 초기화한다 . 2) 모든 LED 를 ON 한다 . ** Red, Yellow, Green LED (in tos/interface/) - make telosb docs

Télécharger la présentation

NesC 프로그래밍 실습 I

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. NesC 프로그래밍 실습 I 1. Booting, LED 2. Timer 사용 (Blink) 3. Timer 2개 이상

  2. Basic : Lesson.1 • Requirements : 1) 모든 LED를 초기화한다. 2) 모든 LED를 ON 한다. ** Red, Yellow, Green LED (in tos/interface/) - make telosb docs ( in /doc/nesdoc/telosb/ )

  3. Test.nc configuration Test{ } implementation{ components Main, TestM, LedsC; Main.StdControl -> TestM; TestM.Leds ->LedsC; }

  4. TestM.nc module TestM{ provides { interface StdControl; } uses { interface Leds; } } implementation{ command result_t StdControl.init() { call Leds.init(); return SUCCESS; } command result_t StdControl.start() { call Leds.redOn(); call Leds.greenOn(); call Leds.yellowOn(); return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } }

  5. Basic : Lesson. 2 TimerC.timer[unique(“Timer”)]

  6. Test.nc configuration Test{ } implementation{ components Main, TestM, LedsC, TimerC; Main.StdControl -> TestM.StdControl; Main.StdControl -> TimerC. StdControl TestM.Leds ->LedsC.Leds; TestM.Timer -> TimerC.Timer[unique(“Timer”)] }

  7. TestM.nc command result_t StdControl.start() { call Timer.start(TIMER_REPEAT, 1000); return SUCCESS; } commandresult_t StdControl.stop() { call Timer.stop(); return SUCCESS; } eventresult_t Timer.fired(){ call Led.redToggle(); return SUCCESS; } } module TestM{ provides { interface StdControl; } uses { interface Leds; interface Timer; } } implementation{ command result_t StdControl.init() { call Leds.init(); return SUCCESS; }

  8. Basic : Lesson. 3 • Timer 2개 이상인 경우 Test.nc 에서 TimerC.Timer[unique(“Timer”)] TimerC.Timer2[unique(“Timer”)] TestM.nc 에서 Interface Timer as Timer2 event추가

  9. Test.nc configuration Test{ } implementation{ components Main, TestM, LedsC, TimerC; Main.StdControl -> TestM.StdControl; Main.StdControl -> TimerC. StdControl TestM.Leds -> LedsC.Leds; TestM.Timer -> TimerC.Timer[unique(“Timer”)] TestM.Timer2 -> TimerC.Timer[unique(“Timer”)] }

  10. TestM.nc command result_t StdControl.start() { call Timer.start(TIMER_REPEAT, 1000); call Timer2.start(TIMER_REPEAT,2000); return SUCCESS; } command result_t StdControl.stop() { call Timer.stop(); return SUCCESS; } Event result_t Timer.fired(){ call Led.redToggle(); return SUCCESS; } Event result_t Timer2.fired(){ call Led.redToggle(); return SUCCESS; } } module TestM{ provides { interface StdControl; } uses { interface Leds; interface Timer; interface Timer as Timer2 } } Implementation { command result_t StdControl.init() { call Leds.init(); return SUCCESS; }

  11. NesC 프로그래밍 실습 II 4. MSP430GeneralIO 5. MSP430Inturrupt 6. UART 통신

  12. Basic : Lesson. 4 • Requirements : • MSP430GeneralIOC component를 사용하여 LED를 제어하는 • 프로그램 작성 • - MSP430GeneralIO interface 사용 • (in tos/platform/msp430/) • - Msp430GeneralIOC Component 이용 • (in tos/platform/msp430/)

  13. Test.nc configurationTest{ } implementation{ components Main, TestM, LedsC, MSP430GeneralIOC; Main.StdControl -> TestM.StdControl; TestM.Leds ->LedsC.Leds; TestM.MSP430GeneralIO -> MSP430GeneralIOC.Port54 }

  14. TestM.nc module TestM { provides {        interface StdControl;      } uses {        interface MSP430GeneralIO;      }    } implementation { command result_t StdControl.init() {  call Leds.init();  call MSP430GeneralIO.makeOutput();  call MSP430GeneralIO.setHigh();  return SUCCESS; } commandresult_t StdControl.start() {         call MSP430GeneralIO.setLow(); return SUCCESS;     } commandresult_t StdControl.stop() {         return SUCCESS; } }

  15. Basic : Lesson. 5 Requirements : 1) LED를 초기화한다. 2) User 버튼(Port27)을 누르면, Red LED가 Toggle 한다. Msp430InterruptC Component 이용 (in tos/platform/msp430/)

  16. 센서 플랫폼 MCU 회로도

  17. 센서 플랫폼 MCU 회로도

  18. chattering call MSP430Interrupt.enable(); call MSP430Interrupt.disable; call MSP430Interrupt.clear(); call Leds.redToggle(); // do something call MSP430Interrupt.enable();

  19. Test.nc configurationTest{ } implementation{ components Main, TestM, LedsC, MSP430InterruptC; Main.StdControl -> TestM.StdControl; TestM.Leds ->LedsC.Leds; TestM.MSP430Interrupt -> MSP430InterruptC.Port27 }

  20. TestM.nc command result_t StdControl.start() { return SUCCESS; } command result_t StdControl.stop() { return SUCCESS; } async event void MSP430Interrupt.fired(){ call MSP430Interrupt.disable(); call MSP430Interrupt.clear(); call Leds.redToggle(); call MSP430Interrupt.enable(); } } module TestM{ provides { interface StdControl; } uses { interface Leds; interface MSP430Interrupt; } } implementation{ command result_t StdControl.init() { call Leds.init(); call MSP430Interrupt.enable(); call MSP430Interrupt.edge(TRUE); return SUCCESS; }

  21. Basic : Lesson. 6 • Requirements : • UART component 를 사용하여 인터럽트 발생시 0x47를 전송하는 • 프로그램 작성 • -ByteComm interface 사용 • (in tos/interface/) • -Msp430InterruptC Component 이용 • (in tos/platform/msp430/)

  22. Test.nc configurationTest{ } implementation{ components Main, TestM, LedsC, MSP430InterruptC, UART; Main.StdControl -> TestM.StdControl; Main.StdControl -> UART.Control; TestM.Leds ->LedsC.Leds; TestM.MSP430Interrupt -> MSP430InterruptC.Port27 TestM.ByteComm ->UART.ByteComm; }

  23. TestM.nc  async event void MSP430Interrupt.fired(){        call MSP430Interrupt.disable();        call MSP430Interrupt.clear();        call Leds.redToggle();        call MSP430Interrupt.enable();  // do something        call ByteComm.txByte(0x47);    // 0x47 means 'G'      }    async event result_t ByteComm.rxByteReady(uint8_t data, bool error, uint16_t strength){        // RX occurs, do something        call ByteComm.txByte(data);        call Leds.yellowToggle();        return SUCCESS;      }    async event result_t ByteComm.txByteReady(bool success){        // Second, third, fourth.....  byte tx via UART        // such as call ByteComm.txByte(0x47);        call Leds.greenToggle();        return SUCCESS;      }    async event result_t ByteComm.txDone(){        return SUCCESS;      } module TestM { provides {        interface StdControl;      } uses {        interface Leds;        interface ByteComm;        interface MSP430Interrupt;      }    } implementation { command result_t StdControl.init() {        call Leds.init();        call MSP430Interrupt.enable();        call MSP430Interrupt.edge(FALSE);        return SUCCESS;      } command result_t StdControl.start() {        return SUCCESS;      }   command result_t StdControl.stop() {        return SUCCESS;      }

  24. NesC 프로그래밍 실습 III 7. GenericComm

  25. Basic : Lesson. 7 • Requirements : • 인터럽트 발생하면 데이터 송수신 • - GenericComm component 사용 • (in tos/system/) • - Msp430InterruptC Component 이용 • (in tos/platform/msp430/) • - AM packet (in tos/platform/telos/) • - make 파일에 PFLAGS += -v 옵션을 주면 컴파일하는 파일을 모두 보여줌

  26. Test.nc configurationTest{ } implementation{ components Main, TestM, LedsC, MSP430InterruptC, GenericComm; Main.StdControl -> TestM.StdControl; TestM.Leds ->LedsC.Leds; TestM.MSP430Interrupt -> MSP430InterruptC.Port27 TestM.SendMsg -> GenericComm.SendMsg[1]; TestM.ReceiveMsg -> GenericComm.ReceiveMsg[1]; }

  27. TestM.nc module TestM { provides {        interface StdControl;      } uses {        interface Leds;        interface MSP430Interrupt; interface SendMsg; interface ReceiveMsg;      }    } implementation { command result_t StdControl.init() {        call Leds.init();        call MSP430Interrupt.enable();        call MSP430Interrupt.edge(FALSE);        return SUCCESS;      } command result_t StdControl.start() {        return SUCCESS;      } command result_t StdControl.stop() {        return SUCCESS; } TOS_Msg test_msg; async event void MSP430Interrupt.fired(){        call MSP430Interrupt.disable();        call MSP430Interrupt.clear();        call Leds.redToggle();        call MSP430Interrupt.enable();         call SendMsg(TOS_BCAST_ADDR, 28, &test_msg); } event result_t SendMsg,sendDone(TOS_MsgPtr msg,result_t success){ call Leds.yellowToggle();        return SUCCESS; } event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m){ call Leds.greenToggle();        return m; }

  28. SendMsg 2개 이상인 경우 • TestM.SendMsg -> GenericComm.SendMsg[1]; • TestM.ReceiveMsg -> GenericComm.ReceiveMsg[1]; • TestM.DeltaSendMsg -> GenericComm.SendMsg[2]; • TestM.DeltaReceiveMsg -> GenericComm.ReceiveMsg[2];

  29. Test.nc configurationTest{ } implementation{ components Main, TestM, LedsC, MSP430InterruptC, GenericComm; Main.StdControl -> TestM.StdControl; TestM.Leds ->LedsC.Leds; TestM.MSP430Interrupt -> MSP430Interrupt.Port27 TestM.SendMsg -> GenericComm.SendMsg[1]; TestM.ReceiveMsg -> GenericComm.ReceiveMsg[1]; TestM.DeltaSendMsg -> GenericComm.SendMsg[2]; TestM.DeltaReceiveMsg -> GenericComm.ReceiveMsg[2]; }

  30. TestM.nc command result_t StdControl.stop() { return SUCCESS; } TOS_Msg test_msg; async event void MSP430Interrupt.fired(){ call MSP430Interrupt.disable(); call MSP430Interrupt.clear(); call Leds.redOn(); call MSP430Interrupt.enable(); call SendMsg(TOS_BCAST_ADDR, 28, &test_msg); // call DeltaSendMsg(TOS_BCAST_ADDR, 28, &test_msg); } event result_t SendMsg,sendDone(TOS_MsgPtr msg,result_t success){ call Leds.redOff(); return SUCCESS; } event TOS_MsgPtr ReceiveMsg.receive(TOS_MsgPtr m){ call Leds.greenToggle(); return m; } event result_t DeltaSendMsg,sendDone(TOS_MsgPtr msg,result_t success){ call Leds.redOff(); return SUCCESS; } event TOS_MsgPtr DeltaReceiveMsg.receive(TOS_MsgPtr m){ call Leds.yellowToggle(); return m; } module TestM { provides {         interface StdControl;      } uses {        interface Leds;        interface MSP430Interrupt; interface SendMsg; interface ReceiveMsg; interface SendMsg as DeltaSendMsg; interface ReceiveMsg as DeltaSendMsg;      }    } implementation { command result_t StdControl.init() {         call Leds.init();         call MSP430Interrupt.enable();         call MSP430Interrupt.edge(FALSE);         return SUCCESS;       } command result_t StdControl.start() {         return SUCCESS;       }

More Related