int main(int argc, char* argv[]) { // Send a greeting to the trace device (skipped on Release). trace_puts("Hello ARM World!"); // At this stage the system clock should have already been configured // at high speed. trace_printf("System clock: %u Hz\n", SystemCoreClock); timer_start(); blink_led_init(); uint32_t seconds = 0; // Infinite loop while (1) { blink_led_on(); timer_sleep(seconds == 0 ? TIMER_FREQUENCY_HZ : BLINK_ON_TICKS); blink_led_off(); timer_sleep(BLINK_OFF_TICKS); ++seconds; // Count seconds on the trace device. trace_printf("Second %u\n", seconds); } // Infinite loop, never return. }
void *power_set_measurement(void *arg) { unsigned long poll_num = 0; struct mstimer timer; set_rapl_power(watt_cap, watt_cap); double watts = watt_cap; // According to the Intel docs, the counter wraps a most once per second. // 100 ms should be short enough to always get good information. init_msTimer(&timer, 1500); init_data(); start = now_ms(); poll_num++; timer_sleep(&timer); while (running) { take_measurement(); if (poll_num%5 == 0) { if (watts >= watt_cap) { poll_dir = -5; } if (watts <= 30) { poll_dir = 5; } watts += poll_dir; set_rapl_power(watts, watts); } poll_num++; timer_sleep(&timer); } }
int main(int argc, char *argv[]) { u_int led; u_int count; u_int status; u_int all_mask = 0; device_t dev; int err; printf("led driver test program\n"); printf("Open led device... "); err = device_open("led", O_RDWR, &dev); check(err); if (err) { return 0; } printf("Query led count... "); check(led_count(dev, &count)); printf("Count is %d\n", count); timer_sleep(1000, 0); for (led = 0; led < count; ++led) { printf("Turn on LED %d... ", led); check(led_on(dev, 1 << led)); timer_sleep(1000, 0); printf("Turn off LED %d... ", led); check(led_off(dev, 1 << led)); timer_sleep(1000, 0); all_mask |= (1 << led); } printf("Turn on all LEDs... "); check(led_on(dev, all_mask)); printf("Get LED status... "); check(led_status(dev, &status)); printf("Status is %x == %x\n", status, all_mask); timer_sleep(1000, 0); printf("Turn off all LEDs... "); check(led_off(dev, all_mask)); printf("Get LED status... "); check(led_status(dev, &status)); printf("Status is %x == 0\n", status); timer_sleep(1000, 0); printf("Close the device..."); err = device_close(dev); check(err); return 0; }
static void load_thread (void *seq_no_) { int seq_no = (int) seq_no_; int sleep_time = TIMER_FREQ * (10 + seq_no); int spin_time = sleep_time + TIMER_FREQ * THREAD_CNT; int exit_time = TIMER_FREQ * (THREAD_CNT * 2); timer_sleep (sleep_time - timer_elapsed (start_time)); while (timer_elapsed (start_time) < spin_time) continue; timer_sleep (exit_time - timer_elapsed (start_time)); }
int main(int argc, char* argv[]) { int x; // Show the program parameters (passed via semihosting). // Output is via the semihosting output channel. trace_dump_args(argc, argv); // Send a greeting to the trace device (skipped on Release). trace_puts("Hello ARM World!"); // Send a message to the standard output. puts("Standard output message."); // Send a message to the standard error. fprintf(stderr, "Standard error message.\n"); // At this stage the system clock should have already been configured // at high speed. trace_printf("System clock: %uHz\n", SystemCoreClock); timer_start(); blink_led_init(); uint32_t seconds = 0; printf("input x\r\n"); scanf("%d",&x); printf("%d",x); test_read_file_from_host("d:/test.txt"); // Infinite loop while (1) { blink_led_on(); timer_sleep(BLINK_ON_TICKS); blink_led_off(); timer_sleep(BLINK_OFF_TICKS); ++seconds; // Count seconds on the trace device. trace_printf("Second %u\n", seconds); } // Infinite loop, never return. }
void* power_measurement(void* arg) { struct mstimer timer; // according to the Intel docs, the counter wraps a most once per second // 100 ms should be short enough to always get good information init_msTimer(&timer, 100); init_data(); read_rapl_init(); start = now_ms(); timer_sleep(&timer); while(running) { take_measurement(); timer_sleep(&timer); } }
static pid_t my_exec(const char *cmd_line) { //printf("execute\n"); if(!address_valid(cmd_line)) my_exit(-1); struct thread *t = thread_current(); //printf("process_execute start\n"); tid_t tid = process_execute(cmd_line); //printf("process_execute finish tid %d\n",tid); //printf("my_exec_new_tid : %d\n", tid); //printf("my_exec : %p, tid : %d, name : %s\n", t, t->tid, t->pname); struct child_process* cp = get_child_by_tid(tid); //printf("cp in exec : %p : load : %d\n", cp, cp->load); //printf("process_execute end tid: %d && cp->load : %d\n", tid, cp->load); while(cp->not_load == true) timer_sleep(1); if(cp->load == false) return -1; // printf("exec return tid: %d\n",tid); return tid; }
void test_mlfqs_load_60 (void) { int i; ASSERT (thread_mlfqs); start_time = timer_ticks (); msg ("Starting %d niced load threads...", THREAD_CNT); for (i = 0; i < THREAD_CNT; i++) { char name[16]; snprintf(name, sizeof name, "load %d", i); thread_create (name, PRI_DEFAULT, load_thread, NULL); } msg ("Starting threads took %d seconds.", timer_elapsed (start_time) / TIMER_FREQ); for (i = 0; i < 90; i++) { int64_t sleep_until = start_time + TIMER_FREQ * (2 * i + 10); int load_avg; //printf("LIST NUMBER : %d\n", get_list_size ()); timer_sleep (sleep_until - timer_ticks ()); load_avg = thread_get_load_avg (); msg ("After %d seconds, load average=%d.%02d.", i * 2, load_avg / 100, load_avg % 100); } }
/** @brief Initialization the accelerometer sensor @return none **/ void Sensor_Init(void) { DioPulPin(CSACC_PORT, CSACC_PIN_NUMBER, 0); /* Disable the internal pull up on CSACC pin */ DioOenPin(CSACC_PORT, CSACC_PIN_NUMBER, 1); /* Set CSACC pin as output */ DioPulPin(INT1ACC_PORT, INT1ACC_PIN_NUMBER, 0); /* Disable the internal pull up on INT1ACC pin */ DioOenPin(INT1ACC_PORT, INT1ACC_PIN_NUMBER, 0); /* Set INT1ACC pin as input */ DioPulPin(INT2ACC_PORT, INT2ACC_PIN_NUMBER, 0); /* Disable the internal pull up on INT2ACC pin */ DioOenPin(INT2ACC_PORT, INT2ACC_PIN_NUMBER, 0); /* Set INT2ACC pin as input */ SPI_Write(SOFT_RESET_REG, 0x52, SPI_WRITE_REG); /* Soft reset accelerometer */ timer_sleep(100); /* Wait at least 0.5 ms */ /* Set activity threshold */ SPI_Write(THRESH_ACT_L, ACT_VALUE & 0xFF, SPI_WRITE_REG); SPI_Write(THRESH_ACT_H, ACT_VALUE >> 8, SPI_WRITE_REG); SPI_Write(TIME_ACT, (ACT_TIMER / 10), SPI_WRITE_REG); /* Set activity time at 100Hz data rate */ /* Set inactivity threshold */ SPI_Write(THRESH_INACT_L, INACT_VALUE & 0xFF, SPI_WRITE_REG); SPI_Write(THRESH_INACT_H, INACT_VALUE >> 8, SPI_WRITE_REG); /* Set inactivity time at 100Hz data rate */ SPI_Write(TIME_INACT_L, ((INACT_TIMER * 100) & 0xFF), SPI_WRITE_REG); SPI_Write(TIME_INACT_H, ((INACT_TIMER * 100) >> 8), SPI_WRITE_REG); SPI_Write(ACT_INACT_CTL, 0x3F, SPI_WRITE_REG); /* Set Loop mode, referenced mode for activity and inactivity, enable activity and inactivity functionality */ SPI_Write(INTMAP1, 0x40, SPI_WRITE_REG); /* Map the awake status to INT1 pin */ }
/* Sleep for approximately NUM/DENOM seconds. */ static void real_time_sleep (int64_t num, int32_t denom) { /* Convert NUM/DENOM seconds into timer ticks, rounding down. (NUM / DENOM) s ---------------------- = NUM * TIMER_FREQ / DENOM ticks. 1 s / TIMER_FREQ ticks */ int64_t ticks = num * TIMER_FREQ / denom; ASSERT (intr_get_level () == INTR_ON); if (ticks > 0) { /* We're waiting for at least one full timer tick. Use timer_sleep() because it will yield the CPU to other processes. */ timer_sleep (ticks); } else { /* Otherwise, use a busy-wait loop for more accurate sub-tick timing. */ real_time_delay (num, denom); } }
/** @brief ADC converter reset @return none **/ void AD7793_Reset(void) { SPI_Write(0, 0, 4); /* Write 4 bytes = 0xFF */ timer_sleep(0.05); /* Wait time before accessing any registers after reset */ }
/** @brief Perform a power-up of the device - keeps CONVST pin high for 50 ms @return uint16_t - conversion result **/ void AD7091R_PowerUp(void) { CONVST_PORT->GPSET = CONVST_PIN; /* Pull CONVST high */ timer_sleep(50); /* Wait 50 ms */ }
/* * The main routine create 10 copy of this thread. But, since the * initial semaphore value is 3, only 3 threads can run at same time. */ static void new_thread(void) { thread_t t; t = thread_self(); printf("Start thread=%x\n", (u_int)t); thread_yield(); /* * Acquire semaphore */ sem_wait(&sem, 0); /* * Sleep 2000 ms */ printf("Running thread=%x\n", (u_int)t); timer_sleep(2000, 0); /* * Release semaphore */ sem_post(&sem); printf("End thread=%x\n", (u_int)t); thread_terminate(t); }
void narrow_bridge(UNUSED unsigned int num_vehicles_left, UNUSED unsigned int num_vehicles_right, UNUSED unsigned int num_emergency_left, UNUSED unsigned int num_emergency_right) { int left = num_vehicles_left; int right = num_vehicles_right; int urgent_left = num_emergency_left; int urgent_right = num_emergency_right; int sum_vehicles = left + right + urgent_left + urgent_right; init(); while(left>0){ thread_create("left vehicle", 0, createLeft, NULL); left--; } while(right>0){ thread_create("right vehicle", 0, createRight, NULL); right--; } while(urgent_left>0){ thread_create("left urgent vehicle", 0, createUrgentLeft, NULL); urgent_left--; } while(urgent_right>0){ thread_create("right urgent vehicle", 0, createUrgentRight, NULL); urgent_right--; } timer_sleep(3000); }
void test_mlfqs_block (void) { int64_t start_time; struct lock lock; ASSERT (thread_mlfqs); msg ("Main thread acquiring lock."); lock_init (&lock); lock_acquire (&lock); msg ("Main thread creating block thread, sleeping 25 seconds..."); thread_create ("block", PRI_DEFAULT, block_thread, &lock); timer_sleep (25 * TIMER_FREQ); msg ("Main thread spinning for 5 seconds..."); start_time = timer_ticks (); while (timer_elapsed (start_time) < 5 * TIMER_FREQ) continue; msg ("Main thread releasing lock."); lock_release (&lock); msg ("Block thread should have already acquired lock."); }
/* Sleeper thread. */ static void sleeper (void *test_) { struct sleep_test *test = test_; int i; /* Make sure we're at the beginning of a timer tick. */ timer_sleep (1); for (i = 1; i <= test->iterations; i++) { int64_t sleep_until = test->start + i * 10; timer_sleep (sleep_until - timer_ticks ()); *test->output_pos++ = timer_ticks () - test->start; thread_yield (); } }
unsigned int sleep(unsigned int seconds) { unsigned int remain = 0; timer_sleep(seconds * 1000, (u_long *)&remain); return remain; }
void* uploadProc(void* arg) { // Get thread number int threadNum = (int)arg; // Do not start all at the same time timer_sleep(m_interval * threadNum / m_numThreads); // Get handle to CURL (only use one handle in one thread at any time!) CURL* curl = curl_easy_init(); if (!curl) { LOG(0, "Failed to initialize curl for thread %d\n", threadNum); return NULL; } // Process measurements while (m_running) { // Grab a measurement from queue char* data = NULL; if (!queue_dequeue(m_queue, &data) || !data) { // Nothing to do, so have a break timer_sleep(m_interval); continue; } // Send measurement to server while (!performPOST(curl, data)) { // Failed to send measurement // Wait a bit and then try again timer_sleep(m_interval); } LOG(3, "Thread %d sent measurement successfully\n", threadNum); // Cleanup free(data); } // Cleanup curl_easy_cleanup(curl); return NULL; }
/* * Send thread */ static void send_thread(void) { struct my_msg msg; object_t o1, o2; int error; char string[] = "A lazy dog laying on the road!!"; printf("Send thread is starting...\n"); /* * Find objects. */ error = object_lookup("test-A", &o1); error = object_lookup("test-B", &o2); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Delete object A. */ printf("Delete object A\n"); object_destroy(o1); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Send message to object B. */ printf("Send message to object B.\n"); strncpy(msg.data, string, sizeof(string)); msg.hdr.code = 42; msg_send(o2, &msg, sizeof(msg)); printf("Send completed.\n"); for (;;) ; }
void lcd_cmd(struct lcdInfo* lcdinfo ,unsigned char data, unsigned int char_mode) { timer_sleep(1000); if(char_mode) { gpio_outputSet(lcdinfo->rs); } else { gpio_outputClr(lcdinfo->rs); } gpio_outputClr(lcdinfo->db[0]); gpio_outputClr(lcdinfo->db[1]); gpio_outputClr(lcdinfo->db[2]); gpio_outputClr(lcdinfo->db[3]); int n = 0; for(n = 0; n < 4; n++) { if(data & (0b1 << n)) { gpio_outputSet(lcdinfo->db[n + 4]); } } gpio_outputSet(lcdinfo->e); timer_sleep(500); gpio_outputClr(lcdinfo->e); timer_sleep(500); gpio_outputClr(lcdinfo->db[0]); gpio_outputClr(lcdinfo->db[1]); gpio_outputClr(lcdinfo->db[2]); gpio_outputClr(lcdinfo->db[3]); for(n = 0; n < 4; n++) { if(data & (0b1 << (n))) { gpio_outputSet(lcdinfo->db[n]); } } gpio_outputSet(lcdinfo->e); timer_sleep(500); gpio_outputClr(lcdinfo->e); timer_sleep(500); }
/* * Main routine */ int main(int argc, char *argv[]) { syslog(LOG_INFO, "\nfifo: fs test program\n"); /* Wait 1 sec until loading fs server */ timer_sleep(1000, 0); /* * Prepare to use a file system. */ fslib_init(); /* * Mount file systems */ mount("", "/", "ramfs", 0, NULL); mkdir("/dev", 0); mount("", "/dev", "devfs", 0, NULL); /* device */ mkdir("/tmp", 0); /* * Prepare stdio */ open("/dev/tty", O_RDWR); /* stdin */ dup(0); /* stdout */ dup(0); /* stderr */ if (mkfifo(fifo_name, 0) < 0) err(1, "mkfifo(%s)", fifo_name); blocking_test(); nonblock_test(); /* sleep a bit */ timer_sleep(2000/*ms*/, NULL); /* * Disconnect from a file system. */ fslib_exit(); return 0; }
void uart_init() { mem_write(UART0_CR, 0x00000000); mem_write(GPPUD, 0x00000000); timer_sleep(1); mem_write(GPPUDCLK0, (1 << 14) | (1 << 15)); timer_sleep(1); mem_write(GPPUDCLK0, 0x00000000); mem_write(UART0_ICR, 0x7FF); mem_write(UART0_IBRD, 1); mem_write(UART0_FBRD, 40); mem_write(UART0_LCRH, (1 << 4) | (1 << 5) | (1 << 6)); mem_write(UART0_IMSC, (1 << 1) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 8) | (1 << 9) | (1 << 10)); mem_write(UART0_CR, (1 << 0) | (1 << 8) | (1 << 9)); }
/* * Send thread */ static void send_thread(void) { struct msg msg; object_t o1, o2; int error; printf("Send thread is starting...\n"); /* * Find objects. */ error = object_lookup("test-A", &o1); error = object_lookup("test-B", &o2); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Delete object A. */ printf("Delete object A\n"); object_destroy(o1); /* * Wait a sec. */ timer_sleep(1000, 0); /* * Send message to object B. */ printf("Send message to object B.\n"); msg_send(o2, &msg, sizeof(msg)); printf("Send completed.\n"); for (;;) ; }
static void blocking_test(void) { thread_t th; int rc; for (int i = 0; i < BUF_SIZE; i++) write_buf[i] = i & 0x7F; syslog(LOG_INFO, "fifo blocking:\n wr_open..."); if ((wr_fd = open(fifo_name, O_WRONLY, 0)) < 0) err(1, "open(%s)", fifo_name); syslog(LOG_INFO, "write open ok\n write1..."); if ((rc = write(wr_fd, write_buf, WR1_SIZE)) != -1) errx(1, "write1 %d, expected %d", rc, 0); else if (errno != EPIPE) err(1, "write1 %d", WR1_SIZE); syslog(LOG_INFO, "write1 ok\n rd_open..."); if ((rd_fd = open(fifo_name, O_RDONLY, 0)) < 0) err(1, "open(%s)", fifo_name); syslog(LOG_INFO, "read open ok\n write1a..."); if ((rc = write(wr_fd, write_buf, WR1_SIZE)) < 0) err(1, "write1a %d", WR1_SIZE); else if (rc != WR1_SIZE) errx(1, "wrote1a %d, expected %d", rc, WR1_SIZE); syslog(LOG_INFO, "write1a ok\n thread_run..."); th = thread_run("read", read_thread, th_stack, sizeof(th_stack), 1); syslog(LOG_INFO, "thread_run ok\n write2..."); rc = write(wr_fd, write_buf + WR1_SIZE, WR2_SIZE); if (rc < 0) err(1, "write2 %d", WR2_SIZE); else if (rc != WR2_SIZE) errx(1, "wrote2 %d, expected %d", rc, WR2_SIZE); syslog(LOG_INFO, "write2 ok\n close..."); if (close(wr_fd) < 0) err(1, "close(%d)", wr_fd); syslog(LOG_INFO, "write close ok\n sleep..."); timer_sleep(1000/*ms*/, NULL); syslog(LOG_INFO, "sleep done\n data check..."); if (validate_write(0, BUF_SIZE) || validate_read(0, BUF_SIZE)) errx(1, "data corrupt"); syslog(LOG_INFO, "data check ok\nblocking test complete\n"); }
/* * Main routine */ int main(int argc, char *argv[]) { char test_str[] = "test stdout...\n\n"; syslog(LOG_INFO, "\nfileio: fs test program\n"); /* Wait 1 sec until loading fs server */ timer_sleep(1000, 0); /* * Prepare to use a file system. */ fslib_init(); /* * Mount file systems */ mount("", "/", "ramfs", 0, NULL); mkdir("/dev", 0); mount("", "/dev", "devfs", 0, NULL); /* device */ mkdir("/boot", 0); mount("/dev/ram0", "/boot", "arfs", 0, NULL); /* archive */ mkdir("/tmp", 0); /* * Prepare stdio */ open("/dev/tty", O_RDWR); /* stdin */ dup(0); /* stdout */ dup(0); /* stderr */ /* Test device write */ write(STDOUT_FILENO, test_str, strlen(test_str)); test_write(); cat_file(); /* test read/write */ test_invalid(); /* test invalid request */ test_read(); /* test read loop */ test_open(); /* test open/close loop */ /* * Disconnect from a file system. */ fslib_exit(); return 0; }
int epos_control_start(epos_control_p control) { int result = epos_device_set_control(control->dev, EPOS_DEVICE_CONTROL_ENABLE_OPERATION); #ifdef __ELMO__ if (!result) result = epos_device_set_control(control->dev, EPOS_DEVICE_CONTROL_ENABLE_OPERATION); #endif if (!result) timer_sleep(EPOS_CONTROL_START_SLEEP); return result; }
int main(int argc, char *argv[]) { device_t pm_dev; int state; timer_sleep(2000, 0); if (device_open("pm", 0, &pm_dev) != 0) exit(1); state = POWER_REBOOT; device_ioctl(pm_dev, PMIOC_SET_POWER, &state); device_close(pm_dev); exit(1); }
/* Sleeper thread. */ static void sleeper (void *t_) { struct sleep_thread *t = t_; struct sleep_test *test = t->test; int i; for (i = 1; i <= test->iterations; i++) { int64_t sleep_until = test->start + i * t->duration; timer_sleep (sleep_until - timer_ticks ()); lock_acquire (&test->output_lock); *test->output_pos++ = t->id; lock_release (&test->output_lock); } }
void test_mlfqs_load_1 (void) { int64_t start_time; int elapsed; int load_avg; ASSERT (thread_mlfqs); msg ("spinning for up to 45 seconds, please wait..."); start_time = timer_ticks (); for (;;) { load_avg = thread_get_load_avg (); ASSERT (load_avg >= 0); elapsed = timer_elapsed (start_time) / TIMER_FREQ; if (load_avg > 100) fail ("load average is %d.%02d " "but should be between 0 and 1 (after %d seconds)", load_avg / 100, load_avg % 100, elapsed); else if (load_avg > 50) break; else if (elapsed > 45) { msg ("load average is %d.%02d ", load_avg / 100, load_avg % 100); fail ("load average stayed below 0.5 for more than 45 seconds"); } } if (elapsed < 38) fail ("load average took only %d seconds to rise above 0.5", elapsed); msg ("load average rose to 0.5 after %d seconds", elapsed); msg ("sleeping for another 10 seconds, please wait..."); timer_sleep (TIMER_FREQ * 10); load_avg = thread_get_load_avg (); if (load_avg < 0) fail ("load average fell below 0"); if (load_avg > 50) fail ("load average stayed above 0.5 for more than 10 seconds"); msg ("load average fell back below 0.5 (to %d.%02d)", load_avg / 100, load_avg % 100); pass (); }
int test_timersleep() { timer_init(); TimerData timer; timer_start(&timer); timer_sleep(1E4); timer_stop(&timer); if (timer_print(&timer) < 0.01) goto fail; if (timer_print(&timer) > 0.015) goto fail; timer_finalize(); return 1; fail: timer_finalize(); return 0; }