Beispiel #1
0
void receiver() {
	char data = '\0';

	while(1) {
		AwaitEvent(EVENT_COM2_RX, &data, sizeof(char));
		AwaitEvent(EVENT_COM2_TX, &data, sizeof(char));
	}
}
Beispiel #2
0
ScrollView::~ScrollView() {
  #ifndef GRAPHICS_DISABLED
  svmap_mu->Lock();
  if (svmap[window_id_] != nullptr) {
    svmap_mu->Unlock();
    // So the event handling thread can quit.
    SendMsg("destroy()");

    SVEvent* sve = AwaitEvent(SVET_DESTROY);
    delete sve;
    svmap_mu->Lock();
    svmap[window_id_] = nullptr;
    svmap_mu->Unlock();
    // The event handler thread for this window *must* receive the
    // destroy event and set its pointer to this to nullptr before we allow
    // the destructor to exit.
    while (!event_handler_ended_)
      Update();
  } else {
    svmap_mu->Unlock();
  }
  delete mutex_;
  delete semaphore_;
  delete points_;
  for (int i = 0; i < SVET_COUNT; i++) {
    delete event_table_[i];
  }
  #endif  // GRAPHICS_DISABLED
}
void uart1_receiver_notifier() {
	bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: enters" );

	int server_tid = WhoIs("uart1_receiver");
	UART_request request;
	
	int receive_buffer = 0;


	FOREVER {
		//Wait until there is data in UART1
		//bwprintf( COM2, "F\n" );
		bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: waiting for data" );
		AwaitEvent( UART1_RECEIVE_READY, (int) &receive_buffer );
		bwdebug( DBG_SYS, UART1_RECEIVER_DEBUG_AREA, "UART1_RECEIVER_NOTIFIER: data received" );
		//bwprintf( COM2, "G\n" );

		//Configure the request
		request.type = UART1_RECEIVE_NOTIFIER_REQUEST;
		request.ch = receive_buffer;

		//Send data to the server (uart1_receiver_server)
		Send(server_tid, (char *) &request, sizeof(request), (char *) 0, 0);
	}
}
Beispiel #4
0
// Shows a modal Yes/No Dialog which will return 'y' or 'n'
int ScrollView::ShowYesNoDialog(const char* msg) {
  SendMsg("showYesNoDialog(\"%s\")", msg);
  SVEvent* ev;
  // Wait till an input event (all others are thrown away)
  ev = AwaitEvent(SVET_INPUT);
  int a = ev->parameter[0];
  delete ev;
  return a;
}
Beispiel #5
0
void sender() {
	char data[11] = "0123456789";
	int i = 0;

	while(++i) {
		Delay(100);
		AwaitEvent(EVENT_COM2_TX, &(data[i % 10]), sizeof(char));
	}
}
Beispiel #6
0
void clockTick() {
	unsigned int time = 0;
	int tid = MyTid();
	while(1) {
		AwaitEvent(EVENT_TIME_ELAP, NULL, 0);
		time++;
		bwprintf(COM2, "%d: %ds\n", tid, time);
	}
}
Beispiel #7
0
// Shows a modal Input Dialog which can return any kind of String
char* ScrollView::ShowInputDialog(const char* msg) {
  SendMsg("showInputDialog(\"%s\")", msg);
  SVEvent* ev;
  // wait till an input event (all others are thrown away)
  ev = AwaitEvent(SVET_INPUT);
  char* p = new char[strlen(ev->parameter) + 1];
  strcpy(p, ev->parameter);
  delete ev;
  return p;
}
Beispiel #8
0
void notifier() {
	char cs_name[] = CS_REG_NAME;
	int cs_tid = WhoIs(cs_name);
	assert(cs_tid >= 0, "Notifier cannot find clock server's tid");

	char send[1] = "";
	while (1) {
		AwaitEvent(EVENT_TIME_ELAP, NULL, 0);
		Send(cs_tid, send, 1, NULL, 0);
	}
}
Beispiel #9
0
void clockNotifier()
{
    // Initialize variabels
    int pid = MyParentTid();
    ClockReq req;
    req.type = NOTIFICATION;
    req.data = 0xdeadbeaf;
    for (;;)
    {
        AwaitEvent(TIMER_EVENT);
        Send(pid, &req, sizeof(req), 0, 0);
    }
}
Beispiel #10
0
ScrollView::~ScrollView() {
  if (svmap[window_id_] != NULL) {
    // So the event handling thread can quit.
    SendMsg("destroy()");

    SVEvent* sve = AwaitEvent(SVET_DESTROY);
    delete sve;
  }
  delete mutex_;
  delete semaphore_;
  delete points_;

  svmap.erase(window_id_);
}
Beispiel #11
0
static void timernotifier_task() {
  int parent = MyParentsTid();
  // Enable timer device
  VMEM(TIMER1_BASE + CRTL_OFFSET) &= ~ENABLE_MASK; // stop timer
  VMEM(TIMER1_BASE + LDR_OFFSET)   = 5080; // Corresponds to clock frequency, 10 ticks
  VMEM(TIMER1_BASE + CRTL_OFFSET) |= MODE_MASK; // pre-load mode
  VMEM(TIMER1_BASE + CRTL_OFFSET) |= CLKSEL_MASK; // 508Khz clock
  VMEM(TIMER1_BASE + CRTL_OFFSET) |= ENABLE_MASK; // start

  // Enables timer interrupt.
  VMEM(VIC1 + INT_ENABLE) = 1 << TC1OI;

  for (;;) {
    AwaitEvent(TC1OI);
    Send(parent, (char*)NULL, 0, (char*)NULL, 0);
  }
}
Beispiel #12
0
/*
 * Notifier task for the serial server -- Awaits the UART1TRANS event
 */
void notifier_uart1tx()
{
  int r, tid;
  char data = 't';
  char dummy;
  tid = WhoIs("com1");

  FOREVER {
    AwaitEvent(UART1TRANS);
    *(uint*)(UART1_BASE+UART_INTR_OFFSET) = 0xFFFFFFFF;  // clear interrupt

 //   DPRINTOK ("UART1 TRANSMISSION INTERRUPT.\n");
    
    if ((*(int*)(UART1_BASE+UART_FLAG_OFFSET) & CTS_MASK) && (*(int*)(UART1_BASE+UART_FLAG_OFFSET) & TXFE_MASK)) {
      *(uint*)(VIC2BASE+INTENCL_OFFSET)  = UART1_MASK;
      r = Send (tid, &data,1, &dummy, 1);
      if (r) { *(uint*)(VIC2BASE+INTEN_OFFSET) = UART1_MASK;} // if uart1 server asked us to we turn back on interrupts
    }
  }
}
Beispiel #13
0
void display_notifier(void){
	int parentTid = MyParentTid(); // since it was the clockserver that created this task

	// construct the tick message hat we will send when we receive a tick
	MsgClockServer tickMsg;
	tickMsg.type = MSG_TICK;
	tickMsg.data = 0x0;

	int tickcount = 0;

	FOREVER {
		AwaitEvent(EVENT_TICK, NULL, 0); // enable timer interrupts and wait for a tick event
		// a tick has occured, so send a tick message to the clock server; expect no reply data
		tickcount++;
		if(tickcount >= 10){
			tickcount = 0;
			Send(parentTid, (char *)&tickMsg, CLOCKSERVER_BUF_LEN, NULL, 0);
		}
	}
}
Beispiel #14
0
ScrollView::~ScrollView() {
  svmap_mu->Lock();
  if (svmap[window_id_] != NULL) {
    svmap_mu->Unlock();
    // So the event handling thread can quit.
    SendMsg("destroy()");

    SVEvent* sve = AwaitEvent(SVET_DESTROY);
    delete sve;
    svmap_mu->Lock();
    svmap[window_id_] = NULL;
    svmap_mu->Unlock();
    // The event handler thread for this window *must* receive the
    // destroy event and set its pointer to this to NULL before we allow
    // the destructor to exit.
    while (!event_handler_ended_)
      Update();
  } else {
    svmap_mu->Unlock();
  }
  delete mutex_;
  delete semaphore_;
  delete points_;
}
Beispiel #15
0
static void tioNotifier(void) {
    int serverTid = MyParentTid();

    /* set baud: 2400 bps */
    *((volatile unsigned int *) (UART1_BASE + UART_LCRM_OFFSET)) = 0x0;
    *((volatile unsigned int *) (UART1_BASE + UART_LCRL_OFFSET)) = 0xbf;
    /* disable the fifo */
    volatile unsigned int *high =
        (volatile unsigned int *) (UART1_BASE + UART_LCRH_OFFSET);
    *high &= ~FEN_MASK;

    /* initialize the tx buffer */
    g_tio_tx_buffer.head = g_tio_tx_buffer.tail = 0;
    g_tio_tx_buffer.buffer[0] = 0x60;
    g_tio_tx_buffer.buffer[1] = 0x61;
    g_tio_tx_buffer.buffer[2] = 0x60;
    g_tio_tx_buffer.buffer[3] = 0xc0;
    g_tio_tx_buffer.tail = 4;

    /* UART registers */
    volatile unsigned short *data =
        (volatile unsigned short *) (UART1_BASE + UART_DATA_OFFSET);
    volatile unsigned short *flags =
        (volatile unsigned short *) (UART1_BASE + UART_FLAG_OFFSET);

    while(!(*flags & RXFE_MASK)){
        (void) *data;
    }

    bool txfe = false, cts = true, clear_cts = true;

    while (1) {
        if (g_tio_quit) {
            break;
        }

        /* transmit data if possible */
        if (txfe && clear_cts && cts && !(*flags & TXFF_MASK) &&
                !(*flags & TXBUSY_MASK) && (*flags & CTS_MASK) &&
                g_tio_tx_buffer.head != g_tio_tx_buffer.tail) {
            *data = g_tio_tx_buffer.buffer[g_tio_tx_buffer.head];
            g_tio_tx_buffer.head =
                (g_tio_tx_buffer.head + 1) % TIO_TX_BUFFER_LEN;
            txfe = false;
            cts = false;
            clear_cts = false;
        }

        /* Always enable receive and modem status interrupts.
         * Don't need receive timeout because we aren't using FIFO.
         */
        unsigned short int_flags = UARTEN_MASK | RIEN_MASK | MSIEN_MASK;

        if (!txfe) {
            /* Only enable transmit interrupt when we have something to send or
             * we're waiting to know when the transmit buffer is empty.
             *
             * Use the same software interrupt trick on transmit as mio.
             */
            int_flags |= TIEN_MASK;
        }

        *((volatile unsigned short *) (UART1_BASE + UART_CTLR_OFFSET)) =
            int_flags;

        AwaitEvent(INT_UART1);

        unsigned short intr =
            *((volatile unsigned short *) (UART1_BASE + UART_INTR_OFFSET));

        if (intr & RIS_MASK) {
            /* receive interrupt */
            struct String str;
            sinit(&str);

            char c = *data;
            ssettag(&str, CMD_NOTIFIER_RX);
            sputc(&str, c);

            Send(
                serverTid,
                (char *) &str, sizeof (struct String),
                (char *) 0, 0
            );
        }

        if (intr & TIS_MASK) {
            /* transmit interrupt */
            txfe = true;
        }

        if (intr & MIS_MASK) {
            /* modem status interrupt */
            if (*flags & CTS_MASK) {
                cts = true;
            } else {
                clear_cts = true;
            }
            *((volatile unsigned short *) (UART1_BASE + UART_INTR_OFFSET)) = 1;
        }

        /* Software interrupt. Just clear it so we can re-evaluate the
         * transmit buffer state. */
        *((volatile unsigned int *)
            (SOFTINT_BASE + VIC_SOFTWARE_INT_CLEAR)) = SOFTINT_POS;
    }

    Exit();
}
void uart1_sender_notifier() {
	bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: enters" );

	int* uart_flags =	(int *)( UART1_BASE + UART_FLAG_OFFSET );
	int* uart_data =	(int *)( UART1_BASE + UART_DATA_OFFSET );
	int* modem_ctrl =	(int *)( UART1_BASE + UART_MDMCTL_OFFSET);
	int* modem_status =	(int *)( UART1_BASE + UART_MDMSTS_OFFSET);
	
	int uart_flags_temp = 0;
	int modem_ctrl_temp = 0;
	int modem_status_temp = 0;

	int sender_tid;
	UART_request request;
	
	//State machine variables
	//CTS states:
	//	0 - CTS is set to '1' before the character is sent
	//	1 - CTS is set to '0' after the character is sent
	//	2 - CTS is set to '1' after the character is sent
	int cts_state = 0;
	
	//Transmit states:
	//	0 - Transmit is set to '0' right after the character is sent
	//	1 - Transmit is set to '1' after the character is sent
	int txfe_state = 0;

	//Utility variables
	int first_request = 1;
	int first_iter = 1;

	FOREVER {
		//Get request with character from the uart1_sender_server
		bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: Waiting for request..." );
		Receive(&sender_tid, (char *) &request, sizeof(request));
		//Reply, to unblock the uart1_sender_server
		Reply(sender_tid, (char *) 0, 0);
		bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: Received send request." );

		//Reinitialize modem
		//RTSn pin is set to low
		//DTRn pin is set to low
		modem_ctrl_temp = *modem_ctrl;
		*modem_ctrl = modem_ctrl_temp | 3;

		//Initialize the state machine
		cts_state = 0;
		txfe_state = 0;
		first_iter = 1;
		
		FOREVER {
			//*uart_data = 'b';
			//Wait until UART1 is ready to receive a character
			if(txfe_state == 0 || first_iter) {
				bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: Waiting for INIT event." );
				AwaitEvent(UART1_INIT_SEND, 0);
			}
			else {
				bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: Waiting for SEND READY event." );
				AwaitEvent(UART1_SEND_READY, 0);
			}

			
			//*uart_data = 'd';
			
			first_iter = 0;
			//txfe_state = 1;
			//*uart_data = 'e';
			
			modem_status_temp = *modem_status;
			uart_flags_temp = *uart_flags;

			//Changing state of the state machine////////////////////
			// bwprintf( COM2, "STATE00: CTS: %d TXFE: %d\n", cts_state, txfe_state );
			
			//IF   CTS value has changed
			//AND  CTS value is now set to '1'
			//THEN CTS has been reasserted
			if( ((modem_status_temp & DCTS_MASK) || first_request)
				&& (uart_flags_temp & CTS_MASK)) {
				cts_state = 2;
				// bwprintf( COM2, "STATE03: CTS: %d TXFE: %d\n", cts_state, txfe_state );
			}
			
			//IF   CTS value is set to '0'
			//THEN CTS has been deasserted
			if( cts_state == 0 && !(uart_flags_temp & CTS_MASK) ) {
				cts_state = 1;
				// bwprintf( COM2, "STATE02: CTS: %d TXFE: %d\n", cts_state, txfe_state );
			}
			
			

			//IF   CTS has been deasserted
			//AND  CTS value is now set to '1'
			//THEN CTS has been reasserted
			if( cts_state == 1 && (uart_flags_temp & CTS_MASK) ) {
				cts_state = 2;
				// bwprintf( COM2, "STATE04: CTS: %d TXFE: %d\n", cts_state, txfe_state );
			}
			
			//IF transmit is set to '1'
			if( (uart_flags_temp & TXFE_MASK) ) {
				txfe_state = 1;
				// bwprintf( COM2, "STATE01: CTS: %d TXFE: %d\n", cts_state, txfe_state );
			}
			
			//IF   CTS has been reasserted
			//AND  Transmit has been reasserted
			//THEN Send the character to UART1
			if( cts_state == 2 && txfe_state == 1 ) {
				*uart_data = (char) request.ch;
				first_request = 0;
				bwdebug( DBG_SYS, UART1_SENDER_DEBUG_AREA, "UART1_SENDER_NOTIFIER: Sending data" );
				break;
			}
		}
	}
}
Beispiel #17
0
static void mioNotifier(void) {
    int serverTid = MyParentTid();

    /* set baud: 115.2 kbps */
    *((volatile unsigned int *) (UART2_BASE + UART_LCRM_OFFSET)) = 0x0;
    *((volatile unsigned int *) (UART2_BASE + UART_LCRL_OFFSET)) = 0x3;
    /* enable the fifo */
    volatile unsigned int *high =
        (volatile unsigned int *) (UART2_BASE + UART_LCRH_OFFSET);
    *high |= FEN_MASK;

    /* initialize the tx buffer */
    g_mio_tx_buffer.head = g_mio_tx_buffer.tail = 0;

    while (true) {
        if (g_mio_quit) {
            break;
        }

        /* always enable receive interrupts. FIXME: what about modem status? */
        unsigned short int_flags = UARTEN_MASK | RIEN_MASK | RTIEN_MASK;
        /* DANGER WILL ROBINSON: THIS CAN BREAK HORRIBLY!
         *
         * To prevent useless interrupts when we have nothing to send, we only
         * enable the transmit interrupt when necessary. However, if transmit
         * interrupts are disabled and we queue on some output, the output will
         * not be flushed until the next UART interrupt (possibly the user
         * typing something in).
         *
         * Since buffering output till the user types something is clearly
         * broken, we get around this by having the server raise the UART
         * interrupt in software (after loading data into g_mio_tx_buffer). This
         * will eventually bring us to the top of our loop, where we'll
         * re-evaluate our state and enable the transmit interrupt.
         */
        if (g_mio_tx_buffer.head != g_mio_tx_buffer.tail) {
            /* only enable transmit interrupt if we have stuff to send */
            int_flags |= TIEN_MASK;
        }
        *((volatile unsigned short *) (UART2_BASE + UART_CTLR_OFFSET)) =
            int_flags;

        /* Wait for something to happen */
        AwaitEvent(INT_UART2);

        unsigned short intr =
            *((volatile unsigned short *) (UART2_BASE + UART_INTR_OFFSET));
        volatile unsigned short *data =
            (volatile unsigned short *) (UART2_BASE + UART_DATA_OFFSET);
        volatile unsigned short *flags =
            (volatile unsigned short *) (UART2_BASE + UART_FLAG_OFFSET);

        if (intr & (RIS_MASK | RTIS_MASK)) {
            /* receive interrupt */
            struct String str;
            sinit(&str);
            ssettag(&str, CMD_NOTIFIER_RX);

            while (!(*flags & RXFE_MASK)) {
                sputc(&str, *data);
            }

            Send(
                serverTid,
                (char *) &str, sizeof (struct String),
                (char *) 0, 0
            );
        }

        /* FIXME: we don't care about CTS for monitor? */
        if (intr & TIS_MASK) {
            /* transmit interrupt */
            while (g_mio_tx_buffer.head != g_mio_tx_buffer.tail &&
                    !(*flags & TXFF_MASK)) {
                *data = g_mio_tx_buffer.buffer[g_mio_tx_buffer.head];
                g_mio_tx_buffer.head =
                    (g_mio_tx_buffer.head + 1) % MIO_TX_BUFFER_LEN;
            }
        }

        /* Software interrupt. Just clear it so we can re-evaluate the
         * transmit buffer state. */
        *((volatile unsigned int *)
            (SOFTINT_BASE + VIC_SOFTWARE_INT_CLEAR)) = SOFTINT_POS;
    }

    Exit();
}
Beispiel #18
0
void TestMap()
{

   XSizeHints *hints;
   XWindowAttributes attr;
   Window w;

   /* Create the window. */
   w = XCreateSimpleWindow(display, rootWindow, 100, 100, 200, 100, 0, 0, 0);
   XSelectInput(display, w, StructureNotifyMask | PropertyNotify);

   /* Map the window and wait for it. */
   XMapWindow(display, w);
   Assert(AwaitEvent(MapNotify));

   /* Unmap the window and wait for it. */
   XUnmapWindow(display, w);
   Assert(AwaitEvent(UnmapNotify));

   /* Map the window and wait for it (again). */
   XMapWindow(display, w);
   Assert(AwaitEvent(MapNotify));

   /* Minimize and wait. */
   Minimize(w);
   Assert(AwaitEvent(UnmapNotify));

   /* Restore and wait. */
   Unminimize(w);
   Assert(AwaitEvent(MapNotify));

   /* Maximize and wait. */
   Maximize(w, 1, 1);
   Assert(AwaitEvent(ConfigureNotify));

   /* Unmaximize and wait. */
   Unmaximize(w, 0, 1);
   Assert(AwaitEvent(ConfigureNotify));

   /* Unmaximize and wait. */
   Unmaximize(w, 1, 0);
   Assert(AwaitEvent(ConfigureNotify));

   /* Change the size hints. */
   hints = XAllocSizeHints();
   hints->flags = PMinSize;
   hints->min_width = 300;
   hints->min_height = 200;
   XSetWMNormalHints(display, w, hints);
   XFree(hints);
   XSync(display, False);
   sleep(1);
   IgnoreEvents();
   XGetWindowAttributes(display, w, &attr);
   Assert(attr.width == 300);
   Assert(attr.height == 200);

   /* Shade and wait. */
   Shade(w);
   Assert(AwaitEvent(UnmapNotify));

   /* Maximize and wait. */
   Maximize(w, 0, 1);
   Assert(AwaitEvent(MapNotify));

   /* Shade and wait. */
   Shade(w);
   Assert(AwaitEvent(UnmapNotify));

   /* Unshade and wait. */
   Unshade(w);
   Assert(AwaitEvent(MapNotify));

   /* Destroy the window. */
   XDestroyWindow(display, w);

}