From aabe73a084c805ee935d78456edf8cd8bad17be5 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 30 Apr 2014 14:11:53 -0600 Subject: The SAM4S Xplained Pro now uses the extended timer/counter features. From Bob Doiron. --- nuttx/ChangeLog | 9 ++++++ nuttx/configs/sam4s-xplained-pro/Kconfig | 5 +++ nuttx/configs/sam4s-xplained-pro/nsh/defconfig | 14 ++++++--- nuttx/configs/sam4s-xplained-pro/src/sam_tc.c | 43 +++++++++++++++++++++----- 4 files changed, 59 insertions(+), 12 deletions(-) diff --git a/nuttx/ChangeLog b/nuttx/ChangeLog index 1c812baae..f7d4d0c5f 100644 --- a/nuttx/ChangeLog +++ b/nuttx/ChangeLog @@ -7266,3 +7266,12 @@ changes, most correcting memory usage on the Nucleo-F401RE (2014-4-30). * /drivers/mtd/w25.c: Extended by Mark Whitehorn to support the 8Mbit W25Q80BV part (2014-4-30). + * configs/sam4s-xplained-pro: Update LED control logic from Bob Doiron + (2014-4-30). + * drivers/timer.c and include/nuttx/timer.h: Enhanced timer interface + from Bob Doiron (2014-4-30). + * arch/arm/src/sam34/Kconfig and sam_tc.c: Enhanced timer/counter driver + from Bob Doiron (2014-4-30). + * configs/sam4s-xplained-pro/Kconfig, nsh/defconfig, and src/sam_tc.c: + The SAM4S Xplained Pro now uses the extended timer/counter features. + From Bob Doiron (2014-4-30). diff --git a/nuttx/configs/sam4s-xplained-pro/Kconfig b/nuttx/configs/sam4s-xplained-pro/Kconfig index c050077cf..dd2134c3a 100644 --- a/nuttx/configs/sam4s-xplained-pro/Kconfig +++ b/nuttx/configs/sam4s-xplained-pro/Kconfig @@ -10,4 +10,9 @@ config SAM4S_XPLAINED_PRO_CDCACM_DEVMINOR default 0 depends on SAM34_UDP && USBDEV && CDCACM +config SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH + string "CPU Load Timer Device Path" + default "/dev/tc0" + depends on TIMER && SCHED_CPULOAD && SCHED_CPULOAD_EXTCLK + endif diff --git a/nuttx/configs/sam4s-xplained-pro/nsh/defconfig b/nuttx/configs/sam4s-xplained-pro/nsh/defconfig index 21c24a4e3..25c41d06a 100644 --- a/nuttx/configs/sam4s-xplained-pro/nsh/defconfig +++ b/nuttx/configs/sam4s-xplained-pro/nsh/defconfig @@ -342,6 +342,7 @@ CONFIG_NSH_MMCSDSLOTNO=0 # Board-Specific Options # CONFIG_SAM4S_XPLAINED_PRO_CDCACM_DEVMINOR=0 +CONFIG_SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH="/dev/tc0" # # RTOS Features @@ -389,7 +390,8 @@ CONFIG_NPTHREAD_KEYS=4 # Performance Monitoring # CONFIG_SCHED_CPULOAD=y -# CONFIG_SCHED_CPULOAD_EXTCLK is not set +CONFIG_SCHED_CPULOAD_EXTCLK=y +CONFIG_SCHED_CPULOAD_TICKSPERSEC=333 CONFIG_SCHED_CPULOAD_TIMECONSTANT=2 # CONFIG_SCHED_INSTRUMENTATION is not set @@ -513,8 +515,8 @@ CONFIG_USART1_ISUART=y CONFIG_MCU_SERIAL=y CONFIG_STANDARD_SERIAL=y # CONFIG_SERIAL_TIOCSERGSTRUCT is not set -CONFIG_UART0_SERIAL_CONSOLE=y -# CONFIG_UART1_SERIAL_CONSOLE is not set +# CONFIG_UART0_SERIAL_CONSOLE is not set +CONFIG_UART1_SERIAL_CONSOLE=y # CONFIG_USART1_SERIAL_CONSOLE is not set # CONFIG_NO_SERIAL_CONSOLE is not set @@ -784,6 +786,8 @@ CONFIG_EXAMPLES_NSH_CXXINITIALIZE=y # CONFIG_EXAMPLES_ROMFS is not set # CONFIG_EXAMPLES_SENDMAIL is not set CONFIG_EXAMPLES_SERIALBLASTER=y +CONFIG_EXAMPLES_SERIALBLASTER_STACKSIZE=2048 +CONFIG_EXAMPLES_SERIALBLASTER_PRIORITY=50 CONFIG_EXAMPLES_SERIALRX=y CONFIG_EXAMPLES_SERIALRX_STACKSIZE=2048 CONFIG_EXAMPLES_SERIALRX_PRIORITY=50 @@ -1007,8 +1011,8 @@ CONFIG_SYSTEM_SYSINFO_STACKSIZE=1024 # CONFIG_SYSTEM_STACKMONITOR=y CONFIG_SYSTEM_STACKMONITOR_STACKSIZE=1024 -CONFIG_SYSTEM_STACKMONITOR_PRIORITY=50 -CONFIG_SYSTEM_STACKMONITOR_INTERVAL=2 +CONFIG_SYSTEM_STACKMONITOR_PRIORITY=110 +CONFIG_SYSTEM_STACKMONITOR_INTERVAL=1 # # USB CDC/ACM Device Commands diff --git a/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c b/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c index b10477f29..5408689a4 100755 --- a/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c +++ b/nuttx/configs/sam4s-xplained-pro/src/sam_tc.c @@ -57,6 +57,10 @@ #include "sam_lowputc.h" #include "sam_tc.h" +#if defined(CONFIG_SCHED_CPULOAD) && defined(CONFIG_SCHED_CPULOAD_EXTCLK) +# include +#endif + #ifdef CONFIG_TIMER /**************************************************************************** @@ -82,8 +86,6 @@ /* Timer Definitions ********************************************************/ -#define TINTERVAL (3042) - /* Debug ********************************************************************/ /* Non-standard debug that may be enabled just for testing the watchdog * timer @@ -114,6 +116,12 @@ * Private Functions ****************************************************************************/ +static bool calc_cpuload(FAR uint32_t *next_interval_us) +{ + sched_process_cpuload(); + return TRUE; /* Reload, no change to interval */ +} + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -165,24 +173,41 @@ int sam_timerinitialize(void) /* Open the timer device */ +#if defined(CONFIG_SCHED_CPULOAD) && defined(CONFIG_SCHED_CPULOAD_EXTCLK) tcvdbg("Opening.\n"); - fd = open(CONFIG_TIMER0_DEVPATH, O_RDONLY); + + fd = open(CONFIG_SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH, O_RDONLY); if (fd < 0) { - tcdbg("open %s failed: %d\n", CONFIG_TIMER0_DEVPATH, errno); + tcdbg("open %s failed: %d\n", CONFIG_SAM4S_XPLAINED_PRO_CPULOAD_TIMER_DEVPATH, errno); goto errout; } /* Set the timeout */ tcvdbg("Timeout = %d.\n", TINTERVAL); - ret = ioctl(fd, TCIOC_SETTIMEOUT, (unsigned long)TINTERVAL); + ret = ioctl(fd, TCIOC_SETTIMEOUT, (unsigned long)1000000 / CONFIG_SCHED_CPULOAD_TICKSPERSEC); if (ret < 0) { tcdbg("ioctl(TCIOC_SETTIMEOUT) failed: %d\n", errno); goto errout_with_dev; } + /* Install user callback */ + + { + struct timer_capture_s tccb; + tccb.newhandler = calc_cpuload; + tccb.oldhandler = NULL; + + ret = ioctl(fd, TCIOC_SETHANDLER, (unsigned long)&tccb); + if (ret < 0) + { + tcdbg("ioctl(TCIOC_SETHANDLER) failed: %d\n", errno); + goto errout_with_dev; + } + } + /* Start the timer */ tcvdbg("Starting.\n"); @@ -192,13 +217,17 @@ int sam_timerinitialize(void) tcdbg("ioctl(TCIOC_START) failed: %d\n", errno); goto errout_with_dev; } - - return OK; + goto success; errout_with_dev: close(fd); errout: return ERROR; +#endif + +success: + return OK; + } #endif /* CONFIG_TIMER */ -- cgit v1.2.3