Linux <-> RTOS Mailbox driver

I’m looking at the rtos mailbox /dev/cvi-rtos-cmdqu. i want to access it from a userspace high level language (python etc).
It seems that the command values to use it are set a compile time.

#define RTOS_CMDQU_DEV_NAME "cvi-rtos-cmdqu"
#define RTOS_CMDQU_SEND         _IOW('r', CMDQU_SEND, unsigned long)
#define RTOS_CMDQU_REQUEST      _IOW('r', CMDQU_REQUEST, unsigned long)
#define RTOS_CMDQU_REQUEST_FREE _IOW('r', CMDQU_REQUEST_FREE, unsigned long)
#define RTOS_CMDQU_SEND_WAIT    _IOW('r', CMDQU_SEND_WAIT, unsigned long)
#define RTOS_CMDQU_SEND_WAKEUP  _IOW('r', CMDQU_SEND_WAKEUP, unsigned long)

Short of writing a C client library, anyone found an alternative solution?

1 Like

What I want to do is offload 1-wire temperature sensors like the DS18B20 to the RTOS core. They use a bit banging protocol, so timing is important.

I also have a MODBUS application, which also uses the timing of bits in it’s protocol. So again, more suited to the RTOS core.

These two protocols would use useful additions, to Linux user space.

1 Like

I have created a pull request

This modification to the Linux Mailbox driver, exposes the mailbox command values to user space.

[root@milkv-duo]~# ls -la /sys/class/misc/cvi-rtos-cmdqu/ioctl_cmds
-r--r--r-- 1 root root 4096 Apr 19 17:58 rtos_cmdqu_request
-r--r--r-- 1 root root 4096 Apr 19 17:58 rtos_cmdqu_request_free
-r--r--r-- 1 root root 4096 Apr 19 17:58 rtos_cmdqu_send
-r--r--r-- 1 root root 4096 Apr 19 17:58 rtos_cmdqu_send_wait
-r--r--r-- 1 root root 4096 Apr 19 17:58 rtos_cmdqu_send_wakeup

So in Python (for example) you could do something like:

import fcntl
import os

DEV_PATH = "/dev/cvi-rtos-cmdqu"
SYSFS_BASE = "/sys/class/misc/cvi-rtos-cmdqu/ioctl_cmds/"

def get_ioctl_cmd(name):
    """Reads an ioctl command value from sysfs."""
    try:
        with open(os.path.join(SYSFS_BASE, name), 'r') as f:
            val_str = f.read().strip()
            return int(val_str, 16) # Parse as hexadecimal
    except FileNotFoundError:
        print(f"Error: Sysfs entry not found for {name}")
        return None
    except Exception as e:
        print(f"Error reading sysfs entry {name}: {e}")
        return None

# Get the command numbers at runtime
rtos_cmdqu_send_nr = get_ioctl_cmd("rtos_cmdqu_send_cmd")
rtos_cmdqu_send_wait_nr = get_ioctl_cmd("rtos_cmdqu_send_wait_cmd")

3 Likes