Version 0.08
authorTom Knot <tomasknot@gmail.com>
Fri, 18 May 2018 11:53:22 +0000 (13:53 +0200)
committerTom Knot <tomasknot@gmail.com>
Fri, 18 May 2018 11:53:22 +0000 (13:53 +0200)
- Changed reading frequency to be user-specifiable (1-1000 Hz)

modules/unipi/src/unipi_common.h
modules/unipi/src/unipi_platform.c
modules/unipi/src/unipi_spi.c
modules/unipi/src/unipi_spi.h
modules/unipi/src/unipi_sysfs.c
modules/unipi/src/unipi_sysfs.h

index feb5c67a29d2db2bd37915fd8a21ea2dad0a3a0f..52cfdcd710cfa8727c8c6d1aafc4a8f35c52b1f7 100644 (file)
@@ -51,7 +51,7 @@
 #if NEURONSPI_SCHED_REQUIRED > 0
        #include <uapi/linux/sched/types.h>
 #endif
-#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.07:30:04:2018"
+#define NEURONSPI_MAJOR_VERSIONSTRING "Development Beta Version 0.08:18:05:2018"
 
 #define NEURONSPI_MAX_DEVS                             3
 #define NEURONSPI_MAX_UART                             128
index c4ce3907fc12ab4f8ad9321127bd746d4d882605..b0c3813d20788b615ba76c7d3ac0ce3f758c499c 100644 (file)
@@ -18,6 +18,7 @@
 #include "unipi_platform.h"
 #include "unipi_spi.h"
 #include "unipi_common.h"
+#include "unipi_sysfs.h"
 
 /***************************
  * Static Data Definitions *
@@ -1485,9 +1486,18 @@ struct neuronspi_model_definition NEURONSPI_MODELTABLE[NEURONSPI_MODELTABLE_LEN]
 s32 neuronspi_regmap_invalidate(void *data)
 {
        int i;
+       u32 reading_freq;
        int freq_cnt = 0;
        while (!kthread_should_stop()) {
-               usleep_range(15000,25000);
+               if (unipi_use_custom_speed) {
+                       mutex_lock(&unipi_inv_speed_mutex);
+                       reading_freq = unipi_custom_speed_value;
+                       mutex_unlock(&unipi_inv_speed_mutex);
+                       // TODO: This could be moved to sysfs.c so it does not have to be evaluated so often
+                       usleep_range((1000000 / (reading_freq * 4)) * 3, (1000000 / (reading_freq * 4)) * 5);
+               } else {
+                       usleep_range(15000,25000);
+               }
                if (freq_cnt == 450001) freq_cnt = 0;
                for (i = 0; i < NEURONSPI_MAX_DEVS; i++) {
                        if (neuronspi_s_dev[i] != NULL) {
index 4a2ce4e80cf27ed981adb7a6f36afa60156a0642..6bdb00565ab9ea4ed049b66efb81efdf51a02fd5 100644 (file)
@@ -61,6 +61,7 @@ struct neuronspi_char_driver neuronspi_cdrv =
 };
 
 struct mutex neuronspi_master_mutex;
+struct mutex unipi_inv_speed_mutex;
 struct spinlock* neuronspi_ldisc_spinlock;
 struct spinlock* neuronspi_spi_w_spinlock;
 u8 neuronspi_spi_w_flag = 1;
@@ -1536,6 +1537,7 @@ static s32 __init neuronspi_init(void)
        neuronspi_spi_w_spinlock = kzalloc(sizeof(struct spinlock), GFP_KERNEL);
        spin_lock_init(neuronspi_spi_w_spinlock);
        mutex_init(&neuronspi_master_mutex);
+       mutex_init(&unipi_inv_speed_mutex);
        memset(&neuronspi_s_dev, 0, sizeof(neuronspi_s_dev));
        ret = spi_register_driver(&neuronspi_spi_driver);
        if (ret < 0) {
index 4aa4bb8eba59ea181d5af0b8c985e1345ee1c495..dbf209bed6b63732d38016e1e9d15fe77e9d1713 100644 (file)
@@ -195,6 +195,8 @@ int neuronspi_spi_gpio_di_get(struct spi_device* spi_dev, u32 id);
 extern struct spi_driver neuronspi_spi_driver;
 extern struct file_operations file_ops;
 
+extern struct mutex unipi_inv_speed_mutex;
+
 static const struct regmap_bus neuronspi_regmap_bus =
 {
        .fast_io                                        = 0,
index de883e0a5731527a38692f227be9b96f99f239a9..3374d1507e117790a52cd43b6f13317ded6df2e8 100644 (file)
  ************/
 
 #include "unipi_sysfs.h"
+#include "unipi_spi.h"
+
+/*********************
+ * Data Declarations *
+ *********************/
+
+int unipi_use_custom_speed = 0;
+u32 unipi_custom_speed_value = NEURONSPI_DEFAULT_SYSFS_SPEED;
 
 /************************
  * Static Functions *
@@ -31,6 +39,36 @@ static ssize_t neuronspi_show_model(struct device *dev, struct device_attribute
        return ret;
 }
 
+static ssize_t neuronspi_show_sysfs_speed(struct device *dev, struct device_attribute *attr, char *buf)
+{
+       ssize_t ret = 0;
+       mutex_lock(&unipi_inv_speed_mutex);
+       ret = scnprintf(buf, 255, "%d Hz\n", unipi_custom_speed_value);
+       mutex_unlock(&unipi_inv_speed_mutex);
+       return ret;
+}
+
+static ssize_t neuronspi_store_sysfs_speed(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
+{
+       ssize_t err = 0;
+       unsigned int val = 0;
+       err = kstrtouint(buf, 0, &val);
+       if (err < 0) goto err_end;
+       if (val == NEURONSPI_DEFAULT_SYSFS_SPEED) {
+               unipi_use_custom_speed = 0;
+               mutex_lock(&unipi_inv_speed_mutex);
+               unipi_custom_speed_value = 50;
+               mutex_unlock(&unipi_inv_speed_mutex);
+       } else if (val > 0) {
+               unipi_use_custom_speed = 1;
+               mutex_lock(&unipi_inv_speed_mutex);
+               unipi_custom_speed_value = val > 1000 ? 1000 : val;
+               mutex_unlock(&unipi_inv_speed_mutex);
+       }
+err_end:
+       return count;
+}
+
 static ssize_t neuronspi_show_driver_version(struct device *dev, struct device_attribute *attr, char *buf)
 {
        ssize_t ret = 0;
@@ -797,7 +835,9 @@ static ssize_t neuronspi_spi_gpio_show_di_count(struct device *dev, struct devic
        n_di = platform_get_drvdata(plat);
        n_spi = spi_get_drvdata(n_di->spi);
        if (n_spi->features && n_spi->features->di_count > 0 && n_spi->di_driver) {
+               spin_lock(&n_spi->sysfs_regmap_lock);
                ret = scnprintf(buf, 255, "%d\n", n_spi->di_driver[n_di->di_index]->gpio_c.ngpio);
+               spin_unlock(&n_spi->sysfs_regmap_lock);
        }
        return ret;
 }
@@ -939,6 +979,7 @@ err_end:
  **********************************/
 
 static DEVICE_ATTR(model_name, 0440, neuronspi_show_model, NULL);
+static DEVICE_ATTR(sys_reading_freq, 0660, neuronspi_show_sysfs_speed, neuronspi_store_sysfs_speed);
 static DEVICE_ATTR(sys_eeprom_name, 0440, neuronspi_show_eeprom, NULL);
 static DEVICE_ATTR(driver_version, 0440, neuronspi_show_driver_version, NULL);
 static DEVICE_ATTR(register_read, 0660, neuronspi_show_regmap, neuronspi_store_regmap);
@@ -980,6 +1021,7 @@ static DEVICE_ATTR(mode_ao_type_b, 0660, neuronspi_iio_show_secondary_ao_mode, n
 
 static struct attribute *neuron_plc_attrs[] = {
                &dev_attr_model_name.attr,
+               &dev_attr_sysfs_reading_freq.attr,
                &dev_attr_sys_eeprom_name.attr,
                &dev_attr_driver_version.attr,
                NULL,
index bd558967863ba980d8a9b05e2d904d0d790a1a0a..560b3a800d31fa1a90e0848591f54d635e5cddf9 100644 (file)
 #include "unipi_common.h"
 #include "unipi_platform.h"
 
+#define NEURONSPI_DEFAULT_SYSFS_SPEED 50
+
+extern int unipi_use_custom_speed;
+extern u32 unipi_custom_speed_value;
+
 extern const struct attribute_group neuron_stm_ai_group;
 extern const struct attribute_group neuron_stm_ao_group;
 extern const struct attribute_group neuron_sec_ai_group;