void init(void) { // set up watchdog wd_init(); // set up serial serial_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up default feedrate current_position.F = startpoint.F = next_target.target.F = SEARCH_FEEDRATE_Z; // start up analog read interrupt loop, if anything uses analog as determined by ANALOG_MASK in your config.h analog_init(); // set up temperature inputs temp_init(); // enable interrupts sei(); // reset watchdog wd_reset(); // say hi to host serial_writestr_P(PSTR("Start\nok\n")); }
//------------------------------------------------------------------------------ // void TaskRcv (void) // // DESCRIPTION: // Task that periodically checks to receive a packet //------------------------------------------------------------------------------ void TaskRcv() { uint8_t len; int8_t rssi; uint8_t *local_rx_buf; // widom init must be in a task wd_init (WD_CHANNEL); // This sets the next RX buffer. // This can be called at anytime before releasing the packet // if you wish to do a zero-copy buffer switch wd_rx_pkt_set_buffer (rx_buf, RF_MAX_PAYLOAD_SIZE); while(1) { nrk_led_toggle(GREEN_LED); if (wd_wait_until_rx_packet() == NRK_OK) { // Get the RX packet local_rx_buf = wd_rx_pkt_get (&len, &rssi); printf ("Rx Packet len=%u, prio=%u\r\n", len, local_rx_buf[1]); // // do something with packet here ... // //for (i = 0; i < len; i++) // printf ("%c", rx_buf[i]); //printf ("]\r\n"); wd_rx_pkt_release(); } nrk_wait_until_next_period(); } }
/* * Driver ioctl handler */ static int wd_ioctl (struct ifnet *ifp, ioctl_command_t command, caddr_t data) { struct wd_softc *sc = ifp->if_softc; int error = 0; switch (command) { case SIOCGIFADDR: case SIOCSIFADDR: ether_ioctl (ifp, command, data); break; case SIOCSIFFLAGS: switch (ifp->if_flags & (IFF_UP | IFF_RUNNING)) { case IFF_RUNNING: wd_stop (sc); break; case IFF_UP: wd_init (sc); break; case IFF_UP | IFF_RUNNING: wd_stop (sc); wd_init (sc); break; default: break; } break; case SIO_RTEMS_SHOW_STATS: wd_stats (sc); break; /* * FIXME: All sorts of multicast commands need to be added here! */ default: error = EINVAL; break; } return error; }
/// Startup code, run when we come out of reset void init(void) { halInit(); chSysInit(); #if defined(PORT_LED1) && defined(PIN_LED1) palSetPadMode(PORT_LED1, PIN_LED1, PAL_MODE_OUTPUT_PUSHPULL); #endif #if defined(PORT_LED2) && defined(PIN_LED2) palSetPadMode(PORT_LED2, PIN_LED2, PAL_MODE_OUTPUT_PUSHPULL); #endif // set up watchdog wd_init(); // set up serial serial_init(); // set up G-code parsing gcode_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up dda dda_init(); // start up analog read interrupt loop, // if any of the temp sensors in your config.h use analog interface analog_init(); // set up temperature inputs temp_init(); // enable interrupts enable_irq(); // reset watchdog wd_reset(); // say hi to host serial_writestr_P(PSTR("start\nok\n")); }
int main(int argc, char *argv[]) { int rtn; signal(SIGCHLD, SIG_DFL); signal(SIGHUP, SIG_IGN); signal(SIGINT, wd_exit); signal(SIGQUIT, wd_exit); signal(SIGTERM, wd_exit); signal(SIGPIPE, SIG_IGN); mypid = getpid(); rtn = pool_init_config(); pool_config->recovery_user = "******"; pool_config->trusted_servers = "paris"; pool_config->delegate_IP = "192.168.100.99"; pool_config->pgpool2_hostname = "vm1"; pool_config->port = 5432; pool_config->wd_port = 9999; pool_config->other_wd->num_wd = 2; strcpy(pool_config->other_wd->wd_info[0].hostname, "vm2"); pool_config->other_wd->wd_info[0].pgpool_port = 5432; pool_config->other_wd->wd_info[0].wd_port = 9999; pool_config->other_wd->wd_info[0].status = WD_INIT; strcpy(pool_config->other_wd->wd_info[1].hostname, "paris"); pool_config->other_wd->wd_info[1].pgpool_port = 5432; pool_config->other_wd->wd_info[1].wd_port = 9999; pool_config->other_wd->wd_info[1].status = WD_INIT; pool_config->ping_path = "/bin"; pool_config->ifconfig_path = "/sbin"; pool_config->if_up_cmd = "ifconfig eth0:0 inet $_IP_$ netmask 255.255.255.0"; pool_config->if_down_cmd = "ifconfig eth0:0 down"; pool_config->wd_interval = 3; pool_config->wd_life_point = 1; wd_init(); wd_child(1); for (;;) { wdlist_dump(); sleep(5); } }
static boolean init(void) { int error; char *fullname; xw_get(NULL, WF_WORKXYWH, &screen_info.dsk); if ((fullname = xshel_find(optname, &error)) != NULL) { free(optname); optname = fullname; } else { if ((error == EFILNF) && ((fullname = x_fullname(optname, &error)) != NULL)) { free(optname); optname = fullname; } if (error != 0) { xform_error(error); return TRUE; } } if (dsk_init() == TRUE) return TRUE; ft_init(); icnt_init(); app_init(); prg_init(); wd_init(); menu_bar(menu, 1); x_setpath("\\"); load_options(); return FALSE; }
/// Startup code, run when we come out of reset void init(void) { // set up watchdog wd_init(); // set up serial serial_init(); // set up G-code parsing gcode_init(); // set up inputs and outputs io_init(); // set up timers timer_init(); // read PID settings from EEPROM heater_init(); // set up dda dda_init(); // start up analog read interrupt loop, // if any of the temp sensors in your config.h use analog interface analog_init(); // set up temperature inputs temp_init(); // enable interrupts sei(); // reset watchdog wd_reset(); // prepare the power supply power_init(); // say hi to host serial_writestr_P(PSTR("start\nok\n")); }
int main(void) { RCC_Configuration(); init_GPIO(); delay_init(); NVIC_cfg();//配置中断 MBRTU_ini(0x01); //Tim3初始化 init_TIM3(); wd_init(); TM7711_init(); init_serial();//串口初始化 // TIM3_Start(0); MeasurePoll_init(); while(1) { MBRTUPoll(); MeasurePoll(); } }
int main () { nrk_setup_ports(); nrk_setup_uart(UART_BAUDRATE_115K2); nrk_init(); printf( "Starting up... (NODE_ADDR=%d)\r\n", NODE_ADDR); nrk_led_clr(ORANGE_LED); nrk_led_clr(BLUE_LED); nrk_led_set(GREEN_LED); nrk_led_clr(RED_LED); // widom init (must be in main unless wd_timer_cpu_clk.h uses timer/counter1) wd_init(WD_CHANNEL); #ifdef CONTINUOUS_SEND // Testing purposes only; The node will try to access the medium // continuously, acting like it is always backlogged. // defined in widom.h // put just two bytes of payload in the packet... tx_buf[0]=0xCB; tx_buf[1]=MSG_PRIO; // put MSG_PRIO in the payload also // This function transmits packets in a non-blocking manner wd_tx_packet_enqueue (tx_buf, 2, MSG_PRIO); while (1); #endif nrk_time_set(0,0); nrk_create_taskset(); nrk_start(); return 0; }
pid_t wd_main(int fork_wait_time) { int i; if (!pool_config->use_watchdog) return 0; /* check pool_config data */ wd_check_config(); /* initialize */ wd_init(); wd_ppid = getpid(); /* launch child process */ child_pid = wd_child(1); if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT)) { for (i = 0; i < pool_config->num_hb_if; i++) { /* heartbeat receiver process */ hb_receiver_pid[i] = wd_hb_receiver(1, &(pool_config->hb_if[i])); /* heartbeat sender process */ hb_sender_pid[i] = wd_hb_sender(1, &(pool_config->hb_if[i])); } } /* fork lifecheck process*/ lifecheck_pid = fork_a_lifecheck(fork_wait_time); return lifecheck_pid; }
pid_t wd_main(int fork_wait_time) { int status = WD_INIT; int i; if (!pool_config->use_watchdog) { return 0; } /* check pool_config data */ status = wd_check_config(); if (status != WD_OK) { pool_error("watchdog: wd_check_config failed"); return 0; } /* initialize */ status = wd_init(); if (status != WD_OK) { pool_error("watchdog: wd_init failed"); return 0; } wd_ppid = getpid(); /* launch child process */ child_pid = wd_child(1); if (child_pid < 0 ) { pool_error("launch wd_child failed"); return 0; } if (!strcmp(pool_config->wd_lifecheck_method, MODE_HEARTBEAT)) { for (i = 0; i < pool_config->num_hb_if; i++) { /* heartbeat receiver process */ hb_receiver_pid[i] = wd_hb_receiver(1, pool_config->hb_if[i]); if (hb_receiver_pid[i] < 0 ) { pool_error("launch wd_hb_receiver failed"); return hb_receiver_pid[i]; } /* heartbeat sender process */ hb_sender_pid[i] = wd_hb_sender(1, pool_config->hb_if[i]); if (hb_sender_pid[i] < 0 ) { pool_error("launch wd_hb_sender failed"); return hb_sender_pid[i]; } } } /* fork lifecheck process*/ lifecheck_pid = fork_a_lifecheck(fork_wait_time); if (lifecheck_pid < 0 ) { pool_error("launch lifecheck process failed"); return 0; } return lifecheck_pid; }
int main(void) { unsigned char ch; unsigned char prev_ch=0; unsigned char chr_nl=0; unsigned char msgparsestate; unsigned char cksum=0; unsigned char seqnum=0; int msglen=0; int i=0; uart_init(); wd_init(); LED_INIT; LED_OFF; sei(); msgparsestate=MSG_IDLE; // default values: CONFIG_PARAM_SW_MINOR=D_CONFIG_PARAM_SW_MINOR; CONFIG_PARAM_SW_MAJOR=D_CONFIG_PARAM_SW_MAJOR; if (eeprom_read_byte((uint8_t *)EEPROM_MAGIC) == 20){ // ok magic number matches accept values CONFIG_PARAM_SW_MINOR=eeprom_read_byte(EEPROM_MINOR); CONFIG_PARAM_SW_MAJOR=eeprom_read_byte(EEPROM_MAJOR); } while(1){ if (msgparsestate==MSG_IDLE){ ch=uart_getchar(1); }else{ ch=uart_getchar(0); } // parse message according to appl. note AVR068 table 3-1: if (msgparsestate==MSG_IDLE && ch == MESSAGE_START){ msgparsestate=MSG_WAIT_SEQNUM; cksum = ch^0; continue; } // The special avrusb500 terminal mode. // Just connect a serial terminal and press enter twice. // Both Windows and Linux send normally \r (=0xd) as the // only line end character. It is however possible to configure // \r\n as line end in some serial terminals. Therefore we // must handle it. if (msgparsestate==MSG_IDLE && (ch == '\r'||ch == '\n')){ i++; if(chr_nl ==0 && ch=='\n' && prev_ch== '\r'){ // terminal sends \r\n for new line chr_nl=1; } prev_ch=ch; if (chr_nl){ // wait for \r\n \r\n if (i==4){ terminalmode(1); i=0; } }else{ // Linux wait for \n\n if (i==2){ terminalmode(0); i=0; } } continue; } if (msgparsestate==MSG_WAIT_SEQNUM){ seqnum=ch; cksum^=ch; msgparsestate=MSG_WAIT_SIZE1; continue; } if (msgparsestate==MSG_WAIT_SIZE1){ cksum^=ch; msglen=ch<<8; msgparsestate=MSG_WAIT_SIZE2; continue; } if (msgparsestate==MSG_WAIT_SIZE2){ cksum^=ch; msglen|=ch; msgparsestate=MSG_WAIT_TOKEN; continue; } if (msgparsestate==MSG_WAIT_TOKEN){ cksum^=ch; if (ch==TOKEN){ msgparsestate=MSG_WAIT_MSG; i=0; }else{ msgparsestate=MSG_IDLE; } continue; } if (msgparsestate==MSG_WAIT_MSG && i<msglen && i<280){ cksum^=ch; msg_buf[i]=ch; i++; wdt_reset(); //wd_kick(); if (i==msglen){ msgparsestate=MSG_WAIT_CKSUM; } continue; } if (msgparsestate==MSG_WAIT_CKSUM){ if (ch==cksum && msglen > 0){ // message correct, process it wdt_reset(); //wd_kick(); programcmd(seqnum); }else{ msg_buf[0] = ANSWER_CKSUM_ERROR; msg_buf[1] = STATUS_CKSUM_ERROR; transmit_answer(seqnum,2); } // no continue here, set state=MSG_IDLE } msgparsestate=MSG_IDLE; msglen=0; seqnum=0; prev_ch=0; i=0; } return(0); }