xtensa/esp32: Adds oneshot timer driver.
This commit is contained in:
parent
21159666fc
commit
59313c86d1
@ -957,6 +957,19 @@ config ESP32_RT_TIMER_TASK_STACK_SIZE
|
|||||||
|
|
||||||
endmenu # Real-Time Timer
|
endmenu # Real-Time Timer
|
||||||
|
|
||||||
|
if ESP32_TIMER
|
||||||
|
menu "Timer/counter Configuration"
|
||||||
|
|
||||||
|
config ESP32_ONESHOT
|
||||||
|
bool "One-shot wrapper"
|
||||||
|
default n
|
||||||
|
---help---
|
||||||
|
Enable a wrapper around the low level timer/counter functions to
|
||||||
|
support one-shot timer.
|
||||||
|
|
||||||
|
endmenu # Timer/counter Configuration
|
||||||
|
endif # ESP32_TIMER
|
||||||
|
|
||||||
menu "Partition Configuration"
|
menu "Partition Configuration"
|
||||||
depends on ESP32_PARTITION
|
depends on ESP32_PARTITION
|
||||||
|
|
||||||
|
@ -153,6 +153,13 @@ CHIP_CSRCS += esp32_tim_lowerhalf.c
|
|||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ESP32_ONESHOT),y)
|
||||||
|
CHIP_CSRCS += esp32_oneshot.c
|
||||||
|
ifeq ($(CONFIG_ONESHOT),y)
|
||||||
|
CHIP_CSRCS += esp32_oneshot_lowerhalf.c
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_ESP32_PARTITION),y)
|
ifeq ($(CONFIG_ESP32_PARTITION),y)
|
||||||
CHIP_CSRCS += esp32_partition.c
|
CHIP_CSRCS += esp32_partition.c
|
||||||
endif
|
endif
|
||||||
|
449
arch/xtensa/src/esp32/esp32_oneshot.c
Normal file
449
arch/xtensa/src/esp32/esp32_oneshot.c
Normal file
@ -0,0 +1,449 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32/esp32_oneshot.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/timers/oneshot.h>
|
||||||
|
#include <nuttx/clock.h>
|
||||||
|
|
||||||
|
#include "hardware/esp32_soc.h"
|
||||||
|
|
||||||
|
#include "esp32_tim.h"
|
||||||
|
#include "esp32_clockconfig.h"
|
||||||
|
#include "esp32_oneshot.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_ONESHOT
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#define MAX_TIMER_COUNTER UINT64_MAX
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_oneshot_handler(int irq, void * context, void *arg);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_handler
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Oneshot interrupt Handler. When any oneshot timer interrupt
|
||||||
|
* expires, this function will be triggered. It will forward the call to
|
||||||
|
* the next level up.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* irq - IRQ associated to that interrupt
|
||||||
|
* arg - A pointer to the argument provided when the interrupt was
|
||||||
|
* registered.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero on success; a negated errno value on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_oneshot_handler(int irq, void * context, void *arg)
|
||||||
|
{
|
||||||
|
int ret = OK;
|
||||||
|
struct esp32_oneshot_s *oneshot = (struct esp32_oneshot_s *)arg;
|
||||||
|
|
||||||
|
DEBUGASSERT(oneshot != NULL && oneshot->handler != NULL);
|
||||||
|
|
||||||
|
tmrinfo("Oneshot handler triggered\n");
|
||||||
|
|
||||||
|
/* Stop timer
|
||||||
|
* Note: It's not necessary to disable the alarm because
|
||||||
|
* it automatically disables each time it expires.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ESP32_TIM_STOP(oneshot->tim);
|
||||||
|
|
||||||
|
/* Disable int */
|
||||||
|
|
||||||
|
ESP32_TIM_DISABLEINT(oneshot->tim);
|
||||||
|
|
||||||
|
/* Detach handler */
|
||||||
|
|
||||||
|
ret = ESP32_TIM_SETISR(oneshot->tim, NULL, NULL);
|
||||||
|
|
||||||
|
/* Call the callback */
|
||||||
|
|
||||||
|
oneshot->handler((void *)oneshot->arg);
|
||||||
|
|
||||||
|
/* Restore state */
|
||||||
|
|
||||||
|
oneshot->running = false;
|
||||||
|
oneshot->handler = NULL;
|
||||||
|
oneshot->arg = NULL;
|
||||||
|
|
||||||
|
/* Clear the Interrupt */
|
||||||
|
|
||||||
|
ESP32_TIM_ACKINT(oneshot->tim);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the oneshot timer wrapper.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure.
|
||||||
|
* chan Timer counter channel to be used.
|
||||||
|
* resolution The required resolution of the timer in units of
|
||||||
|
* microseconds. NOTE that the range is restricted to the
|
||||||
|
* range of uint16_t (excluding zero).
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_initialize(struct esp32_oneshot_s *oneshot, int chan,
|
||||||
|
uint16_t resolution)
|
||||||
|
{
|
||||||
|
uint16_t pre;
|
||||||
|
int ret = OK;
|
||||||
|
tmrinfo("chan=%d resolution=%d usecs\n", chan, resolution);
|
||||||
|
DEBUGASSERT(oneshot != NULL);
|
||||||
|
DEBUGASSERT(resolution > 0);
|
||||||
|
|
||||||
|
oneshot->chan = chan;
|
||||||
|
|
||||||
|
oneshot->tim = esp32_tim_init(chan);
|
||||||
|
if (oneshot->tim == NULL)
|
||||||
|
{
|
||||||
|
tmrerr("ERROR: Failed to allocate TIM %d\n", chan);
|
||||||
|
ret = -EBUSY;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Initialize the remaining fields in the state structure. */
|
||||||
|
|
||||||
|
oneshot->running = false;
|
||||||
|
oneshot->handler = NULL;
|
||||||
|
oneshot->arg = NULL;
|
||||||
|
oneshot->resolution = resolution;
|
||||||
|
|
||||||
|
/* Ensure timer is disabled.
|
||||||
|
* Change the prescaler divider with the timer enabled can lead to
|
||||||
|
* unpredictable results.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ESP32_TIM_STOP(oneshot->tim);
|
||||||
|
|
||||||
|
/* Calculate the suitable prescaler according to the current apb
|
||||||
|
* frequency to generate a period equals to resolution.
|
||||||
|
*/
|
||||||
|
|
||||||
|
pre = (esp_clk_apb_freq() * resolution) / USEC_PER_SEC;
|
||||||
|
|
||||||
|
/* Configure TIMER prescaler */
|
||||||
|
|
||||||
|
ESP32_TIM_SETPRE(oneshot->tim, pre);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_max_delay
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* usec The maximum delay in us.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK).
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_max_delay(struct esp32_oneshot_s *oneshot, uint64_t *usec)
|
||||||
|
{
|
||||||
|
DEBUGASSERT(oneshot != NULL && usec != NULL);
|
||||||
|
|
||||||
|
/* In theory, Maximum delay (us) = resolution (us) * MAX_TIMER_COUNTER
|
||||||
|
* But if the resolution is bigger than 1 us, the value will not fit
|
||||||
|
* in a uint64_t. So, this function assumes the max delay using a
|
||||||
|
* resolution of 1 us.
|
||||||
|
*/
|
||||||
|
|
||||||
|
*usec = MAX_TIMER_COUNTER;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_start
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Start the oneshot timer
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* handler The function to call when when the oneshot timer expires.
|
||||||
|
* arg An opaque argument that will accompany the callback.
|
||||||
|
* ts Provides the duration of the one shot timer.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_start(struct esp32_oneshot_s *oneshot,
|
||||||
|
oneshot_handler_t handler, void *arg,
|
||||||
|
const struct timespec *ts)
|
||||||
|
{
|
||||||
|
uint64_t timeout_us;
|
||||||
|
int ret = OK;
|
||||||
|
|
||||||
|
tmrinfo("handler=%p arg=%p, ts=(%lu, %lu)\n",
|
||||||
|
handler, arg, (unsigned long)ts->tv_sec,
|
||||||
|
(unsigned long)ts->tv_nsec);
|
||||||
|
DEBUGASSERT(oneshot != NULL);
|
||||||
|
DEBUGASSERT(handler != NULL);
|
||||||
|
DEBUGASSERT(ts != NULL);
|
||||||
|
|
||||||
|
if (oneshot->running)
|
||||||
|
{
|
||||||
|
tmrinfo("One shot timer already in use. Cancelling it ...\n");
|
||||||
|
|
||||||
|
/* If the oneshot timer was already started, cancel it and then
|
||||||
|
* restart.
|
||||||
|
*/
|
||||||
|
|
||||||
|
esp32_oneshot_cancel(oneshot, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Save the new callback and its argument */
|
||||||
|
|
||||||
|
oneshot->handler = handler;
|
||||||
|
oneshot->arg = arg;
|
||||||
|
|
||||||
|
/* Retrieve the duration from timespec in microsecond */
|
||||||
|
|
||||||
|
timeout_us = (uint64_t)ts->tv_sec * USEC_PER_SEC +
|
||||||
|
(uint64_t)(ts->tv_nsec / NSEC_PER_USEC);
|
||||||
|
|
||||||
|
/* Verify if it is a multiple of the configured resolution.
|
||||||
|
* In case it isn't, warn the user.
|
||||||
|
*/
|
||||||
|
|
||||||
|
if ((timeout_us % oneshot->resolution) != 0)
|
||||||
|
{
|
||||||
|
tmrwarn("Warning: The interval is not multiple of the resolution.\n"
|
||||||
|
"Adjust the resolution in your bringup file.\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Set the timer */
|
||||||
|
|
||||||
|
/* Ensure timer is stopped */
|
||||||
|
|
||||||
|
ESP32_TIM_STOP(oneshot->tim);
|
||||||
|
|
||||||
|
/* Configure TIMER mode */
|
||||||
|
|
||||||
|
ESP32_TIM_SETMODE(oneshot->tim, ESP32_TIM_MODE_UP);
|
||||||
|
|
||||||
|
/* Clear TIMER counter value */
|
||||||
|
|
||||||
|
ESP32_TIM_CLEAR(oneshot->tim);
|
||||||
|
|
||||||
|
/* Disable autoreload */
|
||||||
|
|
||||||
|
ESP32_TIM_SETARLD(oneshot->tim, false);
|
||||||
|
|
||||||
|
/* Set the timeout */
|
||||||
|
|
||||||
|
ESP32_TIM_SETALRVL(oneshot->tim, timeout_us / oneshot->resolution);
|
||||||
|
|
||||||
|
/* Enable TIMER alarm */
|
||||||
|
|
||||||
|
ESP32_TIM_SETALRM(oneshot->tim, true);
|
||||||
|
|
||||||
|
/* Clear Interrupt Bits Status */
|
||||||
|
|
||||||
|
ESP32_TIM_ACKINT(oneshot->tim);
|
||||||
|
|
||||||
|
/* Set the interrupt */
|
||||||
|
|
||||||
|
/* Register the handler that calls the callback */
|
||||||
|
|
||||||
|
ret = ESP32_TIM_SETISR(oneshot->tim, esp32_oneshot_handler, oneshot);
|
||||||
|
if (ret == OK)
|
||||||
|
{
|
||||||
|
ESP32_TIM_ENABLEINT(oneshot->tim);
|
||||||
|
|
||||||
|
/* Finally, start the TIMER */
|
||||||
|
|
||||||
|
ESP32_TIM_START(oneshot->tim);
|
||||||
|
|
||||||
|
oneshot->running = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_cancel
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Cancel the oneshot timer and return the time remaining on the timer.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* ts The location in which to return the time remaining on the
|
||||||
|
* oneshot timer. A time of zero is returned if the timer is
|
||||||
|
* not running. ts may be zero in which case the time remaining
|
||||||
|
* is not returned.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success. A call to up_timer_cancel() when
|
||||||
|
* the timer is not active should also return success; a negated errno
|
||||||
|
* value is returned on any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_cancel(struct esp32_oneshot_s *oneshot,
|
||||||
|
struct timespec *ts)
|
||||||
|
{
|
||||||
|
int ret = OK;
|
||||||
|
uint64_t current_us;
|
||||||
|
uint64_t remaining_us;
|
||||||
|
uint64_t timeout_us;
|
||||||
|
uint64_t counter_value;
|
||||||
|
uint64_t alarm_value;
|
||||||
|
|
||||||
|
DEBUGASSERT(oneshot);
|
||||||
|
|
||||||
|
if (oneshot->running == false)
|
||||||
|
{
|
||||||
|
tmrinfo("Trying to cancel a non started oneshot timer.\n");
|
||||||
|
ts->tv_sec = 0;
|
||||||
|
ts->tv_nsec = 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
/* Stop timer */
|
||||||
|
|
||||||
|
ESP32_TIM_STOP(oneshot->tim);
|
||||||
|
|
||||||
|
/* Disable int */
|
||||||
|
|
||||||
|
ESP32_TIM_DISABLEINT(oneshot->tim);
|
||||||
|
|
||||||
|
/* Detach handler */
|
||||||
|
|
||||||
|
ret = ESP32_TIM_SETISR(oneshot->tim, NULL, NULL);
|
||||||
|
|
||||||
|
if (ts != NULL)
|
||||||
|
{
|
||||||
|
/* Get the current counter value */
|
||||||
|
|
||||||
|
ESP32_TIM_GETCTR(oneshot->tim, &counter_value);
|
||||||
|
|
||||||
|
/* Get the current configured timeout */
|
||||||
|
|
||||||
|
ESP32_TIM_GETALRVL(oneshot->tim, &alarm_value);
|
||||||
|
|
||||||
|
current_us = counter_value * oneshot->resolution;
|
||||||
|
timeout_us = alarm_value * oneshot->resolution;
|
||||||
|
|
||||||
|
/* Remaining time (us) = timeout (us) - current (us) */
|
||||||
|
|
||||||
|
remaining_us = timeout_us - current_us;
|
||||||
|
ts->tv_sec = remaining_us / USEC_PER_SEC;
|
||||||
|
remaining_us = remaining_us - ts->tv_sec * USEC_PER_SEC;
|
||||||
|
ts->tv_nsec = remaining_us * NSEC_PER_USEC;
|
||||||
|
}
|
||||||
|
|
||||||
|
oneshot->running = false;
|
||||||
|
oneshot->handler = NULL;
|
||||||
|
oneshot->arg = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_current
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* usec The maximum delay in us.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK).
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_current(struct esp32_oneshot_s *oneshot, uint64_t *usec)
|
||||||
|
{
|
||||||
|
/* Get the current counter value */
|
||||||
|
|
||||||
|
ESP32_TIM_GETCTR(oneshot->tim, usec);
|
||||||
|
|
||||||
|
*usec = *usec * (uint64_t)oneshot->resolution;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_ESP32_ONESHOT */
|
202
arch/xtensa/src/esp32/esp32_oneshot.h
Normal file
202
arch/xtensa/src/esp32/esp32_oneshot.h
Normal file
@ -0,0 +1,202 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32/esp32_oneshot.h
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#ifndef __ARCH_XTENSA_SRC_ESP32_ONESHOT_H
|
||||||
|
#define __ARCH_XTENSA_SRC_ESP32_ONESHOT_H
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "esp32_tim.h"
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_ONESHOT
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* This describes the callback function that will be invoked when the oneshot
|
||||||
|
* timer expires. The oneshot fires, the client will receive:
|
||||||
|
*
|
||||||
|
* arg - The opaque argument provided when the interrupt was registered
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef void (*oneshot_handler_t)(void *arg);
|
||||||
|
|
||||||
|
/* The oneshot client must allocate an instance of this structure and call
|
||||||
|
* esp32_oneshot_initialize() before using the oneshot facilities. The
|
||||||
|
* client should not access the contents of this structure directly since
|
||||||
|
* the contents are subject to change.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct esp32_oneshot_s
|
||||||
|
{
|
||||||
|
uint8_t chan; /* The timer/counter in use */
|
||||||
|
volatile bool running; /* True: the timer is running */
|
||||||
|
FAR struct esp32_tim_dev_s *tim; /* Pointer returned by
|
||||||
|
* esp32_tim_init() */
|
||||||
|
volatile oneshot_handler_t handler; /* Oneshot expiration callback */
|
||||||
|
volatile void *arg; /* The argument that will accompany
|
||||||
|
* the callback */
|
||||||
|
uint32_t resolution; /* us */
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#if defined(__cplusplus)
|
||||||
|
#define EXTERN extern "C"
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#else
|
||||||
|
#define EXTERN extern
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the oneshot timer wrapper.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Allocated instance of the oneshot state structure.
|
||||||
|
* chan Timer counter channel to be used.
|
||||||
|
* resolution The required resolution of the timer in units of
|
||||||
|
* microseconds. NOTE that the range is restricted to the
|
||||||
|
* range of uint16_t (excluding zero).
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_initialize(struct esp32_oneshot_s *oneshot, int chan,
|
||||||
|
uint16_t resolution);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_max_delay
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Determine the maximum delay of the one-shot timer (in microseconds).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Allocated instance of the oneshot state structure.
|
||||||
|
* chan The location in which to return the maximum delay in us.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_max_delay(struct esp32_oneshot_s *oneshot, uint64_t *usec);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_start
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Start the oneshot timer
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* handler The function to call when the oneshot timer expires.
|
||||||
|
* arg An opaque argument that will accompany the callback.
|
||||||
|
* ts Provides the duration of the one shot timer.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_start(struct esp32_oneshot_s *oneshot,
|
||||||
|
oneshot_handler_t handler, void *arg,
|
||||||
|
const struct timespec *ts);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_cancel
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Cancel the oneshot timer and return the time remaining on the timer.
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* ts The location in which to return the time remaining on the
|
||||||
|
* oneshot timer. A time of zero is returned if the timer is
|
||||||
|
* not running.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success. A call to up_timer_cancel() when
|
||||||
|
* the timer is not active should also return success; a negated errno
|
||||||
|
* value is returned on any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_cancel(struct esp32_oneshot_s *oneshot,
|
||||||
|
struct timespec *ts);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_current
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* oneshot Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* esp32_oneshot_initialize();
|
||||||
|
* usec The maximum delay in us.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK).
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int esp32_oneshot_current(struct esp32_oneshot_s *oneshot, uint64_t *usec);
|
||||||
|
|
||||||
|
#undef EXTERN
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_ESP32_ONESHOT */
|
||||||
|
#endif /* __ARCH_XTENSA_SRC_ESP32_ONESHOT_H */
|
368
arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c
Normal file
368
arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c
Normal file
@ -0,0 +1,368 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* arch/xtensa/src/esp32/esp32_oneshot_lowerhalf.c
|
||||||
|
*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
|
* this work for additional information regarding copyright ownership. The
|
||||||
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance with the
|
||||||
|
* License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||||
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||||
|
* License for the specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Included Files
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <debug.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <nuttx/arch.h>
|
||||||
|
#include <nuttx/timers/oneshot.h>
|
||||||
|
#include <nuttx/kmalloc.h>
|
||||||
|
|
||||||
|
#include "esp32_oneshot.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Types
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
struct esp32_oneshot_lowerhalf_s
|
||||||
|
{
|
||||||
|
/* This is the part of the lower half driver that is visible to the upper-
|
||||||
|
* half client of the driver. This must be the first thing in this
|
||||||
|
* structure so that pointers to struct oneshot_lowerhalf_s are cast
|
||||||
|
* compatible to struct esp32_oneshot_lowerhalf_s and vice versa.
|
||||||
|
* That means, opaque pointers.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct oneshot_lowerhalf_s lh; /* Lower half instance */
|
||||||
|
struct esp32_oneshot_s oneshot; /* ESP32-specific oneshot state */
|
||||||
|
oneshot_callback_t callback; /* Upper half Interrupt callback */
|
||||||
|
FAR void *arg; /* Argument passed to handler */
|
||||||
|
uint16_t resolution;
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Function Prototypes
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void esp32_oneshot_lh_handler(void *arg);
|
||||||
|
|
||||||
|
/* "Lower half" driver methods **********************************************/
|
||||||
|
|
||||||
|
static int esp32_max_lh_delay(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts);
|
||||||
|
static int esp32_lh_start(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
oneshot_callback_t callback,
|
||||||
|
FAR void *arg,
|
||||||
|
FAR const struct timespec *ts);
|
||||||
|
static int esp32_lh_cancel(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts);
|
||||||
|
static int esp32_lh_current(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Data
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/* "Lower half" driver methods */
|
||||||
|
|
||||||
|
static const struct oneshot_operations_s g_esp32_timer_ops =
|
||||||
|
{
|
||||||
|
.max_delay = esp32_max_lh_delay,
|
||||||
|
.start = esp32_lh_start,
|
||||||
|
.cancel = esp32_lh_cancel,
|
||||||
|
.current = esp32_lh_current
|
||||||
|
};
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Private Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_oneshot_lh_handler
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Timer expiration handler.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* arg - Should be the same argument provided when esp32_oneshot_start()
|
||||||
|
* was called.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static void esp32_oneshot_lh_handler(void *arg)
|
||||||
|
{
|
||||||
|
FAR struct esp32_oneshot_lowerhalf_s *priv =
|
||||||
|
(FAR struct esp32_oneshot_lowerhalf_s *)arg;
|
||||||
|
|
||||||
|
DEBUGASSERT(priv != NULL);
|
||||||
|
DEBUGASSERT(priv->callback != NULL);
|
||||||
|
|
||||||
|
tmrinfo("Oneshot LH handler triggered\n");
|
||||||
|
|
||||||
|
/* Call the callback */
|
||||||
|
|
||||||
|
priv->callback(&priv->lh, priv->arg);
|
||||||
|
|
||||||
|
/* Restore state */
|
||||||
|
|
||||||
|
priv->callback = NULL;
|
||||||
|
priv->arg = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_max_lh_delay
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Determine the maximum delay of the one-shot timer (in microseconds).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lower An instance of the lower-half oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* oneshot_initialize();
|
||||||
|
* ts The location in which to return the maximum delay.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_max_lh_delay(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts)
|
||||||
|
{
|
||||||
|
DEBUGASSERT(ts != NULL);
|
||||||
|
|
||||||
|
/* The real maximum delay surpass the limit that timespec can
|
||||||
|
* reprent. Even using the better case: a resolution of
|
||||||
|
* 1 us.
|
||||||
|
* Therefore, here, fulfill the timespec with the
|
||||||
|
* maximum value it can represent.
|
||||||
|
*/
|
||||||
|
|
||||||
|
ts->tv_sec = UINT32_MAX;
|
||||||
|
ts->tv_nsec = NSEC_PER_SEC - 1;
|
||||||
|
|
||||||
|
tmrinfo("max sec=%" PRIu32 "\n", ts->tv_sec);
|
||||||
|
tmrinfo("max nsec=%ld\n", ts->tv_nsec);
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_lh_start
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Start the oneshot timer.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lower An instance of the lower-half oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* oneshot_initialize();
|
||||||
|
* callback The function to call when when the oneshot timer expires.
|
||||||
|
* Inside the handler scope.
|
||||||
|
* arg A pointer to the argument that will accompany the callback.
|
||||||
|
* ts Provides the duration of the one shot timer.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success; a negated errno value is returned
|
||||||
|
* on failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_lh_start(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
oneshot_callback_t callback,
|
||||||
|
FAR void *arg,
|
||||||
|
FAR const struct timespec *ts)
|
||||||
|
{
|
||||||
|
FAR struct esp32_oneshot_lowerhalf_s *priv =
|
||||||
|
(FAR struct esp32_oneshot_lowerhalf_s *)lower;
|
||||||
|
int ret;
|
||||||
|
irqstate_t flags;
|
||||||
|
|
||||||
|
DEBUGASSERT(priv != NULL);
|
||||||
|
DEBUGASSERT(callback != NULL);
|
||||||
|
DEBUGASSERT(arg != NULL);
|
||||||
|
DEBUGASSERT(ts != NULL);
|
||||||
|
|
||||||
|
/* Save the callback information and start the timer */
|
||||||
|
|
||||||
|
flags = enter_critical_section();
|
||||||
|
priv->callback = callback;
|
||||||
|
priv->arg = arg;
|
||||||
|
ret = esp32_oneshot_start(&priv->oneshot,
|
||||||
|
esp32_oneshot_lh_handler, priv, ts);
|
||||||
|
leave_critical_section(flags);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
tmrerr("ERROR: esp32_oneshot_start failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_lh_cancel
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Cancel the oneshot timer and return the time remaining on the timer.
|
||||||
|
*
|
||||||
|
* NOTE: This function may execute at a high rate with no timer running (as
|
||||||
|
* when pre-emption is enabled and disabled).
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lower Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* oneshot_initialize();
|
||||||
|
* ts The location in which to return the time remaining on the
|
||||||
|
* oneshot timer. A time of zero is returned if the timer is
|
||||||
|
* not running.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success. A call to up_timer_cancel() when
|
||||||
|
* the timer is not active should also return success; a negated errno
|
||||||
|
* value is returned on any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_lh_cancel(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts)
|
||||||
|
{
|
||||||
|
FAR struct esp32_oneshot_lowerhalf_s *priv =
|
||||||
|
(FAR struct esp32_oneshot_lowerhalf_s *)lower;
|
||||||
|
irqstate_t flags;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
DEBUGASSERT(priv != NULL);
|
||||||
|
|
||||||
|
/* Cancel the timer */
|
||||||
|
|
||||||
|
flags = enter_critical_section();
|
||||||
|
ret = esp32_oneshot_cancel(&priv->oneshot, ts);
|
||||||
|
priv->callback = NULL;
|
||||||
|
priv->arg = NULL;
|
||||||
|
leave_critical_section(flags);
|
||||||
|
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
tmrerr("ERROR: esp32_oneshot_cancel failed: %d\n", flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: esp32_lh_current
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Get the current time.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* lower Caller allocated instance of the oneshot state structure. This
|
||||||
|
* structure must have been previously initialized via a call to
|
||||||
|
* oneshot_initialize();
|
||||||
|
* ts The location in which to return the current time. A time of zero
|
||||||
|
* is returned for the initialization moment.
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) is returned on success, a negated errno value is returned on
|
||||||
|
* any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static int esp32_lh_current(FAR struct oneshot_lowerhalf_s *lower,
|
||||||
|
FAR struct timespec *ts)
|
||||||
|
{
|
||||||
|
FAR struct esp32_oneshot_lowerhalf_s *priv =
|
||||||
|
(FAR struct esp32_oneshot_lowerhalf_s *)lower;
|
||||||
|
uint64_t current_us;
|
||||||
|
|
||||||
|
DEBUGASSERT(priv != NULL);
|
||||||
|
DEBUGASSERT(ts != NULL);
|
||||||
|
|
||||||
|
esp32_oneshot_current(&priv->oneshot, ¤t_us);
|
||||||
|
ts->tv_sec = current_us / USEC_PER_SEC;
|
||||||
|
current_us = current_us - ts->tv_sec * USEC_PER_SEC;
|
||||||
|
ts->tv_nsec = current_us * NSEC_PER_USEC;
|
||||||
|
|
||||||
|
return OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: oneshot_initialize
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Initialize the oneshot timer and return a oneshot lower half driver
|
||||||
|
* instance.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* chan Timer counter channel to be used.
|
||||||
|
* resolution The required resolution of the timer in units of
|
||||||
|
* microseconds. NOTE that the range is restricted to the
|
||||||
|
* range of uint16_t (excluding zero).
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* On success, a non-NULL instance of the oneshot lower-half driver is
|
||||||
|
* returned. NULL is return on any failure.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
FAR struct oneshot_lowerhalf_s *oneshot_initialize(int chan,
|
||||||
|
uint16_t resolution)
|
||||||
|
{
|
||||||
|
FAR struct esp32_oneshot_lowerhalf_s *priv;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
/* Allocate an instance of the lower half driver */
|
||||||
|
|
||||||
|
priv = (FAR struct esp32_oneshot_lowerhalf_s *)kmm_zalloc(
|
||||||
|
sizeof(struct esp32_oneshot_lowerhalf_s));
|
||||||
|
|
||||||
|
if (priv == NULL)
|
||||||
|
{
|
||||||
|
tmrerr("ERROR: Failed to initialize oneshot state structure\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
priv->lh.ops = &g_esp32_timer_ops; /* Pointer to the LH operations */
|
||||||
|
priv->callback = NULL; /* No callback yet */
|
||||||
|
priv->arg = NULL; /* No arg yet */
|
||||||
|
priv->resolution = resolution; /* Configured resolution */
|
||||||
|
|
||||||
|
/* Initialize esp32_oneshot_s structure */
|
||||||
|
|
||||||
|
ret = esp32_oneshot_initialize(&priv->oneshot, chan, resolution);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
tmrerr("ERROR: esp32_oneshot_initialize failed: %d\n", ret);
|
||||||
|
kmm_free(priv);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return &priv->lh;
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* boards/xtensa/esp32/common/include/esp32_board_tim.h
|
* boards/xtensa/esp32/common/include/esp32_board_oneshot.h
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -18,8 +18,8 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_TIM_H
|
#ifndef __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_ONESHOT_H
|
||||||
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_TIM_H
|
#define __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_ONESHOT_H
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Included Files
|
* Included Files
|
||||||
@ -27,6 +27,10 @@
|
|||||||
|
|
||||||
#include <nuttx/config.h>
|
#include <nuttx/config.h>
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Pre-processor Definitions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
#ifndef __ASSEMBLY__
|
#ifndef __ASSEMBLY__
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
@ -46,13 +50,17 @@ extern "C"
|
|||||||
* Public Function Prototypes
|
* Public Function Prototypes
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_ONESHOT
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: board_timer_init
|
* Name: esp32_oneshot_init
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Configure the timer driver.
|
* Configure the oneshot.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* timer - Timer instance to be used as oneshot timer.
|
||||||
|
* resolution - Oneshot timer resolution.
|
||||||
*
|
*
|
||||||
* Returned Value:
|
* Returned Value:
|
||||||
* Zero (OK) is returned on success; A negated errno value is returned
|
* Zero (OK) is returned on success; A negated errno value is returned
|
||||||
@ -60,9 +68,9 @@ extern "C"
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int board_timer_init(void);
|
int esp32_oneshot_init(int timer, uint16_t resolution);
|
||||||
|
|
||||||
#endif /* CONFIG_TIMER */
|
#endif /* CONFIG_ONESHOT */
|
||||||
|
|
||||||
#undef EXTERN
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
@ -70,4 +78,4 @@ int board_timer_init(void);
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* __ASSEMBLY__ */
|
#endif /* __ASSEMBLY__ */
|
||||||
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_TIM_H */
|
#endif /* __BOARDS_XTENSA_ESP32_COMMON_INCLUDE_BOARD_ONESHOT_H */
|
@ -18,14 +18,14 @@
|
|||||||
#
|
#
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
ifeq ($(CONFIG_TIMER),y)
|
|
||||||
CSRCS += esp32_board_tim.c
|
|
||||||
endif
|
|
||||||
|
|
||||||
ifeq ($(CONFIG_WATCHDOG),y)
|
ifeq ($(CONFIG_WATCHDOG),y)
|
||||||
CSRCS += esp32_board_wdt.c
|
CSRCS += esp32_board_wdt.c
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifeq ($(CONFIG_ONESHOT),y)
|
||||||
|
CSRCS += esp32_oneshot.c
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(CONFIG_I2C_DRIVER),y)
|
ifeq ($(CONFIG_I2C_DRIVER),y)
|
||||||
CSRCS += esp32_board_i2c.c
|
CSRCS += esp32_board_i2c.c
|
||||||
endif
|
endif
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* boards/xtensa/esp32/common/src/esp32_board_tim.c
|
* boards/xtensa/esp32/common/src/esp32_oneshot.c
|
||||||
*
|
*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||||
* contributor license agreements. See the NOTICE file distributed with
|
* contributor license agreements. See the NOTICE file distributed with
|
||||||
@ -27,30 +27,14 @@
|
|||||||
#include <debug.h>
|
#include <debug.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <nuttx/timers/timer.h>
|
#include <nuttx/timers/timer.h>
|
||||||
|
#include <nuttx/clock.h>
|
||||||
#include "esp32_tim_lowerhalf.h"
|
#include <nuttx/timers/oneshot.h>
|
||||||
#include "esp32_board_tim.h"
|
#include "esp32_board_oneshot.h"
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Pre-processor Definitions
|
* Pre-processor Definitions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER0
|
|
||||||
# define ESP32_TIMER0 (0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER1
|
|
||||||
# define ESP32_TIMER1 (1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER2
|
|
||||||
# define ESP32_TIMER2 (2)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER3
|
|
||||||
# define ESP32_TIMER3 (3)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Functions
|
* Public Functions
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
@ -67,55 +51,33 @@
|
|||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int board_timer_init(void)
|
int esp32_oneshot_init(int timer, uint16_t resolution)
|
||||||
{
|
{
|
||||||
int ret = OK;
|
int ret = OK;
|
||||||
|
FAR struct oneshot_lowerhalf_s *os_lower = NULL;
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER0
|
os_lower = oneshot_initialize(timer, resolution);
|
||||||
ret = esp32_timer_initialize("/dev/timer0", ESP32_TIMER0);
|
if (os_lower != NULL)
|
||||||
if (ret < 0)
|
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR,
|
#if defined(CONFIG_CPULOAD_ONESHOT)
|
||||||
"ERROR: Failed to initialize timer driver: %d\n",
|
/* Configure the oneshot timer to support CPU load measurement */
|
||||||
ret);
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER1
|
nxsched_oneshot_extclk(os_lower);
|
||||||
ret = esp32_timer_initialize("/dev/timer1", ESP32_TIMER1);
|
|
||||||
if (ret < 0)
|
#else
|
||||||
|
ret = oneshot_register("/dev/oneshot", os_lower);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to register oneshot at /dev/oneshot: %d\n", ret);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_CPULOAD_ONESHOT */
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR, "ERROR: oneshot_initialize failed\n");
|
||||||
"ERROR: Failed to initialize timer driver: %d\n",
|
ret = -EBUSY;
|
||||||
ret);
|
|
||||||
goto errout;
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER2
|
|
||||||
ret = esp32_timer_initialize("/dev/timer2", ESP32_TIMER2);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,
|
|
||||||
"ERROR: Failed to initialize timer driver: %d\n",
|
|
||||||
ret);
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CONFIG_ESP32_TIMER3
|
|
||||||
ret = esp32_timer_initialize("/dev/timer3", ESP32_TIMER3);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
syslog(LOG_ERR,
|
|
||||||
"ERROR: Failed to initialize timer driver: %d\n",
|
|
||||||
ret);
|
|
||||||
goto errout;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
errout:
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
59
boards/xtensa/esp32/esp32-devkitc/configs/oneshot/defconfig
Normal file
59
boards/xtensa/esp32/esp32-devkitc/configs/oneshot/defconfig
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_ARCH_LEDS is not set
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
# CONFIG_NSH_CMDPARMS is not set
|
||||||
|
CONFIG_ALARM_ARCH=y
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="esp32-devkitc"
|
||||||
|
CONFIG_ARCH_BOARD_ESP32_DEVKITC=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_ESP32_ONESHOT=y
|
||||||
|
CONFIG_ESP32_TIMER0=y
|
||||||
|
CONFIG_ESP32_TIMER1=y
|
||||||
|
CONFIG_ESP32_TIMER2=y
|
||||||
|
CONFIG_ESP32_TIMER3=y
|
||||||
|
CONFIG_ESP32_UART0=y
|
||||||
|
CONFIG_EXAMPLES_ONESHOT=y
|
||||||
|
CONFIG_EXAMPLES_TIMER=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_MAX_TASKS=16
|
||||||
|
CONFIG_MM_REGIONS=3
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_ONESHOT=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_SDCLONE_DISABLE=y
|
||||||
|
CONFIG_SPI=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_TIMER=y
|
||||||
|
CONFIG_TIMER_ARCH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -50,6 +50,18 @@
|
|||||||
|
|
||||||
#define GPIO_MCP2515_IRQ 22
|
#define GPIO_MCP2515_IRQ 22
|
||||||
|
|
||||||
|
/* TIMERS */
|
||||||
|
|
||||||
|
#define TIMER0 0
|
||||||
|
#define TIMER1 1
|
||||||
|
#define TIMER2 2
|
||||||
|
#define TIMER3 3
|
||||||
|
|
||||||
|
/* ONESHOT */
|
||||||
|
|
||||||
|
#define ONESHOT_TIMER 1
|
||||||
|
#define ONESHOT_RESOLUTION_US 1
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -52,7 +52,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
# include "esp32_board_tim.h"
|
#include <esp32_tim_lowerhalf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ONESHOT
|
||||||
|
# include "esp32_board_oneshot.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_WATCHDOG
|
#ifdef CONFIG_WATCHDOG
|
||||||
@ -240,18 +244,69 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* First, register the timer drivers and let timer 1 for oneshot
|
||||||
|
* if it is enabled.
|
||||||
|
*/
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
/* Configure timer driver */
|
|
||||||
|
|
||||||
ret = board_timer_init();
|
#ifdef CONFIG_ESP32_TIMER0
|
||||||
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"ERROR: Failed to initialize timer drivers: %d\n",
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
ret);
|
ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT)
|
||||||
|
ret = esp32_timer_initialize("/dev/timer1", TIMER1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER2
|
||||||
|
ret = esp32_timer_initialize("/dev/timer2", TIMER2);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER3
|
||||||
|
ret = esp32_timer_initialize("/dev/timer3", TIMER3);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_TIMER */
|
||||||
|
|
||||||
|
/* Now register one oneshot driver */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32_TIMER1)
|
||||||
|
|
||||||
|
ret = esp32_oneshot_init(ONESHOT_TIMER, ONESHOT_RESOLUTION_US);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: esp32_oneshot_init() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_ONESHOT */
|
||||||
|
|
||||||
#ifdef CONFIG_USERLED
|
#ifdef CONFIG_USERLED
|
||||||
/* Register the LED driver */
|
/* Register the LED driver */
|
||||||
|
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
# CONFIG_NSH_CMDPARMS is not set
|
||||||
|
CONFIG_ALARM_ARCH=y
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="esp32-ethernet-kit"
|
||||||
|
CONFIG_ARCH_BOARD_ESP32_ETHERNETKIT=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_ESP32_ONESHOT=y
|
||||||
|
CONFIG_ESP32_TIMER0=y
|
||||||
|
CONFIG_ESP32_TIMER1=y
|
||||||
|
CONFIG_ESP32_TIMER2=y
|
||||||
|
CONFIG_ESP32_TIMER3=y
|
||||||
|
CONFIG_ESP32_UART0=y
|
||||||
|
CONFIG_EXAMPLES_ONESHOT=y
|
||||||
|
CONFIG_EXAMPLES_TIMER=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_MAX_TASKS=16
|
||||||
|
CONFIG_MM_REGIONS=3
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_ONESHOT=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_SDCLONE_DISABLE=y
|
||||||
|
CONFIG_SPI=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_TIMER=y
|
||||||
|
CONFIG_TIMER_ARCH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -39,6 +39,18 @@
|
|||||||
|
|
||||||
#define BUTTON_BOOT 0
|
#define BUTTON_BOOT 0
|
||||||
|
|
||||||
|
/* TIMERS */
|
||||||
|
|
||||||
|
#define TIMER0 0
|
||||||
|
#define TIMER1 1
|
||||||
|
#define TIMER2 2
|
||||||
|
#define TIMER3 3
|
||||||
|
|
||||||
|
/* ONESHOT */
|
||||||
|
|
||||||
|
#define ONESHOT_TIMER 1
|
||||||
|
#define ONESHOT_RESOLUTION_US 1
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -48,7 +48,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
# include "esp32_board_tim.h"
|
#include <esp32_tim_lowerhalf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ONESHOT
|
||||||
|
# include "esp32_board_oneshot.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_WATCHDOG
|
#ifdef CONFIG_WATCHDOG
|
||||||
@ -215,18 +219,69 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* First, register the timer drivers and let timer 1 for oneshot
|
||||||
|
* if it is enabled.
|
||||||
|
*/
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
/* Configure timer driver */
|
|
||||||
|
|
||||||
ret = board_timer_init();
|
#ifdef CONFIG_ESP32_TIMER0
|
||||||
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"ERROR: Failed to initialize timer drivers: %d\n",
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
ret);
|
ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT)
|
||||||
|
ret = esp32_timer_initialize("/dev/timer1", TIMER1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER2
|
||||||
|
ret = esp32_timer_initialize("/dev/timer2", TIMER2);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER3
|
||||||
|
ret = esp32_timer_initialize("/dev/timer3", TIMER3);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_TIMER */
|
||||||
|
|
||||||
|
/* Now register one oneshot driver */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32_TIMER1)
|
||||||
|
|
||||||
|
ret = esp32_oneshot_init(ONESHOT_TIMER, ONESHOT_RESOLUTION_US);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: esp32_oneshot_init() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_ONESHOT */
|
||||||
|
|
||||||
#ifdef CONFIG_USERLED
|
#ifdef CONFIG_USERLED
|
||||||
/* Register the LED driver */
|
/* Register the LED driver */
|
||||||
|
|
||||||
|
@ -0,0 +1,58 @@
|
|||||||
|
#
|
||||||
|
# This file is autogenerated: PLEASE DO NOT EDIT IT.
|
||||||
|
#
|
||||||
|
# You can use "make menuconfig" to make any modifications to the installed .config file.
|
||||||
|
# You can then do "make savedefconfig" to generate a new defconfig file that includes your
|
||||||
|
# modifications.
|
||||||
|
#
|
||||||
|
# CONFIG_NSH_ARGCAT is not set
|
||||||
|
# CONFIG_NSH_CMDOPT_HEXDUMP is not set
|
||||||
|
# CONFIG_NSH_CMDPARMS is not set
|
||||||
|
CONFIG_ALARM_ARCH=y
|
||||||
|
CONFIG_ARCH="xtensa"
|
||||||
|
CONFIG_ARCH_BOARD="esp32-wrover-kit"
|
||||||
|
CONFIG_ARCH_BOARD_ESP32_WROVERKIT=y
|
||||||
|
CONFIG_ARCH_CHIP="esp32"
|
||||||
|
CONFIG_ARCH_CHIP_ESP32=y
|
||||||
|
CONFIG_ARCH_CHIP_ESP32WROVER=y
|
||||||
|
CONFIG_ARCH_STACKDUMP=y
|
||||||
|
CONFIG_ARCH_XTENSA=y
|
||||||
|
CONFIG_BOARD_LOOPSPERMSEC=16717
|
||||||
|
CONFIG_BUILTIN=y
|
||||||
|
CONFIG_ESP32_ONESHOT=y
|
||||||
|
CONFIG_ESP32_TIMER0=y
|
||||||
|
CONFIG_ESP32_TIMER1=y
|
||||||
|
CONFIG_ESP32_TIMER2=y
|
||||||
|
CONFIG_ESP32_TIMER3=y
|
||||||
|
CONFIG_ESP32_UART0=y
|
||||||
|
CONFIG_EXAMPLES_ONESHOT=y
|
||||||
|
CONFIG_EXAMPLES_TIMER=y
|
||||||
|
CONFIG_FS_PROCFS=y
|
||||||
|
CONFIG_HAVE_CXX=y
|
||||||
|
CONFIG_HAVE_CXXINITIALIZE=y
|
||||||
|
CONFIG_IDLETHREAD_STACKSIZE=3072
|
||||||
|
CONFIG_INTELHEX_BINARY=y
|
||||||
|
CONFIG_MAX_TASKS=16
|
||||||
|
CONFIG_MM_REGIONS=3
|
||||||
|
CONFIG_NSH_ARCHINIT=y
|
||||||
|
CONFIG_NSH_BUILTIN_APPS=y
|
||||||
|
CONFIG_NSH_FILEIOSIZE=512
|
||||||
|
CONFIG_NSH_LINELEN=64
|
||||||
|
CONFIG_NSH_READLINE=y
|
||||||
|
CONFIG_ONESHOT=y
|
||||||
|
CONFIG_PREALLOC_TIMERS=4
|
||||||
|
CONFIG_RAM_SIZE=114688
|
||||||
|
CONFIG_RAM_START=0x20000000
|
||||||
|
CONFIG_RAW_BINARY=y
|
||||||
|
CONFIG_RR_INTERVAL=200
|
||||||
|
CONFIG_SCHED_WAITPID=y
|
||||||
|
CONFIG_SDCLONE_DISABLE=y
|
||||||
|
CONFIG_SPI=y
|
||||||
|
CONFIG_START_DAY=6
|
||||||
|
CONFIG_START_MONTH=12
|
||||||
|
CONFIG_START_YEAR=2011
|
||||||
|
CONFIG_SYSTEM_NSH=y
|
||||||
|
CONFIG_TIMER=y
|
||||||
|
CONFIG_TIMER_ARCH=y
|
||||||
|
CONFIG_UART0_SERIAL_CONSOLE=y
|
||||||
|
CONFIG_USER_ENTRYPOINT="nsh_main"
|
@ -45,6 +45,18 @@
|
|||||||
|
|
||||||
#define BUTTON_BOOT 0
|
#define BUTTON_BOOT 0
|
||||||
|
|
||||||
|
/* TIMERS */
|
||||||
|
|
||||||
|
#define TIMER0 0
|
||||||
|
#define TIMER1 1
|
||||||
|
#define TIMER2 2
|
||||||
|
#define TIMER3 3
|
||||||
|
|
||||||
|
/* ONESHOT */
|
||||||
|
|
||||||
|
#define ONESHOT_TIMER 1
|
||||||
|
#define ONESHOT_RESOLUTION_US 1
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Types
|
* Public Types
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
@ -49,7 +49,11 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
# include "esp32_board_tim.h"
|
#include <esp32_tim_lowerhalf.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ONESHOT
|
||||||
|
# include "esp32_board_oneshot.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef CONFIG_WATCHDOG
|
#ifdef CONFIG_WATCHDOG
|
||||||
@ -224,18 +228,69 @@ int esp32_bringup(void)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* First, register the timer drivers and let timer 1 for oneshot
|
||||||
|
* if it is enabled.
|
||||||
|
*/
|
||||||
#ifdef CONFIG_TIMER
|
#ifdef CONFIG_TIMER
|
||||||
/* Configure timer driver */
|
|
||||||
|
|
||||||
ret = board_timer_init();
|
#ifdef CONFIG_ESP32_TIMER0
|
||||||
|
ret = esp32_timer_initialize("/dev/timer0", TIMER0);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR,
|
||||||
"ERROR: Failed to initialize timer drivers: %d\n",
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
ret);
|
ret);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(CONFIG_ESP32_TIMER1) && !defined(CONFIG_ONESHOT)
|
||||||
|
ret = esp32_timer_initialize("/dev/timer1", TIMER1);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER2
|
||||||
|
ret = esp32_timer_initialize("/dev/timer2", TIMER2);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef CONFIG_ESP32_TIMER3
|
||||||
|
ret = esp32_timer_initialize("/dev/timer3", TIMER3);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR,
|
||||||
|
"ERROR: Failed to initialize timer driver: %d\n",
|
||||||
|
ret);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* CONFIG_TIMER */
|
||||||
|
|
||||||
|
/* Now register one oneshot driver */
|
||||||
|
|
||||||
|
#if defined(CONFIG_ONESHOT) && defined(CONFIG_ESP32_TIMER1)
|
||||||
|
|
||||||
|
ret = esp32_oneshot_init(ONESHOT_TIMER, ONESHOT_RESOLUTION_US);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
syslog(LOG_ERR, "ERROR: esp32_oneshot_init() failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* CONFIG_ONESHOT */
|
||||||
|
|
||||||
#ifdef CONFIG_USERLED
|
#ifdef CONFIG_USERLED
|
||||||
/* Register the LED driver */
|
/* Register the LED driver */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user