void init_usart(void) { /* First rs232 port for debugging */ rs232_init(RS232_PORT_0, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); rs232_init(RS232_PORT_1, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #if WITH_UIP || WITH_UIP6 slip_arch_init(USART_BAUD_38400); #else rs232_redirect_stdout(RS232_PORT_0); #endif /* WITH_UIP */ }
// настроить порт int port_init ( askue_port_t *Port, const char *file, const char *speed, const char *dbits, const char *sbits, const char *parity ) { int RS232 = rs232_open ( file ); if ( rs232_init ( RS232, &( Port->Termios ) ) ) { rs232_close ( RS232 ); return -1; } rs232_set_databits ( &( Port->Termios ), dbits ); rs232_set_stopbits ( &( Port->Termios ), sbits ); rs232_set_parity ( &( Port->Termios ), parity ); rs232_set_speed ( &( Port->Termios ), speed ); if ( rs232_apply ( RS232, &( Port->Termios ) ) ) { rs232_close ( RS232 ); return -1; } Port->RS232 = RS232; if ( __port_open ( Port ) ) { close ( Port->RS232 ); return -1; } else { return 0; } }
/* * rs232 = require("luars232") * error, port = rs232.open(device) * error, port = rs232.open("/dev/ttyUSB0") */ static int lua_port_open(lua_State *L) { int ret = 0; struct rs232_port_t *p = NULL; struct rs232_port_t **ud = NULL; const char *dev = luaL_checkstring(L, 1); p = rs232_init(); if (p == NULL) { lua_pushinteger(L, RS232_ERR_CONFIG); lua_pushnil(L); return 2; } DBG("p=%p \n", (void *)p); rs232_set_device(p, dev); ret = rs232_open(p); if (ret > RS232_ERR_NOERROR) { free(p->pt); free(p); lua_pushinteger(L, ret); lua_pushnil(L); return 2; } lua_pushinteger(L, RS232_ERR_NOERROR); ud = lua_newuserdata(L, sizeof(struct rs232_port_t *)); *ud = p; luaL_getmetatable(L, MODULE_NAMESPACE); lua_setmetatable(L, -2); return 2; }
void init_lowlevel(void) { esb_sensors_init(); esb_sensors_on(); leds_init(); rs232_init(); }
void init_lowlevel(void) { #ifdef RAVEN_LCD_INTERFACE /* First rs232 port for Raven 3290 port */ rs232_init(RS232_PORT_0, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Set input handler for 3290 port */ rs232_set_input(0,raven_lcd_serial_input); #endif /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); }
void mx_console_init(uint8_t port) { rs232_init(port, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); rs232_set_input(port, rs232_serial_input); rs232_redirect_stdout(port); rs232_stdout = stdout; mx_console_mode.debugOn = 1; }
int main(int argc, char **argv) { FILE *dst; int gps_fd=-1; char *port; int baudrate; char *dst_fn; struct pollfd pfd = {.fd=-1, .events=POLLIN|POLLERR|POLLHUP}; struct timespec ts; assert(argc > 3); port = argv[1]; baudrate = atoi(argv[2]); dst_fn = argv[3]; dst = fopen(dst_fn, "a"); assert(dst); while(1) { int res; if(gps_fd < 0) { gps_fd = rs232_init(port, baudrate, 0, 0); if(gps_fd>=0) { fd_nonblock(gps_fd); pfd.fd = gps_fd; puts("GPS connected"); } } res = poll(&pfd, 1, 1000); clock_gettime(CLOCK_REALTIME, &ts); if(res < 0) continue; if(pfd.revents & (POLLERR|POLLHUP)) { close(gps_fd); gps_fd = -1; pfd.fd = -1; puts("GPS lost"); } else if(pfd.revents & POLLIN) { res=read(gps_fd, buf, sizeof(buf)); if(res > 0) { fprintf(dst, "%d.%ld\n",(int)ts.tv_sec, ts.tv_nsec); fwrite(buf, res, 1, dst); fflush(dst); } if(res >= 0) continue; close(gps_fd); gps_fd = -1; pfd.fd = -1; puts("GPS lost"); } } return 0; }
// порт cli_result_t parse4port ( void *Port, int argc, char **argv ) { const char *PortCfg[ 5 ]; #define File ( PortCfg[ 0 ] ) #define Parity ( PortCfg[ 1 ] ) #define Speed ( PortCfg[ 2 ] ) #define DBits ( PortCfg[ 3 ] ) #define SBits ( PortCfg[ 4 ] ) // настроить порт cli_arg_t JournalArgs[] = { { "port_file", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &File }, { "port_parity", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &Parity }, { "port_speed", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &Speed }, { "port_sbits", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &DBits }, { "port_dbits", 0, CLI_OPTIONAL_ARG, CLI_REQUIRED_VAL, __parse4port_strp, &SBits }, CLI_LAST_ARG }; cli_result_t Result = cli_parse ( JournalArgs, argc, argv ); if ( Result != CLI_SUCCESS ) { return Result; } if ( rs232_init ( ( *( askue_port_t** ) Port )->RS232, &( ( *( askue_port_t** ) Port )->Termios ) ) ) { return CLI_ERROR_HANDLER; } rs232_set_speed ( &( ( *( askue_port_t** ) Port )->Termios ), Speed ); rs232_set_databits ( &( ( *( askue_port_t** ) Port )->Termios ), DBits ); rs232_set_stopbits ( &( ( *( askue_port_t** ) Port )->Termios ), SBits ); rs232_set_parity ( &( ( *( askue_port_t** ) Port )->Termios ), Parity ); if ( rs232_apply ( ( *( askue_port_t** ) Port )->RS232, &( ( *( askue_port_t** ) Port )->Termios ) ) ) { return CLI_ERROR_HANDLER; } if ( port_init ( *( askue_port_t** ) Port, File, Speed, DBits, SBits, Parity ) == -1 ) { return CLI_ERROR_HANDLER; } return Result; #undef File #undef Parity #undef Speed #undef DBits #undef SBits }
void init_usart(void) { /* First rs232 port for debugging */ rs232_init(RS232_PORT_0, USART_BAUD_115200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to first port */ rs232_redirect_stdout(RS232_PORT_0); }
void init_lowlevel(void) { /* Configure default slip port with 19200 baud */ //rs232_init(RS232_PORT_0, USART_BAUD_19200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_57600, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout (RS232_PORT_1); }
int _open(const char *name, int flags, int mode) { if (strcmp("uart0", name) == 0) { stdout_rs232_port = RS232_PORT_0; } else if (strcmp("uart1", name) == 0) { stdout_rs232_port = RS232_PORT_1; } rs232_init(stdout_rs232_port, 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); return 1; }
void initSystem(void) { OSCCON = 0x70; //16 MHz Clock __delay_us(1); initPorts(); rs232_init(); config_init(); pocsagPhy_init(); interrupts_init(); }
bool QRS232::open(QString & port, enum rs232_baud_e baud) { m_port = rs232_init(); rs232_set_device(m_port, port.toLatin1().data()); rs232_set_baud(m_port, baud); unsigned int ret = rs232_open(m_port); if (ret == RS232_ERR_NOERROR) { m_open = true; return true; } return false; }
void initialize(void) { watchdog_init(); watchdog_start(); #if STACKMONITOR /* Simple stack pointer highwater monitor. Checks for magic numbers in the main * loop. In conjuction with TESTRTIMER, never-used stack will be printed * every STACKMONITOR seconds. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=4; } while (p<SP-4); //don't overwrite our own stack } #endif /* rtimers needed for radio cycling */ rtimer_init(); rs232_init(RS232_PORT_0, BAUD_RATE(38400), USART_DATA_BITS_8 | USART_PARITY_NONE | USART_STOP_BITS_1); rs232_redirect_stdout(RS232_PORT_0); clock_init(); sei(); /* Initialize drivers and event kernel */ process_init(); led_init(); #if 0 procinit_init(); #else process_start(&etimer_process, NULL); process_start(&led_process, NULL); process_start(&led2_process, NULL); #endif PRINTA(CONTIKI_VERSION_STRING " started\r\n"); /* Comment this out if autostart_processes not defined at link */ /* Note AUTOSTART_PROCESSES(...) is only effective in the .co module */ autostart_start(autostart_processes); }
/*-----------------------------------------------------------------------------------*/ void rs232dev_init(void) { char err; err = rs232_init(0); rs232_err(err); err = rs232_params(RS_BAUD_9600 | RS_BITS_8 | RS_STOP_1, RS_PAR_NONE); rs232_err(err); len = 0; return; }
unsigned int rs232_simple_test(void) { unsigned int try = 0; unsigned int bytes = 0; unsigned char data[1]; unsigned int ret = 0; struct rs232_port_t *p = NULL; p = rs232_init(); if (p == NULL) return 1; #ifdef WIN32 rs232_set_device(p, "COM1"); #else rs232_set_device(p, "/dev/ttyS1"); #endif ret = rs232_open(p); if (ret) { rs232_end(p); return err(ret); } rs232_set_baud(p, RS232_BAUD_115200); printf("[*] port settings: %s\n", rs232_to_string(p)); rs232_flush(p); while (try++ < 10) { printf("%02d. [*] read: ", try); data[0] = 0x00; ret = rs232_read_timeout(p, data, 1, &bytes, 1000); if (ret) err(ret); else printf("0x%02x len: %d\n", data[0], bytes); data[0] = 0x05; bytes = 0; printf("%02d. [*] write: ", try); ret = rs232_write_timeout(p, data, 1, &bytes, 1000); if (ret) err(ret); else printf("len: %d\n", bytes); } rs232_end(p); return 0; }
void main(void) { unsigned char i; // Make sure we're disconnected from the upstream port bUSBCTL = 0x00; rs232_init(); rs232_printstr("Hello world!\r\n"); InitializeUsbFunction(); // Initialize the USB embedded function while(1) { // Indefinite loop to handle keyboard scanning } }
void init_lowlevel(void) { leds_init(); //init LEDs leds_on(LEDS_ALL); _delay_us(50000); leds_off(LEDS_ALL); /* rs232 port for debugging */ rs232_init(RS232_PORT_0, USART_BAUD_38400, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to rs232 port */ rs232_redirect_stdout(RS232_PORT_0); }
void init_lowlevel(void) { rs232_init(USART_PORT, USART_BAUD, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); #if WITH_UIP || WITH_UIP6 /* Initialise SPLIP on USART port */ slip_arch_init(SLIP_BAUD); #else /* Redirect stdout and stdin to USART port */ rs232_redirect_stdout(USART_PORT); rs232_set_input(USART_PORT, serial_line_input_byte); #endif }
/** * initialize - Performs all initialization procedures * * Returns a CHARLIE_STAT_* constant that indicates the succes or * failure of the initialization. */ static uint8_t initialize(void) { charlie.shutdown = FALSE; init_atmega(); init_ports(); debug_init_ports(); rs232_init(); spi_init_master(); i2c_init(); if (rtc_init()) { return CHARLIE_STAT_RTC_ERROR; } time_init(); time_sync_to_realtime(); sched_init(); if (card_init()) { return CHARLIE_STAT_CARD_ERROR; } if (fsys_init()) { return CHARLIE_STAT_FSYS_ERROR; } if (fsys_check_read_only()) { return CHARLIE_STAT_FSYS_READONLY; } cfg_load(); if (enc28j60_init(&cfg.mac_addr)) { return CHARLIE_STAT_NET_ERROR; } net_init(); adc_init(); sensors_init(); pump_init(); plants_init(); sei(); return CHARLIE_STAT_OK; }
/** * Test reading and writing multiple bytes to the serial port */ int rs232_test_multi_char() { printf("%s\n", __func__); rs232_init(); /* Test program to check communication to Hyperterminal/GtkTerm */ while (1) { unsigned char buffer[6] = {'\0'}; rs232_get_n_char(buffer, sizeof(buffer) - 1); printf("Received buffer <%s>\n", buffer); rs232_put_n_char(buffer, sizeof(buffer) - 1); } /* Should not return */ return 1; }
/** * Test reading and writing single bytes to the serial port */ int rs232_test_single_char() { printf("%s\n", __func__); rs232_init(); /* Test program to check communication to Hyperterminal/GtkTerm */ unsigned char recv; while (1) { recv = rs232_get_char(); printf("Received <%c> <0x%x>\n", recv, recv); rs232_put_char(recv); } /* Should not return */ return 1; }
static int init_serial(void) { unsigned int ret = 0; port = rs232_init(); if (port == NULL) return 1; rs232_set_device(port, portname); ret = rs232_open(port); // open port if (ret) { printf("%s (%s)\n", rs232_strerror(ret), errno > 0 ? strerror(errno) : ""); return ret; } rs232_set_baud(port, RS232_BAUD_115200); rs232_flush(port); // wait for arduino init sleep(3); return 0; }
int main() { RS485N_DDR = RS485N_BITS; // RS485 out + RS485I_DDR = RS485I_BITS; // RS485 out - LED_DDR |= LED_BITS; // LED pins out OSCCAL += 5; // 115200 reception is flaky today. rs232_init(UBRV(RS232_BAUD)); // even parity! // timer_init(); for (;;) { while(tx_bytes != 0) ; // wait for the next command cli(); send_lumitile(cmd_buf[0], cmd_buf[1], cmd_buf[2], cmd_buf[3], 1); tx_bytes = 5; sei(); } }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<RAMEND-100); } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n")); #endif #endif Leds_init(); /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before ctimer init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(!get_eui64_from_eeprom(tmp_addr.u8)) { #if JACKDAW_CONF_RANDOM_MAC // It doesn't look like we have a valid EUI-64 address // so let's try to make a new one from scratch. Leds_off(); Led2_on(); generate_new_eui64(tmp_addr.u8); if(!set_eui64_to_eeprom(tmp_addr.u8)) { watchdog_periodic(); int i; for(i=0;i<20;i++) { Led1_toggle(); _delay_ms(100); } Led1_off(); } Led2_off(); #else tmp_addr.u8[0]=0x02; tmp_addr.u8[1]=0x12; tmp_addr.u8[2]=0x13; tmp_addr.u8[3]=0xff; tmp_addr.u8[4]=0xfe; tmp_addr.u8[5]=0x14; tmp_addr.u8[6]=0x15; tmp_addr.u8[7]=0x16; #endif /* JACKDAW_CONF_RANDOM_MAC */ } //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); #if JACKDAW_CONF_USE_SETTINGS /* Allow radio code to overrite power for testing miniature Raven mesh */ #ifndef RF230_MAX_TX_POWER rf230_set_txpower(settings_get_uint8(SETTINGS_KEY_TXPOWER,0)); #endif #endif rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); rf230_set_channel(get_channel_from_eeprom()); #if ANNOUNCE && USB_CONF_RS232 printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } printf_P(PSTR("\n")); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTF ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTF ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTF ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Setup USB */ process_start(&usb_process, NULL); #if USB_CONF_SERIAL process_start(&cdc_process, NULL); #endif process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif #if ANNOUNCE #if USB_CONF_SERIAL&&!USB_CONF_RS232 {unsigned short i; printf_P(PSTR("\n\n\n********BOOTING CONTIKI*********\n\r")); /* Allow USB CDC to keep up with printfs */ for (i=0;i<8000;i++) process_run(); #if RF230BB printf_P(PSTR("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r"),tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); for (i=0;i<8000;i++) process_run(); printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { i=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (i<65535) printf_P(PSTR(", check rate %u Hz"),i); } printf_P(PSTR("\n\r")); for (i=0;i<8000;i++) process_run(); #endif /* RF230BB */ printf_P(PSTR("System online.\n\r")); } #elif USB_CONF_RS232 printf_P(PSTR("System online.\n")); #endif #endif /* ANNOUNCE */ }
int main(void) { #if WITH_SD int r; #endif /* WITH_SD */ msp430_cpu_init(); watchdog_stop(); /* Platform-specific initialization. */ msb_ports_init(); adc_init(); clock_init(); rtimer_init(); sht11_init(); leds_init(); leds_on(LEDS_ALL); irq_init(); process_init(); /* serial interface */ rs232_set_input(serial_line_input_byte); rs232_init(); serial_line_init(); uart_lock(UART_MODE_RS232); uart_unlock(UART_MODE_RS232); #if WITH_UIP slip_arch_init(BAUD2UBR(115200)); #endif #if WITH_SD r = sd_initialize(); if(r < 0) { printf("Failed to initialize the SD driver: %s\n", sd_error_string(r)); } else { sd_offset_t capacity; printf("The SD driver was successfully initialized\n"); capacity = sd_get_capacity(); if(capacity < 0) { printf("Failed to get the SD card capacity: %s\n", sd_error_string(r)); } else { printf("SD card capacity: %u MB\n", (unsigned)(capacity / (1024UL * 1024))); } } #endif /* System services */ process_start(&etimer_process, NULL); ctimer_init(); node_id_restore(); init_net(); energest_init(); #if PROFILE_CONF_ON profile_init(); #endif /* PROFILE_CONF_ON */ leds_off(LEDS_ALL); printf(CONTIKI_VERSION_STRING " started. Node id %u, using %s.\n", node_id, rime_mac->name); autostart_start(autostart_processes); /* * This is the scheduler loop. */ ENERGEST_ON(ENERGEST_TYPE_CPU); while (1) { int r; #if PROFILE_CONF_ON profile_episode_start(); #endif /* PROFILE_CONF_ON */ do { /* Reset watchdog. */ watchdog_periodic(); r = process_run(); } while(r > 0); #if PROFILE_CONF_ON profile_episode_end(); #endif /* PROFILE_CONF_ON */ /* * Idle processing. */ int s = splhigh(); /* Disable interrupts. */ if (process_nevents() != 0) { splx(s); /* Re-enable interrupts. */ } else { static unsigned long irq_energest = 0; /* Re-enable interrupts and go to sleep atomically. */ ENERGEST_OFF(ENERGEST_TYPE_CPU); ENERGEST_ON(ENERGEST_TYPE_LPM); /* * We only want to measure the processing done in IRQs when we * are asleep, so we discard the processing time done when we * were awake. */ energest_type_set(ENERGEST_TYPE_IRQ, irq_energest); if (uart_edge) { _BIC_SR(LPM1_bits + GIE); } else { _BIS_SR(LPM1_bits + GIE); } /* * We get the current processing time for interrupts that was * done during the LPM and store it for next time around. */ dint(); irq_energest = energest_type_time(ENERGEST_TYPE_IRQ); eint(); ENERGEST_OFF(ENERGEST_TYPE_LPM); ENERGEST_ON(ENERGEST_TYPE_CPU); #if PROFILE_CONF_ON profile_clear_timestamps(); #endif /* PROFILE_CONF_ON */ } } return 0; }
void init_lowlevel(void) { /* Second rs232 port for debugging */ rs232_init(RS232_PORT_1, USART_BAUD_115200, USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_1); /* Clock */ clock_init(); /* rtimers needed for radio cycling */ rtimer_init(); /* Initialize process subsystem */ process_init(); /* etimers must be started before ctimer_init */ process_start(&etimer_process, NULL); #if RF230BB ctimer_init(); /* Start radio and radio receive process */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ linkaddr_t addr; memset(&addr, 0, sizeof(linkaddr_t)); eeprom_read_block ((void *)&addr.u8, &mac_address, 8); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &addr.u8, 8); #endif rf230_set_pan_addr(IEEE802154_PANID, 0, (uint8_t *)&addr.u8); #ifdef CHANNEL_802_15_4 rf230_set_channel(CHANNEL_802_15_4); #else rf230_set_channel(26); #endif linkaddr_set_node_addr(&addr); PRINTF("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n",addr.u8[0],addr.u8[1],addr.u8[2],addr.u8[3],addr.u8[4],addr.u8[5],addr.u8[6],addr.u8[7]); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE_BOOT printf_P(PSTR("%s %s, channel %u"),NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) {//function pointer is zero for sicslowmac unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) printf_P(PSTR(", check rate %u Hz"),tmp); } printf_P(PSTR("\n")); #endif #if UIP_CONF_ROUTER #if ANNOUNCE_BOOT printf_P(PSTR("Routing Enabled\n")); #endif rime_init(rime_udp_init(NULL)); uip_router_register(&rimeroute); #endif process_start(&tcpip_process, NULL); #else /* mac process must be started before tcpip process! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /*RF230BB*/ }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { asm volatile ("clr r1"); watchdog_init(); watchdog_start(); /* Clock */ clock_init(); /* Initialize hardware */ init_lowlevel(); #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ //rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); //ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); generate_random_pan_id_and_aes_key(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf212_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); extern uint16_t mac_dst_pan_id; extern uint16_t mac_src_pan_id; //set pan_id for frame creation mac_dst_pan_id = get_panid_from_eeprom(); mac_src_pan_id = mac_dst_pan_id; rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf212_get_channel()); PRINTA("\n"); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ /* Start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE // process_start(&storage_process, NULL); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif /* Button Process */ process_start(&button_pressed_process, NULL); leds_on(LEDS_GREEN); //normal state indication }
int main() { static uint16_t pulse_width; DDRB = 0; DDRD = 0; LED_DDR |= LED_BITS; // LED pins out DDRB |= (1<<PB4); // PWM out PORTD = (1<<PD2)|(1<<PD3); // pullups for sensors PORTB = (1<<PB0)|(1<<PB1)|(1<<PB2); // pullups for switches timer_init(); hall_init(); sei(); // enable interrupts. uint16_t pwm_stop_val = (PW_MIN+PW_MAX)/2+PW_TUNED_STOP; OCR1B = pulse_width = pwm_stop_val; // start stopped. #define BAUD 19200 rs232_init(UBRV(BAUD), &rs232_recv); uint16_t counter = 0; uint8_t paused = 0; uint8_t button_seen = 0; int16_t incr_counter = 0; for (;;) { if (!button_seen) { if ((PINB & (1<<PB0)) || cmd_seen == '+' || cmd_seen == 'l') { if (!cmd_seen) button_seen = 1; if (paused) { pulse_width = pwm_stop_val; incr_counter = 0; } incr_counter++; pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR; if (pulse_width > PW_MAX) pulse_width = PW_MAX; paused = 0; rs232_send('l'); } if ((PINB & (1<<PB2)) || cmd_seen == '-' || cmd_seen == 'r') { if (!cmd_seen) button_seen = 1; if (paused) { pulse_width = pwm_stop_val; incr_counter = 0; } incr_counter--; pulse_width = pwm_stop_val + speedup(incr_counter) * PW_BUT_INCR; if (pulse_width < PW_MIN) pulse_width = PW_MIN; paused = 0; rs232_send('r'); } if ((PINB & (1<<PB1)) || cmd_seen == ' ') { if (!cmd_seen) button_seen = 1; if (paused) { paused = 0; rs232_send('g'); } else { paused = 1; rs232_send('p'); } } } else { // disable automatic key repeat if (!(PINB & ((1<<PB0)|(1<<PB1)|(1<<PB2)))) button_seen = 0; // need a release before press. if (cmd_seen) rs232_send('!'); } if (paused) OCR1B = pwm_stop_val; else OCR1B = pulse_width; if (cmd_seen) { cmd_seen = 0; // very small race rs232_send_hex(pulse_width>>8); rs232_send_hex(pulse_width&0xff); rs232_send(' '); rs232_send_hex(hall_counter>>8); rs232_send_hex(hall_counter&0xff); rs232_send('\r'); rs232_send('\n'); } if (!(counter++ % 8)) // (1<<(led_what-1)))) { _delay_ms(10.0); if (pulse_width > pwm_stop_val) LED_PORT |= GREEN_LED_BITS; // pull high ... if (pulse_width < pwm_stop_val) LED_PORT |= RED_LED_BITS; // pull high ... _delay_ms(10.0); if (paused) LED_PORT &= ~(LED_BITS); // pull low ... _delay_ms(80.0); if (!paused) LED_PORT &= ~(LED_BITS); // pull low ... } else { _delay_ms(100.0); } } }
/*-----------------------------Low level initialization--------------------*/ static void initialize(void) { watchdog_init(); watchdog_start(); #if CONFIG_STACK_MONITOR /* Simple stack pointer highwater monitor. The 'm' command in cdc_task.c * looks for the first overwritten magic number. */ { extern uint16_t __bss_end; uint16_t p=(uint16_t)&__bss_end; do { *(uint16_t *)p = 0x4242; p+=100; } while (p<SP-100); //don't overwrite our own stack } #endif /* Initialize hardware */ // Checks for "finger", jumps to DFU if present. init_lowlevel(); /* Clock */ clock_init(); /* Leds are referred to by number to prevent any possible confusion :) */ /* Led0 Blue Led1 Red Led2 Green Led3 Yellow */ Leds_init(); Led1_on(); /* Get a random (or probably different) seed for the 802.15.4 packet sequence number. * Some layers will ignore duplicates found in a history (e.g. Contikimac) * causing the initial packets to be ignored after a short-cycle restart. */ ADMUX =0x1E; //Select AREF as reference, measure 1.1 volt bandgap reference. ADCSRA=1<<ADEN; //Enable ADC, not free running, interrupt disabled, fastest clock ADCSRA|=1<<ADSC; //Start conversion while (ADCSRA&(1<<ADSC)); //Wait till done PRINTD("ADC=%d\n",ADC); random_init(ADC); ADCSRA=0; //Disable ADC #if USB_CONF_RS232 /* Use rs232 port for serial out (tx, rx, gnd are the three pads behind jackdaw leds */ rs232_init(RS232_PORT_0, USART_BAUD_57600,USART_PARITY_NONE | USART_STOP_BITS_1 | USART_DATA_BITS_8); /* Redirect stdout to second port */ rs232_redirect_stdout(RS232_PORT_0); #if ANNOUNCE PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif #endif /* rtimer init needed for low power protocols */ rtimer_init(); /* Process subsystem. */ process_init(); /* etimer process must be started before USB or ctimer init */ process_start(&etimer_process, NULL); Led2_on(); /* Now we can start USB enumeration */ process_start(&usb_process, NULL); /* Start CDC enumeration, bearing in mind that it may fail */ /* Hopefully we'll get a stdout for startup messages, if we don't already */ #if USB_CONF_SERIAL process_start(&cdc_process, NULL); {unsigned short i; for (i=0;i<65535;i++) { process_run(); watchdog_periodic(); if (stdout) break; } #if !USB_CONF_RS232 PRINTA("\n\n*******Booting %s*******\n",CONTIKI_VERSION_STRING); #endif } #endif if (!stdout) Led3_on(); #if RF230BB #if JACKDAW_CONF_USE_SETTINGS PRINTA("Settings manager will be used.\n"); #else {uint8_t x[2]; *(uint16_t *)x = eeprom_read_word((uint16_t *)&eemem_channel); if((uint8_t)x[0]!=(uint8_t)~x[1]) { PRINTA("Invalid EEPROM settings detected. Rewriting with default values.\n"); get_channel_from_eeprom(); } } #endif ctimer_init(); /* Start radio and radio receive process */ /* Note this starts RF230 process, so must be done after process_init */ NETSTACK_RADIO.init(); /* Set addresses BEFORE starting tcpip process */ memset(&tmp_addr, 0, sizeof(rimeaddr_t)); if(get_eui64_from_eeprom(tmp_addr.u8)); //Fix MAC address init_net(); #if UIP_CONF_IPV6 memcpy(&uip_lladdr.addr, &tmp_addr.u8, 8); #endif rf230_set_pan_addr( get_panid_from_eeprom(), get_panaddr_from_eeprom(), (uint8_t *)&tmp_addr.u8 ); rf230_set_channel(get_channel_from_eeprom()); rf230_set_txpower(get_txpower_from_eeprom()); rimeaddr_set_node_addr(&tmp_addr); /* Initialize stack protocols */ queuebuf_init(); NETSTACK_RDC.init(); NETSTACK_MAC.init(); NETSTACK_NETWORK.init(); #if ANNOUNCE PRINTA("MAC address %x:%x:%x:%x:%x:%x:%x:%x\n\r",tmp_addr.u8[0],tmp_addr.u8[1],tmp_addr.u8[2],tmp_addr.u8[3],tmp_addr.u8[4],tmp_addr.u8[5],tmp_addr.u8[6],tmp_addr.u8[7]); PRINTA("%s %s, channel %u",NETSTACK_MAC.name, NETSTACK_RDC.name,rf230_get_channel()); if (NETSTACK_RDC.channel_check_interval) { unsigned short tmp; tmp=CLOCK_SECOND / (NETSTACK_RDC.channel_check_interval == 0 ? 1:\ NETSTACK_RDC.channel_check_interval()); if (tmp<65535) PRINTA(", check rate %u Hz",tmp); } PRINTA("\n"); #endif #if UIP_CONF_IPV6_RPL #if RPL_BORDER_ROUTER process_start(&tcpip_process, NULL); process_start(&border_router_process, NULL); PRINTD ("RPL Border Router Started\n"); #else process_start(&tcpip_process, NULL); PRINTD ("RPL Started\n"); #endif #if RPL_HTTPD_SERVER extern struct process httpd_process; process_start(&httpd_process, NULL); PRINTD ("Webserver Started\n"); #endif #endif /* UIP_CONF_IPV6_RPL */ #else /* RF230BB */ /* The order of starting these is important! */ process_start(&mac_process, NULL); process_start(&tcpip_process, NULL); #endif /* RF230BB */ /* Start ethernet network and storage process */ process_start(&usb_eth_process, NULL); #if USB_CONF_STORAGE process_start(&storage_process, NULL); #endif /* Autostart other processes */ /* There are none in the default build so autostart_processes will be unresolved in the link. */ /* The AUTOSTART_PROCESSES macro which defines it can only be used in the .co module. */ /* See /examples/ravenusbstick/ravenusb.c for an autostart template. */ #if 0 autostart_start(autostart_processes); #endif #if ANNOUNCE #if USB_CONF_RS232 PRINTA("Online.\n"); #else PRINTA("Online. Type ? for Jackdaw menu.\n"); #endif #endif Leds_off(); }