/* Read the time from the RTC_STAT. time_in_seconds is seconds since Jan 1970 */ int rtc_get(struct rtc_time *tmp) { uint32_t cur_rtc_stat; int time_in_sec; int tm_sec, tm_min, tm_hr, tm_day; pr_stamp(); if (tmp == NULL) { puts("Error getting the date/time\n"); return -1; } rtc_init(); wait_for_complete(); /* Read the RTC_STAT register */ cur_rtc_stat = bfin_read_RTC_STAT(); /* Convert our encoded format into actual time values */ tm_sec = (cur_rtc_stat & RTC_SEC) >> RTC_SEC_P; tm_min = (cur_rtc_stat & RTC_MIN) >> RTC_MIN_P; tm_hr = (cur_rtc_stat & RTC_HR ) >> RTC_HR_P; tm_day = (cur_rtc_stat & RTC_DAY) >> RTC_DAY_P; /* Calculate the total number of seconds since epoch */ time_in_sec = (tm_sec) + MIN_TO_SECS(tm_min) + HRS_TO_SECS(tm_hr) + DAYS_TO_SECS(tm_day); to_tm(time_in_sec, tmp); return 0; }
/* Set the time. Get the time_in_secs which is the number of seconds since Jan 1970 and set the RTC registers * based on this value. */ int rtc_set(struct rtc_time *tmp) { unsigned long remain, days, hrs, mins, secs; pr_stamp(); if (tmp == NULL) { puts("Error setting the date/time\n"); return -1; } rtc_init(); wait_for_complete(); /* Calculate number of seconds this incoming time represents */ remain = mktime(tmp->tm_year, tmp->tm_mon, tmp->tm_mday, tmp->tm_hour, tmp->tm_min, tmp->tm_sec); /* Figure out how many days since epoch */ days = remain / NUM_SECS_IN_DAY; /* From the remaining secs, compute the hrs(0-23), mins(0-59) and secs(0-59) */ remain = remain % NUM_SECS_IN_DAY; hrs = remain / NUM_SECS_IN_HR; remain = remain % NUM_SECS_IN_HR; mins = remain / NUM_SECS_IN_MIN; secs = remain % NUM_SECS_IN_MIN; /* Encode these time values into our RTC_STAT register */ bfin_write_RTC_STAT(SET_ALARM(days, hrs, mins, secs)); return 0; }
void loopback_run(struct loopback_test *t) { int i; int ret; for (i = 0; dict[i].name != NULL; i++) { if (strstr(dict[i].name, t->test_name)) t->test_id = dict[i].type; } if (!t->test_id) { fprintf(stderr, "invalid test %s\n", t->test_name); usage(); return; } prepare_devices(t); ret = open_poll_files(t); if (ret) goto err; start(t); ret = wait_for_complete(t); close_poll_files(t); if (ret) goto err; get_results(t); log_results(t); return; err: printf("Error running test\n"); return; }
void loopback_run(struct loopback_test *t) { int i; int ret; for (i = 0; dict[i].name != NULL; i++) { if (strstr(dict[i].name, t->test_name)) t->test_id = dict[i].type; } if (!t->test_id) { fprintf(stderr, "invalid test %s\n", t->test_name); usage(); return; } prepare_devices(t); ret = register_for_notification(t); if (ret) goto err; start(t); sleep(1); wait_for_complete(t); unregister_for_notification(t); get_results(t); log_results(t); return; err: printf("Error running test\n"); return; }
uint8_t MyI2C_read(uint8_t ack) { TWCR = (1<<TWINT) | (1<<TWEN) | (ack<<TWEA); wait_for_complete(); return TWDR; }
void MyI2C_write(uint8_t data) { TWDR = data; TWCR = (1<<TWINT) | (1<<TWEN); wait_for_complete(); }
void MyI2C_start(void) { TWCR = (1<< TWINT) | (1 << TWSTA) | (1 << TWEN); wait_for_complete(); }