Skip to content

Day16 - IOCTL Control Plane

Objective

Implement and test ioctl interface for mygpio driver.


IOCTL Commands

1. Set Debounce

#define MYGPIO_IOC_SET_DEBOUNCE \
    _IOW(MYGPIO_IOC_MAGIC, 1, struct mygpio_ioc_debounce)

2. Get Status

#define MYGPIO_IOC_GET_STATUS \
    _IOR(MYGPIO_IOC_MAGIC, 2, struct mygpio_ioc_status)

3. Clear Events

#define MYGPIO_IOC_CLR_EVENTS \
    _IO(MYGPIO_IOC_MAGIC, 3)

Driver Implementation (Key Part)

static long mygpio_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
{
    ...
}

Build

make
sudo insmod mygpio.ko

Test Programs

1. SET_DEBOUNCE

./test_ioctl_set_debounce 100

Expected:

  • dmesg shows debounce updated

2. GET_STATUS

./test_ioctl_get_status

Expected output:

version        : 1
led1           : 0
led2           : 0
button         : 0
pending_events : 0
debounce_ms    : 20

3. CLR_EVENTS

./test_ioctl_clear

Expected:

  • event queue cleared

Functional Tests

Test A: LED Control

echo led1=1 > /dev/mygpio
./test_ioctl_get_status

Test B: Debounce Update

./test_ioctl_set_debounce 80
./test_ioctl_get_status

Test C: Button Events

  1. Press button multiple times
  2. Check:
./test_ioctl_get_status

Test D: Clear Events

./test_ioctl_clear
./test_ioctl_get_status

Result

All ioctl commands:

  • work correctly
  • update driver state as expected
  • integrate with event system

Conclusion

Control plane successfully implemented using ioctl.