ISR(UART1RX, uart1_rx_interrupt) { uint8_t c; ENERGEST_ON(ENERGEST_TYPE_IRQ); if(!(URXIFG1 & IFG2)) { /* Edge detect if IFG not set? */ U1TCTL &= ~URXSE; /* Clear the URXS signal */ U1TCTL |= URXSE; /* Re-enable URXS - needed here?*/ rx_in_progress = 1; LPM4_EXIT; } else { rx_in_progress = 0; /* Check status register for receive errors. */ if(URCTL1 & RXERR) { c = RXBUF1; /* Clear error flags by forcing a dummy read. */ } else { c = RXBUF1; if(uart1_input_handler != NULL) { if(uart1_input_handler(c)) { LPM4_EXIT; } } } } ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
__interrupt void uart1_rx_isr(void) { ENERGEST_ON(ENERGEST_TYPE_IRQ); URX1IF = 0; if(uart1_input_handler != NULL) { uart1_input_handler(U1DBUF); } ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
/*--------------------------------------------------------------------------*/ void uart1_rx_interrupt(void) { uint8_t c; c = SC1_DATA; if(uart1_input_handler != NULL) { uart1_input_handler(c); } }
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) { /* printf("read: %c [%d,%d]\n", (unsigned char)rxbuf[RXBUFSIZE - last_size], */ /* last_size, size); */ uart1_input_handler((unsigned char)rxbuf[RXBUFSIZE - last_size]); last_size--; if(last_size == 0) last_size = RXBUFSIZE; } ctimer_reset(&rxdma_timer); }
/*---------------------------------------------------------------------------*/ ISR(USCI_A1, uart1_rx_interrupt) { uint8_t c; ENERGEST_ON(ENERGEST_TYPE_IRQ); /*leds_toggle(LEDS_ALL);*/ if(UCA1IV == 2) { if(UCA1STAT & UCRXERR) { c = UCA1RXBUF; /* Clear error flags by forcing a dummy read. */ } else { c = UCA1RXBUF; if(uart1_input_handler != NULL) { if(uart1_input_handler(c)) { LPM4_EXIT; } } } } ENERGEST_OFF(ENERGEST_TYPE_IRQ); }
/*---------------------------------------------------------------------------*/ void USART1_IRQHandler(void) { uint8_t c; GPIO_SetBits(GPIOD, GPIO_Pin_12); if(USART_GetITStatus(USART1, USART_IT_RXNE)) { USART_ClearITPendingBit(USART1,USART_IT_RXNE); c=USART_ReceiveData(USART1); if(uart1_input_handler != NULL) { uart1_input_handler(c); } } if(USART_GetITStatus(USART1, USART_IT_ORE|USART_IT_IDLE)) { USART_ClearITPendingBit(USART1,USART_IT_ORE|USART_IT_IDLE); } GPIO_ResetBits(GPIOD, GPIO_Pin_12); }
int main(void) { mc1322x_init(); /* m12_init() flips the mux switch */ /* trims the main crystal load capacitance */ if (!FORCE_ECONOTAG_I && CRM->SYS_CNTLbits.XTAL32_EXISTS) { /* M12 based econotag */ PRINTF("trim xtal for M12\n\r"); CRM->XTAL_CNTLbits.XTAL_CTUNE = (M12_CTUNE_4PF << 4) | M12_CTUNE; CRM->XTAL_CNTLbits.XTAL_FTUNE = M12_FTUNE; /* configure pullups for low power */ GPIO->FUNC_SEL.GPIO_63 = 3; GPIO->PAD_PU_SEL.GPIO_63 = 0; GPIO->FUNC_SEL.SS = 3; GPIO->PAD_PU_SEL.SS = 1; GPIO->FUNC_SEL.VREF2H = 3; GPIO->PAD_PU_SEL.VREF2H = 1; GPIO->FUNC_SEL.U1RTS = 3; GPIO->PAD_PU_SEL.U1RTS = 1; } else { /* econotag I */ PRINTF("trim xtal for Econotag I\n\r"); CRM->XTAL_CNTLbits.XTAL_CTUNE = (ECONOTAG_CTUNE_4PF << 4) | ECONOTAG_CTUNE; CRM->XTAL_CNTLbits.XTAL_FTUNE = ECONOTAG_FTUNE; } /* create mac address if blank*/ if (mc1322x_config.eui == 0) { /* mac address is blank */ /* construct a new mac address based on IAB or OUI definitions */ /* if an M12_SERIAL number is not defined */ /* generate a random extension in the Redwire experimental IAB */ /* The Redwire IAB (for development only) is: */ /* OUI: 0x0050C2 IAB: 0xA8C */ /* plus a random 24-bit extension */ /* Otherwise, construct a mac based on the M12_SERIAL */ /* Owners of an Econotag I (not M12 based) can request a serial number from Redwire */ /* to use here */ /* M12 mac is of the form "EC473C4D12000000" */ /* Redwire's OUI: EC473C */ /* M12: 4D12 */ /* next six nibbles are the M12 serial number as hex */ /* e.g. if the barcode reads: "12440021" = BDD1D5 */ /* full mac is EC473C4D12BDD1D5 */ #if (M12_SERIAL == 0) /* use random mac from experimental range */ mc1322x_config.eui = (0x0050C2A8Cull << 24) | (*MACA_RANDOM & (0xffffff)); #else /* construct mac from serial number */ mc1322x_config.eui = (0xEC473C4D12ull << 24) | M12_SERIAL; #endif mc1322x_config_save(&mc1322x_config); } /* configure address on maca hardware and RIME */ contiki_maca_set_mac_address(mc1322x_config.eui); #if NETSTACK_CONF_WITH_IPV6 memcpy(&uip_lladdr.addr, &linkaddr_node_addr.u8, sizeof(uip_lladdr.addr)); queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if DEBUG_ANNOTATE print_netstack(); #endif #if ! SLIP_RADIO process_start(&tcpip_process, NULL); #endif #if DEBUG_ANNOTATE print_lladdrs(); #endif #endif /* endif NETSTACK_CONF_WITH_IPV6 */ process_start(&sensors_process, NULL); print_processes(autostart_processes); autostart_start(autostart_processes); /* Main scheduler loop */ while(1) { check_maca(); if(uart1_input_handler != NULL) { if(uart1_can_get()) { uart1_input_handler(uart1_getc()); } } process_run(); } return 0; }