Пример #1
0
int main(int argc, char *argv[])
{
	/* Declare Variables */
	double syshz = 1000000;
	double systimestart = 0;
	double systimeend = 0;
	double elapsed_time = 0;

	/* Initialize bcm2835 library and check for errors */
	if(!bcm2835_init()){
		perror("bcm2835");
		exit(EXIT_FAILURE);
	}

	/* get system time
	 * sleep for 1 second
	 * get system time after sleep
	 * calculate difference of system time in seconds
	 */
	systimestart = (double) bcm2835_st_read();
	sleep(1);
	systimeend = (double) bcm2835_st_read();
	elapsed_time = (systimeend - systimestart)/syshz;

	printf("Sleep(1) elapsed time: %f seconds\n",elapsed_time);

	/* Close the library deallocating any allocated memory */
	bcm2835_close();
	return EXIT_SUCCESS;
}
Пример #2
0
// Delays for the specified number of microseconds with offset
void bcm2835_st_delay(uint64_t offset_micros, uint64_t micros)
{
    uint64_t compare = offset_micros + micros;

    while(bcm2835_st_read() < compare)
	;
}
Пример #3
0
/* microseconds */
void bcm2835_delayMicroseconds(uint64_t micros)
{
    struct timespec t1;
    uint64_t        start;
	
    if (debug)
    {
	/* Cant access sytem timers in debug mode */
	printf("bcm2835_delayMicroseconds %lld\n", micros);
	return;
    }

    /* Calling nanosleep() takes at least 100-200 us, so use it for
    // long waits and use a busy wait on the System Timer for the rest.
    */
    start =  bcm2835_st_read();
   
    /* Not allowed to access timer registers (result is not as precise)*/
    if (start==0)
    {
	t1.tv_sec = 0;
	t1.tv_nsec = 1000 * (long)(micros);
	nanosleep(&t1, NULL);
	return;
    }

    if (micros > 450)
    {
	t1.tv_sec = 0;
	t1.tv_nsec = 1000 * (long)(micros - 200);
	nanosleep(&t1, NULL);
    }    
  
    bcm2835_st_delay(start, micros);
}
Пример #4
0
void events_init() {
	int i;
	uint64_t st_read_now = bcm2835_st_read();
	for (i = 0; i < (sizeof(events) / sizeof(events[0])); i++) {
		events_elapsed_time[i] += st_read_now;
	}
}
Пример #5
0
void sys_time_init(void) {
	struct rtc_time tm_rtc;
	struct tm tmbuf;

	sys_time_init_startup_micros = bcm2835_st_read();

	if (mcp7941x_start(0x00) == MCP7941X_ERROR) {
		tmbuf.tm_hour = 0;
		tmbuf.tm_min = 0;
		tmbuf.tm_sec = 0;
		tmbuf.tm_mday = 1;
		tmbuf.tm_wday = 1;
		tmbuf.tm_mon = 0;
		tmbuf.tm_year = 18;
		tmbuf.tm_isdst = 0; // 0 (DST not in effect, just take RTC time)
		//tmbuf.tm_yday = 0;

		rtc_startup_seconds = mktime(&tmbuf);
		return;
	}

	mcp7941x_get_date_time(&tm_rtc);

	tmbuf.tm_hour = tm_rtc.tm_hour;
	tmbuf.tm_min = tm_rtc.tm_min;
	tmbuf.tm_sec = tm_rtc.tm_sec;
	tmbuf.tm_mday = tm_rtc.tm_mday;
	tmbuf.tm_wday = tm_rtc.tm_mday;
	tmbuf.tm_mon = tm_rtc.tm_mon;
	tmbuf.tm_year = tm_rtc.tm_year;
	tmbuf.tm_isdst = 0; // 0 (DST not in effect, just take RTC time)

	rtc_startup_seconds = mktime(&tmbuf);
}
Пример #6
0
const uint32_t millis(void) {
	dmb();
	const uint32_t elapsed = ((uint32_t) (bcm2835_st_read() - sys_time_init_startup_micros) / (uint32_t) 1000);
	dmb();

	return elapsed;
}
//uint64_t bcm2835_st_read(void);
/// Call bcm2835_st_read
/// \par            Refer
/// \par            Modify
void ope_st_read(void)
{
uint64_t ret;
    ret = bcm2835_st_read();
    set_ope_code( OPE_ST_READ );
    set_long_code( ret );
    put_reply();
    mark_sync();
}
Пример #8
0
static inline void events_check() {
	int i;
	uint64_t st_read_now = bcm2835_st_read();
	for (i = 0; i < (sizeof(events) / sizeof(events[0])); i++) {
		if (st_read_now > events_elapsed_time[i] + events[i].period) {
			events[i].f();
			events_elapsed_time[i] += events[i].period;
		}
	}
}
Пример #9
0
/**
 * @ingroup time
 *
 *  Returns the time as the number of seconds since the Epoch, 1970-01-01 00:00:00 +0000 (UTC).
 *  If \ref __timer is non-NULL, the return value is also stored in the memory pointed to by __timer.
 *
 * @param __timer
 * @return  The value of time in seconds since the Epoch
 */
time_t time(time_t *__timer) {
	dmb();
	time_t elapsed = (time_t) ((bcm2835_st_read() - sys_time_init_startup_micros) / (uint64_t) 1000000);
	dmb();

	elapsed = elapsed + rtc_startup_seconds;

	if (__timer != NULL) {
		*__timer = elapsed;
	}

	return elapsed;
}
Пример #10
0
// return utc time in microseconds
uint64_t GetTimeUTC( ) 
{
	uint64_t t;
#if defined _WIN32
	FILETIME        ft;
    SYSTEMTIME      st;
    GetSystemTime(&st);
    SystemTimeToFileTime(&st,&ft);

	t  = FileTimeToUTCTime(ft);
#else
	t = bcm2835_st_read();
#endif // defined _WIN32
    return t; 
}
Пример #11
0
// microseconds
void bcm2835_delayMicroseconds(uint64_t micros)
{
    struct timespec t1;
    uint64_t        start;
	
    // Calling nanosleep() takes at least 100-200 us, so use it for
    // long waits and use a busy wait on the System Timer for the rest.
    start =  bcm2835_st_read();
    
    if (micros > 450)
    {
	t1.tv_sec = 0;
	t1.tv_nsec = 1000 * (long)(micros - 200);
	nanosleep(&t1, NULL);
    }    
  
    bcm2835_st_delay(start, micros);
}
Пример #12
0
/**
 * @ingroup hal
 *
 */
void hardware_init(void) {
#if defined ( RPI2 ) || defined ( RPI3 )
#ifndef ARM_ALLOW_MULTI_CORE
	// put all secondary cores to sleep
	uint8_t core_number = 1;
	for (core_number = 1 ; core_number < 4; core_number ++) {
		*(uint32_t *) (SMP_CORE_BASE + (core_number * 0x10)) = (uint32_t) _init_core;
	}
#endif
#endif
	(void) console_init();

	hardware_init_startup_micros = bcm2835_st_read();

	sys_time_init();

	bcm2835_rng_init();

	(void) bcm2835_vc_set_power_state(BCM2835_VC_POWER_ID_SDCARD, BCM2835_VC_SET_POWER_STATE_ON_WAIT);

#if (_FFCONF == 82786)	/* R0.09b */
	(void) f_mount((BYTE) 0, &fat_fs);
#elif (_FFCONF == 32020)/* R0.11 */
	(void) f_mount(&fat_fs, (const TCHAR *) "", (BYTE) 1);
#else
#error Not a recognized/tested FatFs version
#endif

	const uint32_t board_revision = bcm2835_vc_get_get_board_revision();

	if ((board_revision == 0xa02082) || (board_revision == 0xa22082)) {
		_hardware_led_f.init = bcm2837_gpio_virt_init;
		_hardware_led_f.set = bcm2837_gpio_virt_led_set;
	} else if (board_revision > 0x00000f) {
		_hardware_led_f.init = led_rpiplus_init;
		_hardware_led_f.set = led_rpiplus_set;
	}

	hardware_led_init();
	hardware_led_set(1);
}
Пример #13
0
void inline bcm2835_delayMicroseconds(unsigned long long micros)
{
    bcm2835_st_delay(bcm2835_st_read(), micros);
}
Пример #14
0
/**
 * @ingroup hal
 *
 * @return The board uptime in seconds
 */
const uint64_t hardware_uptime_seconds(void) {
	return (((bcm2835_st_read() - hardware_init_startup_micros) / 1E6));
}
Пример #15
0
void sys_time_set(const struct tm *tmbuf) {
	sys_time_init_startup_micros = bcm2835_st_read();
	rtc_startup_seconds = mktime((struct tm *) tmbuf);
}
Пример #16
-1
int notmain (void)
{
	FRESULT rc;				/* Result code */
	DIR dir;				/* Directory object */
	FILINFO fno;			/* File information object */
	UINT br ;

	bcm2835_uart_begin();

	f_mount(0, &Fatfs);		/* Register volume work area (never fails) */

#if 1
	printf("\r\nOpen an existing file (rainbowcircle.ild).\r\n");
	rc = f_open(&Fil, "rainbowcircle.ild", FA_READ);
	if (rc) die(rc);


	for (;;) {
		uint32_t i1 = bcm2835_st_read();
		rc = f_read(&Fil, Buff, 20, &br);	/* Read a chunk of file */
		uint32_t i2 = bcm2835_st_read();
		if (rc || !br) break;			/* Error or end of file */
		printf("br [%d] i2-i1 [%d]\n", br, (int)(i2-i1));
	}
	if (rc) die(rc);

	printf("\r\nClose the file.\r\n");
	rc = f_close(&Fil);
	if (rc) die(rc);
#endif
#if 0
	printf("\r\nCreate a new file (hello.txt).\r\n");
	rc = f_open(&Fil, "HELLO.TXT", FA_WRITE | FA_CREATE_ALWAYS);
	if (rc) die(rc);

	printf("\r\nWrite a text data. (Hello world!)\r\n");
	rc = f_write(&Fil, "Hello world!\r\n", 14, &bw);
	if (rc) die(rc);
	printf("%u bytes written.\r\n", bw);

	printf("\r\nClose the file.\r\n");
	rc = f_close(&Fil);
	if (rc) die(rc);
#endif
	printf("\r\nOpen root directory.\r\n");
	rc = f_opendir(&dir, "");
	if (rc) die(rc);

	char filename_buf[32];

	printf("\r\nDirectory listing...\r\n");
	for (;;) {
		fno.lfname = filename_buf;
		fno.lfsize = sizeof(filename_buf);
		rc = f_readdir(&dir, &fno);		/* Read a directory item */
		if (rc || !fno.fname[0]) break;	/* Error or end of dir */
		if (fno.fattrib & AM_DIR)
			printf("   <dir>  %s\r\n", fno.fname);
		else {
			char * fn = *fno.lfname ? fno.lfname : fno.fname;
			printf("%8lu  %s\r\n", fno.fsize, (char *) fn);
		}
	}
	if (rc) die(rc);

	printf("\nTest completed.\n");

	die(0);

	return 0;

}