static void timer_test_constants(void) { kprintf("TIMER_HW_HPTICKS_PER_SEC=%lu\n", (unsigned long)TIMER_HW_HPTICKS_PER_SEC); #ifdef TIMER_PRESCALER kprintf("TIMER_PRESCALER = %lu\n", (unsigned long)TIMER_PRESCALER); #endif #ifdef TIMER1_OVF_COUNT kprintf("TIMER1_OVF_COUNT = %lu\n", (unsigned long)TIMER1_OVF_COUNT); #endif kprintf("TIMER_TICKS_PER_SEC= %lu\n", (unsigned long)TIMER_TICKS_PER_SEC); kprintf("\n"); kprintf("ms_to_ticks(100) = %lu\n", (unsigned long)ms_to_ticks(100)); kprintf("ms_to_ticks(10000) = %lu\n", (unsigned long)ms_to_ticks(10000)); kprintf("us_to_ticks(100) = %lu\n", (unsigned long)us_to_ticks(100)); kprintf("us_to_ticks(10000) = %lu\n", (unsigned long)us_to_ticks(10000)); kprintf("\n"); kprintf("ticks_to_ms(100) = %lu\n", (unsigned long)ticks_to_ms(100)); kprintf("ticks_to_ms(10000) = %lu\n", (unsigned long)ticks_to_ms(10000)); kprintf("ticks_to_us(100) = %lu\n", (unsigned long)ticks_to_us(100)); kprintf("ticks_to_us(10000) = %lu\n", (unsigned long)ticks_to_us(10000)); kprintf("\n"); kprintf("hptime_to_us(100) = %lu\n", (unsigned long)hptime_to_us(100)); #if (SIZEOF_HPTIME_T > 1) kprintf("hptime_to_us(10000)= %lu\n", (unsigned long)hptime_to_us(10000)); #endif kprintf("us_to_hptime(100) = %lu\n", (unsigned long)us_to_hptime(100)); kprintf("us_to_hptime(10000)= %lu\n", (unsigned long)us_to_hptime(10000)); }
static bool cutoff_checkTime(ticks_t now) { static bool logged = false; static bool warn_logged = false; if (now - status_missionStartTicks() > ms_to_ticks(mission_timeout * 1000)) { if (!logged) { radio_printf("CUTOFF:mission timeout\n"); logged = true; } return false; } else if (now - status_missionStartTicks() > ms_to_ticks(mission_timeout * 1000) - ms_to_ticks(5*60*1000)) { if (!warn_logged) { radio_printf("CUTOFF:mission end in %ds\n", mission_timeout - ticks_to_ms(now - status_missionStartTicks()) / 1000); warn_logged = true; } return true; } else { logged = false; warn_logged = false; return true; } }
//=====[ Control Loop ]========================================================= void controlSetup(void) { // Init list of synchronous timers LIST_INIT(&timers_lst); // Schedule SMS handling task GSM(gsmSMSDelRead()); timer_setDelay(&sms_tmr, ms_to_ticks(SMS_CHECK_SEC*1000)); timer_setSoftint(&sms_tmr, sms_task, (iptr_t)&sms_tmr); synctimer_add(&sms_tmr, &timers_lst); // Schedule Console handling task timer_setDelay(&cmd_tmr, ms_to_ticks(CMD_CHECK_SEC*1000)); timer_setSoftint(&cmd_tmr, cmd_task, (iptr_t)&cmd_tmr); synctimer_add(&cmd_tmr, &timers_lst); // Setup Button handling task timer_setDelay(&btn_tmr, ms_to_ticks(BTN_CHECK_SEC*1000)); timer_setSoftint(&btn_tmr, btn_task, (iptr_t)&btn_tmr); // Setup console RX timeout console_init(&dbg_port.fd); ser_settimeouts(&dbg_port, 0, 1000); // Dump ADE7753 configuration meter_ade7753_dumpConf(); // Get bitmask of enabled channels chEnabled = ee_getEnabledChMask(); // Get bitmask of enabled channels chCritical = ee_getCriticalChMask(); // Enabling calibration only for enabled channels chCalib = chEnabled; // Setup channels calibration data for (uint8_t ch=0; ch<16; ch++) loadCalibrationData(ch); // Update signal level GSM(updateCSQ()); // Setup Re-Calibration Weeks resetCalibrationCountdown(); // Enabling the watchdog for the control loop WATCHDOG_ENABLE(); // Initi the analog MUX to current channel switchAnalogMux(curCh); }
void ser_settimeouts(struct Serial *fd, mtime_t rxtimeout, mtime_t txtimeout) { #if CONFIG_SER_RXTIMEOUT != -1 fd->rxtimeout = ms_to_ticks(rxtimeout); #else (void)rxtimeout; #endif #if CONFIG_SER_TXTIMEOUT != -1 fd->txtimeout = ms_to_ticks(txtimeout); #else (void)txtimeout; #endif }
bool cutoff_check(ticks_t now, int32_t curr_alt, udegree_t lat, udegree_t lon) { bool cutoff =(!cutoff_checkTime(now) || !cutoff_checkDist(lat, lon, now) || !cutoff_checkAltitude(curr_alt, now) || !cutoff_checkMaxalt(curr_alt, now)); static bool logged = false; if (cutoff) { if (cutoff_pause_time && timer_clock() - cutoff_pause_time < ms_to_ticks(PAUSE_TIME)) { if (!logged) { radio_printf("CUTOFF pending!\n"); logged = true; } } else { cutoff_pause_time = 0; logged = false; cutoff_cut(); } } else { if (logged) radio_printf("Pending CUTOFF cancelled\n"); logged = false; } return cutoff; }
static void synctimer_test(void) { size_t i; LIST_INIT(&synctimer_list); for (i = 0; i < countof(synctimer_timers); ++i) { Timer *timer = &synctimer_timers[i]; timer_setDelay(timer, ms_to_ticks(test_delays[i])); timer_setSoftint(timer, synctimer_test_hook, (iptr_t)timer); synctimer_add(timer, &synctimer_list); } int secs = 0; mtime_t start_time = ticks_to_ms(timer_clock()); mtime_t now; while (secs <= 10) { now = ticks_to_ms(timer_clock()); synctimer_poll(&synctimer_list); if (now - start_time >= 1000) { ++secs; start_time += 1000; kprintf("seconds = %d, ticks=%lu\n", secs, (unsigned long)now); } wdt_reset(); } for (i = 0; i < countof(synctimer_timers); ++i) { synctimer_abort(&synctimer_timers[i]); } }
static bool flash_wait(struct KBlock *blk, uint32_t event) { Flash *fls = FLASH_CAST(blk); ticks_t start = timer_clock(); while (true) { if (!(FLASH_FMC_R & event)) break; if (FLASH_FCRIS_R & FLASH_FCRIS_ARIS) { fls->hw->status |= FLASH_WR_PROTECT; LOG_ERR("wr protect..\n"); return false; } if (timer_clock() - start > ms_to_ticks(CONFIG_FLASH_WR_TIMEOUT)) { fls->hw->status |= FLASH_WR_TIMEOUT; LOG_ERR("Timeout..\n"); return false; } cpu_relax(); } return true; }
/** * Handle keyboard debounce */ static keymask_t kbd_debHandlerFunc(keymask_t key) { /** Buffer for debounce */ static keymask_t debounce_key; /** Timer for keyboard debounce */ static ticks_t debounce_time; /** Key aquired after debounce */ static keymask_t new_key; ticks_t now = timer_clock(); if (key != debounce_key) { /* Reset debounce timer */ debounce_key = key; debounce_time = now; } else if ((new_key != debounce_key) && (now - debounce_time > ms_to_ticks(KBD_DEBOUNCE_TIME))) { new_key = debounce_key; debounce_time = now; } return new_key; }
static int __init at91wdt_probe(struct platform_device *pdev) { int res; if (at91wdt_miscdev.parent) return -EBUSY; at91wdt_miscdev.parent = &pdev->dev; /* Set watchdog */ res = at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000)); if (res) return res; res = misc_register(&at91wdt_miscdev); if (res) return res; at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; setup_timer(&at91wdt_private.timer, at91_ping, 0); mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); printk(KERN_INFO DRV_NAME " enabled (heartbeat=%d sec, nowayout=%d)\n", heartbeat, nowayout); return 0; }
// The task to process Console events static void btn_task(iptr_t timer) { ticks_t start = timer_clock(); ticks_t elapsed; (void)timer; DB2(LOG_INFO("Button timer...\r\n")); // LightUp all LEDS to notify calibration/reset pending LED_NOTIFY_ON(); // Wait for button release or reset timeout while (!signal_status(SIGNAL_PLAT_BUTTON)) { elapsed = timer_clock() - start; if ( ms_to_ticks(BTN_RESET_SEC*1000) <= elapsed ) { // Button pressed fot t > BTN_CHECK_SEC+BTN_RESET_SEC reset_board(); } DELAY(100); } // Button pressed BTN_CHECK_SEC < t < BTN_CHECK_SEC+BTN_RESET_SEC LED_NOTIFY_OFF(); ERR_OFF(); controlCalibration(); }
static bool flash_wait(struct KBlock *blk) { Flash *fls = FLASH_CAST(blk); ticks_t start = timer_clock(); while (true) { if (!(EMB_FLASH->SR & FLASH_FLAG_BSY)) break; if (EMB_FLASH->SR & FLASH_FLAG_PGERR) { fls->hw->status |= FLASH_NOT_ERASED; LOG_ERR("flash not erased..\n"); return false; } if (EMB_FLASH->SR & FLASH_FLAG_WRPRTERR) { fls->hw->status |= FLASH_WR_PROTECT; LOG_ERR("wr protect..\n"); return false; } if (timer_clock() - start > ms_to_ticks(CONFIG_FLASH_WR_TIMEOUT)) { fls->hw->status |= FLASH_WR_TIMEOUT; LOG_ERR("Timeout..\n"); return false; } cpu_relax(); } return true; }
int main(void) { init(); ticks_t start = timer_clock(); unsigned char x = 0; // FIXME memcpy(path[1].call, MYCALL, 6); path[1].ssid = MYCALL_SSID; while (1) { /* As long as CONFIG_AFSK_RXTIMEOUT is set to 0, this function won't block and return immediately. */ ax25_poll(&ax25); #if 1 /* Send out message every 15sec */ if (timer_clock() - start > ms_to_ticks(APRS_BEACON_TIME * 1000L)) { kfile_printf(&ser.fd, "Beep %d\n", x++); start = timer_clock(); ax25_sendVia(&ax25, path, countof(path), APRS_BEACON_MSG, sizeof(APRS_BEACON_MSG)); } #endif } return 0; }
static void akbd_repeat(void *xsc) { struct adb_kbd_softc *sc = xsc; int notify_kbd = 0; /* Fake an up/down key repeat so long as we have the free buffers */ mtx_lock(&sc->sc_mutex); if (sc->buffers < 7) { sc->buffer[sc->buffers++] = sc->last_press | (1 << 7); sc->buffer[sc->buffers++] = sc->last_press; notify_kbd = 1; } mtx_unlock(&sc->sc_mutex); if (notify_kbd && KBD_IS_ACTIVE(&sc->sc_kbd) && KBD_IS_BUSY(&sc->sc_kbd)) { sc->sc_kbd.kb_callback.kc_func(&sc->sc_kbd, KBDIO_KEYINPUT, sc->sc_kbd.kb_callback.kc_arg); } /* Reschedule the callout */ callout_reset(&sc->sc_repeater, ms_to_ticks(sc->sc_kbd.kb_delay2), akbd_repeat, sc); }
int main (void) { init(); #if SERIAL_PROTOCOL == PROTOCOL_KISS while (true) { ax25_poll(&AX25); if (serial_available(0)) { char sbyte = uart0_getchar_nowait(); kiss_serialCallback(sbyte); } } #endif #if SERIAL_PROTOCOL == PROTOCOL_SIMPLE_SERIAL ticks_t start = timer_clock(); while (1) { ax25_poll(&AX25); if (!sertx && serial_available(0)) { sbyte = uart0_getchar_nowait(); #if SERIAL_DEBUG if ((serialLen < AX25_MAX_FRAME_LEN) && (sbyte != 10)) { serialBuffer[serialLen] = sbyte; serialLen++; } else { sertx = true; } #else if (serialLen < AX25_MAX_FRAME_LEN-1) { serialBuffer[serialLen] = sbyte; serialLen++; } else { serialBuffer[serialLen] = sbyte; serialLen++; sertx = true; } start = timer_clock(); #endif } else { if (!SERIAL_DEBUG && serialLen > 0 && timer_clock() - start > ms_to_ticks(TX_MAXWAIT)) { sertx = true; } } if (sertx) { ss_serialCallback(serialBuffer, serialLen, &AX25); sertx = false; serialLen = 0; } } #endif return(0); }
/** * Initialize keyboard ports and softtimer */ void kbd_init(void) { #if CONFIG_KBD_BEEP MOD_CHECK(buzzer); #endif KBD_HW_INIT; /* Init handlers lists */ LIST_INIT(&kbd_handlers); LIST_INIT(&kbd_rawHandlers); /* Add debounce keyboard handler */ kbd_debHandler.hook = kbd_debHandlerFunc; kbd_debHandler.pri = 100; /* high priority */ kbd_debHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_debHandler); #if CONFIG_KBD_LONGPRESS /* Add long pression keyboard handler */ kbd_lngHandler.hook = kbd_lngHandlerFunc; kbd_lngHandler.pri = 90; /* high priority */ kbd_lngHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_lngHandler); #endif /* Add repeat keyboard handler */ kbd_rptHandler.hook = kbd_rptHandlerFunc; kbd_rptHandler.pri = 80; /* high priority */ kbd_rptHandler.flags = KHF_RAWKEYS; kbd_addHandler(&kbd_rptHandler); /* Add default keyboard handler */ kbd_defHandler.hook = kbd_defHandlerFunc; kbd_defHandler.pri = -128; /* lowest priority */ kbd_addHandler(&kbd_defHandler); #if CONFIG_KBD_OBSERVER observer_InitSubject(&kbd_subject); #endif #if CONFIG_KBD_POLL == KBD_POLL_SOFTINT MOD_CHECK(timer); /* Add kbd handler to soft timers list */ event_initSoftint(&kbd_timer.expire, kbd_softint, NULL); timer_setDelay(&kbd_timer, ms_to_ticks(KBD_CHECK_INTERVAL)); timer_add(&kbd_timer); #else #error "Define keyboard poll method" #endif MOD_INIT(kbd); }
int dsk1interrupt(void) { request_desc_p target, prev; disk_desc *ptr; int ticks; double seek_time, rotate_time, transfer_time; STATWORD ps; disable(ps); ptr = (disk_desc *)devtab[DISK1].dvioblk; if(!ptr) { restore(ps); return SYSERR; } if(!ptr -> request_head) { disk1_preempt = MAXINT; restore(ps); return OK; } for(target = ptr -> request_head, prev = NULL;target -> next;prev = target, target = target -> next); if(prev != NULL) prev -> next = NULL; else ptr -> request_head = NULL; if(target -> type == READ_OPERATION) { ptr -> no_of_reads++; memncpy(target -> buffer, ptr -> disk + target -> block_no * ptr -> block_size, ptr -> block_size * target -> count); } else { ptr -> no_of_writes++; memncpy(ptr -> disk + target -> block_no * ptr -> block_size, target -> buffer, ptr -> block_size * target -> count); } ptr -> head_sector = target -> block_no + target -> count; ready(target -> process_id, RESCHNO); freemem(target, sizeof(request_desc)); // Disk Schedule dskschedule(ptr, PA4_DISK_SCHEDULE); if(ptr -> request_head) { for(target = ptr -> request_head;target -> next;target = target -> next); calculate_time(ptr, target -> block_no, &seek_time, &rotate_time); calculate_transfer_time(ptr, target -> block_no, target -> count, &transfer_time); ticks = ms_to_ticks(seek_time + rotate_time + transfer_time); target -> ticks = ticks; disk1_preempt = ticks; } else disk1_preempt = MAXINT; restore(ps); return OK; }
/* * dskread() is responsible for serving each read request. * It does: * check simple parameter integrity, * calculate seek time, rotate time, and transfer time * insert the current request into each queue * schedule the interrupt related to this request * make the current process into block state. * This function supports multiple continuous blocks. * Please notice that when calling this function, block_no + count does not have to * exceed the last block number. This function does not guarantee that block_no + count * does not exceed. * parameter: * pdev: device descriptor * buffer: a buffer to store read blocks * block_no: the start block number to be read * count: the number of continuous blocks to be read */ int dskread(struct devsw *pdev, char *buffer, int block_no, int count) { disk_desc *ptr; double seek_time = 0.0; double rotate_time = 0.0; double read_time = 0.0; int code, ticks; request_desc_p request; STATWORD ps; disable(ps); if(!pdev || !buffer || count <= 0) { restore(ps); return SYSERR; } ptr = (disk_desc *)pdev -> dvioblk; if(block_no < 0 || block_no + count > ptr -> logical_blocks) { restore(ps); return SYSERR; } request = (request_desc_p)getmem(sizeof(request_desc)); if(request == (request_desc_p)SYSERR) { restore(ps); return (int)request; } if(!ptr -> request_head) { calculate_time(ptr, block_no, &seek_time, &rotate_time); calculate_transfer_time(ptr, block_no, count, &read_time); ticks = ms_to_ticks(seek_time + rotate_time + read_time); if(pdev == &devtab[DISK0]) disk0_preempt = ticks; else if(pdev == &devtab[DISK1]) disk1_preempt = ticks; request -> ticks = ticks; } //kprintf("\n------------dsk read\n"); request -> type = READ_OPERATION; request -> block_no = block_no; request -> process_id = currpid; request -> buffer = buffer; request -> count = count; request -> next = ptr -> request_head; ptr -> request_head = request; //kprintf("\n req buf is %s\n", request->buffer); restore(ps); if(dskresched() == SYSERR) { return SYSERR; } return OK; }
static void timer_test_async(void) { size_t i; for (i = 0; i < countof(test_timers); ++i) { Timer *timer = &test_timers[i]; timer_setDelay(timer, ms_to_ticks(test_delays[i])); timer_setSoftint(timer, timer_test_hook, (iptr_t)timer); timer_add(timer); } }
static int __init at91wdt_probe(struct platform_device *pdev) { struct at91wdt_drvdata *driver_data; struct resource *r; int ret; driver_data = devm_kzalloc(&pdev->dev, sizeof(*driver_data), GFP_KERNEL); if (!driver_data) { dev_err(&pdev->dev, "Unable to alloacate watchdog device\n"); return -ENOMEM; } watchdog_set_drvdata(&at91wdt_wdd, driver_data); r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) return -ENODEV; driver_data->phybase = ioremap(r->start, resource_size(r)); if (!driver_data->phybase) { dev_err(&pdev->dev, "failed to map registers, aborting.\n"); return -ENOMEM; } ret = watchdog_register_device(&at91wdt_wdd); if (ret) { dev_err(&pdev->dev, "cannot register watchdog (%d)\n", ret); return ret; } watchdog_set_nowayout(&at91wdt_wdd, nowayout); watchdog_init_timeout(&at91wdt_wdd, heartbeat, pdev->dev.of_node); ret = at91wdt_enable(&at91wdt_wdd, ms_to_ticks(WDT_HW_TIMEOUT * 1000)); if (ret) { pr_info("the watchdog has been disabled\n"); return 0; } driver_data->next_heartbeat = jiffies + at91wdt_wdd.timeout * HZ; setup_timer(&driver_data->timer, at91wdt_timer_tick, (unsigned long)&at91wdt_wdd); mod_timer(&driver_data->timer, jiffies + WDT_TIMEOUT); pr_info("enabled (heartbeat=%d sec, nowayout=%d)\n", at91wdt_wdd.timeout, nowayout); return 0; }
/** * Handle long pression keys. */ static keymask_t kbd_lngHandlerFunc(keymask_t key) { static ticks_t start; ticks_t now = timer_clock(); if (key & K_LNG_MASK) { if (now - start > ms_to_ticks(KBD_LNG_DELAY)) key |= K_LONG; } else start = now; return key; }
/** * Wait up to \c timeout ms for a keypress * and return the mask of depressed keys, or K_TIMEOUT * if the timeout was reacked. */ keymask_t kbd_get_timeout(mtime_t timeout) { keymask_t key; ticks_t start = timer_clock(); ticks_t stop = ms_to_ticks(timeout); do { if ((key = kbd_peek())) return key; } while (timer_clock() - start < stop); return K_TIMEOUT; }
/** * Discard input to resynchronize with remote end. * * Discard incoming data until the kfile_getc stops receiving * characters for at least \a delay milliseconds. * * \note If the timeout occur, we reset the error before to * quit. */ void kfile_resync(KFile *fd, mtime_t delay) { ticks_t start_time = timer_clock(); for(;;) { if(kfile_getc(fd) != EOF) start_time = timer_clock(); if ((timer_clock() - start_time) > ms_to_ticks(delay)) { kfile_clearerr(fd); break; } } }
static void check_run_mode(void){ if(currentMode == g_settings.run_mode){ return; } static ticks_t start = 0; ticks_t now = timer_clock_unlocked(); if(start == 0){ start = now; }else if(now - start > ms_to_ticks(10000)){ if(currentMode != g_settings.run_mode){ char c[2]; c[0] = (g_settings.run_mode + 48); c[1] = 0; cmd_switch_mode(&g_serial,c,1); } } }
static bool cutoff_checkDist(udegree_t lat, udegree_t lon, ticks_t now) { static ticks_t dist_ko_time; if (status_currStatus() != BSM2_GROUND_WAIT && status_currStatus() != BSM2_NOFIX) { float curr_dist = distance(start_latitude, start_longitude, lat / 1e6, lon / 1e6); if (curr_dist > dist_max_meters) { static bool logged = false; if (dist_ok) { radio_printf("CUTOFF:distance over range\n"); radio_printf("CUTOFF in %lds\n", (long)dist_timeout); LOG_INFO("Current position %8.06f %9.06f, distance from base: %.0fm; limit %ldm, starting %lds timeout\n", lat / 1e6, lon / 1e6, curr_dist, (long)dist_max_meters, (long)dist_timeout); dist_ok = false; dist_ko_time = now; logged = false; } else if (now - dist_ko_time > ms_to_ticks(dist_timeout * 1000)) { if (!logged) { radio_printf("CUTOFF:distance timeout\n"); logged = true; } return false; } return true; } } if (!dist_ok) LOG_INFO("Distance from base ok\n"); dist_ok = true; return true; }
int add_tmr (pid_t pid, unsigned int ms) { int tmr; unsigned int ticks; if ((tmr = get_free_tmr ()) < 0) { DPRINTF ("XMK: add_tmr -> Out of timers\r\n"); return -1; } ticks = ms_to_ticks (ms); ticks = (ticks == 0) ? 1 : ticks; // Bump it up a little soft_tmrs[tmr].pid = pid; soft_tmrs[tmr].timeout = ticks; active_tmrs[nactive] = tmr; nactive++; return 0; }
static bool cutoff_checkMaxalt(int32_t curr_alt, ticks_t now) { static ticks_t maxalt_ko_time; if (status_currStatus() != BSM2_GROUND_WAIT && status_currStatus() != BSM2_NOFIX) { if (curr_alt > altmax_meters) { static bool logged = false; if (maxalt_ok) { radio_printf("CUTOFF:altitude over range\n"); radio_printf("CUTOFF in %lds\n", (long)altmax_timeout); LOG_INFO("Altitude: %ldm; limit %ldm, starting %lds timeout\n", (long)curr_alt, (long)altmax_meters, (long)altmax_timeout); maxalt_ok = false; maxalt_ko_time = now; logged = false; } else if (now - maxalt_ko_time > ms_to_ticks(altmax_timeout * 1000)) { if (!logged) { radio_printf("CUTOFF:altitude timeout\n"); logged = true; } return false; } return true; } } if (!maxalt_ok) LOG_INFO("Maximum altitude ok\n"); maxalt_ok = true; return true; }
static bool cutoff_checkAltitude(int32_t curr_alt, ticks_t now) { static ticks_t alt_ko_time; if (status_currStatus() != BSM2_GROUND_WAIT && status_currStatus() != BSM2_NOFIX) { alt_max = MAX(alt_max, curr_alt); if (alt_max - curr_alt > delta_altitude) { static bool logged = false; if (alt_ok) { radio_printf("CUTOFF:burst detected\n"); radio_printf("CUTOFF in %lds\n", (long)altitude_timeout); LOG_INFO("Current altitude %ld, peak altitude %ld; current altitude lower than delta, starting %ld s timeout\n", (long)curr_alt, (long)alt_max, (long)altitude_timeout); alt_ok = false; logged = false; alt_ko_time = now; } else if (now - alt_ko_time > ms_to_ticks(altitude_timeout * 1000)) { if (!logged) { radio_printf("CUTOFF:burst timeout\n"); logged = true; } return false; } return true; } } if (!alt_ok) LOG_INFO("Current altitude ok\n"); alt_ok = true; return true; }
static int __init at91wdt_probe(struct platform_device *pdev) { struct resource *r; int res; if (at91wdt_miscdev.parent) return -EBUSY; at91wdt_miscdev.parent = &pdev->dev; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); if (!r) return -ENODEV; at91wdt_private.base = ioremap(r->start, resource_size(r)); if (!at91wdt_private.base) { dev_err(&pdev->dev, "failed to map registers, aborting.\n"); return -ENOMEM; } /* Set watchdog */ res = at91_wdt_settimeout(ms_to_ticks(WDT_HW_TIMEOUT * 1000)); if (res) return res; res = misc_register(&at91wdt_miscdev); if (res) return res; at91wdt_private.next_heartbeat = jiffies + heartbeat * HZ; setup_timer(&at91wdt_private.timer, at91_ping, 0); mod_timer(&at91wdt_private.timer, jiffies + WDT_TIMEOUT); pr_info("enabled (heartbeat=%d sec, nowayout=%d)\n", heartbeat, nowayout); return 0; }
void kiss_csma(AX25Ctx *ctx, uint8_t *buf, size_t len) { bool sent = false; while (!sent) { //puts("Waiting in CSMA"); if(!channel->hdlc.receiving) { uint8_t tp = rand() & 0xFF; if (tp < p) { ax25_sendRaw(ctx, buf, len); sent = true; } else { ticks_t start = timer_clock(); long slot_ticks = ms_to_ticks(slotTime); while (timer_clock() - start < slot_ticks) { cpu_relax(); } } } else { while (!sent && channel->hdlc.receiving) { // Continously poll the modem for data // while waiting, so we don't overrun // receive buffers ax25_poll(ax25ctx); if (channel->status != 0) { // If an overflow or other error // occurs, we'll back off and drop // this packet silently. channel->status = 0; sent = true; } } } } }
int main(void) { init(); ticks_t start = timer_clock(); while (1) { /* * This function will look for new messages from the AFSK channel. * It will call the message_callback() function when a new message is received. * If there's nothing to do, this function will call cpu_relax() */ ax25_poll(&ax25); /* Send out message every 15sec */ if (timer_clock() - start > ms_to_ticks(15000L)) { start = timer_clock(); ax25_sendVia(&ax25, path, countof(path), APRS_MSG, sizeof(APRS_MSG)); } } return 0; }