void timer_set_interval_ms(timer_regs_t* const timer, uint36_t interval) { int prescale = 0; while ((interval > 262144) && (prescale < 8)) { prescale++; interval >>= 1; } timer_set_interval(timer, prescale, --interval); }
/* Create a timer fd to poller */ int ev_add_timer(int poller_fd, int timerfd, int sec, int msec, bool once_only) { timer_set_interval(timerfd, sec, msec, once_only); struct epoll_event event; event.data.fd = timerfd; event.events = EPOLLIN | EPOLLET; return epoll_ctl(poller_fd, EPOLL_CTL_ADD, timerfd, &event); }
void scheduler_test_scheduling(){ void scheduler_test_switch_to_next_guest(void *pdata); timer_init(timer_sched); /* 100Mhz -> 1 count == 10ns at RTSM_VE_CA15, fast model*/ timer_set_interval(timer_sched, 1000000); timer_add_callback(timer_sched, &scheduler_test_switch_to_next_guest); timer_start(timer_sched); timer_add_callback(timer_sched, &extra_timer_callback); }
/* Timer interrupt handler. * To receive the scheduled interrupt, the software must have previously enabled the corresponding * IRQ line using the BCM2835 interrupt controller. */ static void timer_irq_handler(struct interrupts_stack_frame *stack_frame) { // printf("\nKernel - Timer Interrupt Handler."); // The System Timer compare has to be reseted after the timer interrupt. timer_reset_timer_compare(IRQ_1); thread_tick(stack_frame); //timer_msleep(1000000); //timer_msleep(300000); // The System Timer compare register has to be set up with the new time after the timer interrupt. timer_set_interval(IRQ_1, TIMER_PERIODIC_INTERVAL); }
void longHandler(uart_long_function data) { if (data.address != id && data.address != 0) return; switch (data.command) { case 1: { if (data.length != 2) return; uint16_t value = data.data[0] << 8 | data.data[1]; timer_set_interval(value); } break; case 2: { if (data.address == 0) return; uint16_t value = timer_get_interval(); uart_send((uint8_t *)&value,2); } break; case 3: { if (data.length != 1) return; uint8_t value = data.data[0]; led_set_beacon_fade_div(value); } break; case 4: { //Set the whole bar to 0 led_clear_strip(); led_clear_buffer(); } break; case 5: { } break; case 6: { } break; case 7: { } break; case 8: { if (data.length != 1) return; uint8_t value = data.data[0]; led_invert_direction(value); led_hide_target(value); } break; } }
void timer_init() { printf("\nInitializing timer....."); interrupts_register_irq(IRQ_1, timer_irq_handler, "Timer Interrupt"); timer_set_interval(IRQ_1, TIMER_PERIODIC_INTERVAL); }
int main(int argc, char **argv) { struct netif netif; sigset_t mask, oldmask, empty; int ch; char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0}; /* startup defaults (may be overridden by one or more opts) */ IP4_ADDR(&gw, 192,168,0,1); IP4_ADDR(&ipaddr, 192,168,0,2); IP4_ADDR(&netmask, 255,255,255,0); trap_flag = 0; /* use debug flags defined by debug.h */ debug_flags = LWIP_DBG_OFF; while ((ch = getopt_long(argc, argv, "dhg:i:m:t:", longopts, NULL)) != -1) { switch (ch) { case 'd': debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT); break; case 'h': usage(); exit(0); break; case 'g': ipaddr_aton(optarg, &gw); break; case 'i': ipaddr_aton(optarg, &ipaddr); break; case 'm': ipaddr_aton(optarg, &netmask); break; case 't': trap_flag = !0; /* @todo: remove this authentraps tweak when we have proper SET & non-volatile mem */ snmpauthentraps_set = 1; ipaddr_aton(optarg, &trap_addr); strncpy(ip_str, ipaddr_ntoa(&trap_addr),sizeof(ip_str)); printf("SNMP trap destination %s\n", ip_str); break; default: usage(); break; } } argc -= optind; argv += optind; strncpy(ip_str, ipaddr_ntoa(&ipaddr), sizeof(ip_str)); strncpy(nm_str, ipaddr_ntoa(&netmask), sizeof(nm_str)); strncpy(gw_str, ipaddr_ntoa(&gw), sizeof(gw_str)); printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str); #ifdef PERF perf_init("/tmp/minimal.perf"); #endif /* PERF */ lwip_init(); printf("TCP/IP initialized.\n"); netif_add(&netif, &ipaddr, &netmask, &gw, NULL, mintapif_init, ethernet_input); netif_set_default(&netif); netif_set_up(&netif); #if SNMP_PRIVATE_MIB != 0 /* initialize our private example MIB */ lwip_privmib_init(); #endif snmp_trap_dst_ip_set(0,&trap_addr); snmp_trap_dst_enable(0,trap_flag); snmp_set_syscontact(syscontact_str,&syscontact_len); snmp_set_syslocation(syslocation_str,&syslocation_len); snmp_set_snmpenableauthentraps(&snmpauthentraps_set); snmp_init(); echo_init(); timer_init(); timer_set_interval(TIMER_EVT_ETHARPTMR, ARP_TMR_INTERVAL / 10); timer_set_interval(TIMER_EVT_TCPTMR, TCP_TMR_INTERVAL / 10); #if IP_REASSEMBLY timer_set_interval(TIMER_EVT_IPREASSTMR, IP_TMR_INTERVAL / 10); #endif printf("Applications started.\n"); while (1) { /* poll for input packet and ensure select() or read() arn't interrupted */ sigemptyset(&mask); sigaddset(&mask, SIGALRM); sigprocmask(SIG_BLOCK, &mask, &oldmask); /* start of critical section, poll netif, pass packet to lwIP */ if (mintapif_select(&netif) > 0) { /* work, immediatly end critical section hoping lwIP ended quickly ... */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } else { /* no work, wait a little (10 msec) for SIGALRM */ sigemptyset(&empty); sigsuspend(&empty); /* ... end critical section */ sigprocmask(SIG_SETMASK, &oldmask, NULL); } if(timer_testclr_evt(TIMER_EVT_TCPTMR)) { tcp_tmr(); } #if IP_REASSEMBLY if(timer_testclr_evt(TIMER_EVT_IPREASSTMR)) { ip_reass_tmr(); } #endif if(timer_testclr_evt(TIMER_EVT_ETHARPTMR)) { etharp_tmr(); } } return 0; }
void parse_cli(int argc, char **argv, http_request *request) { int ch; while ((ch = getopt(argc, argv, "b:c:d:fH:hm:p:t:v")) != -1) { switch(ch) { case 'b': request->file_upload = optarg; struct stat file; if (stat(request->file_upload, &file) != 0) { SCREEN(SCREEN_RED, stderr, "Cannot stat your input file %s: %s\n", request->file_upload, strerror(errno)); exit(EXIT_FAILURE); } request->method = POST; request->content_length = file.st_size; request->file_size = file.st_size; strncpy(request->content_type, "application/octet-stream", 256); break; case 'c': if (atoi(optarg) < 1) { SCREEN(SCREEN_RED, stderr, "Connection number must be equal to or greater than one.\n"); exit(EXIT_FAILURE); } if (atoi(optarg) > 65535) { SCREEN(SCREEN_RED, stderr, "Connection number cannot exceed ephemeral port range.\n"); exit(EXIT_FAILURE); } request->connections = atoi(optarg); SCREEN(SCREEN_YELLOW, stdout, "TCP connections:\t"); SCREEN(SCREEN_DARK_GREEN, stdout, "%d\n", request->connections); break; case 'd': request->method = POST; request->content_length = strlen(optarg); strncpy(request->content_type, "application/x-www-form-urlencoded", 256); memcpy(request->bodydata, optarg, 4096); break; case 'f': request->file_upload = optarg; break; case 'H': request->additional_header = optarg; break; case 'h': help(); break; case 'm': if (atoi(optarg) < 1) { printf("Duration time must be equal to or greater than one minute.\n"); exit(EXIT_FAILURE); } request->duration = 60 * atoi(optarg); break; case 'p': if (atoi(optarg) < 1 || atoi(optarg) > 65535) { SCREEN(SCREEN_RED, stderr, "Invalid port number.\n"); exit(EXIT_FAILURE); } request->port = atoi(optarg); break; case 't': if (atoi(optarg) < 1) { SCREEN(SCREEN_RED, stderr, "Invalid duration seconds.\n"); exit(EXIT_FAILURE); } request->duration = atoi(optarg); timerfd = timer_create_fd(); if (timerfd < 0) { SCREEN(SCREEN_RED, stderr, "Create timerfd failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } if (timer_set_interval(timerfd, request->duration, 0, true) < 0) { SCREEN(SCREEN_RED, stderr, "Set benchmark duration failed: %s\n", strerror(errno)); exit(EXIT_FAILURE); } SCREEN(SCREEN_YELLOW, stdout, "Duration:\t\t"); SCREEN(SCREEN_DARK_GREEN, stdout, "%d seconds\n", request->duration); break; case 'v': show_version(); break; case '?': exit(EXIT_FAILURE); break; case ':': break; default: break; } } }
void scheduler_init(void) { round_robin_index = 0; timer_set_interval(200000); register_interrupt_handler(TIMER_IRQ, handle_timer); }