Mercurial > ~darius > hgwebdir.cgi > stm32temp
annotate rtc.h @ 44:f1cc171b06b5
Remove useless delay test. Add GPIO PE2 changes to make testing arbitary delays possible.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 02 Apr 2013 10:54:20 +1030 |
parents | 435c6330896c |
children |
rev | line source |
---|---|
30
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */ |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 #define RTC_PRESCALE 32768 |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 /* usec = x * 1e6 / 32768 |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * However, 1e6 / 32768 = 30.5 which will result in a large error (max of 15807 usec), so we use |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 * some extra bits to get more precision. We can scale up until 32768 * n is > 2^32. |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 * This results in a maximum error of 1 usec. |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 */ |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 #define RTC_PS2USEC(x) ( \ |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 (uint32_t)( \ |
435c6330896c
Set tv_usec in gettimeofday() by using the prescaler counter.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 (uint32_t)((1 << 9) * (1e6 / RTC_PRESCALE)) * (RTC_PRESCALE - (x))) >> 9) |