Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/Linux_based_host/SDIO_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Please reboot Raspberry-Pi after changing this file.
$ cd host/linux/host_control/
$ ./rpi_init.sh sdio
```
* This script compiles and loads host driver on Raspberry-Pi. It also creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral
* This script compiles and loads host driver on Raspberry-Pi. The driver creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral.

### 2.2 ESP Peripheral Firmware
One can load pre-built release binaries on ESP peripheral or compile those from source. Below subsection explains both these methods.
Expand Down
2 changes: 1 addition & 1 deletion docs/Linux_based_host/SPI_setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ Please reboot Raspberry-Pi after changing this file.
$ cd host/linux/host_control/
$ ./rpi_init.sh spi
```
* This script compiles and loads host driver on Raspberry-Pi. It also creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral
* This script compiles and loads host driver on Raspberry-Pi. The driver creates virtual serial interface `/dev/esps0` which is used as a control interface for Wi-Fi on ESP peripheral

### 2.2 ESP Peripheral Firmware
One can load pre-built release binaries on ESP peripheral or compile those from source. Below subsection explains both these methods.
Expand Down
2 changes: 0 additions & 2 deletions host/linux/host_control/rpi_init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ wlan_init()

cd ../host_driver/esp32/
if [ `lsmod | grep esp32 | wc -l` != "0" ]; then
sudo rm /dev/esps0
if [ `lsmod | grep esp32_sdio | wc -l` != "0" ]; then
sudo rmmod esp32_sdio &> /dev/null
else
Expand All @@ -56,7 +55,6 @@ wlan_init()
fi
if [ `lsmod | grep esp32 | wc -l` != "0" ]; then
echo "esp32 module inserted "
sudo mknod /dev/esps0 c 221 0
sudo chmod 666 /dev/esps0
echo "/dev/esps0 device created"
echo "RPi init successfully completed"
Expand Down
42 changes: 30 additions & 12 deletions host/linux/host_driver/esp32/esp_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
//#define ESP_SERIAL_TEST

static struct esp_serial_devs {
struct device* dev;
struct cdev cdev;
int dev_index;
esp_rb_t rb;
Expand Down Expand Up @@ -220,20 +221,30 @@ static int thread_fn(void *unused)
}
#endif

int esp_serial_init(void *priv)
{
int err = 0, i = 0;
static dev_t dev_first;
static struct class *cl;

int esp_serial_init(void* priv) {
int err, i;

err = register_chrdev_region(MKDEV(ESP_SERIAL_MAJOR, 0), ESP_SERIAL_MINOR_MAX, "esp_serial_driver");
err = alloc_chrdev_region(&dev_first, 0, ESP_SERIAL_MINOR_MAX, "esp_serial_driver");
if (err) {
printk(KERN_ERR "%s, Error registering chrdev region %d\n", __func__, err);
return -1;
goto err;
}

cl = class_create(THIS_MODULE, "esp_serial_chardrv");
if (IS_ERR(cl)) {
err = PTR_ERR(cl);
goto err_class_create;
}

for (i = 0; i < ESP_SERIAL_MINOR_MAX; i++) {
cdev_init(&devs[i].cdev, &esp_serial_fops);
dev_t dev_num = dev_first + i;
devs[i].dev_index = i;
cdev_add(&devs[i].cdev, MKDEV(ESP_SERIAL_MAJOR, i), 1);
devs[i].dev = device_create(cl, NULL, dev_num, NULL, "esps%d", i);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this removed from OS automatically when driver unloads?
If not, it would be better to remove this manually before driver unloading.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is removed in line 269, device_destroy(cl, dev_num);

cdev_init(&devs[i].cdev, &esp_serial_fops);
cdev_add(&devs[i].cdev, dev_num, 1);
esp_rb_init(&devs[i].rb, ESP_RX_RB_SIZE);
devs[i].priv = priv;
mutex_init(&devs[i].lock);
Expand All @@ -243,16 +254,23 @@ int esp_serial_init(void *priv)
kthread_run(thread_fn, NULL, "esptest-thread");
#endif
return 0;
err_class_create:
unregister_chrdev_region(dev_first, ESP_SERIAL_MINOR_MAX);

err:
return err;
}

void esp_serial_cleanup(void)
{
int i = 0;
void esp_serial_cleanup(void) {
int i;

for (i = 0; i < ESP_SERIAL_MINOR_MAX; i++) {
dev_t dev_num = dev_first + i;
device_destroy(cl, dev_num);
cdev_del(&devs[i].cdev);
esp_rb_cleanup(&devs[i].rb);
mutex_destroy(&devs[i].lock);
}
unregister_chrdev_region(MKDEV(ESP_SERIAL_MAJOR, 0), ESP_SERIAL_MINOR_MAX);
return;
class_destroy(cl);
unregister_chrdev_region(dev_first, ESP_SERIAL_MINOR_MAX);
}