]> rtime.felk.cvut.cz Git - pes-rpp/rpp-lib.git/commitdiff
Update adc and spi to the new port interface
authorMichal Sojka <sojkam1@fel.cvut.cz>
Sat, 1 Aug 2015 14:53:29 +0000 (16:53 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 7 Aug 2015 17:57:02 +0000 (19:57 +0200)
rpp/include/drv/adc.h
rpp/include/drv/spi.h
rpp/src/drv/_tms570_rpp/adc.c
rpp/src/drv/spi.c

index f3a9f70d1e1e80b4318f076bd855b1bdabe04c00..96b8fa7707808d19ef23d88f2ff9acdb5f3dd92e 100644 (file)
@@ -14,6 +14,7 @@
 #define __DRV_ADC_H
 
 #include "sys/ti_drv_adc.h"
+#include "drv/port.h"
 
 #define ADC_MAX_CHANNELS 24
 
@@ -26,5 +27,6 @@ uint32_t drv_adc_read_houtifbk(adcData_t *data);
 
 uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
                                                  uint32_t *values);
+int8_t port_adc_get(const struct port_desc *port, void *values, size_t size);
 
 #endif /* __DRV_ADC_H */
index 87094c8b3fa39b06ad26ea2f4574e86ccc684c38..5ab98540098f7c847476ca18c181647153eca209 100644 (file)
@@ -2,7 +2,7 @@
  *
  * @file spi.h
  *
- * @copyright Copyright (C) 2012-2013 Czech Technical University in Prague
+ * @copyright Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  */
 
@@ -24,5 +24,6 @@ UL_LIST_CUST_DEC(spi_rq_queue, spi_drv_t, spi_msg_head_t, rq_queue, node)
 int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void *rx_buf);
 //spi_drv_t *spi_find_drv(char *name, int number);
 int spi_msg_rq_ins(spi_drv_t *ifc, spi_msg_head_t *msg);
+int8_t port_spi_set(const struct port_desc *port, void *values, size_t size);
 
 #endif /* _SPI_DRV_H_ */
index 480daf740b706e049c1841376d10567893032580..54763e27f424bf575b997b59f19e3d09776e6344 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2012-2013 Czech Technical University in Prague
+/* Copyright (C) 2012-2013, 2015 Czech Technical University in Prague
  *
  * Authors:
  *     - Michal Horn
@@ -19,6 +19,7 @@
 
 
 #include "drv/drv.h"
+#include "drv/port.h"
 
 // Binary semaphore for ADC1 GRP1 conversion (AIN)
 xSemaphoreHandle adcSemaphore_ADC1GRP1;
@@ -158,26 +159,27 @@ uint32_t drv_adc_read_houtifbk(adcData_t *data)
        return result;
 }
 
-uint32_t adc_get_port_val(uint32_t *config, uint32_t num_channels,
-                                                 uint32_t *values)
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+int8_t port_adc_get(const struct port_desc *port, void *values, size_t size)
 {
        uint32_t i;
-       adcBASE_t *adcReg = (adcBASE_t *)config[0];
-       uint32_t adcGroup = config[1];
-       uint32_t adcSemaphore = config[2];
        adcData_t data[ADC_MAX_CHANNELS];
+       int count = MIN(port->numchn, size/sizeof(uint16_t));
+       uint16_t *adcval = values;
+
+       assert(port->bpch == 16);
+       assert(size % sizeof(uint16_t) == 0);
 
        drv_adc_generic_read(
-               adcReg,
-               adcGroup,
-               (adcSemaphore == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
+               port->cfg.adc.reg,
+               port->cfg.adc.group,
+               (port->cfg.adc.sem == 1) ? adcSemaphore_ADC1GRP1 : adcSemaphore_ADC2GRP1,
                data
                );
 
-       for (i = 0; i < num_channels; i++) {
-               values[i] = data[i].value;
-               values[i+num_channels] = data[i].id;
-       }
+       for (i = 0; i < count; i++)
+               adcval[i] = data[i].value;
 
        return 0;
 }
index d4ed1bf0f50b9b4ba31958aaa236be5119af8ab3..1cb0ca5be44ff2e08aaa286967b6b612650d6e0c 100644 (file)
@@ -65,3 +65,27 @@ int spi_transfer(spi_drv_t *ifc, int addr, int rq_len, const void *tx_buf, void
 
        return msg.rq_len;
 }
+
+#define MIN(a,b) ((a) < (b) ? (a) : (b))
+
+int8_t port_spi_set(const struct port_desc *port, void *values, size_t size)
+{
+       spi_drv_t *ifc;
+       uint8_t rx[4];
+
+       assert(port->numchn == 1);
+       assert(size == port->bpch/8);
+       assert(size <= sizeof(rx));
+
+       ifc = spi_find_drv(NULL, port->cfg.spi.ifc);
+       if (ifc == NULL)
+               return FAILURE;
+
+       if (!(ifc->flags & SPI_IFC_ON))
+               return FAILURE;
+
+       spi_transfer(ifc, port->cfg.spi.cs, size, values, rx);
+
+       memcpy(values, rx, MIN(size, port->numchn * port->bpch/8));
+       return SUCCESS;
+}