Ejemplo n.º 1
0
    virtual void onNotify(Observable&,ObservableEvent::E event,void *) {

      if(event==ObservableEvent::USART_ReadyToTransmit && *_dataToSend) {

        // send the next character and increment the pointer

        _usart.send(*_dataToSend++);

        // if we are now at the end of the string then disable further interrupts
        // because we are done

        if(*_dataToSend=='\0')
          _usart.disableInterrupts(MyUsartInterrupt::TRANSMIT);
      }
    }
    void onInterrupt(UsartEventType uet) {

      if(uet==UsartEventType::EVENT_RECEIVE) {

        // receive the next character

        _buffer[_index++]=_usart.receive();

        // if we've got the 5 characters then disable receiving interrupts
        // and enable sending

        if(_index==5) {
          _index=0;
          _usart.disableInterrupts(MyUsartInterrupt::RECEIVE);
          _usart.enableInterrupts(MyUsartInterrupt::TRANSMIT);
        }
      }
      else if(uet==UsartEventType::EVENT_READY_TO_TRANSMIT) {

        // send the next character

        _usart.send(_buffer[_index++]);

        // if we've sent back all 5 then disable sending interrupts and go back
        // to receiving again

        if(_index==5) {
          _index=0;
          _usart.disableInterrupts(MyUsartInterrupt::TRANSMIT);
          _usart.enableInterrupts(MyUsartInterrupt::RECEIVE);
        }
      }
    }
Ejemplo n.º 3
0
    void run()  {

      // we're using interrupts, set up the NVIC

      Nvic::initialise();

      // set the initial string pointer

      _dataToSend="Hello World";

      // register ourselves as an observer of the USART interrupts

      _usart.insertObserver(*this);

      // enable interrupts. this will cause an immediate ready-to-send interrupt

      _usart.enableInterrupts(MyUsartInterrupt::TRANSMIT);

      // finished

      for(;;);
    }
    void run()  {

      /*
       * We're using interrupts, set up the NVIC
       */

      Nvic::initialise();

      // register ourselves as an observer of the USART interrupts

      _usart.UsartInterruptEventSender.insertSubscriber(
          UsartInterruptEventSourceSlot::bind(this,&UsartReceiveInterruptsTest::onInterrupt)
        );

      // enable the receive interrupt. this will start the whole chain of events

      _index=0;
      _usart.enableInterrupts(MyUsartInterrupt::RECEIVE);

      // it's all going on in the background now. wish us luck :)

      for(;;);
    }