diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2014-10-23 07:14:37 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2014-10-23 07:14:37 -0600 |
commit | 14db21a670d63baf01d537edb608ef1814aea97e (patch) | |
tree | 1c0d2a7f72d0c824b1aa351aef9ec8406d498ebe /nuttx/arch/arm/src/lpc43xx | |
parent | f6d2c32e031c11a516c062ee43eebef81790867c (diff) | |
download | nuttx-14db21a670d63baf01d537edb608ef1814aea97e.tar.gz nuttx-14db21a670d63baf01d537edb608ef1814aea97e.tar.bz2 nuttx-14db21a670d63baf01d537edb608ef1814aea97e.zip |
Update to the LPC43xx RIT/Tickless code. From Brandon Warhurst
Diffstat (limited to 'nuttx/arch/arm/src/lpc43xx')
-rw-r--r-- | nuttx/arch/arm/src/lpc43xx/Kconfig | 5 | ||||
-rw-r--r-- | nuttx/arch/arm/src/lpc43xx/chip/lpc43_rit.h | 3 | ||||
-rw-r--r-- | nuttx/arch/arm/src/lpc43xx/lpc43_rit.c | 43 | ||||
-rw-r--r-- | nuttx/arch/arm/src/lpc43xx/lpc43_rit.h | 2 |
4 files changed, 40 insertions, 13 deletions
diff --git a/nuttx/arch/arm/src/lpc43xx/Kconfig b/nuttx/arch/arm/src/lpc43xx/Kconfig index 80bb19606..703eae9e9 100644 --- a/nuttx/arch/arm/src/lpc43xx/Kconfig +++ b/nuttx/arch/arm/src/lpc43xx/Kconfig @@ -203,6 +203,11 @@ config LPC43_RIT bool "Repetitive Interrupt Timer (RIT)" default n +config LPC43_RIT_RES + int "Interrupt schedule resolution (nS)" + default 250 + depends on LPC43_RIT + config LPC43_RTC bool "Real Time Clock (RTC)" default n diff --git a/nuttx/arch/arm/src/lpc43xx/chip/lpc43_rit.h b/nuttx/arch/arm/src/lpc43xx/chip/lpc43_rit.h index 85aba157c..90c911e4d 100644 --- a/nuttx/arch/arm/src/lpc43xx/chip/lpc43_rit.h +++ b/nuttx/arch/arm/src/lpc43xx/chip/lpc43_rit.h @@ -2,7 +2,8 @@ * arch/arm/src/lpc43xx/lpc43_rit.h * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> + * Author: Brandon Warhurst <warhurst_002@yahoo.com> + * Original Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_rit.c b/nuttx/arch/arm/src/lpc43xx/lpc43_rit.c index 2ee8c70be..380de90a1 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_rit.c +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_rit.c @@ -34,6 +34,16 @@ ****************************************************************************/ /**************************************************************************** + * WARNING -- This code is currently *NOT* thread safe. No checking is done + * that one alarm call might not override an already enabled one. + * You might be able to handle this with some kind of cascading + * scheme where alarm receives the next value in a list of alarms + * all in the future. + * + * Brandon Warhurst + ****************************************************************************/ + +/**************************************************************************** * Included Files ****************************************************************************/ @@ -53,13 +63,15 @@ * Pre-processor Definitions ****************************************************************************/ -/* set the timer resolution at 1uS +/* Set the timer resolution at 1uS * * This is a battery waster, but I need this kind of resolution for 1-wire * protocols... Until I can find a better way to implement them. - */ + * + * This should probable be Kconfig material. + */ -#define RIT_TIMER_RESOLUTION 250 +#define RIT_TIMER_RESOLUTION CONFIG_LPC43_RIT_RES /**************************************************************************** * Private Data @@ -166,6 +178,7 @@ void up_timer_initialize(void) * resolution, that would be 250ns resolution. The timer is an integer * value, although maybe this should change, but that means * 250/1000000000*0.00000000490 = 51.02 ticks or 51 ticks, roughly. + * We round up by 1 tick. */ ticks_per_int = RIT_TIMER_RESOLUTION/(1000000000*sec_per_tick)+1; @@ -176,10 +189,10 @@ void up_timer_initialize(void) * 64 bit nanosecond timer than can "free-run" by being updated every * RIT_TIMER_RESOLUTION cycles. I would have implemented the better * approach, but I didn't have a good way to determine how to manage a - * 32 bit ns timer. Every 21 seconds the thing rolls over, so you'd have - * to set up the compare interrupt to handle the roll over. It WOULD be - * fewer interrupts, but it seemed to make things more complicated. When - * I have a better idea, I'll change this. + * 32 bit ns timer. Every 21 seconds the thing rolls over@ 204MHz, so + * you'd have to set up the compare interrupt to handle the roll over. It + * WOULD be fewer interrupts, but it seemed to make things more + * complicated. When I have a better idea, I'll change this. */ while(!((mask_test >> mask_bits) & ticks_per_int)) mask_bits++; @@ -221,6 +234,11 @@ int up_alarm_cancel(FAR struct timespec *ts) int up_alarm_start(FAR const struct timespec *ts) { + /* According to the docs, this version should expect to receive the time + * in the future when the alarm should expire. So that's the way it's + * coded. + */ + alarm = (uint64_t)ts->tv_sec * (uint64_t)1000000000 + (uint64_t)ts->tv_nsec; return OK; } @@ -230,6 +248,7 @@ int up_timer_cancel(FAR struct timespec *ts) /* Currently this is just an alarm and both are implemented. This is *NOT* * how it is supposed to be and will be corrected, but for now, this is a * simple way to implement both. + * FIXME */ return up_alarm_cancel(ts); @@ -237,12 +256,14 @@ int up_timer_cancel(FAR struct timespec *ts) int up_timer_start(FAR const struct timespec *ts) { - /* Currently this is just an alarm and both are implemented. This is *NOT* - * how it is supposed to be and will be corrected, but for now, this is a - * simple way to implement both. + /* According to the docs, this version should basically compute the time + * in the future when an alarm should go off. That is the way it could + * potentially be implemented, so that's the way I did it. */ - return up_alarm_start(ts); + alarm = internal_timer; + alarm += (uint64_t)ts->tv_sec * (uint64_t)1000000000 + (uint64_t)ts->tv_nsec; + return OK; } #endif /* CONFIG_LPC43_RIT */ diff --git a/nuttx/arch/arm/src/lpc43xx/lpc43_rit.h b/nuttx/arch/arm/src/lpc43xx/lpc43_rit.h index 8ef367bc4..5855b8ca5 100644 --- a/nuttx/arch/arm/src/lpc43xx/lpc43_rit.h +++ b/nuttx/arch/arm/src/lpc43xx/lpc43_rit.h @@ -2,7 +2,7 @@ * arch/arm/src/lpc43xx/lpc43_rit.h * * Copyright (C) 2012 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt <gnutt@nuttx.org> + * Author: Brandon Warhurst <warhurst_002@yahoo.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions |