This is an automated email from the ASF dual-hosted git repository. acassis pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit 9c35b01cd832497cc7997a1f1bfcab01f2220deb Author: yangyalei <[email protected]> AuthorDate: Fri Jun 13 16:34:38 2025 +0800 nuttx/audio: Add audio_mmap 1. mmap hw_ptr_s, 2. mmap apb buffers; Signed-off-by: yangyalei <[email protected]> --- audio/audio.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/audio/audio.c b/audio/audio.c index e9be095dab7..828ed5d80af 100644 --- a/audio/audio.c +++ b/audio/audio.c @@ -100,6 +100,8 @@ static ssize_t audio_write(FAR struct file *filep, static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg); +static int audio_mmap(FAR struct file *filep, + FAR struct mm_map_entry_s *map); static int audio_allocbuffer(FAR struct audio_upperhalf_s *upper, FAR struct audio_buf_desc_s * bufdesc); static int audio_freebuffer(FAR struct audio_upperhalf_s *upper, @@ -132,6 +134,7 @@ static const struct file_operations g_audioops = audio_write, /* write */ NULL, /* seek */ audio_ioctl, /* ioctl */ + audio_mmap, /* mmap */ }; /**************************************************************************** @@ -761,6 +764,68 @@ static int audio_ioctl(FAR struct file *filep, int cmd, unsigned long arg) return ret; } +/**************************************************************************** + * Name: audio_munmap + * + * Description: + * The standard unmap method. + * + ****************************************************************************/ + +static int audio_munmap(FAR struct task_group_s *group, + FAR struct mm_map_entry_s *entry, FAR void *start, + size_t length) +{ + return mm_map_remove(get_group_mm(group), entry); +} + +/**************************************************************************** + * Name: audio_mmap + * + * Description: + * The standard mmap method. + * + ****************************************************************************/ + +static int audio_mmap(FAR struct file *filep, FAR struct mm_map_entry_s *map) +{ + FAR struct inode *inode = filep->f_inode; + FAR struct audio_upperhalf_s *upper = inode->i_private; + int ret; + + ret = nxmutex_lock(&upper->lock); + if (ret < 0) + { + return ret; + } + + /* Return the address corresponding to the start of frame buffer. */ + + if (upper->apbs != NULL && map->length == upper->apbs[0]->nmaxbytes) + { + ret = map->offset / upper->apbs[0]->nmaxbytes; + + DEBUGASSERT(ret < upper->periods); + + map->vaddr = (FAR char *)upper->apbs[ret]->samp; + map->munmap = audio_munmap; + ret = mm_map_add(get_current_mm(), map); + } + else if (map->length == sizeof(struct audio_status_s)) + { + map->vaddr = (FAR char *)upper->status; + map->munmap = audio_munmap; + ret = mm_map_add(get_current_mm(), map); + } + else + { + ret = -EINVAL; + } + + nxmutex_unlock(&upper->lock); + return ret; +} + /**************************************************************************** * Name: audio_allocbuffer *
