From 0047c1f1b1910b118c259fef8657b3e6e6921e7b Mon Sep 17 00:00:00 2001 From: patacongo Date: Tue, 20 Dec 2011 14:41:32 +0000 Subject: [PATCH] First round of PWM driver debug changes git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@4204 7fd9a85b-ad96-42d3-883c-3090e2eb8679 --- apps/examples/pwm/pwm_main.c | 8 +++- nuttx/arch/arm/src/stm32/stm32_pwm.c | 6 ++- nuttx/configs/stm3240g-eval/README.txt | 6 +++ nuttx/configs/stm3240g-eval/include/board.h | 2 +- nuttx/drivers/pwm.c | 50 ++++++++++++++++++++- 5 files changed, 67 insertions(+), 5 deletions(-) diff --git a/apps/examples/pwm/pwm_main.c b/apps/examples/pwm/pwm_main.c index 18b93f8d13..cbabb564fd 100644 --- a/apps/examples/pwm/pwm_main.c +++ b/apps/examples/pwm/pwm_main.c @@ -265,7 +265,10 @@ int pwm_main(int argc, char *argv[]) /* Configure the characteristics of the pulse train */ info.frequency = g_pwmstate.freq; - info.duty = (info.duty < 16) / 100; + info.duty = ((uint32_t)g_pwmstate.duty << 16) / 100; + + message("pwm_main: starting output with frequency: %d duty: %08x\n", + info.frequency, info.duty); ret = ioctl(fd, PWMIOC_SETCHARACTERISTICS, (unsigned long)((uintptr_t)&info)); if (ret < 0) @@ -289,6 +292,9 @@ int pwm_main(int argc, char *argv[]) /* Then stop the pulse train */ + message("pwm_main: stopping output\n", + info.frequency, info.duty); + ret = ioctl(fd, PWMIOC_STOP, 0); if (ret < 0) { diff --git a/nuttx/arch/arm/src/stm32/stm32_pwm.c b/nuttx/arch/arm/src/stm32/stm32_pwm.c index 1e3f4f07d6..420537ebb6 100644 --- a/nuttx/arch/arm/src/stm32/stm32_pwm.c +++ b/nuttx/arch/arm/src/stm32/stm32_pwm.c @@ -70,6 +70,7 @@ * Pre-processor Definitions ****************************************************************************/ /* Debug ********************************************************************/ +/* Non-standard debug that may be enabled just for testing PWM */ #ifdef CONFIG_DEBUG_PWM # define pwmdbg dbg @@ -434,10 +435,13 @@ static int pwm_start(FAR struct pwm_lowerhalf_s *dev, FAR const struct pwm_info_ uint16_t ocmode1; uint16_t ocmode2; + DEBUGASSERT(priv != NULL && info != NULL); + pwmvdbg("TIM%d channel: %d frequency: %d duty: %08x\n", priv->timid, priv->channel, info->frequency, info->duty); + DEBUGASSERT(info->frequency > 0 && info->duty > 0 && info->duty < uitoub16(100)); - /* Caculate optimal values for the timer prescaler and for the timer reload + /* Calculate optimal values for the timer prescaler and for the timer reload * register. If' frequency' is the desired frequency, then * * reload = timclk / frequency diff --git a/nuttx/configs/stm3240g-eval/README.txt b/nuttx/configs/stm3240g-eval/README.txt index 4fcc63938e..ac3ebb1033 100755 --- a/nuttx/configs/stm3240g-eval/README.txt +++ b/nuttx/configs/stm3240g-eval/README.txt @@ -521,3 +521,9 @@ Where is one of the following: CONFIG_NSH_IPADDR=(10<<24|0<<16|0<<8|2) : Target IP address 10.0.0.2 CONFIG_NSH_DRIPADDR=(10<<24|0<<16|0<<8|1) : Host IP address 10.0.0.1 + NOTE: This example assumes that a network is connected. During its + initialization, it will try to negotiate the link speed. If you have + no network connected when you reset the board, there will be a long + delay (maybe 30 seconds?) before anything happens. That is the timeout + before the networking finally gives up and decides that no network is + available. diff --git a/nuttx/configs/stm3240g-eval/include/board.h b/nuttx/configs/stm3240g-eval/include/board.h index ba1016910a..9ae54a4d02 100755 --- a/nuttx/configs/stm3240g-eval/include/board.h +++ b/nuttx/configs/stm3240g-eval/include/board.h @@ -274,7 +274,7 @@ * FSMC must be disabled in this case! */ -#define GPIO_TIM4_CH2 GPIO_TIM4_CH2_1 +#define GPIO_TIM4_CH2 GPIO_TIM4_CH2_2 /************************************************************************************ * Public Data diff --git a/nuttx/drivers/pwm.c b/nuttx/drivers/pwm.c index 15447e9bec..455e727061 100644 --- a/nuttx/drivers/pwm.c +++ b/nuttx/drivers/pwm.c @@ -66,6 +66,20 @@ /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ +/* Debug ********************************************************************/ +/* Non-standard debug that may be enabled just for testing PWM */ + +#ifdef CONFIG_DEBUG_PWM +# define pwmdbg dbg +# define pwmvdbg vdbg +# define pwmlldbg lldbg +# define pwmllvdbg llvdbg +#else +# define pwmdbg(x...) +# define pwmvdbg(x...) +# define pwmlldbg(x...) +# define pwmllvdbg(x...) +#endif /**************************************************************************** * Private Type Definitions @@ -128,6 +142,8 @@ static int pwm_open(FAR struct file *filep) uint8_t tmp; int ret; + pwmvdbg("crefs: %d\n", upper->crefs); + /* Get exclusive access to the device structures */ ret = sem_wait(&upper->sem); @@ -159,6 +175,9 @@ static int pwm_open(FAR struct file *filep) /* Yes.. perform one time hardware initialization. */ + DEBUGASSERT(lower->ops->setup != NULL); + pwmvdbg("calling setup\n"); + ret = lower->ops->setup(lower); if (ret < 0) { @@ -192,6 +211,8 @@ static int pwm_close(FAR struct file *filep) FAR struct pwm_upperhalf_s *upper = inode->i_private; int ret; + pwmvdbg("crefs: %d\n", upper->crefs); + /* Get exclusive access to the device structures */ ret = sem_wait(&upper->sem); @@ -219,6 +240,9 @@ static int pwm_close(FAR struct file *filep) /* Disable the PWM device */ + DEBUGASSERT(lower->ops->shutdown != NULL); + pwmvdbg("calling shutdown: %d\n"); + lower->ops->shutdown(lower); } ret = OK; @@ -275,6 +299,8 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) /* Handle built-in ioctl commands */ + pwmvdbg("cmd: %d arg: %ld\n", cmd, arg); + switch (cmd) { /* PWMIOC_SETCHARACTERISTICS - Set the characteristics of the next pulsed @@ -290,6 +316,11 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_SETCHARACTERISTICS: { FAR const struct pwm_info_s *info = (FAR const struct pwm_info_s*)((uintptr_t)arg); + DEBUGASSERT(info != NULL && lower->ops->start != NULL); + + pwmvdbg("PWMIOC_SETCHARACTERISTICS frequency: %d duty: %08x started: %d\n", + info->frequency, info->duty, upper->started); + memcpy(&upper->info, info, sizeof(struct pwm_info_s)); if (upper->started) { @@ -308,7 +339,11 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_GETCHARACTERISTICS: { FAR struct pwm_info_s *info = (FAR struct pwm_info_s*)((uintptr_t)arg); + DEBUGASSERT(info != NULL); + memcpy(info, &upper->info, sizeof(struct pwm_info_s)); + pwmvdbg("PWMIOC_GETCHARACTERISTICS frequency: %d duty: %08x\n", + info->frequency, info->duty); } break; @@ -320,6 +355,11 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_START: { + pwmvdbg("PWMIOC_START frequency: %d duty: %08x started: %d\n", + upper->info.frequency, upper->info.duty, upper->started); + + DEBUGASSERT(lower->ops->start != NULL); + if (!upper->started) { ret = lower->ops->start(lower, &upper->info); @@ -335,6 +375,9 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) case PWMIOC_STOP: { + pwmvdbg("PWMIOC_STOP: started: %d\n", upper->started); + DEBUGASSERT(lower->ops->stop != NULL); + if (upper->started) { ret = lower->ops->stop(lower); @@ -347,6 +390,8 @@ static int pwm_ioctl(FAR struct file *filep, int cmd, unsigned long arg) default: { + pwmvdbg("Forwarding unrecognized cmd: %d arg: %ld\n", cmd, arg); + DEBUGASSERT(lower->ops->ioctl != NULL); ret = lower->ops->ioctl(lower, cmd, arg); } break; @@ -392,6 +437,7 @@ int pwm_register(FAR const char *path, FAR struct pwm_lowerhalf_s *dev) upper = (FAR struct pwm_upperhalf_s *)zalloc(sizeof(struct pwm_upperhalf_s)); if (!upper) { + pwmdbg("Allocation failed\n"); return -ENOMEM; } @@ -402,8 +448,8 @@ int pwm_register(FAR const char *path, FAR struct pwm_lowerhalf_s *dev) /* Register the PWM device */ - vdbg("Registering %s\n", path); - return register_driver(path, &g_pwmops, 0666, dev); + pwmvdbg("Registering %s\n", path); + return register_driver(path, &g_pwmops, 0666, upper); } #endif /* CONFIG_PWM */