Exemplo n.º 1
0
__interrupt void uart0_rx_isr(void)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  URX0IF = 0;
  if(uart0_input_handler != NULL) {
    uart0_input_handler(U0DBUF);
  }
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Exemplo n.º 2
0
/*---------------------------------------------------------------------------*/
void UART0IntHandler(void)
{
	unsigned long ulStatus;

	ulStatus = ROM_UARTIntStatus(UART0_BASE, true);
	ROM_UARTIntClear(UART0_BASE, ulStatus);

	while(ROM_UARTCharsAvail(UART0_BASE))
	{
		uart0_input_handler(ROM_UARTCharGetNonBlocking(UART0_BASE));
	}
}
Exemplo n.º 3
0
ISR(USCIAB0RX, uartA0B0_rx_interrupt)
{
  uint8_t c;
  /* Check status register for receive errors. */
  if(UCA0STAT & UCRXERR) {
    c = UCA0RXBUF;   /* Clear error flags by forcing a dummy read. */
  } else {
    c = UCA0RXBUF;
    if(uart0_input_handler != NULL) {
      if(uart0_input_handler(c)) {
      	LPM4_EXIT;
      }
    }
  }
}
Exemplo n.º 4
0
static void
handle_rxdma_timer(void *ptr)
{
  uint16_t size;
  size = DMA0SZ; /* Note: loop requires that size is less or eq to RXBUFSIZE */
  while(last_size != size) {
    uart0_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]);
    last_size--;
    if(last_size == 0) {
      last_size = RXBUFSIZE;
    }
  }

  ctimer_reset(&rxdma_timer);
}
Exemplo n.º 5
0
ISR(USCIAB0RX, uart0_rx_interrupt)
{
  uint8_t c;

  ENERGEST_ON(ENERGEST_TYPE_IRQ);
  if(UCA0STAT & UCRXERR) {
    c = UCA0RXBUF;   /* Clear error flags by forcing a dummy read. */
  } else {
    c = UCA0RXBUF;
    if(uart0_input_handler != NULL) {
      if(uart0_input_handler(c)) {
        LPM4_EXIT;
      }
    }
  }
  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Exemplo n.º 6
0
/*---------------------------------------------------------------------------*/
static void
uart_event_handler(nrf_drv_uart_event_t * p_event, void * p_context)
{
  ENERGEST_ON(ENERGEST_TYPE_IRQ);

  if (p_event->type == NRF_DRV_UART_EVT_RX_DONE) {
    if (uart0_input_handler != NULL) {
      uart0_input_handler(p_event->data.rxtx.p_data[0]);
    }
    (void)nrf_drv_uart_rx(rx_buffer, 1);
  } else if (p_event->type == NRF_DRV_UART_EVT_TX_DONE) {
    if (ringbuf_elements(&txbuf) > 0) {
      uint8_t c = ringbuf_get(&txbuf);
      nrf_drv_uart_tx(&c, 1);
    }
  }

  ENERGEST_OFF(ENERGEST_TYPE_IRQ);
}
Exemplo n.º 7
0
int
main(int argc, char **argv)
{
    bool flip_flop = false;

    asm ("di");
    /* Setup clocks */
    CMC = 0x11U;                                        /* Enable XT1, disable X1 */
    CSC = 0x80U;                                        /* Start XT1 and HOCO, stop X1 */
    CKC = 0x00U;
    delay_1sec();
    OSMC = 0x00;                                       /* Supply fsub to peripherals, including Interval Timer */
    uart0_init();

#if __GNUC__
    /* Force linking of custom write() function: */
    write(1, NULL, 0);
#endif

    /* Setup 12-bit interval timer */
    RTCEN = 1;                                              /* Enable 12-bit interval timer and RTC */
    ITMK = 1;                                               /* Disable IT interrupt */
    ITPR0 = 0;                                              /* Set interrupt priority - highest */
    ITPR1 = 0;
    ITMC = 0x8FFFU;                                    /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */
    ITIF = 0;                                               /* Clear interrupt request flag */
    ITMK = 0;                                               /* Enable IT interrupt */
    /* asm ("ei");                                             / * Enable interrupts * / */

    /* Disable analog inputs because they can conflict with the SPI buses: */
    ADPC = 0x01;  /* Configure all analog pins as digital I/O. */
    PMC0 &= 0xF0; /* Disable analog inputs. */

    clock_init();

    /* Initialize Joystick Inputs: */
    PM5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Set pins as inputs. */
    PU5 |= BIT(5) | BIT(4) | BIT(3) | BIT(2) | BIT(1); /* Enable internal pull-up resistors. */

    /* Initialize LED outputs: */
#define BIT(n) (1 << (n))
    PM12 &= ~BIT(0); /* LED1 */
    PM4 &= ~BIT(3);  /* LED2 */
    PM1 &= ~BIT(6);  /* LED3 */
    PM1 &= ~BIT(5);  /* LED4 */
    PM0 &= ~BIT(6);  /* LED5 */
    PM0 &= ~BIT(5);  /* LED6 */
    PM3 &= ~BIT(0);  /* LED7 */
    PM5 &= ~BIT(0);  /* LED8 */

#if UIP_CONF_IPV6
#if UIP_CONF_IPV6_RPL
    printf(CONTIKI_VERSION_STRING " started with IPV6, RPL" NEWLINE);
#else
    printf(CONTIKI_VERSION_STRING " started with IPV6" NEWLINE);
#endif
#else
    printf(CONTIKI_VERSION_STRING " started" NEWLINE);
#endif

    /* crappy way of remembering and accessing argc/v */
    contiki_argc = argc;
    contiki_argv = argv;

    process_init();
    process_start(&etimer_process, NULL);
    ctimer_init();

    set_rime_addr();

    queuebuf_init();

    netstack_init();
    printf("MAC %s RDC %s NETWORK %s" NEWLINE, NETSTACK_MAC.name, NETSTACK_RDC.name, NETSTACK_NETWORK.name);

#if WITH_UIP6
    memcpy(&uip_lladdr.addr, serial_id, sizeof(uip_lladdr.addr));

    process_start(&tcpip_process, NULL);
    printf("Tentative link-local IPv6 address ");
    {
        uip_ds6_addr_t *lladdr;
        int i;
        lladdr = uip_ds6_get_link_local(-1);
        for(i = 0; i < 7; ++i) {
            printf("%02x%02x:", lladdr->ipaddr.u8[i * 2],
                   lladdr->ipaddr.u8[i * 2 + 1]);
        }
        /* make it hardcoded... */
        lladdr->state = ADDR_AUTOCONF;

        printf("%02x%02x" NEWLINE, lladdr->ipaddr.u8[14], lladdr->ipaddr.u8[15]);
    }
#else
    process_start(&tcpip_process, NULL);
#endif

    serial_line_init();

    autostart_start(autostart_processes);

    while(1) {
        watchdog_periodic();

        if(NETSTACK_RADIO.pending_packet()) {
            int len;
            packetbuf_clear();
            len = NETSTACK_RADIO.read(packetbuf_dataptr(), PACKETBUF_SIZE);
            if(len > 0) {
                packetbuf_set_datalen(len);
                NETSTACK_RDC.input();
            }
        }

        while(uart0_can_getchar()) {
            char c;
            UART_RX_LED = 1;
            c = uart0_getchar();
            if(uart0_input_handler) {
                uart0_input_handler(c);
            }
        }
        UART_RX_LED = 0;

        process_run();

        etimer_request_poll();

        HEARTBEAT_LED1 = flip_flop;
        flip_flop = !flip_flop;
        HEARTBEAT_LED2 = flip_flop;
    }

    return 0;
}