Compare commits

...

9 commits

Author SHA1 Message Date
红桃六
f89e6f372c
Merge e2fcd5dbee into a2d4d74af7 2025-01-12 16:53:14 +08:00
hujun5
a2d4d74af7 clock_timekeeping: remove enter_critical_section in sched/clock/clock_timekeeping.c
reason:
We would like to replace the critical section with a small lock.

Signed-off-by: hujun5 <hujun5@xiaomi.com>
2025-01-12 16:51:40 +08:00
wangmingrong1
2149d89336 macro/align: Use ALIGN_UP and ALIGN_DOWN uniformly
Signed-off-by: wangmingrong1 <wangmingrong1@xiaomi.com>
2025-01-12 16:48:35 +08:00
Yanfeng Liu
71a4e86718 risc-v/Toolchain.defs: guard -r in LDELFFLAGS
This guards use of `-r` in LDELFFLAGS in risc-v common/Toolchain.defs so
that it is only used when BINFMT_ELF_RELOCATABLE is selected.

Signed-off-by: Yanfeng Liu <yfliu2008@qq.com>
2025-01-12 16:47:54 +08:00
Leo Chung
63c8de5f03 sim: Fixes the linker 'noexecstack' warning
Signed-off-by: Leo Chung <gewalalb@gmail.com>
2025-01-12 16:17:52 +08:00
liuhongchao
e2fcd5dbee nuxxt: add open and close callback functions for the mouse.
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-12-16 15:05:24 +08:00
liuhongchao
54a46b07c7 nuttx: Open mouse/touch/keyboard options can be configured
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-12-16 15:04:32 +08:00
liuhongchao
12b9fe8e3a nuttx: Support for rpmsgdev custom ioctl
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-12-16 15:02:56 +08:00
liuhongchao
97b30a6e5b nuttx: Support for the mouse ioctl interface
Signed-off-by: liuhongchao <liuhongchao@xiaomi.com>
2024-12-16 14:59:39 +08:00
20 changed files with 239 additions and 73 deletions

View file

@ -727,6 +727,7 @@ else()
OUTPUT nuttx.rel
COMMAND
${CMAKE_C_COMPILER} ARGS -r $<$<BOOL:${CONFIG_SIM_M32}>:-m32>
$<$<BOOL:${CONFIG_HOST_LINUX}>:-Wl,-z,noexecstack>
$<TARGET_OBJECTS:sim_head> $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--start-group>
${nuttx_libs_paths} $<$<NOT:$<BOOL:${APPLE}>>:-Wl,--end-group> -o
nuttx.rel

View file

@ -1103,7 +1103,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
&src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1161,7 +1161,7 @@ static void imxrt_lpi2c_setclock(struct imxrt_lpi2c_priv_s *priv,
#endif
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1010,7 +1010,7 @@ static void s32k1xx_lpi2c_setclock(struct s32k1xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -990,7 +990,7 @@ static void s32k3xx_lpi2c_setclock(struct s32k3xx_lpi2c_priv_s *priv,
DEBUGASSERT(src_freq != 0);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -1122,7 +1122,7 @@ static void imx9_lpi2c_setclock(struct imx9_lpi2c_priv_s *priv,
imx9_get_rootclock(priv->config->clk_root, &src_freq);
/* LPI2C output frequency = (Source Clock (Hz)/ 2^prescale) /
* (CLKLO + 1 + CLKHI + 1 + ROUNDDOWN((2 + FILTSCL) / 2^prescale)
* (CLKLO + 1 + CLKHI + 1 + ALIGN_DOWN((2 + FILTSCL)/2^prescale)
*
* Assume CLKLO = 2 * CLKHI, SETHOLD = CLKHI, DATAVD = CLKHI / 2
*/

View file

@ -433,7 +433,12 @@ LDMODULEFLAGS = -r -T $(call CONVERT_PATH,$(TOPDIR)/libs/libc/modlib/gnu-elf.ld)
CELFFLAGS = $(CFLAGS) -fvisibility=hidden
CXXELFFLAGS = $(CXXFLAGS) -fvisibility=hidden
LDELFFLAGS = -r -e main
LDELFFLAGS = -e main
ifeq ($(CONFIG_BINFMT_ELF_RELOCATABLE),y)
LDELFFLAGS += -r
endif
ifeq ($(CONFIG_ARCH_RV32),y)
LDELFFLAGS += --oformat elf32-littleriscv
else

View file

@ -200,3 +200,7 @@ else()
add_link_options(-Wl,--gc-sections)
add_link_options(-Wl,-Ttext-segment=0x40000000)
endif()
if(CONFIG_HOST_LINUX)
add_link_options(-Wl,-z,noexecstack)
endif()

View file

@ -31,18 +31,13 @@
#include <errno.h>
#include <nuttx/kmalloc.h>
#include <nuttx/nuttx.h>
#include <nuttx/binfmt/binfmt.h>
#include "binfmt.h"
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL) && !defined(CONFIG_BINFMT_DISABLE)
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
/****************************************************************************
* Public Functions
****************************************************************************/
@ -98,7 +93,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
case SPAWN_FILE_ACTION_OPEN:
open = (FAR struct spawn_open_file_action_s *)entry;
size += ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
size += ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(open->path)),
sizeof(FAR void *));
break;
@ -155,7 +150,7 @@ int binfmt_copyactions(FAR const posix_spawn_file_actions_t **copy,
strcpy(open->path, tmp->path);
buffer = (FAR char *)buffer +
ROUNDUP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
ALIGN_UP(SIZEOF_OPEN_FILE_ACTION_S(strlen(tmp->path)),
sizeof(FAR void *));
break;

View file

@ -65,7 +65,7 @@ endif # FF_AW86225
endif # INPUT_FF
config INPUT_MOUSE
bool
bool "Enable mouse support"
default n
---help---
Enable support for mouse devices.
@ -82,11 +82,11 @@ config INPUT_MOUSE_WHEEL
endif # INPUT_MOUSE
config INPUT_TOUCHSCREEN
bool
bool "Enable touchscreen support"
default n
config INPUT_KEYBOARD
bool
bool "Enable keyboard support"
default n
config INPUT_UINPUT

View file

@ -68,6 +68,8 @@ static int mouse_open(FAR struct file *filep);
static int mouse_close(FAR struct file *filep);
static ssize_t mouse_read(FAR struct file *filep, FAR char *buffer,
size_t buflen);
static int mouse_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
static int mouse_poll(FAR struct file *filep, FAR struct pollfd *fds,
bool setup);
@ -82,7 +84,7 @@ static const struct file_operations g_mouse_fops =
mouse_read, /* read */
NULL, /* write */
NULL, /* seek */
NULL, /* ioctl */
mouse_ioctl, /* ioctl */
NULL, /* mmap */
NULL, /* truncate */
mouse_poll /* poll */
@ -101,6 +103,7 @@ static int mouse_open(FAR struct file *filep)
FAR struct mouse_openpriv_s *openpriv;
FAR struct inode *inode = filep->f_inode;
FAR struct mouse_upperhalf_s *upper = inode->i_private;
FAR struct mouse_lowerhalf_s *lower = upper->lower;
int ret;
ret = nxmutex_lock(&upper->lock);
@ -129,6 +132,11 @@ static int mouse_open(FAR struct file *filep)
nxmutex_init(&openpriv->lock);
list_add_tail(&upper->head, &openpriv->node);
if (lower->open && list_is_singular(&openpriv->node))
{
ret = lower->open(lower);
}
/* Save the buffer node pointer so that it can be used directly
* in the read operation.
*/
@ -147,6 +155,7 @@ static int mouse_close(FAR struct file *filep)
FAR struct mouse_openpriv_s *openpriv = filep->f_priv;
FAR struct inode *inode = filep->f_inode;
FAR struct mouse_upperhalf_s *upper = inode->i_private;
FAR struct mouse_lowerhalf_s *lower = upper->lower;
int ret;
ret = nxmutex_lock(&upper->lock);
@ -155,6 +164,11 @@ static int mouse_close(FAR struct file *filep)
return ret;
}
if (lower->close && list_is_singular(&openpriv->node))
{
ret = lower->close(lower);
}
list_delete(&openpriv->node);
circbuf_uninit(&openpriv->circbuf);
nxsem_destroy(&openpriv->waitsem);
@ -217,6 +231,36 @@ out:
return ret;
}
/****************************************************************************
* Name: mouse_ioctl
****************************************************************************/
static int mouse_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
{
FAR struct inode *inode = filep->f_inode;
FAR struct mouse_upperhalf_s *upper = inode->i_private;
FAR struct mouse_lowerhalf_s *lower = upper->lower;
int ret;
ret = nxmutex_lock(&upper->lock);
if (ret < 0)
{
return ret;
}
if (lower->control)
{
ret = lower->control(lower, cmd, arg);
}
else
{
ret = -ENOTTY;
}
nxmutex_unlock(&upper->lock);
return ret;
}
/****************************************************************************
* Name: mouse_poll
****************************************************************************/

View file

@ -45,6 +45,7 @@
#include <nuttx/net/ioctl.h>
#include <nuttx/drivers/rpmsgdev.h>
#include <nuttx/power/battery_ioctl.h>
#include <nuttx/input/mouse.h>
#include "rpmsgdev.h"
@ -103,7 +104,7 @@ static ssize_t rpmsgdev_write(FAR struct file *filep, FAR const char *buffer,
size_t buflen);
static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset,
int whence);
static ssize_t rpmsgdev_ioctl_arglen(int cmd);
static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned long arg);
static int rpmsgdev_ioctl(FAR struct file *filep, int cmd,
unsigned long arg);
static int rpmsgdev_poll(FAR struct file *filep, FAR struct pollfd *fds,
@ -591,6 +592,7 @@ static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset, int whence)
*
* Parameters:
* cmd - the ioctl command
* arg - the ioctl arguments
*
* Returned Values:
* 0 - ioctl command not support
@ -598,7 +600,7 @@ static off_t rpmsgdev_seek(FAR struct file *filep, off_t offset, int whence)
*
****************************************************************************/
static ssize_t rpmsgdev_ioctl_arglen(int cmd)
static ssize_t rpmsgdev_ioctl_arglen(int cmd, unsigned long arg)
{
switch (cmd)
{
@ -622,6 +624,9 @@ static ssize_t rpmsgdev_ioctl_arglen(int cmd)
case BATIOC_GET_PROTOCOL:
case BATIOC_OPERATE:
return sizeof(struct batio_operate_msg_s);
case MSIOC_VENDOR:
return sizeof(struct mouse_vendor_cmd_s) +
((FAR struct mouse_vendor_cmd_s *)(uintptr_t)arg)->len;
default:
return -ENOTTY;
}
@ -661,7 +666,7 @@ static int rpmsgdev_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
/* Call our internal routine to perform the ioctl */
arglen = rpmsgdev_ioctl_arglen(cmd);
arglen = rpmsgdev_ioctl_arglen(cmd, arg);
if (arglen < 0)
{
return arglen;

View file

@ -108,6 +108,7 @@
#define _PINCTRLBASE (0x4000) /* Pinctrl driver ioctl commands */
#define _PCIBASE (0x4100) /* Pci ioctl commands */
#define _I3CBASE (0x4200) /* I3C driver ioctl commands */
#define _MSIOCBASE (0x4300) /* Mouse ioctl commands */
#define _WLIOCBASE (0x8b00) /* Wireless modules ioctl network commands */
/* boardctl() commands share the same number space */
@ -370,6 +371,11 @@
#define _TSIOCVALID(c) (_IOC_TYPE(c)==_TSIOCBASE)
#define _TSIOC(nr) _IOC(_TSIOCBASE,nr)
/* NuttX mouse ioctl definitions (see nuttx/input/mouse.h) ******************/
#define _MSIOCVALID(c) (_IOC_TYPE(c)==_MSIOCBASE)
#define _MSIOC(nr) _IOC(_MSIOCBASE,nr)
/* NuttX sensor ioctl definitions (see nuttx/sensor/ioctl.h) ****************/
#define _SNIOCVALID(c) (_IOC_TYPE(c)==_SNIOCBASE)

View file

@ -37,6 +37,7 @@
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/fs/ioctl.h>
/****************************************************************************
* Pre-processor Definitions
@ -50,6 +51,54 @@
#define MOUSE_BUTTON_2 (1 << 1) /* True: Right mouse button pressed */
#define MOUSE_BUTTON_3 (1 << 2) /* True: Middle mouse button pressed */
/* IOCTL Commands ***********************************************************/
/* Common mouse IOCTL commands */
#define MSIOC_VENDOR _MSIOC(0x0001) /* Vendor-specific commands */
#define MSC_FIRST 0x0001 /* First common command */
#define MSC_NCMDS 1 /* One common commands */
/* Vendor-specific command structure
*
* This structure is used to pass vendor-specific commands to the mouse
* driver. The vendor-specific command is identified by the 'cmd' field
* and the length of the data is specified by the 'len' field. The
* data follows the structure in a contiguous block of memory.
*
* The vendor-specific command is defined by the vendor and is not
* standardized. The data format and meaning is defined by the vendor.
*
* The usage is as follows :
*
* struct mse_vendor_data_s
* {
* uint16_t cmd;
* uint16_t len;
* uint16_t data;
* ... ... ...
* };
*
* struct mse_vendor_data_s cmd_data;
* cmd_data.cmd = VENDOR_CMD_ID;
* cmd_data.data = 12;
*
* struct mouse_vendor_cmd_s *ioctl;
* ioctl = malloc(sizeof(*ioctl) + sizeof(struct mse_vendor_data_s));
* ioctl->len = sizeof(struct mse_vendor_data_s);
* memcpy(ioctl->data, &cmd_data, sizeof(struct mse_vendor_data_s));
*
* ioctl(file, MSIOC_VENDOR, ioctl);
*
*/
struct mouse_vendor_cmd_s
{
size_t len;
char data[1];
};
/****************************************************************************
* Public Types
****************************************************************************/
@ -75,6 +124,64 @@ struct mouse_report_s
struct mouse_lowerhalf_s
{
FAR void *priv; /* Save the upper half pointer */
/**************************************************************************
* Name: control
*
* Description:
* Users can use this interface to implement custom IOCTL.
*
* Arguments:
* lower - The instance of lower half of mouse device.
* cmd - User defined specific command.
* arg - Argument of the specific command.
*
* Return Value:
* Zero(OK) on success; a negated errno value on failure.
* -ENOTTY - The command is not supported.
**************************************************************************/
CODE int (*control)(FAR struct mouse_lowerhalf_s *lower,
int cmd, unsigned long arg);
/**************************************************************************
* Name: open
*
* Description:
* This function pointer is used to open a connection to the mouse driver
* instance. It initializes the mouse and prepares it for subsequent
* interactions with the user. This function typically sets up the state
* of the driver and allocates any necessary resources.
*
* Input Parameters:
* lower - A pointer to the instance of the lower half mouse driver.
* filep - A pointer to the file structure representing the user.
*
* Returned Value:
* It returns zero (OK) on success; a negative errno value on failure.
**************************************************************************/
CODE int (*open)(FAR struct mouse_lowerhalf_s *lower);
/**************************************************************************
* Name: close
*
* Description:
* This function pointer is used to close the connection to the mouse
* driver instance. It performs any necessary cleanup operations, such as
* releasing resources and resetting the state of the mouse driver,
* before ending theinteraction with the user.
*
* Input Parameters:
* lower - A pointer to the instance of the lower half mouse driver.
* filep - A pointer to the file structure representing the user closing
* the mouse connection.
*
* Returned Value:
* Returns zero (OK) on success; a negative errno value on failure.
**************************************************************************/
CODE int (*close)(FAR struct mouse_lowerhalf_s *lower);
};
/****************************************************************************

View file

@ -35,6 +35,7 @@
#include <nuttx/init.h>
#include <nuttx/kmalloc.h>
#include <nuttx/fs/fs.h>
#include <nuttx/nuttx.h>
#include <nuttx/spinlock.h>
/****************************************************************************
@ -112,11 +113,6 @@
#define MAXARCS (1 << 20)
/* General rounding functions. */
#define ROUNDDOWN(x, y) (((x) / (y)) * (y))
#define ROUNDUP(x, y) ((((x) + (y) - 1) / (y)) * (y))
/* See profil(2) where this is described (incorrectly) */
#define SCALE_1_TO_1 0x10000
@ -288,12 +284,12 @@ void moncontrol(int mode)
if (mode)
{
uintptr_t lowpc = ROUNDDOWN((uintptr_t)&_stext,
uintptr_t lowpc = ALIGN_DOWN((uintptr_t)&_stext,
HISTFRACTION * sizeof(HISTCOUNTER));
uintptr_t highpc = ROUNDUP((uintptr_t)&_etext,
uintptr_t highpc = ALIGN_UP((uintptr_t)&_etext,
HISTFRACTION * sizeof(HISTCOUNTER));
size_t textsize = highpc - lowpc;
size_t kcountsize = ROUNDUP(textsize / HISTFRACTION,
size_t kcountsize = ALIGN_UP(textsize / HISTFRACTION,
sizeof(*p->kcount));
int scale = kcountsize >= textsize ? SCALE_1_TO_1 :
(float)kcountsize / textsize * SCALE_1_TO_1;
@ -370,10 +366,10 @@ void monstartup(unsigned long lowpc, unsigned long highpc)
* so the rest of the scaling (here and in gprof) stays in ints.
*/
lowpc = ROUNDDOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ROUNDUP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
lowpc = ALIGN_DOWN(lowpc, HISTFRACTION * sizeof(HISTCOUNTER));
highpc = ALIGN_UP(highpc, HISTFRACTION * sizeof(HISTCOUNTER));
textsize = highpc - lowpc;
fromssize = ROUNDUP(textsize / HASHFRACTION, sizeof(*p->froms));
fromssize = ALIGN_UP(textsize / HASHFRACTION, sizeof(*p->froms));
tolimit = textsize * ARCDENSITY / 100;
if (tolimit < MINARCS)

View file

@ -41,8 +41,6 @@
* Pre-processor Definitions
****************************************************************************/
#define ROUNDUP(x, y) (((x) + (y) - 1) / (y) * (y))
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_IOB_DEBUG)
# define ioberr _err
# define iobwarn _warn

View file

@ -35,6 +35,7 @@
#ifdef CONFIG_IOB_ALLOC
# include <nuttx/kmalloc.h>
#endif
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h>
#include "iob.h"
@ -333,7 +334,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
FAR struct iob_s *iob;
size_t alignsize;
alignsize = ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
alignsize = ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT) + size;
iob = kmm_memalign(CONFIG_IOB_ALIGNMENT, alignsize);
if (iob)
@ -344,7 +345,7 @@ FAR struct iob_s *iob_alloc_dynamic(uint16_t size)
iob->io_bufsize = size; /* Total length of the iob buffer */
iob->io_pktlen = 0; /* Total length of the packet */
iob->io_free = iob_free_dynamic; /* Customer free callback */
iob->io_data = (FAR uint8_t *)ROUNDUP((uintptr_t)(iob + 1),
iob->io_data = (FAR uint8_t *)ALIGN_UP((uintptr_t)(iob + 1),
CONFIG_IOB_ALIGNMENT);
}

View file

@ -28,6 +28,7 @@
#include <stdbool.h>
#include <nuttx/nuttx.h>
#include <nuttx/mm/iob.h>
#include "iob.h"
@ -39,10 +40,10 @@
/* Fix the I/O Buffer size with specified alignment size */
#ifdef CONFIG_IOB_ALLOC
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s) + CONFIG_IOB_BUFSIZE, \
CONFIG_IOB_ALIGNMENT)
#else
# define IOB_ALIGN_SIZE ROUNDUP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
# define IOB_ALIGN_SIZE ALIGN_UP(sizeof(struct iob_s), CONFIG_IOB_ALIGNMENT)
#endif
#define IOB_BUFFER_SIZE (IOB_ALIGN_SIZE * CONFIG_IOB_NBUFFERS + \
@ -137,7 +138,7 @@ void iob_initialize(void)
* aligned to the CONFIG_IOB_ALIGNMENT memory boundary
*/
buf = ROUNDUP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
buf = ALIGN_UP((uintptr_t)g_iob_buffer + offsetof(struct iob_s, io_data),
CONFIG_IOB_ALIGNMENT) - offsetof(struct iob_s, io_data);
/* Get I/O buffer instance from the start address and add each I/O buffer

View file

@ -53,6 +53,7 @@ static struct timespec g_clock_wall_time;
static uint64_t g_clock_last_counter;
static uint64_t g_clock_mask;
static long g_clock_adjust;
static spinlock_t g_clock_lock = SP_UNLOCKED;
/****************************************************************************
* Private Functions
@ -72,7 +73,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
time_t sec;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -96,7 +97,7 @@ static int clock_get_current_time(FAR struct timespec *ts,
ts->tv_sec = base->tv_sec + sec;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}
@ -123,7 +124,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
uint64_t counter;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -137,7 +138,7 @@ int clock_timekeeping_set_wall_time(FAR const struct timespec *ts)
g_clock_last_counter = counter;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return ret;
}
@ -188,7 +189,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
return -1;
}
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
adjust_usec = delta->tv_sec * USEC_PER_SEC + delta->tv_usec;
@ -199,7 +200,7 @@ int adjtime(FAR const struct timeval *delta, FAR struct timeval *olddelta)
g_clock_adjust = adjust_usec;
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
return OK;
}
@ -217,7 +218,7 @@ void clock_update_wall_time(void)
time_t sec;
int ret;
flags = enter_critical_section();
flags = spin_lock_irqsave(&g_clock_lock);
ret = up_timer_gettick(&counter);
if (ret < 0)
@ -271,7 +272,7 @@ void clock_update_wall_time(void)
g_clock_last_counter = counter;
errout_in_critical_section:
leave_critical_section(flags);
spin_unlock_irqrestore(&g_clock_lock, flags);
}
/****************************************************************************
@ -280,6 +281,9 @@ errout_in_critical_section:
void clock_inittimekeeping(FAR const struct timespec *tp)
{
irqstate_t flags;
flags = spin_lock_irqsave(&g_clock_lock);
up_timer_getmask(&g_clock_mask);
if (tp)
@ -292,6 +296,7 @@ void clock_inittimekeeping(FAR const struct timespec *tp)
}
up_timer_gettick(&g_clock_last_counter);
spin_unlock_irqrestore(&g_clock_lock, flags);
}
#endif /* CONFIG_CLOCK_TIMEKEEPING */

View file

@ -32,6 +32,7 @@
#include <nuttx/coredump.h>
#include <nuttx/elf.h>
#include <nuttx/nuttx.h>
#include <nuttx/sched.h>
#include "sched/sched.h"
@ -54,9 +55,6 @@
#define PROGRAM_ALIGNMENT 64
#define ROUNDUP(x, y) ((x + (y - 1)) / (y)) * (y)
#define ROUNDDOWN(x ,y) (((x) / (y)) * (y))
/****************************************************************************
* Private Types
****************************************************************************/
@ -166,7 +164,7 @@ static int elf_emit(FAR struct elf_dumpinfo_s *cinfo,
static int elf_emit_align(FAR struct elf_dumpinfo_s *cinfo)
{
off_t align = ROUNDUP(cinfo->stream->nput,
off_t align = ALIGN_UP(cinfo->stream->nput,
ELF_PAGESIZE) - cinfo->stream->nput;
unsigned char null[256];
off_t total = align;
@ -258,9 +256,9 @@ static int elf_get_note_size(int stksegs)
{
int total;
total = stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
total = stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prstatus_t));
total += stksegs * (sizeof(Elf_Nhdr) + ROUNDUP(CONFIG_TASK_NAME_SIZE, 8) +
total += stksegs * (sizeof(Elf_Nhdr) + ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8) +
sizeof(elf_prpsinfo_t));
return total;
}
@ -276,7 +274,7 @@ static int elf_get_note_size(int stksegs)
static void elf_emit_tcb_note(FAR struct elf_dumpinfo_s *cinfo,
FAR struct tcb_s *tcb)
{
char name[ROUNDUP(CONFIG_TASK_NAME_SIZE, 8)];
char name[ALIGN_UP(CONFIG_TASK_NAME_SIZE, 8)];
elf_prstatus_t status;
elf_prpsinfo_t info;
FAR uintptr_t *regs;
@ -414,8 +412,8 @@ static void elf_emit_tcb_stack(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
sp = ROUNDDOWN(buf, PROGRAM_ALIGNMENT);
len = ROUNDUP(len + (buf - sp), PROGRAM_ALIGNMENT);
sp = ALIGN_DOWN(buf, PROGRAM_ALIGNMENT);
len = ALIGN_UP(len + (buf - sp), PROGRAM_ALIGNMENT);
buf = sp;
elf_emit(cinfo, (FAR void *)buf, len);
@ -546,17 +544,17 @@ static void elf_emit_tcb_phdr(FAR struct elf_dumpinfo_s *cinfo,
(tcb->stack_base_ptr - tcb->stack_alloc_ptr);
}
sp = ROUNDDOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ROUNDUP(phdr->p_filesz +
sp = ALIGN_DOWN(phdr->p_vaddr, PROGRAM_ALIGNMENT);
phdr->p_filesz = ALIGN_UP(phdr->p_filesz +
(phdr->p_vaddr - sp), PROGRAM_ALIGNMENT);
phdr->p_vaddr = sp;
phdr->p_type = PT_LOAD;
phdr->p_offset = ROUNDUP(*offset, ELF_PAGESIZE);
phdr->p_offset = ALIGN_UP(*offset, ELF_PAGESIZE);
phdr->p_paddr = phdr->p_vaddr;
phdr->p_memsz = phdr->p_filesz;
phdr->p_flags = PF_X | PF_W | PF_R;
*offset += ROUNDUP(phdr->p_memsz, ELF_PAGESIZE);
*offset += ALIGN_UP(phdr->p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, phdr, sizeof(*phdr));
}
@ -608,13 +606,13 @@ static void elf_emit_phdr(FAR struct elf_dumpinfo_s *cinfo,
for (i = 0; i < memsegs; i++)
{
phdr.p_type = PT_LOAD;
phdr.p_offset = ROUNDUP(offset, ELF_PAGESIZE);
phdr.p_offset = ALIGN_UP(offset, ELF_PAGESIZE);
phdr.p_vaddr = cinfo->regions[i].start;
phdr.p_paddr = phdr.p_vaddr;
phdr.p_filesz = cinfo->regions[i].end - cinfo->regions[i].start;
phdr.p_memsz = phdr.p_filesz;
phdr.p_flags = cinfo->regions[i].flags;
offset += ROUNDUP(phdr.p_memsz, ELF_PAGESIZE);
offset += ALIGN_UP(phdr.p_memsz, ELF_PAGESIZE);
elf_emit(cinfo, &phdr, sizeof(phdr));
}
}