Parcourir la source

Работа с ADC.

TelenkovDmitry il y a 1 an
Parent
commit
2965acc424
43 fichiers modifiés avec 6593 ajouts et 1621 suppressions
  1. BIN
      doc/ADC_AD.pdf
  2. BIN
      doc/MS5192T_C1509032.pdf
  3. BIN
      doc/adc/ad7793_generic.zip
  4. 313 0
      doc/adc/ad7793_generic/AD7793.c
  5. 194 0
      doc/adc/ad7793_generic/AD7793.h
  6. 113 0
      doc/adc/ad7793_generic/Communication.c
  7. 71 0
      doc/adc/ad7793_generic/Communication.h
  8. BIN
      doc/adc/ad7793_rl78g13.zip
  9. 313 0
      doc/adc/ad7793_rl78g13/AD7793.c
  10. 194 0
      doc/adc/ad7793_rl78g13/AD7793.h
  11. 186 0
      doc/adc/ad7793_rl78g13/Communication.c
  12. 78 0
      doc/adc/ad7793_rl78g13/Communication.h
  13. 165 0
      doc/adc/ad7793_rl78g13/Main.c
  14. 376 0
      doc/adc/ad7793_rl78g13/ST7579.c
  15. 78 0
      doc/adc/ad7793_rl78g13/ST7579.h
  16. 77 0
      doc/adc/ad7793_rl78g13/YRDKRL78G13.c
  17. 72 0
      doc/adc/ad7793_rl78g13/YRDKRL78G13.h
  18. BIN
      doc/adc/ad7793_rx62n.zip
  19. 244 0
      doc/adc/ad7793_rx62n/AD7793.c
  20. 171 0
      doc/adc/ad7793_rx62n/AD7793.h
  21. 292 0
      doc/adc/ad7793_rx62n/Communication.c
  22. 80 0
      doc/adc/ad7793_rx62n/Communication.h
  23. 159 0
      doc/adc/ad7793_rx62n/Main.c
  24. 375 0
      doc/adc/ad7793_rx62n/ST7579.c
  25. 77 0
      doc/adc/ad7793_rx62n/ST7579.h
  26. 96 0
      doc/adc/ad7793_rx62n/YRDKRX62N.c
  27. 93 0
      doc/adc/ad7793_rx62n/YRDKRX62N.h
  28. 271 0
      fw/modules/adc/AD7793.c
  29. 5 0
      fw/modules/adc/Communication.c
  30. 22 0
      fw/modules/adc/Communication.h
  31. 313 0
      fw/modules/adc/adc_transport.c
  32. 34 0
      fw/modules/adc/adc_transport.h
  33. 272 110
      fw/modules/adc/ms5192t.c
  34. 150 14
      fw/modules/adc/ms5192t.h
  35. 151 0
      fw/modules/adc/ms5192t_old.c
  36. 18 0
      fw/modules/adc/ms5192t_old.h
  37. 304 299
      fw/user/main.c
  38. 40 40
      fw/user/main.h
  39. BIN
      output/fw.bin
  40. 362 364
      project/ewarm/iap/iap.dep
  41. 828 794
      project/ewarm/module_universal_io.dep
  42. 3 0
      project/ewarm/module_universal_io.ewp
  43. 3 0
      project/ewarm/module_universal_io.ewt

BIN
doc/ADC_AD.pdf


BIN
doc/MS5192T_C1509032.pdf


BIN
doc/adc/ad7793_generic.zip


+ 313 - 0
doc/adc/ad7793_generic/AD7793.c

@@ -0,0 +1,313 @@
+/***************************************************************************//**
+ *   @file   AD7793.c
+ *   @brief  Implementation of AD7793 Driver.
+ *   @author Bancisor MIhai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 500
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "AD7793.h"				// AD7793 definitions.
+#include "Communication.h"		// Communication definitions.
+
+/***************************************************************************//**
+ * @brief Initializes the AD7793 and checks if the device is present.
+ *
+ * @return status - Result of the initialization procedure.
+ *                  Example: 1 - if initialization was successful (ID is 0x0B).
+ *                           0 - if initialization was unsuccessful.
+*******************************************************************************/
+unsigned char AD7793_Init(void)
+{ 
+	unsigned char status = 0x1;
+    
+    SPI_Init(0, 1000000, 1, 1);
+    if((AD7793_GetRegisterValue(AD7793_REG_ID, 1, 1) & 0x0F) != AD7793_ID)
+	{
+		status = 0x0;
+	}
+    
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Sends 32 consecutive 1's on SPI in order to reset the part.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_Reset(void)
+{
+	unsigned char dataToSend[5] = {0x03, 0xff, 0xff, 0xff, 0xff};
+	
+    ADI_PART_CS_LOW;	    
+	SPI_Write(dataToSend,4);
+	ADI_PART_CS_HIGH;	
+}
+/***************************************************************************//**
+ * @brief Reads the value of the selected register
+ *
+ * @param regAddress - The address of the register to read.
+ * @param size - The size of the register to read.
+ *
+ * @return data - The value of the selected register register.
+*******************************************************************************/
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, 
+                                      unsigned char size,
+                                      unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};
+	unsigned long receivedData = 0x00;
+    unsigned char i            = 0x00; 
+    
+	data[0] = 0x01 * modifyCS;
+	data[1] = AD7793_COMM_READ |  AD7793_COMM_ADDR(regAddress); 
+	SPI_Read(data,(1 + size));
+	for(i = 1;i < size + 1;i ++)
+    {
+        receivedData = (receivedData << 8) + data[i];
+    }
+    
+    return (receivedData);
+}
+/***************************************************************************//**
+ * @brief Writes the value to the register
+ *
+ * @param -  regAddress - The address of the register to write to.
+ * @param -  regValue - The value to write to the register.
+ * @param -  size - The size of the register to write.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetRegisterValue(unsigned char regAddress,
+                             unsigned long regValue, 
+                             unsigned char size,
+                             unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};	
+	unsigned char* dataPointer = (unsigned char*)&regValue;
+    unsigned char bytesNr      = size + 1;
+    
+    data[0] = 0x01 * modifyCS;
+    data[1] = AD7793_COMM_WRITE |  AD7793_COMM_ADDR(regAddress);
+    while(bytesNr > 1)
+    {
+        data[bytesNr] = *dataPointer;
+        dataPointer ++;
+        bytesNr --;
+    }	    
+	SPI_Write(data,(1 + size));
+}
+/***************************************************************************//**
+ * @brief  Waits for RDY pin to go low.
+ *
+ * @return None.
+*******************************************************************************/
+void AD7793_WaitRdyGoLow(void)
+{
+    while( AD7793_RDY_STATE )
+    {
+        ;
+    }
+}
+
+/***************************************************************************//**
+ * @brief Sets the operating mode of AD7793.
+ *
+ * @param mode - Mode of operation.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetMode(unsigned long mode)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_MODE,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_MODE_SEL(0xFF);
+    command |= AD7793_MODE_SEL(mode);
+    AD7793_SetRegisterValue(
+            AD7793_REG_MODE,
+            command,
+            2, 
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Selects the channel of AD7793.
+ *
+ * @param  channel - ADC channel selection.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetChannel(unsigned long channel)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_CHAN(0xFF);
+    command |= AD7793_CONF_CHAN(channel);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief  Sets the gain of the In-Amp.
+ *
+ * @param  gain - Gain.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetGain(unsigned long gain)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_GAIN(0xFF);
+    command |= AD7793_CONF_GAIN(gain);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Sets the reference source for the ADC.
+ *
+ * @param type - Type of the reference.
+ *               Example: AD7793_REFSEL_EXT	- External Reference Selected
+ *                        AD7793_REFSEL_INT	- Internal Reference Selected.
+ *
+ * @return None.    
+*******************************************************************************/
+void AD7793_SetIntReference(unsigned char type)
+{
+    unsigned long command = 0;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_REFSEL(AD7793_REFSEL_INT);
+    command |= AD7793_CONF_REFSEL(type);
+    AD7793_SetRegisterValue(AD7793_REG_CONF,
+							command,
+							2,
+                            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief Performs the given calibration to the specified channel.
+ *
+ * @param mode - Calibration type.
+ * @param channel - Channel to be calibrated.
+ *
+ * @return none.
+*******************************************************************************/
+void AD7793_Calibrate(unsigned char mode, unsigned char channel)
+{
+    unsigned short oldRegValue = 0x0;
+    unsigned short newRegValue = 0x0;
+    
+    AD7793_SetChannel(channel);
+    oldRegValue &= AD7793_GetRegisterValue(AD7793_REG_MODE, 2, 1); // CS is modified by SPI read/write functions.
+    oldRegValue &= ~AD7793_MODE_SEL(0x7);
+    newRegValue = oldRegValue | AD7793_MODE_SEL(mode);
+    ADI_PART_CS_LOW; 
+    AD7793_SetRegisterValue(AD7793_REG_MODE, newRegValue, 2, 0); // CS is not modified by SPI read/write functions.
+    AD7793_WaitRdyGoLow();
+    ADI_PART_CS_HIGH;
+    
+}
+
+/***************************************************************************//**
+ * @brief Returns the result of a single conversion.
+ *
+ * @return regData - Result of a single analog-to-digital conversion.
+*******************************************************************************/
+unsigned long AD7793_SingleConversion(void)
+{
+    unsigned long command = 0x0;
+    unsigned long regData = 0x0;
+    
+    command  = AD7793_MODE_SEL(AD7793_MODE_SINGLE);
+    ADI_PART_CS_LOW;
+    AD7793_SetRegisterValue(AD7793_REG_MODE, 
+                            command,
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    AD7793_WaitRdyGoLow();
+    regData = AD7793_GetRegisterValue(AD7793_REG_DATA, 3, 0); // CS is not modified by SPI read/write functions.
+    ADI_PART_CS_HIGH;
+
+    return(regData);
+}
+
+/***************************************************************************//**
+ * @brief Returns the average of several conversion results.
+ *
+ * @return samplesAverage - The average of the conversion results.
+*******************************************************************************/
+unsigned long AD7793_ContinuousReadAvg(unsigned char sampleNumber)
+{
+    unsigned long samplesAverage = 0x0;
+    unsigned long command        = 0x0;
+    unsigned char count          = 0x0;
+    
+    command = AD7793_MODE_SEL(AD7793_MODE_CONT);
+    ADI_PART_CS_LOW;
+    AD7793_SetRegisterValue(AD7793_REG_MODE,
+                            command, 
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    for(count = 0;count < sampleNumber;count ++)
+    {
+        AD7793_WaitRdyGoLow();
+        samplesAverage += AD7793_GetRegisterValue(AD7793_REG_DATA, 3, 0);  // CS is not modified by SPI read/write functions.
+    }
+    ADI_PART_CS_HIGH;
+    samplesAverage = samplesAverage / sampleNumber;
+    
+    return(samplesAverage);
+}

+ 194 - 0
doc/adc/ad7793_generic/AD7793.h

@@ -0,0 +1,194 @@
+/***************************************************************************//**
+ *   @file   AD7793.h
+ *   @brief  Header file of AD7793 Driver.
+ *   @author Bancisor Mihai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 500
+*******************************************************************************/
+#ifndef __AD7793_H__
+#define __AD7793_H__
+
+/******************************************************************************/
+/* AD7793                                                                   */
+/******************************************************************************/
+
+/* AD7793 GPIO */
+#define AD7793_RDY_STATE       GPIO1_STATE
+
+/*AD7793 Registers*/
+#define AD7793_REG_COMM		0 /* Communications Register(WO, 8-bit) */
+#define AD7793_REG_STAT	    0 /* Status Register	    (RO, 8-bit) */
+#define AD7793_REG_MODE	    1 /* Mode Register	     	(RW, 16-bit */
+#define AD7793_REG_CONF	    2 /* Configuration Register (RW, 16-bit)*/
+#define AD7793_REG_DATA	    3 /* Data Register	     	(RO, 16-/24-bit) */
+#define AD7793_REG_ID	    4 /* ID Register	     	(RO, 8-bit) */
+#define AD7793_REG_IO	    5 /* IO Register	     	(RO, 8-bit) */
+#define AD7793_REG_OFFSET   6 /* Offset Register	    (RW, 24-bit */
+#define AD7793_REG_FULLSALE	7 /* Full-Scale Register	(RW, 24-bit */
+
+/* Communications Register Bit Designations (AD7793_REG_COMM) */
+#define AD7793_COMM_WEN		(1 << 7) 			/* Write Enable */
+#define AD7793_COMM_WRITE	(0 << 6) 			/* Write Operation */
+#define AD7793_COMM_READ    (1 << 6) 			/* Read Operation */
+#define AD7793_COMM_ADDR(x)	(((x) & 0x7) << 3)	/* Register Address */
+#define AD7793_COMM_CREAD	(1 << 2) 			/* Continuous Read of Data Register */
+
+/* Status Register Bit Designations (AD7793_REG_STAT) */
+#define AD7793_STAT_RDY		(1 << 7) /* Ready */
+#define AD7793_STAT_ERR		(1 << 6) /* Error (Overrange, Underrange) */
+#define AD7793_STAT_CH3		(1 << 2) /* Channel 3 */
+#define AD7793_STAT_CH2		(1 << 1) /* Channel 2 */
+#define AD7793_STAT_CH1		(1 << 0) /* Channel 1 */
+
+/* Mode Register Bit Designations (AD7793_REG_MODE) */
+#define AD7793_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
+#define AD7793_MODE_CLKSRC(x)	(((x) & 0x3) << 6) 	/* ADC Clock Source Select */
+#define AD7793_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */
+
+/* AD7793_MODE_SEL(x) options */
+#define AD7793_MODE_CONT		 0 /* Continuous Conversion Mode */
+#define AD7793_MODE_SINGLE		 1 /* Single Conversion Mode */
+#define AD7793_MODE_IDLE		 2 /* Idle Mode */
+#define AD7793_MODE_PWRDN		 3 /* Power-Down Mode */
+#define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
+#define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
+
+/* AD7793_MODE_CLKSRC(x) options */
+#define AD7793_CLK_INT		0 /* Internal 64 kHz Clk not available at the CLK pin */
+#define AD7793_CLK_INT_CO	1 /* Internal 64 kHz Clk available at the CLK pin */
+#define AD7793_CLK_EXT		2 /* External 64 kHz Clock */
+#define AD7793_CLK_EXT_DIV2	3 /* External Clock divided by 2 */
+
+/* Configuration Register Bit Designations (AD7793_REG_CONF) */
+#define AD7793_CONF_VBIAS(x)  (((x) & 0x3) << 14) 	/* Bias Voltage Generator Enable */
+#define AD7793_CONF_BO_EN	  (1 << 13) 			/* Burnout Current Enable */
+#define AD7793_CONF_UNIPOLAR  (1 << 12) 			/* Unipolar/Bipolar Enable */
+#define AD7793_CONF_BOOST	  (1 << 11) 			/* Boost Enable */
+#define AD7793_CONF_GAIN(x)	  (((x) & 0x7) << 8) 	/* Gain Select */
+#define AD7793_CONF_REFSEL(x) (((x) & 0x1) << 7) 	/* INT/EXT Reference Select */
+#define AD7793_CONF_BUF		  (1 << 4) 				/* Buffered Mode Enable */
+#define AD7793_CONF_CHAN(x)	  ((x) & 0x7) 			/* Channel select */
+
+/* AD7793_CONF_GAIN(x) options */
+#define AD7793_GAIN_1       0
+#define AD7793_GAIN_2       1
+#define AD7793_GAIN_4       2
+#define AD7793_GAIN_8       3
+#define AD7793_GAIN_16      4
+#define AD7793_GAIN_32      5
+#define AD7793_GAIN_64      6
+#define AD7793_GAIN_128     7
+
+/* AD7793_CONF_REFSEL(x) options */
+#define AD7793_REFSEL_INT   1	/* Internal Reference Selected. */
+#define AD7793_REFSEL_EXT   0	/* External Reference Applied between REFIN(+) and REFIN(–). */
+
+/* AD7793_CONF_CHAN(x) options */
+#define AD7793_CH_AIN1P_AIN1M	0 /* AIN1(+) - AIN1(-) */
+#define AD7793_CH_AIN2P_AIN2M	1 /* AIN2(+) - AIN2(-) */
+#define AD7793_CH_AIN3P_AIN3M	2 /* AIN3(+) - AIN3(-) */
+#define AD7793_CH_AIN1M_AIN1M	3 /* AIN1(-) - AIN1(-) */
+#define AD7793_CH_TEMP			6 /* Temp Sensor */
+#define AD7793_CH_AVDD_MONITOR	7 /* AVDD Monitor */
+
+/* ID Register Bit Designations (AD7793_REG_ID) */
+#define AD7793_ID			0xB
+#define AD7793_ID_MASK		0xF
+
+/* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */
+#define AD7793_IEXCDIR(x)	(((x) & 0x3) << 2)
+#define AD7793_IEXCEN(x)	(((x) & 0x3) << 0)
+
+/* AD7793_IEXCDIR(x) options*/
+#define AD7793_DIR_IEXC1_IOUT1_IEXC2_IOUT2	0  /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
+#define AD7793_DIR_IEXC1_IOUT2_IEXC2_IOUT1	1  /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT1		2  /* Both current sources IEXC1,2 connect to IOUT1  */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT2		3  /* Both current sources IEXC1,2 connect to IOUT2 */
+
+/* AD7793_IEXCEN(x) options*/
+#define AD7793_EN_IXCEN_10uA				1  /* Excitation Current 10uA */
+#define AD7793_EN_IXCEN_210uA				2  /* Excitation Current 210uA */
+#define AD7793_EN_IXCEN_1mA					3  /* Excitation Current 1mA */
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+/* Initialize AD7793 and check if the device is present*/
+unsigned char AD7793_Init(void);
+
+/* Sends 32 consecutive 1's on SPI in order to reset the part. */
+void AD7793_Reset(void);
+
+/* Reads the value of the selected register. */
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, 
+									  unsigned char size,
+                                      unsigned char modifyCS);
+
+/* Writes a value to the register. */
+void AD7793_SetRegisterValue(unsigned char regAddress,
+							 unsigned long regValue, 
+							 unsigned char size,
+                             unsigned char modifyCS);
+
+/* Waits for RDY pin to go low. */
+void AD7793_WaitRdyGoLow(void);
+
+/* Sets the operating mode of AD7793. */
+void AD7793_SetMode(unsigned long mode);     
+
+/* Selects the channel of AD7793. */
+void AD7793_SetChannel(unsigned long channel);
+
+/* Sets the gain of the In-Amp. */
+void AD7793_SetGain(unsigned long gain);
+
+/* Sets the reference source for the ADC. */
+void AD7793_SetIntReference(unsigned char type);
+
+/* Performs the given calibration to the specified channel. */
+void AD7793_Calibrate(unsigned char mode, unsigned char channel);
+
+/* Returns the result of a single conversion. */
+unsigned long AD7793_SingleConversion(void);
+
+/* Returns the average of several conversion results. */
+unsigned long AD7793_ContinuousReadAvg(unsigned char sampleNumber);
+
+#endif	// _AD7793_H_

+ 113 - 0
doc/adc/ad7793_generic/Communication.c

@@ -0,0 +1,113 @@
+/***************************************************************************//**
+ *   @file   Communication.c
+ *   @brief  Implementation of Communication Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 500
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "Communication.h"
+
+/***************************************************************************//**
+ * @brief Initializes the SPI communication peripheral.
+ *
+ * @param lsbFirst - Transfer format (0 or 1).
+ *                   Example: 0x0 - MSB first.
+ *                            0x1 - LSB first.
+ * @param clockFreq - SPI clock frequency (Hz).
+ *                    Example: 1000 - SPI clock frequency is 1 kHz.
+ * @param clockPol - SPI clock polarity (0 or 1).
+ *                   Example: 0x0 - idle state for SPI clock is low.
+ *	                          0x1 - idle state for SPI clock is high.
+ * @param clockPha - SPI clock phase (0 or 1).
+ *                   Example: 0x0 - data is latched on the leading edge of SPI
+ *                                  clock and data changes on trailing edge.
+ *                            0x1 - data is latched on the trailing edge of SPI
+ *                                  clock and data changes on the leading edge.
+ *
+ * @return 0 - Initialization failed, 1 - Initialization succeeded.
+*******************************************************************************/
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha)
+{
+	// Add your code here.
+	
+    return(1);
+}
+
+/***************************************************************************//**
+ * @brief Writes data to SPI.
+ *
+ * @param data - Write data buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber)
+{
+	// Add your code here.
+
+	return(bytesNumber);
+}
+
+/***************************************************************************//**
+ * @brief Reads data from SPI.
+ *
+ * @param data - As an input parameter, data represents the write buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ *               As an output parameter, data represents the read buffer:
+ *               - from the first byte onwards are located the read data bytes. 
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber)
+{
+	// Add your code here.
+
+	return(bytesNumber);
+}

+ 71 - 0
doc/adc/ad7793_generic/Communication.h

@@ -0,0 +1,71 @@
+/***************************************************************************//**
+ *   @file   Communication.h
+ *   @brief  Header file of Communication Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 500
+*******************************************************************************/
+#ifndef _COMMUNICATION_H_
+#define _COMMUNICATION_H_
+
+/******************************************************************************/
+/* GPIO Definitions                                                           */
+/******************************************************************************/
+
+#define ADI_PAR_CS_PIN        		// Add code here
+#define ADI_PART_CS_PIN_OUT   		// Add code here
+#define ADI_PART_CS_LOW        		// Add code here
+#define ADI_PART_CS_HIGH       		// Add code here
+#define GPIO1_PIN              		// Add code here
+#define GPIO1_STATE            		// Add code here
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+/* Initializes the SPI communication peripheral. */
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha);
+/* Writes data to SPI. */
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber);
+/* Reads data from SPI. */
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber);
+
+#endif	// _COMMUNICATION_H_

BIN
doc/adc/ad7793_rl78g13.zip


+ 313 - 0
doc/adc/ad7793_rl78g13/AD7793.c

@@ -0,0 +1,313 @@
+/***************************************************************************//**
+ *   @file   AD7793.c
+ *   @brief  Implementation of AD7793 Driver.
+ *   @author Bancisor MIhai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "AD7793.h"				// AD7793 definitions.
+#include "Communication.h"		// Communication definitions.
+
+/***************************************************************************//**
+ * @brief Initializes the AD7793 and checks if the device is present.
+ *
+ * @return status - Result of the initialization procedure.
+ *                  Example: 1 - if initialization was successful (ID is 0x0B).
+ *                           0 - if initialization was unsuccessful.
+*******************************************************************************/
+unsigned char AD7793_Init(void)
+{ 
+	unsigned char status = 0x1;
+    
+    SPI_Init(0, 1000000, 1, 1);
+    if((AD7793_GetRegisterValue(AD7793_REG_ID, 1, 1) & 0x0F) != AD7793_ID)
+	{
+		status = 0x0;
+	}
+    
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Sends 32 consecutive 1's on SPI in order to reset the part.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_Reset(void)
+{
+	unsigned char dataToSend[5] = {0x03, 0xff, 0xff, 0xff, 0xff};
+	
+    ADI_PART_CS_LOW;	    
+	SPI_Write(dataToSend,4);
+	ADI_PART_CS_HIGH;	
+}
+/***************************************************************************//**
+ * @brief Reads the value of the selected register
+ *
+ * @param regAddress - The address of the register to read.
+ * @param size - The size of the register to read.
+ *
+ * @return data - The value of the selected register register.
+*******************************************************************************/
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, 
+                                      unsigned char size,
+                                      unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};
+	unsigned long receivedData = 0x00;
+    unsigned char i            = 0x00; 
+    
+	data[0] = 0x01 * modifyCS;
+	data[1] = AD7793_COMM_READ |  AD7793_COMM_ADDR(regAddress); 
+	SPI_Read(data,(1 + size));
+	for(i = 1;i < size + 1;i ++)
+    {
+        receivedData = (receivedData << 8) + data[i];
+    }
+    
+    return (receivedData);
+}
+/***************************************************************************//**
+ * @brief Writes the value to the register
+ *
+ * @param -  regAddress - The address of the register to write to.
+ * @param -  regValue - The value to write to the register.
+ * @param -  size - The size of the register to write.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetRegisterValue(unsigned char regAddress,
+                             unsigned long regValue, 
+                             unsigned char size,
+                             unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};	
+	unsigned char* dataPointer = (unsigned char*)&regValue;
+    unsigned char bytesNr      = size + 1;
+    
+    data[0] = 0x01 * modifyCS;
+    data[1] = AD7793_COMM_WRITE |  AD7793_COMM_ADDR(regAddress);
+    while(bytesNr > 1)
+    {
+        data[bytesNr] = *dataPointer;
+        dataPointer ++;
+        bytesNr --;
+    }	    
+	SPI_Write(data,(1 + size));
+}
+/***************************************************************************//**
+ * @brief  Waits for RDY pin to go low.
+ *
+ * @return None.
+*******************************************************************************/
+void AD7793_WaitRdyGoLow(void)
+{
+    while( AD7793_RDY_STATE )
+    {
+        ;
+    }
+}
+
+/***************************************************************************//**
+ * @brief Sets the operating mode of AD7793.
+ *
+ * @param mode - Mode of operation.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetMode(unsigned long mode)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_MODE,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_MODE_SEL(0xFF);
+    command |= AD7793_MODE_SEL(mode);
+    AD7793_SetRegisterValue(
+            AD7793_REG_MODE,
+            command,
+            2, 
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Selects the channel of AD7793.
+ *
+ * @param  channel - ADC channel selection.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetChannel(unsigned long channel)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_CHAN(0xFF);
+    command |= AD7793_CONF_CHAN(channel);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief  Sets the gain of the In-Amp.
+ *
+ * @param  gain - Gain.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetGain(unsigned long gain)
+{
+    unsigned long command;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_GAIN(0xFF);
+    command |= AD7793_CONF_GAIN(gain);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Sets the reference source for the ADC.
+ *
+ * @param type - Type of the reference.
+ *               Example: AD7793_REFSEL_EXT	- External Reference Selected
+ *                        AD7793_REFSEL_INT	- Internal Reference Selected.
+ *
+ * @return None.    
+*******************************************************************************/
+void AD7793_SetIntReference(unsigned char type)
+{
+    unsigned long command = 0;
+    
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~AD7793_CONF_REFSEL(AD7793_REFSEL_INT);
+    command |= AD7793_CONF_REFSEL(type);
+    AD7793_SetRegisterValue(AD7793_REG_CONF,
+							command,
+							2,
+                            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief Performs the given calibration to the specified channel.
+ *
+ * @param mode - Calibration type.
+ * @param channel - Channel to be calibrated.
+ *
+ * @return none.
+*******************************************************************************/
+void AD7793_Calibrate(unsigned char mode, unsigned char channel)
+{
+    unsigned short oldRegValue = 0x0;
+    unsigned short newRegValue = 0x0;
+    
+    AD7793_SetChannel(channel);
+    oldRegValue &= AD7793_GetRegisterValue(AD7793_REG_MODE, 2, 1); // CS is modified by SPI read/write functions.
+    oldRegValue &= ~AD7793_MODE_SEL(0x7);
+    newRegValue = oldRegValue | AD7793_MODE_SEL(mode);
+    ADI_PART_CS_LOW; 
+    AD7793_SetRegisterValue(AD7793_REG_MODE, newRegValue, 2, 0); // CS is not modified by SPI read/write functions.
+    AD7793_WaitRdyGoLow();
+    ADI_PART_CS_HIGH;
+    
+}
+
+/***************************************************************************//**
+ * @brief Returns the result of a single conversion.
+ *
+ * @return regData - Result of a single analog-to-digital conversion.
+*******************************************************************************/
+unsigned long AD7793_SingleConversion(void)
+{
+    unsigned long command = 0x0;
+    unsigned long regData = 0x0;
+    
+    command  = AD7793_MODE_SEL(AD7793_MODE_SINGLE);
+    ADI_PART_CS_LOW;
+    AD7793_SetRegisterValue(AD7793_REG_MODE, 
+                            command,
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    AD7793_WaitRdyGoLow();
+    regData = AD7793_GetRegisterValue(AD7793_REG_DATA, 3, 0); // CS is not modified by SPI read/write functions.
+    ADI_PART_CS_HIGH;
+
+    return(regData);
+}
+
+/***************************************************************************//**
+ * @brief Returns the average of several conversion results.
+ *
+ * @return samplesAverage - The average of the conversion results.
+*******************************************************************************/
+unsigned long AD7793_ContinuousReadAvg(unsigned char sampleNumber)
+{
+    unsigned long samplesAverage = 0x0;
+    unsigned long command        = 0x0;
+    unsigned char count          = 0x0;
+    
+    command = AD7793_MODE_SEL(AD7793_MODE_CONT);
+    ADI_PART_CS_LOW;
+    AD7793_SetRegisterValue(AD7793_REG_MODE,
+                            command, 
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    for(count = 0;count < sampleNumber;count ++)
+    {
+        AD7793_WaitRdyGoLow();
+        samplesAverage += AD7793_GetRegisterValue(AD7793_REG_DATA, 3, 0);  // CS is not modified by SPI read/write functions.
+    }
+    ADI_PART_CS_HIGH;
+    samplesAverage = samplesAverage / sampleNumber;
+    
+    return(samplesAverage);
+}

+ 194 - 0
doc/adc/ad7793_rl78g13/AD7793.h

@@ -0,0 +1,194 @@
+/***************************************************************************//**
+ *   @file   AD7793.h
+ *   @brief  Header file of AD7793 Driver.
+ *   @author Bancisor Mihai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+#ifndef __AD7793_H__
+#define __AD7793_H__
+
+/******************************************************************************/
+/* AD7793                                                                   */
+/******************************************************************************/
+
+/* AD7793 GPIO */
+#define AD7793_RDY_STATE       GPIO1_STATE
+
+/*AD7793 Registers*/
+#define AD7793_REG_COMM		0 /* Communications Register(WO, 8-bit) */
+#define AD7793_REG_STAT	    0 /* Status Register	    (RO, 8-bit) */
+#define AD7793_REG_MODE	    1 /* Mode Register	     	(RW, 16-bit */
+#define AD7793_REG_CONF	    2 /* Configuration Register (RW, 16-bit)*/
+#define AD7793_REG_DATA	    3 /* Data Register	     	(RO, 16-/24-bit) */
+#define AD7793_REG_ID	    4 /* ID Register	     	(RO, 8-bit) */
+#define AD7793_REG_IO	    5 /* IO Register	     	(RO, 8-bit) */
+#define AD7793_REG_OFFSET   6 /* Offset Register	    (RW, 24-bit */
+#define AD7793_REG_FULLSALE	7 /* Full-Scale Register	(RW, 24-bit */
+
+/* Communications Register Bit Designations (AD7793_REG_COMM) */
+#define AD7793_COMM_WEN		(1 << 7) 			/* Write Enable */
+#define AD7793_COMM_WRITE	(0 << 6) 			/* Write Operation */
+#define AD7793_COMM_READ    (1 << 6) 			/* Read Operation */
+#define AD7793_COMM_ADDR(x)	(((x) & 0x7) << 3)	/* Register Address */
+#define AD7793_COMM_CREAD	(1 << 2) 			/* Continuous Read of Data Register */
+
+/* Status Register Bit Designations (AD7793_REG_STAT) */
+#define AD7793_STAT_RDY		(1 << 7) /* Ready */
+#define AD7793_STAT_ERR		(1 << 6) /* Error (Overrange, Underrange) */
+#define AD7793_STAT_CH3		(1 << 2) /* Channel 3 */
+#define AD7793_STAT_CH2		(1 << 1) /* Channel 2 */
+#define AD7793_STAT_CH1		(1 << 0) /* Channel 1 */
+
+/* Mode Register Bit Designations (AD7793_REG_MODE) */
+#define AD7793_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
+#define AD7793_MODE_CLKSRC(x)	(((x) & 0x3) << 6) 	/* ADC Clock Source Select */
+#define AD7793_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */
+
+/* AD7793_MODE_SEL(x) options */
+#define AD7793_MODE_CONT		 0 /* Continuous Conversion Mode */
+#define AD7793_MODE_SINGLE		 1 /* Single Conversion Mode */
+#define AD7793_MODE_IDLE		 2 /* Idle Mode */
+#define AD7793_MODE_PWRDN		 3 /* Power-Down Mode */
+#define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
+#define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
+
+/* AD7793_MODE_CLKSRC(x) options */
+#define AD7793_CLK_INT		0 /* Internal 64 kHz Clk not available at the CLK pin */
+#define AD7793_CLK_INT_CO	1 /* Internal 64 kHz Clk available at the CLK pin */
+#define AD7793_CLK_EXT		2 /* External 64 kHz Clock */
+#define AD7793_CLK_EXT_DIV2	3 /* External Clock divided by 2 */
+
+/* Configuration Register Bit Designations (AD7793_REG_CONF) */
+#define AD7793_CONF_VBIAS(x)  (((x) & 0x3) << 14) 	/* Bias Voltage Generator Enable */
+#define AD7793_CONF_BO_EN	  (1 << 13) 			/* Burnout Current Enable */
+#define AD7793_CONF_UNIPOLAR  (1 << 12) 			/* Unipolar/Bipolar Enable */
+#define AD7793_CONF_BOOST	  (1 << 11) 			/* Boost Enable */
+#define AD7793_CONF_GAIN(x)	  (((x) & 0x7) << 8) 	/* Gain Select */
+#define AD7793_CONF_REFSEL(x) (((x) & 0x1) << 7) 	/* INT/EXT Reference Select */
+#define AD7793_CONF_BUF		  (1 << 4) 				/* Buffered Mode Enable */
+#define AD7793_CONF_CHAN(x)	  ((x) & 0x7) 			/* Channel select */
+
+/* AD7793_CONF_GAIN(x) options */
+#define AD7793_GAIN_1       0
+#define AD7793_GAIN_2       1
+#define AD7793_GAIN_4       2
+#define AD7793_GAIN_8       3
+#define AD7793_GAIN_16      4
+#define AD7793_GAIN_32      5
+#define AD7793_GAIN_64      6
+#define AD7793_GAIN_128     7
+
+/* AD7793_CONF_REFSEL(x) options */
+#define AD7793_REFSEL_INT   1	/* Internal Reference Selected. */
+#define AD7793_REFSEL_EXT   0	/* External Reference Applied between REFIN(+) and REFIN(–). */
+
+/* AD7793_CONF_CHAN(x) options */
+#define AD7793_CH_AIN1P_AIN1M	0 /* AIN1(+) - AIN1(-) */
+#define AD7793_CH_AIN2P_AIN2M	1 /* AIN2(+) - AIN2(-) */
+#define AD7793_CH_AIN3P_AIN3M	2 /* AIN3(+) - AIN3(-) */
+#define AD7793_CH_AIN1M_AIN1M	3 /* AIN1(-) - AIN1(-) */
+#define AD7793_CH_TEMP			6 /* Temp Sensor */
+#define AD7793_CH_AVDD_MONITOR	7 /* AVDD Monitor */
+
+/* ID Register Bit Designations (AD7793_REG_ID) */
+#define AD7793_ID			0xB
+#define AD7793_ID_MASK		0xF
+
+/* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */
+#define AD7793_IEXCDIR(x)	(((x) & 0x3) << 2)
+#define AD7793_IEXCEN(x)	(((x) & 0x3) << 0)
+
+/* AD7793_IEXCDIR(x) options*/
+#define AD7793_DIR_IEXC1_IOUT1_IEXC2_IOUT2	0  /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
+#define AD7793_DIR_IEXC1_IOUT2_IEXC2_IOUT1	1  /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT1		2  /* Both current sources IEXC1,2 connect to IOUT1  */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT2		3  /* Both current sources IEXC1,2 connect to IOUT2 */
+
+/* AD7793_IEXCEN(x) options*/
+#define AD7793_EN_IXCEN_10uA				1  /* Excitation Current 10uA */
+#define AD7793_EN_IXCEN_210uA				2  /* Excitation Current 210uA */
+#define AD7793_EN_IXCEN_1mA					3  /* Excitation Current 1mA */
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+/* Initialize AD7793 and check if the device is present*/
+unsigned char AD7793_Init(void);
+
+/* Sends 32 consecutive 1's on SPI in order to reset the part. */
+void AD7793_Reset(void);
+
+/* Reads the value of the selected register. */
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, 
+									  unsigned char size,
+                                      unsigned char modifyCS);
+
+/* Writes a value to the register. */
+void AD7793_SetRegisterValue(unsigned char regAddress,
+							 unsigned long regValue, 
+							 unsigned char size,
+                             unsigned char modifyCS);
+
+/* Waits for RDY pin to go low. */
+void AD7793_WaitRdyGoLow(void);
+
+/* Sets the operating mode of AD7793. */
+void AD7793_SetMode(unsigned long mode);     
+
+/* Selects the channel of AD7793. */
+void AD7793_SetChannel(unsigned long channel);
+
+/* Sets the gain of the In-Amp. */
+void AD7793_SetGain(unsigned long gain);
+
+/* Sets the reference source for the ADC. */
+void AD7793_SetIntReference(unsigned char type);
+
+/* Performs the given calibration to the specified channel. */
+void AD7793_Calibrate(unsigned char mode, unsigned char channel);
+
+/* Returns the result of a single conversion. */
+unsigned long AD7793_SingleConversion(void);
+
+/* Returns the average of several conversion results. */
+unsigned long AD7793_ContinuousReadAvg(unsigned char sampleNumber);
+
+#endif	// _AD7793_H_

+ 186 - 0
doc/adc/ad7793_rl78g13/Communication.c

@@ -0,0 +1,186 @@
+/***************************************************************************//**
+ *   @file   Communication.c
+ *   @brief  Implementation of Communication Driver for RENESAS RL78G13
+ *           Processor.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "Communication.h"
+
+/***************************************************************************//**
+ * @brief Initializes the SPI communication peripheral.
+ *
+ * @param lsbFirst - Transfer format (0 or 1).
+ *                   Example: 0x0 - MSB first.
+ *                            0x1 - LSB first.
+ * @param clockFreq - SPI clock frequency (Hz).
+ *                    Example: 1000 - SPI clock frequency is 1 kHz.
+ * @param clockPol - SPI clock polarity (0 or 1).
+ *                   Example: 0x0 - idle state for SPI clock is low.
+ *	                          0x1 - idle state for SPI clock is high.
+ * @param clockPha - SPI clock phase (0 or 1).
+ *                   Example: 0x0 - data is latched on the leading edge of SPI
+ *                                  clock and data changes on trailing edge.
+ *                            0x1 - data is latched on the trailing edge of SPI
+ *                                  clock and data changes on the leading edge.
+ *
+ * @return 0 - Initialization failed, 1 - Initialization succeeded.
+*******************************************************************************/
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha)
+{
+    ST7579_CS_PIN_OUT;
+    ST7579_CS_HIGH;
+    ADI_PART_CS_PIN_OUT;
+    ADI_PART_CS_HIGH;
+    R_CSI10_Start();
+
+    return(1);
+}
+
+/***************************************************************************//**
+ * @brief Writes data to SPI.
+ *
+ * @param data - Write data buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber)
+{
+  	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]  = {0, 0, 0, 0};
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    unsigned char byte          = 0;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        writeData[byte] = data[byte + 1];
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_CSI10_Send_Receive((uint8_t *)&writeData[byte], 
+                             1,
+                             (uint8_t *)readData);
+	    while(CSIIF10 == 0);
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_HIGH;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_HIGH;
+    }
+
+	return(bytesNumber);
+}
+
+/***************************************************************************//**
+ * @brief Reads data from SPI.
+ *
+ * @param data - As an input parameter, data represents the write buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ *               As an output parameter, data represents the read buffer:
+ *               - from the first byte onwards are located the read data bytes. 
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber)
+{
+  	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]  = {0, 0, 0, 0};
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    unsigned char byte          = 0;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        writeData[byte] = data[byte + 1];
+        data[byte + 1] = 0;
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_CSI10_Send_Receive((uint8_t *)&writeData[byte], 
+                             1,
+                             (uint8_t *)&readData[byte]);
+	    while(CSIIF10 == 0);
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_HIGH;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_HIGH;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        data[byte] = readData[byte];
+    }
+    
+	return(bytesNumber);
+}
+

+ 78 - 0
doc/adc/ad7793_rl78g13/Communication.h

@@ -0,0 +1,78 @@
+/***************************************************************************//**
+ *   @file   Communication.h
+ *   @brief  Header file of Communication Driver for RENESAS RL78G13 Processor.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+#ifndef __COMMUNICATION_H__
+#define __COMMUNICATION_H__
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRL78G13.h"
+
+/******************************************************************************/
+/* GPIO Definitions                                                           */
+/******************************************************************************/
+#define ADI_PAR_CS_PIN         (1 << 1)
+#define ADI_PART_CS_PIN_OUT    PM7 &= ~(ADI_PAR_CS_PIN);
+#define ADI_PART_CS_LOW        P7 &= ~ADI_PAR_CS_PIN;
+#define ADI_PART_CS_HIGH       P7 |=  ADI_PAR_CS_PIN;
+#define GPIO1_PIN              (1 << 3)
+#define GPIO1_STATE            (P0 & GPIO1_PIN)
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+/* Initializes the SPI communication peripheral. */
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha);
+
+/* Writes data to SPI. */
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber);
+
+/* Reads data from SPI. */
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber);
+
+#endif	// __COMMUNICATION_H__

+ 165 - 0
doc/adc/ad7793_rl78g13/Main.c

@@ -0,0 +1,165 @@
+/***************************************************************************//**
+ *   @file   Main.c
+ *   @brief  Implementation of the program's main function.
+ *   @author DNechita
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRL78G13.h"    // YRDKRX62N definitions.
+#include "ST7579.h"		    // ST7579 definitions.
+#include "AD7793.h"		    // AD7793 definitions.
+
+/******************************************************************************/
+/* Option Bytes                                                               */
+/******************************************************************************/
+#pragma location = "OPTBYTE"
+__root const uint8_t opbyte0 = 0x00U;
+#pragma location = "OPTBYTE"
+__root const uint8_t opbyte1 = 0xFFU;
+#pragma location = "OPTBYTE"
+__root const uint8_t opbyte2 = 0xE8U;
+#pragma location = "OPTBYTE"
+__root const uint8_t opbyte3 = 0x04U;
+
+/******************************************************************************/
+/* Security ID                                                                */
+/******************************************************************************/
+#pragma location = "SECUID"
+__root const uint8_t secuid[10] = 
+    {0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U, 0x00U};
+
+/******************************************************************************/
+/* Variables Declarations                                                     */
+/******************************************************************************/
+const unsigned char adiLogo [2 * 19] =
+	{ 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x07, 0x07,
+	  0x0F, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F,
+	  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0,
+	  0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC,
+	  0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF };	// ADI Logo.
+
+unsigned long 	value 		= 0;	// value read from the ADC
+
+/***************************************************************************//**
+ * @brief Creates a delay of seconds.
+ *
+ * @param mSeconds - time in miliseconds.
+ *
+ * @return None.
+*******************************************************************************/
+void DelayMs(unsigned long mSeconds)
+{
+    unsigned long time = 0;
+    
+    R_TAU0_Channel0_Start();
+    while(time < mSeconds)
+    {
+        if(TMIF00 == 1)
+        {
+            time++;
+            TMIF00 = 0;
+        }
+    }
+    R_TAU0_Channel0_Stop();
+}
+
+/***************************************************************************//**
+ * @brief Main function.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void  main(void)
+{
+    YRDKRL78G13_Init();
+	ST7579_Init();
+    ST7579_Image(2,0,adiLogo,19,16);
+    ST7579_String(2,21,"ANALOG");
+    ST7579_String(3,21,"DEVICES");
+    ST7579_String(4,0,"wiki.analog.com");
+    DelayMs(2000);
+    ST7579_Clear();
+    ST7579_Image(0,0,adiLogo,19,16);	
+    ST7579_String(0,22,"ST7579 OK");
+    /* Reset AD7793 to bring the SPI interface in a known state */
+    AD7793_Reset();
+	if(AD7793_Init())
+	{
+		ST7579_String(1,22,"AD7793 OK");
+	}
+	else
+	{
+		ST7579_String(1,22,"AD7793 Err");		
+	}
+	/* AD7793 setup */
+    AD7793_SetGain(AD7793_GAIN_1);                // set gain to 1
+    AD7793_SetChannel(AD7793_CH_AIN1P_AIN1M);     // use AIN1(+) - AIN1(-) 
+    AD7793_SetIntReference(AD7793_REFSEL_INT);    // select internal 1.17V reference
+    AD7793_Calibrate(AD7793_MODE_CAL_INT_ZERO,
+                     AD7793_CH_AIN1P_AIN1M);      // Internal Zero-Scale Calibration
+    /* A 20 samples average is displayed. */
+    ST7579_String(3,0,"AVG:");
+    value = AD7793_ContinuousReadAvg(20);
+	ST7579_HexNumber(3,70,value,4);
+    while(1)
+	{
+        value = AD7793_SingleConversion();
+        ST7579_String(5,2,"AIN1(+)-AIN1(-)");
+        ST7579_String(4,0,"Data:");
+        ST7579_HexNumber(4,75,value,4);
+        if(value > 0x800000)
+            {
+                value -= 0x800000;
+                value = ((value * 1170) >> 15);
+                ST7579_String(6,10,"+");
+            }
+            else
+            {
+                value = 0x800000 - value;
+                value = ((value * 1170) >> 15);
+                ST7579_String(6,10,"-");
+            }
+            ST7579_Number(6,55,value,5);
+            ST7579_String(6,65,"mV");
+        DelayMs(250);   
+	}
+}

+ 376 - 0
doc/adc/ad7793_rl78g13/ST7579.c

@@ -0,0 +1,376 @@
+/***************************************************************************//**
+ *   @file   ST7579.c
+ *   @brief  Implementation of ST7579 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "Communication.h"	// Communication definitions.
+#include "ST7579.h"			// ST7579 definitions.
+
+/******************************************************************************/
+/* Private variables                                                          */
+/******************************************************************************/
+const unsigned char st7579Font[95][5] =
+{
+	{ 0x00, 0x00, 0x00, 0x00, 0x00 },	// sp
+	{ 0x00, 0x00, 0x2f, 0x00, 0x00 },	// !
+	{ 0x00, 0x07, 0x00, 0x07, 0x00 },	// "
+	{ 0x14, 0x7f, 0x14, 0x7f, 0x14 },	// #
+	{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 },	// $
+	{ 0xc4, 0xc8, 0x10, 0x26, 0x46 },	// %
+	{ 0x36, 0x49, 0x55, 0x22, 0x50 },	// &
+	{ 0x00, 0x05, 0x03, 0x00, 0x00 },	// '
+	{ 0x00, 0x1c, 0x22, 0x41, 0x00 },	// (
+	{ 0x00, 0x41, 0x22, 0x1c, 0x00 },	// )
+	{ 0x14, 0x08, 0x3E, 0x08, 0x14 },	// *
+	{ 0x08, 0x08, 0x3E, 0x08, 0x08 },	// +
+	{ 0x00, 0x00, 0x50, 0x30, 0x00 },	// ,
+	{ 0x10, 0x10, 0x10, 0x10, 0x10 },	// -
+	{ 0x00, 0x60, 0x60, 0x00, 0x00 },	// .
+	{ 0x20, 0x10, 0x08, 0x04, 0x02 },	// /
+	{ 0x3E, 0x51, 0x49, 0x45, 0x3E },	// 0
+	{ 0x00, 0x42, 0x7F, 0x40, 0x00 },	// 1
+	{ 0x42, 0x61, 0x51, 0x49, 0x46 },	// 2
+	{ 0x21, 0x41, 0x45, 0x4B, 0x31 },	// 3
+	{ 0x18, 0x14, 0x12, 0x7F, 0x10 },	// 4
+	{ 0x27, 0x45, 0x45, 0x45, 0x39 },	// 5
+	{ 0x3C, 0x4A, 0x49, 0x49, 0x30 },	// 6
+	{ 0x01, 0x71, 0x09, 0x05, 0x03 },	// 7
+	{ 0x36, 0x49, 0x49, 0x49, 0x36 },	// 8
+	{ 0x06, 0x49, 0x49, 0x29, 0x1E },	// 9
+	{ 0x00, 0x36, 0x36, 0x00, 0x00 },	// :
+	{ 0x00, 0x56, 0x36, 0x00, 0x00 },	// ;
+	{ 0x08, 0x14, 0x22, 0x41, 0x00 },	// <
+	{ 0x14, 0x14, 0x14, 0x14, 0x14 },	// =
+	{ 0x00, 0x41, 0x22, 0x14, 0x08 },	// >
+	{ 0x02, 0x01, 0x51, 0x09, 0x06 },	// ?
+	{ 0x32, 0x49, 0x59, 0x51, 0x3E },	// @
+	{ 0x7E, 0x11, 0x11, 0x11, 0x7E },	// A
+	{ 0x7F, 0x49, 0x49, 0x49, 0x36 },	// B
+	{ 0x3E, 0x41, 0x41, 0x41, 0x22 },	// C
+	{ 0x7F, 0x41, 0x41, 0x22, 0x1C },	// D
+	{ 0x7F, 0x49, 0x49, 0x49, 0x41 },	// E
+	{ 0x7F, 0x09, 0x09, 0x09, 0x01 },	// F
+	{ 0x3E, 0x41, 0x49, 0x49, 0x7A },	// G
+	{ 0x7F, 0x08, 0x08, 0x08, 0x7F },	// H
+	{ 0x00, 0x41, 0x7F, 0x41, 0x00 },	// I
+	{ 0x20, 0x40, 0x41, 0x3F, 0x01 },	// J
+	{ 0x7F, 0x08, 0x14, 0x22, 0x41 },	// K
+	{ 0x7F, 0x40, 0x40, 0x40, 0x40 },	// L
+	{ 0x7F, 0x02, 0x0C, 0x02, 0x7F },	// M
+	{ 0x7F, 0x04, 0x08, 0x10, 0x7F },	// N
+	{ 0x3E, 0x41, 0x41, 0x41, 0x3E },	// O
+	{ 0x7F, 0x09, 0x09, 0x09, 0x06 },	// P
+	{ 0x3E, 0x41, 0x51, 0x21, 0x5E },	// Q
+	{ 0x7F, 0x09, 0x19, 0x29, 0x46 },	// R
+	{ 0x46, 0x49, 0x49, 0x49, 0x31 },	// S
+	{ 0x01, 0x01, 0x7F, 0x01, 0x01 },	// T
+	{ 0x3F, 0x40, 0x40, 0x40, 0x3F },	// U
+	{ 0x1F, 0x20, 0x40, 0x20, 0x1F },	// V
+	{ 0x3F, 0x40, 0x38, 0x40, 0x3F },	// W
+	{ 0x63, 0x14, 0x08, 0x14, 0x63 },	// X
+	{ 0x07, 0x08, 0x70, 0x08, 0x07 },	// Y
+	{ 0x61, 0x51, 0x49, 0x45, 0x43 },	// Z
+	{ 0x00, 0x7F, 0x41, 0x41, 0x00 },	// [
+	{ 0x55, 0x2A, 0x55, 0x2A, 0x55 },	// /
+	{ 0x00, 0x41, 0x41, 0x7F, 0x00 },	// ]
+	{ 0x04, 0x02, 0x01, 0x02, 0x04 },	// ^
+	{ 0x40, 0x40, 0x40, 0x40, 0x40 },	// _
+	{ 0x00, 0x01, 0x02, 0x04, 0x00 },	// '
+	{ 0x20, 0x54, 0x54, 0x54, 0x78 },	// a
+	{ 0x7F, 0x48, 0x44, 0x44, 0x38 },	// b
+	{ 0x38, 0x44, 0x44, 0x44, 0x20 },	// c
+	{ 0x38, 0x44, 0x44, 0x48, 0x7F },	// d
+	{ 0x38, 0x54, 0x54, 0x54, 0x18 },	// e
+	{ 0x08, 0x7E, 0x09, 0x01, 0x02 },	// f
+	{ 0x0C, 0x52, 0x52, 0x52, 0x3E },	// g
+	{ 0x7F, 0x08, 0x04, 0x04, 0x78 },	// h
+	{ 0x00, 0x44, 0x7D, 0x40, 0x00 },	// i
+	{ 0x20, 0x40, 0x44, 0x3D, 0x00 },	// j
+	{ 0x7F, 0x10, 0x28, 0x44, 0x00 },	// k
+	{ 0x00, 0x41, 0x7F, 0x40, 0x00 },	// l
+	{ 0x7C, 0x04, 0x18, 0x04, 0x78 },	// m
+	{ 0x7C, 0x08, 0x04, 0x04, 0x78 },	// n
+	{ 0x38, 0x44, 0x44, 0x44, 0x38 },	// o
+	{ 0x7C, 0x14, 0x14, 0x14, 0x08 },	// p
+	{ 0x08, 0x14, 0x14, 0x18, 0x7C },	// q
+	{ 0x7C, 0x08, 0x04, 0x04, 0x08 },	// r
+	{ 0x48, 0x54, 0x54, 0x54, 0x20 },	// s
+	{ 0x04, 0x3F, 0x44, 0x40, 0x20 },	// t
+	{ 0x3C, 0x40, 0x40, 0x20, 0x7C },	// u
+	{ 0x1C, 0x20, 0x40, 0x20, 0x1C },	// v
+	{ 0x3C, 0x40, 0x30, 0x40, 0x3C },	// w
+	{ 0x44, 0x28, 0x10, 0x28, 0x44 },	// x
+	{ 0x0C, 0x50, 0x50, 0x50, 0x3C },	// y
+	{ 0x44, 0x64, 0x54, 0x4C, 0x44 },	// z
+	{ 0x08, 0x3e, 0x41, 0x41, 0x00 },	// { 
+	{ 0x00, 0x00, 0x77, 0x00, 0x00 },	// | 
+	{ 0x00, 0x41, 0x41, 0x3e, 0x08 },	// } 
+	{ 0x02, 0x01, 0x02, 0x01, 0x00 }	// ~
+};
+
+/***************************************************************************//**
+ * @brief Transmits 8 bits to ST7579 controller.
+ *
+ * @param data - data to transmit.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_WriteByte(unsigned char data)
+{
+    unsigned char spiWord[2]    = {0};
+    spiWord[0] = 0x02;
+    spiWord[1] = data;
+	SPI_Write(spiWord,1);
+}
+
+/***************************************************************************//**
+ * @brief Initializes the ST7579 controller.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+unsigned char ST7579_Init(void)
+{
+	unsigned char status  = 0x0;
+	status = SPI_Init(0, 1000000, 1, 1);
+	ST7579_RS_PIN_OUT;
+	ST7579_RS_LOW;
+	/* Select LCD bias ratio of the voltage required for driving the LCD. */
+	ST7579_WriteByte(0x21);
+	ST7579_WriteByte(0x16);
+	/* Select Booster efficiency and Booster stage. */
+	ST7579_WriteByte(0x23);
+	ST7579_WriteByte(0x99);
+	/* Set V0 Range. */
+	ST7579_WriteByte(0x20);	
+	ST7579_WriteByte(0x04);
+	/* 50 ms delay is recommended. */
+	/* Set the frame frequency */
+	ST7579_WriteByte(0x23);
+	ST7579_WriteByte(0x0C);
+	/* Set V0. */
+	ST7579_WriteByte(0x21);	
+	ST7579_WriteByte(0xE7);
+	/* Select the display mode */
+	ST7579_WriteByte(0x20);
+	ST7579_WriteByte(0x0C);
+	ST7579_RS_HIGH;
+	/* Clear RAM. */
+	ST7579_Clear();
+
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Clears ST7579 RAM.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Clear(void)
+{
+	unsigned short clearPosition;
+	unsigned char yPosition = 0x0;	
+	for(clearPosition = 0;clearPosition < (64 * 96);clearPosition ++)
+	{
+		if(!(clearPosition % 96))
+		{
+			ST7579_RS_LOW;
+			/* Set X address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x80);
+			/* Set Y address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x40 + yPosition);
+			yPosition ++;
+			ST7579_RS_HIGH;
+		}
+		ST7579_WriteByte(0x00);
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends a character to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param character - The character.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Char(unsigned char yPosition,
+                 unsigned char xPosition,
+                 unsigned char character)
+{
+	volatile unsigned char column;
+	ST7579_RS_LOW;
+	/* Set X address of RAM. */
+	ST7579_WriteByte(0x28);
+	ST7579_WriteByte(0x80 + xPosition);
+	/* Set Y address of RAM. */
+	ST7579_WriteByte(0x28);
+	ST7579_WriteByte(0x40 + yPosition);
+	ST7579_RS_HIGH;
+	/* Send character data. */
+	for(column = 0;column < 5;column ++)
+	{
+		ST7579_WriteByte(st7579Font[character - 32][column] << 1);
+	}
+	ST7579_WriteByte(0x00);
+}
+
+/***************************************************************************//**
+ * @brief Sends a string to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param string - The string.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_String(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned char* string)
+{
+	while(*string)
+	{
+		/* Send each character of the string. */
+		ST7579_Char(yPosition, xPosition, *string++);
+		xPosition += 6;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an integer number to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param number - The number.
+ * @param chNumber - Number of characters.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Number(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned long number,
+                   unsigned char chNumber)
+{
+	while(chNumber--)
+	{
+		ST7579_Char(yPosition, xPosition, (number % 10) + 0x30);
+		xPosition -= 6;
+		number = number / 10;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an integer number in Hexa format to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param number - The number.
+ * @param bytesNumber - Number of bytes.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_HexNumber(unsigned char yPosition,
+					  unsigned char xPosition,
+					  unsigned long number,
+                      unsigned char bytesNumber)
+{
+	char character = 0;
+    bytesNumber *= 2;
+	while(bytesNumber--)
+	{
+		character = (number % 16);
+		if (character <= 9)
+		{
+			character += 0x30;
+		}
+		else
+		{
+			character +=0x37;
+		}
+		ST7579_Char(yPosition, xPosition, character);
+		xPosition -= 6;
+		number = number / 16;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an image array to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param image - The image array.
+ * @param width - The width of the image (pixels).
+ * @param height - The height of the image (pixels).
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Image(unsigned char yPosition,
+                  unsigned char xPosition,
+                  const unsigned char image[],
+                  unsigned char width,
+                  unsigned char height)
+{
+	unsigned short index;
+	for(index = 0;index < (width * height / 8);index ++)
+	{
+		if(!(index % width))
+		{
+			ST7579_RS_LOW;
+			/* Set X address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x80 + xPosition);
+			/* Set Y address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x40 + yPosition);
+			yPosition ++;
+			ST7579_RS_HIGH;
+		}
+		ST7579_WriteByte(image[index]);
+	}
+}

+ 78 - 0
doc/adc/ad7793_rl78g13/ST7579.h

@@ -0,0 +1,78 @@
+/***************************************************************************//**
+ *   @file   ST7579.h
+ *   @brief  Header file of ST7579 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+#ifndef _ST7579_H_
+#define _ST7579_H_
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+/* Transmits 8 bits to ST7579 controller. */
+void ST7579_WriteByte(unsigned char data);
+/* Initializes the ST7579 controller. */
+unsigned char ST7579_Init(void);
+/* Clears ST7579 RAM. */
+void ST7579_Clear(void);
+/* Sends a character to ST7579 controller. */
+void ST7579_Char(unsigned char yPosition,
+                 unsigned char xPosition,
+                 unsigned char character);
+/* Sends a string to ST7579 controller. */
+void ST7579_String(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned char* string);
+/* Sends an integer number to ST7579 controller. */
+void ST7579_Number(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned long number,
+                   unsigned char chNumber);
+/* Sends an integer number in Hexa format to ST7579 controller. */
+void ST7579_HexNumber(unsigned char yPosition,
+					  unsigned char xPosition,
+					  unsigned long number,
+                      unsigned char bytesNumber);
+/* Sends an image array to ST7579 controller. */
+void ST7579_Image(unsigned char yPosition,
+                  unsigned char xPosition,
+                  const unsigned char image[],
+                  unsigned char width,
+                  unsigned char height);
+#endif	// _ST7579_H_

+ 77 - 0
doc/adc/ad7793_rl78g13/YRDKRL78G13.c

@@ -0,0 +1,77 @@
+/***************************************************************************//**
+ *   @file   YRDKRL78G13.h
+ *   @brief  Implementation YRDKRL78G13 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRL78G13.h"
+
+/***************************************************************************//**
+ * @brief Reset the YRDKRL78G13's peripherals.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void YRDKRL78G13_Reset(void)
+{
+    unsigned short delay;
+    P13 = 0x01;
+    for(delay = 0;delay < 1000;delay ++)
+    {
+        __no_operation();
+    }
+    P13 = 0x00;
+}
+
+/***************************************************************************//**
+ * @brief Initializes the YRDKRL78G13.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void YRDKRL78G13_Init(void)
+{
+    __low_level_init();
+    YRDKRL78G13_Reset();
+}

+ 72 - 0
doc/adc/ad7793_rl78g13/YRDKRL78G13.h

@@ -0,0 +1,72 @@
+/***************************************************************************//**
+ *   @file   YRDKRL78G13.h
+ *   @brief  Header file of YRDKRL78G13 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 499
+*******************************************************************************/
+#ifndef _YRDKRL78G13_H_
+#define _YRDKRL78G13_H_
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "..\applilet3_src\r_cg_macrodriver.h"
+#include "..\applilet3_src\r_cg_cgc.h"
+#include "..\applilet3_src\r_cg_serial.h"
+#include "..\applilet3_src\r_cg_timer.h"
+
+/******************************************************************************/
+/* Macros and Constants Definitions                                           */
+/******************************************************************************/
+#define ST7579_CS_PIN       0x01
+#define ST7579_CS_PIN_OUT   PM1 &= ~ST7579_CS_PIN;
+#define ST7579_CS_LOW       P1 &= ~ST7579_CS_PIN;
+#define ST7579_CS_HIGH	    P1 |=  ST7579_CS_PIN;
+#define ST7579_RS_PIN       0x20
+#define ST7579_RS_PIN_OUT   PM1 &= ~ST7579_RS_PIN;
+#define ST7579_RS_LOW       P1 &= ~ST7579_RS_PIN;
+#define	ST7579_RS_HIGH	    P1 |=  ST7579_RS_PIN;
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+/* Reset the YRDKRL78G13's peripherals. */
+void YRDKRL78G13_Reset(void);
+/* Initializes the YRDKRL78G13. */
+void YRDKRL78G13_Init(void); 
+#endif  // YRDKRL78G13

BIN
doc/adc/ad7793_rx62n.zip


+ 244 - 0
doc/adc/ad7793_rx62n/AD7793.c

@@ -0,0 +1,244 @@
+/***************************************************************************//**
+ *   @file   AD7793.c
+ *   @brief  Implementation of AD7793 Driver.
+ *   @author Bancisor MIhai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "AD7793.h"				// AD7793 definitions.
+#include "Communication.h"		// Communication definitions.
+
+/***************************************************************************//**
+ * @brief Initializes the AD7793 and checks if the device is present.
+ *
+ * @param None.
+ *
+ * @return status - Result of the initialization procedure.
+ *                  Example: 1 - if initialization was successful (ID is 0x0B).
+ *                           0 - if initialization was unsuccessful.
+*******************************************************************************/
+unsigned char AD7793_Init(void)
+{ 
+	unsigned char status = 0x1;
+	if((AD7793_GetRegisterValue(AD7793_REG_ID, 1) & 0x0F) != AD7793_ID)
+	{
+		status = 0x0;
+	}
+	
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Sends 32 consecutive 1's on SPI in order to reset the part.
+ *
+ * @param None.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_Reset(void)
+{
+	unsigned char dataToSend[5] = {0x03, 0xff, 0xff, 0xff, 0xff};
+	AD7793_CS_LOW;	    
+	SPI_Write(dataToSend,4);
+	AD7793_CS_HIGH;	
+}
+/***************************************************************************//**
+ * @brief Reads the value of the selected register
+ *
+ * @param regAddress - The address of the register to read.
+ * @param size - The size of the register to read.
+ *
+ * @return data - The value of the selected register register.
+*******************************************************************************/
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, unsigned char size)
+{
+	unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};
+	unsigned long receivedData = 0x00;	
+	data[1] = AD7793_COMM_READ |  AD7793_COMM_ADDR(regAddress);
+	AD7793_CS_LOW;  
+	SPI_Write(data,1);
+	SPI_Read(data,size);
+	AD7793_CS_HIGH;
+	if(size == 1)
+	{
+		receivedData += (data[0] << 0);
+	}
+	if(size == 2)
+	{
+		receivedData += (data[0] << 8);
+		receivedData += (data[1] << 0);
+	}
+	if(size == 3)
+	{
+		receivedData += (data[0] << 16);
+		receivedData += (data[1] << 8);
+		receivedData += (data[2] << 0);
+	}
+    return receivedData;
+}
+/***************************************************************************//**
+ * @brief Writes the value to the register
+ *
+ * @param -  regAddress - The address of the register to write to.
+ * @param -  regValue - The value to write to the register.
+ * @param -  size - The size of the register to write.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetRegisterValue(unsigned char regAddress,
+                             unsigned long regValue, 
+                             unsigned char size)
+{
+	unsigned char data[5] = {0x03, 0x00, 0x00, 0x00, 0x00};	
+	data[1] = AD7793_COMM_WRITE |  AD7793_COMM_ADDR(regAddress);
+    if(size == 1)
+    {
+        data[2] = (unsigned char)regValue;
+    }
+    if(size == 2)
+    {
+		data[3] = (unsigned char)((regValue & 0x0000FF) >> 0);
+        data[2] = (unsigned char)((regValue & 0x00FF00) >> 8);
+    }
+    if(size == 3)
+    {
+		data[4] = (unsigned char)((regValue & 0x0000FF) >> 0);
+		data[3] = (unsigned char)((regValue & 0x00FF00) >> 8);
+        data[2] = (unsigned char)((regValue & 0xFF0000) >> 16);
+    }
+	AD7793_CS_LOW;	    
+	SPI_Write(data,(1 + size));
+	AD7793_CS_HIGH;
+
+}
+/***************************************************************************//**
+ * @brief Reads /RDY bit of status reg.
+ *
+ * @param None.
+ *
+ * @return rdy	- 0 if RDY is 1.
+ *              - 1 if RDY is 0.
+*******************************************************************************/
+unsigned char AD7793_Ready(void)
+{
+    unsigned char rdy = 0;
+    rdy = (AD7793_GetRegisterValue( AD7793_REG_STAT,1) & 0x80);   
+	
+	return(!rdy);
+}
+
+/***************************************************************************//**
+ * @brief Sets the operating mode of AD7793.
+ *
+ * @param mode - Mode of operation.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetMode(unsigned long mode)
+{
+    unsigned long command;
+    command = AD7793_GetRegisterValue(AD7793_REG_MODE,2);
+    command &= ~AD7793_MODE_SEL(0xFF);
+    command |= AD7793_MODE_SEL(mode);
+    AD7793_SetRegisterValue(
+            AD7793_REG_MODE,
+            command,
+            2
+    );
+}
+/***************************************************************************//**
+ * @brief Selects the channel of AD7793.
+ *
+ * @param  channel - ADC channel selection.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetChannel(unsigned long channel)
+{
+    unsigned long command;
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,2);
+    command &= ~AD7793_CONF_CHAN(0xFF);
+    command |= AD7793_CONF_CHAN(channel);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2
+    );
+}
+
+/***************************************************************************//**
+ * @brief  Sets the gain of the In-Amp.
+ *
+ * @param  gain - Gain.
+ *
+ * @return  None.    
+*******************************************************************************/
+void AD7793_SetGain(unsigned long gain)
+{
+    unsigned long command;
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,2);
+    command &= ~AD7793_CONF_GAIN(0xFF);
+    command |= AD7793_CONF_GAIN(gain);
+    AD7793_SetRegisterValue(
+            AD7793_REG_CONF,
+            command,
+            2
+    );
+}
+/***************************************************************************//**
+ * @brief Sets the reference source for the ADC.
+ *
+ * @param type - Type of the reference.
+ *               Example: AD7793_REFSEL_EXT	- External Reference Selected
+ *                        AD7793_REFSEL_INT	- Internal Reference Selected.
+ *
+ * @return None.    
+*******************************************************************************/
+void AD7793_SetReference(unsigned char type)
+{
+    unsigned long command = 0;
+    command = AD7793_GetRegisterValue(AD7793_REG_CONF,2);
+    command &= ~AD7793_CONF_REFSEL(AD7793_REFSEL_INT);
+    command |= AD7793_CONF_REFSEL(type);
+    AD7793_SetRegisterValue(AD7793_REG_CONF,
+							command,
+							2);
+}

+ 171 - 0
doc/adc/ad7793_rx62n/AD7793.h

@@ -0,0 +1,171 @@
+/***************************************************************************//**
+ *   @file   AD7793.h
+ *   @brief  Header file of AD7793 Driver.
+ *   @author Bancisor Mihai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+#ifndef __AD7793_H__
+#define __AD7793_H__
+
+/******************************************************************************/
+/* AD7793                                                                   */
+/******************************************************************************/
+
+/*AD7793 Registers*/
+#define AD7793_REG_COMM		0 /* Communications Register(WO, 8-bit) */
+#define AD7793_REG_STAT	    0 /* Status Register	    (RO, 8-bit) */
+#define AD7793_REG_MODE	    1 /* Mode Register	     	(RW, 16-bit */
+#define AD7793_REG_CONF	    2 /* Configuration Register (RW, 16-bit)*/
+#define AD7793_REG_DATA	    3 /* Data Register	     	(RO, 16-/24-bit) */
+#define AD7793_REG_ID	    4 /* ID Register	     	(RO, 8-bit) */
+#define AD7793_REG_IO	    5 /* IO Register	     	(RO, 8-bit) */
+#define AD7793_REG_OFFSET   6 /* Offset Register	    (RW, 24-bit */
+#define AD7793_REG_FULLSALE	7 /* Full-Scale Register	(RW, 24-bit */
+
+/* Communications Register Bit Designations (AD7793_REG_COMM) */
+#define AD7793_COMM_WEN		(1 << 7) 			/* Write Enable */
+#define AD7793_COMM_WRITE	(0 << 6) 			/* Write Operation */
+#define AD7793_COMM_READ    (1 << 6) 			/* Read Operation */
+#define AD7793_COMM_ADDR(x)	(((x) & 0x7) << 3)	/* Register Address */
+#define AD7793_COMM_CREAD	(1 << 2) 			/* Continuous Read of Data Register */
+
+/* Status Register Bit Designations (AD7793_REG_STAT) */
+#define AD7793_STAT_RDY		(1 << 7) /* Ready */
+#define AD7793_STAT_ERR		(1 << 6) /* Error (Overrange, Underrange) */
+#define AD7793_STAT_CH3		(1 << 2) /* Channel 3 */
+#define AD7793_STAT_CH2		(1 << 1) /* Channel 2 */
+#define AD7793_STAT_CH1		(1 << 0) /* Channel 1 */
+
+/* Mode Register Bit Designations (AD7793_REG_MODE) */
+#define AD7793_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
+#define AD7793_MODE_CLKSRC(x)	(((x) & 0x3) << 6) 	/* ADC Clock Source Select */
+#define AD7793_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */
+
+/* AD7793_MODE_SEL(x) options */
+#define AD7793_MODE_CONT		 0 /* Continuous Conversion Mode */
+#define AD7793_MODE_SINGLE		 1 /* Single Conversion Mode */
+#define AD7793_MODE_IDLE		 2 /* Idle Mode */
+#define AD7793_MODE_PWRDN		 3 /* Power-Down Mode */
+#define AD7793_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
+#define AD7793_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
+#define AD7793_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
+
+/* AD7793_MODE_CLKSRC(x) options */
+#define AD7793_CLK_INT		0 /* Internal 64 kHz Clk not available at the CLK pin */
+#define AD7793_CLK_INT_CO	1 /* Internal 64 kHz Clk available at the CLK pin */
+#define AD7793_CLK_EXT		2 /* External 64 kHz Clock */
+#define AD7793_CLK_EXT_DIV2	3 /* External Clock divided by 2 */
+
+/* Configuration Register Bit Designations (AD7793_REG_CONF) */
+#define AD7793_CONF_VBIAS(x)  (((x) & 0x3) << 14) 	/* Bias Voltage Generator Enable */
+#define AD7793_CONF_BO_EN	  (1 << 13) 			/* Burnout Current Enable */
+#define AD7793_CONF_UNIPOLAR  (1 << 12) 			/* Unipolar/Bipolar Enable */
+#define AD7793_CONF_BOOST	  (1 << 11) 			/* Boost Enable */
+#define AD7793_CONF_GAIN(x)	  (((x) & 0x7) << 8) 	/* Gain Select */
+#define AD7793_CONF_REFSEL(x) (((x) & 0x1) << 7) 	/* INT/EXT Reference Select */
+#define AD7793_CONF_BUF		  (1 << 4) 				/* Buffered Mode Enable */
+#define AD7793_CONF_CHAN(x)	  ((x) & 0x7) 			/* Channel select */
+
+/* AD7793_CONF_GAIN(x) options */
+#define AD7793_GAIN_1       0
+#define AD7793_GAIN_2       1
+#define AD7793_GAIN_4       2
+#define AD7793_GAIN_8       3
+#define AD7793_GAIN_16      4
+#define AD7793_GAIN_32      5
+#define AD7793_GAIN_64      6
+#define AD7793_GAIN_128     7
+
+/* AD7793_CONF_REFSEL(x) options */
+#define AD7793_REFSEL_INT   1	/* External Reference Applied between REFIN(+) and REFIN(–). */
+#define AD7793_REFSEL_EXT   0	/* Internal Reference Selected. */
+
+/* AD7793_CONF_CHAN(x) options */
+#define AD7793_CH_AIN1P_AIN1M	0 /* AIN1(+) - AIN1(-) */
+#define AD7793_CH_AIN2P_AIN2M	1 /* AIN2(+) - AIN2(-) */
+#define AD7793_CH_AIN3P_AIN3M	2 /* AIN3(+) - AIN3(-) */
+#define AD7793_CH_AIN1M_AIN1M	3 /* AIN1(-) - AIN1(-) */
+#define AD7793_CH_TEMP			6 /* Temp Sensor */
+#define AD7793_CH_AVDD_MONITOR	7 /* AVDD Monitor */
+
+/* ID Register Bit Designations (AD7793_REG_ID) */
+#define AD7793_ID			0xB
+#define AD7793_ID_MASK		0xF
+
+/* IO (Excitation Current Sources) Register Bit Designations (AD7793_REG_IO) */
+#define AD7793_IEXCDIR(x)	(((x) & 0x3) << 2)
+#define AD7793_IEXCEN(x)	(((x) & 0x3) << 0)
+
+/* AD7793_IEXCDIR(x) options*/
+#define AD7793_DIR_IEXC1_IOUT1_IEXC2_IOUT2	0  /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
+#define AD7793_DIR_IEXC1_IOUT2_IEXC2_IOUT1	1  /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT1		2  /* Both current sources IEXC1,2 connect to IOUT1  */
+#define AD7793_DIR_IEXC1_IEXC2_IOUT2		3  /* Both current sources IEXC1,2 connect to IOUT2 */
+
+/* AD7793_IEXCEN(x) options*/
+#define AD7793_EN_IXCEN_10uA				1  /* Excitation Current 10uA */
+#define AD7793_EN_IXCEN_210uA				2  /* Excitation Current 210uA */
+#define AD7793_EN_IXCEN_1mA					3  /* Excitation Current 1mA */
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+/* Initialize AD7793 and check if the device is present*/
+unsigned char AD7793_Init(void);
+/* Sends 32 consecutive 1's on SPI in order to reset the part. */
+void AD7792_Reset(void);
+/* Reads the value of the selected register. */
+unsigned long AD7793_GetRegisterValue(unsigned char regAddress, 
+									  unsigned char size);
+/* Writes a value to the register. */
+void AD7793_SetRegisterValue(unsigned char regAddress,
+							 unsigned long regValue, 
+							 unsigned char size);
+/* Sets the operating mode of AD7792. */
+void AD7793_SetMode(unsigned long mode);
+/* Reads /RDY bit of Status register. */
+unsigned char AD7793_Ready(void);              
+/* Selects the channel of AD7792. */
+void AD7793_SetChannel(unsigned long channel);
+/* Sets the gain of the In-Amp. */
+void AD7793_SetGain(unsigned long gain);
+/* Sets the reference source for the ADC. */
+void AD7793_SetIntReference(unsigned char type);
+#endif	// _AD7792_H_

+ 292 - 0
doc/adc/ad7793_rx62n/Communication.c

@@ -0,0 +1,292 @@
+/***************************************************************************//**
+ *   @file   Communication.c
+ *   @brief  Implementation of Communication Driver for RENESAS RX62N
+ *           Processor.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "Communication.h"
+
+/***************************************************************************//**
+ * @brief Initializes the SPI communication peripheral.
+ *
+ * @param lsbFirst - Transfer format (0 or 1).
+ *                   Example: 0x0 - MSB first.
+ *                            0x1 - LSB first.
+ * @param clockFreq - SPI clock frequency (Hz).
+ *                    Example: 1000 - SPI clock frequency is 1 kHz.
+ * @param clockPol - SPI clock polarity (0 or 1).
+ *                   Example: 0x0 - idle state for SPI clock is low.
+ *	                          0x1 - idle state for SPI clock is high.
+ * @param clockPha - SPI clock phase (0 or 1).
+ *                   Example: 0x0 - data is latched on the leading edge of SPI
+ *                                  clock and data changes on trailing edge.
+ *                            0x1 - data is latched on the trailing edge of SPI
+ *                                  clock and data changes on the leading edge.
+ *
+ * @return 0 - Initialization failed, 1 - Initialization succeeded.
+*******************************************************************************/
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha)
+{
+	MISOA_PIN_IN;
+	MOSIA_PIN_OUT;
+    ST7579_CS_PIN_OUT;
+    ST7579_CS_HIGH;
+    AD7793_CS_PIN_OUT;
+    AD7793_CS_HIGH;
+	R_SPI_Create(0,							// Channel selection.
+				 PDL_SPI_MODE_SPI_MASTER |	// Connection mode.
+				 PDL_SPI_PIN_A |			// A pins for signal MISO, MOSI, RSPCK, SSL0, SSL1, SSL2 and SSL3.
+				 PDL_SPI_PIN_MOSI_IDLE_LOW,	// The MOSI output state when no SSLn pin is active.
+				 PDL_SPI_FRAME_1_1,			// Frame configuration selection.
+				 PDL_NO_DATA,				// Extended timing control - default settings.
+                 0x80000000);				// Bit rate or register value.
+	R_SPI_Command(0,						// Channel selection.
+				  0,						// Command selection.
+				  PDL_SPI_CLOCK_MODE_3 |	// Clock is low when idle; data is sampled on the rising edge.
+				  PDL_SPI_DIV_8 |			// Bit rate (specified for R_SPI_Create) : 8.
+				  PDL_SPI_LENGTH_8 |	    // The number of bits in the frame transfer.
+				  PDL_SPI_MSB_FIRST,	    // Most-significant bit first.
+                  PDL_NO_DATA);			    // Extended timing control - default settings.
+	
+    return(1);
+}
+
+/***************************************************************************//**
+ * @brief Writes data to SPI.
+ *
+ * @param data - Write data buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber)
+{
+	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]	= {0, 0, 0, 0};
+	unsigned char byte          = 0;
+	for(byte = 0;byte < bytesNumber;byte ++)
+	{
+		writeData[byte] = data[byte + 1];
+	}
+    if(chipSelect == 1)
+    {
+        AD7793_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+	for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_SPI_Transfer(0,						    		// Channel selection.
+                       PDL_NO_DATA,							// DMAC / DTC control.
+                       (unsigned long*)&writeData[byte],	// Transmit data start address.
+                       PDL_NO_PTR,							// Receive data start address.
+                       1,									// Sequence loop count.
+                       PDL_NO_FUNC,							// Callback function.
+                       0);									// Interrupt priority level.
+    }
+ 	if(chipSelect == 1)
+	{
+		AD7793_CS_HIGH;
+	}
+    if(chipSelect == 2)
+	{
+		ST7579_CS_HIGH;
+	}
+	return(bytesNumber);
+}
+
+/***************************************************************************//**
+ * @brief Reads data from SPI.
+ *
+ * @param data - As an input parameter, data represents the write buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ *               As an output parameter, data represents the read buffer:
+ *               - from the first byte onwards are located the read data bytes. 
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber)
+{
+	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]	= {0, 0, 0, 0};
+	unsigned char byte          = 0;
+	for(byte = 0;byte < bytesNumber;byte ++)
+	{
+		writeData[byte] = data[byte + 1];
+	}
+    if(chipSelect == 1)
+    {
+        AD7793_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+	for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_SPI_Transfer(0,						    		// Channel selection.
+                       PDL_NO_DATA,							// DMAC / DTC control.
+                       (unsigned long*)&writeData[byte],	// Transmit data start address.
+                       (unsigned long*)&data[byte],			// Transmit data start address.
+                       1,									// Sequence loop count.
+                       PDL_NO_FUNC,							// Callback function.
+                       0);									// Interrupt priority level.
+    }
+ 	if(chipSelect == 1)
+	{
+		AD7793_CS_HIGH;
+	}
+    if(chipSelect == 2)
+	{
+		ST7579_CS_HIGH;
+	}
+
+	return(bytesNumber);
+}
+
+/***************************************************************************//**
+ * @brief Initializes the I2C communication peripheral.
+ *
+ * @param clockFreq - I2C clock frequency (Hz).
+ *                    Example: 100000 - I2C clock frequency is 100 kHz.
+ *
+ * @return 0 - Initialization failed, 1 - Initialization succeeded.
+*******************************************************************************/
+unsigned char I2C_Init(unsigned long clockFreq)
+{
+	R_IIC_Create(0,							// Channel selection.
+				 PDL_IIC_MODE_IIC |			// I2C Bus.
+				 PDL_IIC_INT_PCLK_DIV_8,	// The reference clock source,
+				 							// used inside the I2C module.
+				 PDL_NO_DATA,				// Detection configuration.
+				 PDL_NO_DATA,				// Slave address.
+				 PDL_NO_DATA,				// Slave address.
+				 PDL_NO_DATA,				// Slave address.
+				 100E3,						// Transfer rate control.
+				 0);						// Rise and fall time correction.
+
+	return(1);
+}
+
+/***************************************************************************//**
+ * @brief Writes data to I2C.
+ *
+ * @param data - Write data buffer:
+ *       - first byte is the slave address;
+ *       - from the second byte onwards are located data bytes.
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char I2C_Write(unsigned char* data,
+                        unsigned char bytesNumber)
+{
+	unsigned char slaveAddress 		= data[0];
+	unsigned char writeData[4]		= {0, 0, 0, 0};
+	unsigned char byte				= 0;
+	for(byte = 0;byte < bytesNumber;byte ++)
+	{
+		writeData[byte] = data[byte + 1];
+	}
+	R_IIC_MasterSend(0,
+					 PDL_IIC_START_ENABLE | PDL_IIC_STOP_ENABLE,
+					 (slaveAddress << 1 | 0x00),
+					 (uint8_t*)writeData,
+					 bytesNumber,
+					 PDL_NO_FUNC,
+					 0);
+
+	return(bytesNumber);
+}
+
+/***************************************************************************//**
+ * @brief Reads data from I2C.
+ *
+ * @param data - Read data buffer:
+ *		 As an input parameter data must have 2 bytes:
+ *		 - first byte is the slave address;
+ *		 - second byte is the register address; if this byte is 0xFF the write
+ *         operation is not executed.
+ *		 As an output parameter from the first byte onwards are located
+ *		 data bytes.
+ * @param bytesNumber - number of bytes to read.
+ *
+ * @return Number of read bytes.
+*******************************************************************************/
+unsigned char I2C_Read(unsigned char* data, unsigned char bytesNumber)
+{
+	unsigned char slaveAddress		= data[0];
+	unsigned char registerAddress	= data[1];
+	slaveAddress = (slaveAddress << 1);
+    if(registerAddress != 0xFF)
+    {
+		R_IIC_MasterSend(0,
+						 PDL_IIC_START_ENABLE | PDL_IIC_STOP_DISABLE,
+						 slaveAddress,
+						 (uint8_t*)&registerAddress,
+						 1,
+						 PDL_NO_FUNC,
+						 0);
+	}
+	slaveAddress += 1;
+	R_IIC_MasterReceive(0,
+						PDL_NO_DATA,
+						(slaveAddress << 1 | 0x01),
+						(uint8_t*)data,
+						bytesNumber,
+						PDL_NO_FUNC,
+						0);
+	
+	return(bytesNumber);
+}

+ 80 - 0
doc/adc/ad7793_rx62n/Communication.h

@@ -0,0 +1,80 @@
+/***************************************************************************//**
+ *   @file   Communication.h
+ *   @brief  Header file of Communication Driver for RENESAS RX62N Processor.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+#ifndef _COMMUNICATION_H_
+#define _COMMUNICATION_H_
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRX62N.h"
+
+/******************************************************************************/
+/* GPIO Definitions                                                           */
+/******************************************************************************/
+#define AD7793_CS_PIN        PDL_IO_PORT_C_1
+#define AD7793_CS_PIN_OUT    R_IO_PORT_Set(AD7793_CS_PIN, PDL_IO_PORT_OUTPUT)
+#define AD7793_CS_LOW        R_IO_PORT_Write(AD7793_CS_PIN, 0)
+#define AD7793_CS_HIGH       R_IO_PORT_Write(AD7793_CS_PIN, 1)
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+/* Initializes the SPI communication peripheral. */
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha);
+/* Writes data to SPI. */
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber);
+/* Reads data from SPI. */
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber);
+/* Initializes the I2C communication peripheral. */
+unsigned char I2C_Init(unsigned long clockFreq);
+/* Writes data to I2C. */
+unsigned char I2C_Write(unsigned char* data,
+                        unsigned char bytesNumber);
+/* Reads data from I2C. */
+unsigned char I2C_Read(unsigned char* data,
+                       unsigned char bytesNumber);
+#endif	// _COMMUNICATION_H_

+ 159 - 0
doc/adc/ad7793_rx62n/Main.c

@@ -0,0 +1,159 @@
+/***************************************************************************//**
+ *   @file   Main.c
+ *   @brief  Implementation of the program's main function.
+ *   @author Bancisor Mihai
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRX62N.h"	// YRDKRX62N definitions.
+#include "ST7579.h"		// ST7579 definitions.
+#include "AD7793.h"		// ADF4360 definitions.
+
+/******************************************************************************/
+/* Variables Declarations                                                     */
+/******************************************************************************/
+const unsigned char adiLogo [2 * 19] =
+	{ 0xFF, 0xFF, 0xFF, 0x03, 0x03, 0x03, 0x07, 0x07,
+	  0x0F, 0x0F, 0x1F, 0x1F, 0x3F, 0x3F, 0x7F, 0x7F,
+	  0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xC0, 0xC0,
+	  0xC0, 0xE0, 0xE0, 0xF0, 0xF0, 0xF8, 0xF8, 0xFC,
+	  0xFC, 0xFE, 0xFE, 0xFF, 0xFF, 0xFF };
+unsigned char 	periodEnd	= 0;	// Indicates when the OneShot period ends.
+unsigned long 	value 		= 0;	// value read from the ADC
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+void DelaySeconds(float seconds);
+void OneShotCallback(void);
+
+/***************************************************************************//**
+ * @brief Main function.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void main(void)
+{
+	YRDKRX62N_Init();
+	ST7579_Init();
+    ST7579_Image(2,0,adiLogo,19,16);
+    ST7579_String(2,21,"ANALOG");
+    ST7579_String(3,21,"DEVICES");
+    ST7579_String(4,0,"wiki.analog.com");
+	DelaySeconds(2);
+	ST7579_Clear();
+	ST7579_Image(0,0,adiLogo,19,16);	
+	ST7579_String(0,22,"ST7579 OK");
+
+	AD7793_Reset();		// Reset AD7793 to bring the SPI interface in a  known state
+	if(AD7793_Init())
+	{
+		ST7579_String(1,22,"AD7793 OK");
+	}
+	else
+	{
+		ST7579_String(1,22,"AD7793 Err");		
+	}
+	/* AD7792 setup. */
+    AD7793_SetGain(AD7793_GAIN_1);                // set gain to 1
+    AD7793_SetChannel(AD7793_CH_AIN1P_AIN1M);     // use AIN1(+) - AIN1(-) 
+    AD7793_SetReference(AD7793_REFSEL_INT);       // select internal 1.17V reference
+    /* Print the value of the configuration register after setup */
+    ST7579_String(3,0,"Conf Reg:");
+	ST7579_HexNumber(3,70,AD7793_GetRegisterValue( AD7793_REG_CONF,2),2);
+	while(1)
+	{	
+        if(AD7793_Ready())
+        {
+           	ST7579_String(5,2,"AIN1(+)-AIN1(-)");
+            value = AD7793_GetRegisterValue( AD7793_REG_DATA,3);
+            ST7579_String(4,0,"Data:");
+            ST7579_HexNumber(4,75,value,4);
+            if(value > 0x800000)
+            {
+                value -= 0x800000;
+                value = ((value * 1170) >> 23);
+                ST7579_String(6,10,"+");
+            }
+            else
+            {
+                value = 0x800000 - value;
+                value = ((value * 1170) >> 23);
+                ST7579_String(6,10,"-");
+            }
+            ST7579_Number(6,55,value);
+            ST7579_String(6,65,"mV");
+		}
+		 
+	}
+}
+
+/***************************************************************************//**
+ * @brief Creates a delay of seconds.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void DelaySeconds(float seconds)
+{
+	periodEnd = 0;
+	R_TMR_CreateOneShot(PDL_TMR_UNIT0,
+						PDL_TMR_OUTPUT_OFF,
+						seconds,
+						OneShotCallback,
+						4);
+	while(periodEnd == 0);
+}
+
+/***************************************************************************//**
+ * @brief OneShot callback function.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void OneShotCallback(void)
+{
+	periodEnd = 1;
+}

+ 375 - 0
doc/adc/ad7793_rx62n/ST7579.c

@@ -0,0 +1,375 @@
+/***************************************************************************//**
+ *   @file   ST7579.c
+ *   @brief  Implementation of ST7579 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "Communication.h"	// Communication definitions.
+#include "ST7579.h"			// ST7579 definitions.
+
+/******************************************************************************/
+/* Private variables                                                          */
+/******************************************************************************/
+const unsigned char st7579Font[95][5] =
+{
+	{ 0x00, 0x00, 0x00, 0x00, 0x00 },	// sp
+	{ 0x00, 0x00, 0x2f, 0x00, 0x00 },	// !
+	{ 0x00, 0x07, 0x00, 0x07, 0x00 },	// "
+	{ 0x14, 0x7f, 0x14, 0x7f, 0x14 },	// #
+	{ 0x24, 0x2a, 0x7f, 0x2a, 0x12 },	// $
+	{ 0xc4, 0xc8, 0x10, 0x26, 0x46 },	// %
+	{ 0x36, 0x49, 0x55, 0x22, 0x50 },	// &
+	{ 0x00, 0x05, 0x03, 0x00, 0x00 },	// '
+	{ 0x00, 0x1c, 0x22, 0x41, 0x00 },	// (
+	{ 0x00, 0x41, 0x22, 0x1c, 0x00 },	// )
+	{ 0x14, 0x08, 0x3E, 0x08, 0x14 },	// *
+	{ 0x08, 0x08, 0x3E, 0x08, 0x08 },	// +
+	{ 0x00, 0x00, 0x50, 0x30, 0x00 },	// ,
+	{ 0x10, 0x10, 0x10, 0x10, 0x10 },	// -
+	{ 0x00, 0x60, 0x60, 0x00, 0x00 },	// .
+	{ 0x20, 0x10, 0x08, 0x04, 0x02 },	// /
+	{ 0x3E, 0x51, 0x49, 0x45, 0x3E },	// 0
+	{ 0x00, 0x42, 0x7F, 0x40, 0x00 },	// 1
+	{ 0x42, 0x61, 0x51, 0x49, 0x46 },	// 2
+	{ 0x21, 0x41, 0x45, 0x4B, 0x31 },	// 3
+	{ 0x18, 0x14, 0x12, 0x7F, 0x10 },	// 4
+	{ 0x27, 0x45, 0x45, 0x45, 0x39 },	// 5
+	{ 0x3C, 0x4A, 0x49, 0x49, 0x30 },	// 6
+	{ 0x01, 0x71, 0x09, 0x05, 0x03 },	// 7
+	{ 0x36, 0x49, 0x49, 0x49, 0x36 },	// 8
+	{ 0x06, 0x49, 0x49, 0x29, 0x1E },	// 9
+	{ 0x00, 0x36, 0x36, 0x00, 0x00 },	// :
+	{ 0x00, 0x56, 0x36, 0x00, 0x00 },	// ;
+	{ 0x08, 0x14, 0x22, 0x41, 0x00 },	// <
+	{ 0x14, 0x14, 0x14, 0x14, 0x14 },	// =
+	{ 0x00, 0x41, 0x22, 0x14, 0x08 },	// >
+	{ 0x02, 0x01, 0x51, 0x09, 0x06 },	// ?
+	{ 0x32, 0x49, 0x59, 0x51, 0x3E },	// @
+	{ 0x7E, 0x11, 0x11, 0x11, 0x7E },	// A
+	{ 0x7F, 0x49, 0x49, 0x49, 0x36 },	// B
+	{ 0x3E, 0x41, 0x41, 0x41, 0x22 },	// C
+	{ 0x7F, 0x41, 0x41, 0x22, 0x1C },	// D
+	{ 0x7F, 0x49, 0x49, 0x49, 0x41 },	// E
+	{ 0x7F, 0x09, 0x09, 0x09, 0x01 },	// F
+	{ 0x3E, 0x41, 0x49, 0x49, 0x7A },	// G
+	{ 0x7F, 0x08, 0x08, 0x08, 0x7F },	// H
+	{ 0x00, 0x41, 0x7F, 0x41, 0x00 },	// I
+	{ 0x20, 0x40, 0x41, 0x3F, 0x01 },	// J
+	{ 0x7F, 0x08, 0x14, 0x22, 0x41 },	// K
+	{ 0x7F, 0x40, 0x40, 0x40, 0x40 },	// L
+	{ 0x7F, 0x02, 0x0C, 0x02, 0x7F },	// M
+	{ 0x7F, 0x04, 0x08, 0x10, 0x7F },	// N
+	{ 0x3E, 0x41, 0x41, 0x41, 0x3E },	// O
+	{ 0x7F, 0x09, 0x09, 0x09, 0x06 },	// P
+	{ 0x3E, 0x41, 0x51, 0x21, 0x5E },	// Q
+	{ 0x7F, 0x09, 0x19, 0x29, 0x46 },	// R
+	{ 0x46, 0x49, 0x49, 0x49, 0x31 },	// S
+	{ 0x01, 0x01, 0x7F, 0x01, 0x01 },	// T
+	{ 0x3F, 0x40, 0x40, 0x40, 0x3F },	// U
+	{ 0x1F, 0x20, 0x40, 0x20, 0x1F },	// V
+	{ 0x3F, 0x40, 0x38, 0x40, 0x3F },	// W
+	{ 0x63, 0x14, 0x08, 0x14, 0x63 },	// X
+	{ 0x07, 0x08, 0x70, 0x08, 0x07 },	// Y
+	{ 0x61, 0x51, 0x49, 0x45, 0x43 },	// Z
+	{ 0x00, 0x7F, 0x41, 0x41, 0x00 },	// [
+	{ 0x55, 0x2A, 0x55, 0x2A, 0x55 },	// /
+	{ 0x00, 0x41, 0x41, 0x7F, 0x00 },	// ]
+	{ 0x04, 0x02, 0x01, 0x02, 0x04 },	// ^
+	{ 0x40, 0x40, 0x40, 0x40, 0x40 },	// _
+	{ 0x00, 0x01, 0x02, 0x04, 0x00 },	// '
+	{ 0x20, 0x54, 0x54, 0x54, 0x78 },	// a
+	{ 0x7F, 0x48, 0x44, 0x44, 0x38 },	// b
+	{ 0x38, 0x44, 0x44, 0x44, 0x20 },	// c
+	{ 0x38, 0x44, 0x44, 0x48, 0x7F },	// d
+	{ 0x38, 0x54, 0x54, 0x54, 0x18 },	// e
+	{ 0x08, 0x7E, 0x09, 0x01, 0x02 },	// f
+	{ 0x0C, 0x52, 0x52, 0x52, 0x3E },	// g
+	{ 0x7F, 0x08, 0x04, 0x04, 0x78 },	// h
+	{ 0x00, 0x44, 0x7D, 0x40, 0x00 },	// i
+	{ 0x20, 0x40, 0x44, 0x3D, 0x00 },	// j
+	{ 0x7F, 0x10, 0x28, 0x44, 0x00 },	// k
+	{ 0x00, 0x41, 0x7F, 0x40, 0x00 },	// l
+	{ 0x7C, 0x04, 0x18, 0x04, 0x78 },	// m
+	{ 0x7C, 0x08, 0x04, 0x04, 0x78 },	// n
+	{ 0x38, 0x44, 0x44, 0x44, 0x38 },	// o
+	{ 0x7C, 0x14, 0x14, 0x14, 0x08 },	// p
+	{ 0x08, 0x14, 0x14, 0x18, 0x7C },	// q
+	{ 0x7C, 0x08, 0x04, 0x04, 0x08 },	// r
+	{ 0x48, 0x54, 0x54, 0x54, 0x20 },	// s
+	{ 0x04, 0x3F, 0x44, 0x40, 0x20 },	// t
+	{ 0x3C, 0x40, 0x40, 0x20, 0x7C },	// u
+	{ 0x1C, 0x20, 0x40, 0x20, 0x1C },	// v
+	{ 0x3C, 0x40, 0x30, 0x40, 0x3C },	// w
+	{ 0x44, 0x28, 0x10, 0x28, 0x44 },	// x
+	{ 0x0C, 0x50, 0x50, 0x50, 0x3C },	// y
+	{ 0x44, 0x64, 0x54, 0x4C, 0x44 },	// z
+	{ 0x08, 0x3e, 0x41, 0x41, 0x00 },	// { 
+	{ 0x00, 0x00, 0x77, 0x00, 0x00 },	// | 
+	{ 0x00, 0x41, 0x41, 0x3e, 0x08 },	// } 
+	{ 0x02, 0x01, 0x02, 0x01, 0x00 }	// ~
+};
+
+/***************************************************************************//**
+ * @brief Transmits 8 bits to ST7579 controller.
+ *
+ * @param data - data to transmit.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_WriteByte(unsigned char data)
+{
+    unsigned char spiWord[2]    = {0};
+    spiWord[0] = 0x02;
+    spiWord[1] = data;
+	SPI_Write(spiWord,1);
+}
+
+/***************************************************************************//**
+ * @brief Initializes the ST7579 controller.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+unsigned char ST7579_Init(void)
+{
+	unsigned char status  = 0x0;
+	status = SPI_Init(0, 1000000, 1, 0);
+	ST7579_RS_PIN_OUT;
+	ST7579_RS_LOW;
+	/* Select LCD bias ratio of the voltage required for driving the LCD. */
+	ST7579_WriteByte(0x21);
+	ST7579_WriteByte(0x16);
+	/* Select Booster efficiency and Booster stage. */
+	ST7579_WriteByte(0x23);
+	ST7579_WriteByte(0x99);
+	/* Set V0 Range. */
+	ST7579_WriteByte(0x20);	
+	ST7579_WriteByte(0x04);
+	/* 50 ms delay is recommended. */
+	/* Set the frame frequency */
+	ST7579_WriteByte(0x23);
+	ST7579_WriteByte(0x0C);
+	/* Set V0. */
+	ST7579_WriteByte(0x21);	
+	ST7579_WriteByte(0xE7);
+	/* Select the display mode */
+	ST7579_WriteByte(0x20);
+	ST7579_WriteByte(0x0C);
+	ST7579_RS_HIGH;
+	/* Clear RAM. */
+	ST7579_Clear();
+
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Clears ST7579 RAM.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Clear(void)
+{
+	unsigned short clearPosition;
+	unsigned char yPosition = 0x0;	
+	for(clearPosition = 0;clearPosition < (64 * 96);clearPosition ++)
+	{
+		if(!(clearPosition % 96))
+		{
+			ST7579_RS_LOW;
+			/* Set X address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x80);
+			/* Set Y address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x40 + yPosition);
+			yPosition ++;
+			ST7579_RS_HIGH;
+		}
+		ST7579_WriteByte(0x00);
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends a character to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param character - The character.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Char(unsigned char yPosition,
+                 unsigned char xPosition,
+                 unsigned char character)
+{
+	volatile unsigned char column;
+	ST7579_RS_LOW;
+	/* Set X address of RAM. */
+	ST7579_WriteByte(0x28);
+	ST7579_WriteByte(0x80 + xPosition);
+	/* Set Y address of RAM. */
+	ST7579_WriteByte(0x28);
+	ST7579_WriteByte(0x40 + yPosition);
+	ST7579_RS_HIGH;
+	/* Send character data. */
+	for(column = 0;column < 5;column ++)
+	{
+		ST7579_WriteByte(st7579Font[character - 32][column] << 1);
+	}
+	ST7579_WriteByte(0x00);
+}
+
+/***************************************************************************//**
+ * @brief Sends a string to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param string - The string.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_String(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned char* string)
+{
+	while(*string)
+	{
+		/* Send each character of the string. */
+		ST7579_Char(yPosition, xPosition, *string++);
+		xPosition += 6;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an integer number to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param number - The number.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Number(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned int number)
+{
+	char position = 6;
+	while(position--)
+	{
+		ST7579_Char(yPosition, xPosition, (number % 10) + 0x30);
+		xPosition -= 6;
+		number = number / 10;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an integer number in Hexa format to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param number - The number.
+ * @param bytesNumber - Number of bytes.
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_HexNumber(unsigned char yPosition,
+					  unsigned char xPosition,
+					  unsigned int number,
+					  unsigned char bytesNumber)
+{
+	char position = bytesNumber * 2;
+	char character = 0;
+	while(position--)
+	{
+		character = (number % 16);
+		if (character <= 9)
+		{
+			character += 0x30;
+		}
+		else
+		{
+			character +=0x37;
+		}
+		ST7579_Char(yPosition, xPosition, character);
+		xPosition -= 6;
+		number = number / 16;
+	}
+}
+
+/***************************************************************************//**
+ * @brief Sends an image array to ST7579 controller.
+ *
+ * @param yPosition - Y address of RAM.
+ * @param xPosition - X address of RAM.
+ * @param image - The image array.
+ * @param width - The width of the image (pixels).
+ * @param height - The height of the image (pixels).
+ *
+ * @return None.
+*******************************************************************************/
+void ST7579_Image(unsigned char yPosition,
+                  unsigned char xPosition,
+                  const unsigned char image[],
+                  unsigned char width,
+                  unsigned char height)
+{
+	unsigned short index;
+	for(index = 0;index < (width * height / 8);index ++)
+	{
+		if(!(index % width))
+		{
+			ST7579_RS_LOW;
+			/* Set X address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x80 + xPosition);
+			/* Set Y address of RAM. */
+			ST7579_WriteByte(0x28);
+			ST7579_WriteByte(0x40 + yPosition);
+			yPosition ++;
+			ST7579_RS_HIGH;
+		}
+		ST7579_WriteByte(image[index]);
+	}
+}

+ 77 - 0
doc/adc/ad7793_rx62n/ST7579.h

@@ -0,0 +1,77 @@
+/***************************************************************************//**
+ *   @file   ST7579.h
+ *   @brief  Header file of ST7579 Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+#ifndef _ST7579_H_
+#define _ST7579_H_
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+/* Transmits 8 bits to ST7579 controller. */
+void ST7579_WriteByte(unsigned char data);
+/* Initializes the ST7579 controller. */
+unsigned char ST7579_Init(void);
+/* Clears ST7579 RAM. */
+void ST7579_Clear(void);
+/* Sends a character to ST7579 controller. */
+void ST7579_Char(unsigned char yPosition,
+                 unsigned char xPosition,
+                 unsigned char character);
+/* Sends a string to ST7579 controller. */
+void ST7579_String(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned char* string);
+/* Sends an integer number to ST7579 controller. */
+void ST7579_Number(unsigned char yPosition,
+                   unsigned char xPosition,
+                   unsigned int number);
+/* Sends an integer number in Hexa format to ST7579 controller. */
+void ST7579_HexNumber(unsigned char yPosition,
+					  unsigned char xPosition,
+					  unsigned int number,
+					  unsigned char bytesNumber);
+/* Sends an image array to ST7579 controller. */
+void ST7579_Image(unsigned char yPosition,
+                  unsigned char xPosition,
+                  const unsigned char image[],
+                  unsigned char width,
+                  unsigned char height);
+#endif	// _ST7579_H_

+ 96 - 0
doc/adc/ad7793_rx62n/YRDKRX62N.c

@@ -0,0 +1,96 @@
+/***************************************************************************//**
+ *   @file   YRDKRX62N.h
+ *   @brief  Header file of YRDKRX62N Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include "YRDKRX62N.h"
+
+/***************************************************************************//**
+ * @brief Reset the YRDKRX62N's peripherals.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void YRDKRL78G13_Reset(void)
+{
+    unsigned short delay;
+	ST7579_RESET_PIN_OUT;
+	ST7579_RESET_HIGH;
+    for(delay = 0;delay < 1000;delay ++)
+    {
+		nop();
+    }
+	ST7579_RESET_LOW;
+}
+
+/***************************************************************************//**
+ * @brief Initializes the YRDKRX62N.
+ *
+ * @param None.
+ *
+ * @return None.
+*******************************************************************************/
+void YRDKRX62N_Init(void)
+{
+	YRDKRL78G13_Reset();
+	R_CGC_Set(12.0E6,				// Input frequency 12 MHz.
+			  12E6,					// System frequency 12 MHz.
+			  12E6,					// Peripheral module frequency 12 MHz.
+			  PDL_NO_DATA,			// External bus clock frequency.
+			  PDL_CGC_BCLK_HIGH);	// Configuration options.
+	/* All LEDs connected to Port D off. */
+	R_IO_PORT_Write(PDL_IO_PORT_D, 0xFF);
+	/* Port D - Output. */
+    R_IO_PORT_Set(LED14_PIN | LED10_PIN | LED6_PIN  | LED12_PIN |
+				  LED8_PIN  | LED4_PIN  | LED15_PIN | LED11_PIN,
+				  PDL_IO_PORT_OUTPUT);
+	/* All LEDs connected to Port E off. */
+	R_IO_PORT_Write(PDL_IO_PORT_E, 0x0F);
+	/* Port E - Pins 0, 1, 2, 3 output. */
+    R_IO_PORT_Set(LED7_PIN | LED13_PIN | LED9_PIN | LED5_PIN,
+				  PDL_IO_PORT_OUTPUT);
+	/* Port 4 - Pins 0, 1, 2 input. */
+	R_IO_PORT_Set(SW1_PIN | SW2_PIN | SW3_PIN,
+				  PDL_IO_PORT_INPUT | PDL_IO_PORT_INPUT_BUFFER_ON);
+}

+ 93 - 0
doc/adc/ad7793_rx62n/YRDKRX62N.h

@@ -0,0 +1,93 @@
+/***************************************************************************//**
+ *   @file   YRDKRX62N.h
+ *   @brief  Header file of YRDKRX62N Driver.
+ *   @author DBogdan (dragos.bogdan@analog.com)
+********************************************************************************
+ * Copyright 2012(c) Analog Devices, Inc.
+ *
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *  - Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ *  - Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ *  - Neither the name of Analog Devices, Inc. nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *  - The use of this software may or may not infringe the patent rights
+ *    of one or more patent holders.  This license does not release you
+ *    from the requirement that you obtain separate licenses from these
+ *    patent holders to use this software.
+ *  - Use of the software either in source or binary form, must be run
+ *    on or directly connected to an Analog Devices Inc. component.
+ *
+ * THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT,
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+********************************************************************************
+ *   SVN Revision: 381
+*******************************************************************************/
+#ifndef _YRDKRX62N_H_
+#define _YRDKRX62N_H_
+
+/******************************************************************************/
+/* Include Files                                                              */
+/******************************************************************************/
+#include <r_pdl_cgc.h>			// RPDL definitions.
+#include <r_pdl_io_port.h>		// RPDL definitions.
+#include <r_pdl_spi.h>			// RPDL definitions.
+#include <r_pdl_iic.h>			// RPDL definitions.
+#include <r_pdl_tmr.h>			// RPDL definitions.
+#include <r_pdl_definitions.h>	// RPDL device-specific definitions.
+
+/******************************************************************************/
+/* Macros and Constants Definitions                                           */
+/******************************************************************************/
+#define ST7579_CS_PIN		 PDL_IO_PORT_C_2
+#define ST7579_CS_PIN_OUT	 R_IO_PORT_Set(ST7579_CS_PIN, PDL_IO_PORT_OUTPUT)
+#define ST7579_CS_LOW		 R_IO_PORT_Write(ST7579_CS_PIN, 0)
+#define ST7579_CS_HIGH		 R_IO_PORT_Write(ST7579_CS_PIN, 1)
+#define ST7579_RS_PIN		 PDL_IO_PORT_5_1
+#define ST7579_RS_PIN_OUT	 R_IO_PORT_Set(ST7579_RS_PIN, PDL_IO_PORT_OUTPUT)
+#define ST7579_RS_LOW        R_IO_PORT_Write(ST7579_RS_PIN, 0)
+#define	ST7579_RS_HIGH	     R_IO_PORT_Write(ST7579_RS_PIN, 1)
+#define ST7579_RESET_PIN	 PDL_IO_PORT_C_3
+#define ST7579_RESET_PIN_OUT R_IO_PORT_Set(ST7579_RESET_PIN, PDL_IO_PORT_OUTPUT)
+#define ST7579_RESET_LOW	 R_IO_PORT_Write(ST7579_RESET_PIN, 0)
+#define ST7579_RESET_HIGH	 R_IO_PORT_Write(ST7579_RESET_PIN, 1)
+#define MOSIA_PIN			 PDL_IO_PORT_C_6
+#define MOSIA_PIN_OUT		 R_IO_PORT_Set(MOSIA_PIN, PDL_IO_PORT_OUTPUT)
+#define MISOA_PIN			 PDL_IO_PORT_C_7
+#define MISOA_PIN_IN		 R_IO_PORT_Set(MISOA_PIN, PDL_IO_PORT_INPUT)
+#define LED4_PIN			 PDL_IO_PORT_D_5
+#define LED5_PIN			 PDL_IO_PORT_E_3
+#define LED6_PIN			 PDL_IO_PORT_D_2
+#define LED7_PIN			 PDL_IO_PORT_E_0
+#define LED8_PIN			 PDL_IO_PORT_D_4
+#define LED9_PIN			 PDL_IO_PORT_E_2
+#define LED10_PIN			 PDL_IO_PORT_D_1
+#define LED11_PIN			 PDL_IO_PORT_D_7
+#define LED12_PIN			 PDL_IO_PORT_D_3
+#define LED13_PIN			 PDL_IO_PORT_E_1
+#define LED14_PIN			 PDL_IO_PORT_D_0
+#define LED15_PIN			 PDL_IO_PORT_D_6
+#define SW1_PIN				 PDL_IO_PORT_4_0
+#define SW2_PIN				 PDL_IO_PORT_4_1
+#define SW3_PIN				 PDL_IO_PORT_4_2
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+void YRDKRX62N_Init(void);
+#endif	// _YRDKRX62N_H_

+ 271 - 0
fw/modules/adc/AD7793.c

@@ -0,0 +1,271 @@
+#include "AD7793.h"				
+#include "Communication.h"
+
+
+
+/***************************************************************************//**
+ * @brief Initializes the MS5192T and checks if the device is present.
+ *
+ * @return status - Result of the initialization procedure.
+ *                  Example: 1 - if initialization was successful (ID is 0x0B).
+ *                           0 - if initialization was unsuccessful.
+*******************************************************************************/
+unsigned char MS5192T_Init(void)
+{ 
+	unsigned char status = 0x1;
+    
+    if((MS5192T_GetRegisterValue(MS5192T_REG_ID, 1, 1) & 0x0F) != MS5192T_ID)
+	{
+		status = 0x0;
+	}
+    
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Sends 32 consecutive 1's on SPI in order to reset the part.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_Reset(void)
+{
+	unsigned char dataToSend[5] = {0xff, 0xff, 0xff, 0xff};
+	
+    MS5192T_CS_LOW;	    
+	SPI_Write(dataToSend,4);
+	MS5192T_CS_HIGH;	
+}
+/***************************************************************************//**
+ * @brief Reads the value of the selected register
+ *
+ * @param regAddress - The address of the register to read.
+ * @param size - The size of the register to read.
+ *
+ * @return data - The value of the selected register register.
+*******************************************************************************/
+unsigned long MS5192T_GetRegisterValue(unsigned char regAddress, 
+                                      unsigned char size,
+                                      unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};
+	unsigned long receivedData = 0x00;
+    unsigned char i            = 0x00; 
+    
+	data[0] = 0x01 * modifyCS;
+	data[1] = MS5192T_COMM_READ | MS5192T_COMM_ADDR(regAddress); 
+	SPI_Read(data,(1 + size));
+	for(i = 1;i < size + 1;i ++)
+    {
+        receivedData = (receivedData << 8) + data[i];
+    }
+    
+    return (receivedData);
+}
+/***************************************************************************//**
+ * @brief Writes the value to the register
+ *
+ * @param -  regAddress - The address of the register to write to.
+ * @param -  regValue - The value to write to the register.
+ * @param -  size - The size of the register to write.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetRegisterValue(unsigned char regAddress,
+                             unsigned long regValue, 
+                             unsigned char size,
+                             unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};	
+	unsigned char* dataPointer = (unsigned char*)&regValue;
+    unsigned char bytesNr      = size + 1;
+    
+    data[0] = 0x01 * modifyCS;
+    data[1] = MS5192T_COMM_WRITE |  MS5192T_COMM_ADDR(regAddress);
+    while(bytesNr > 1)
+    {
+        data[bytesNr] = *dataPointer;
+        dataPointer ++;
+        bytesNr --;
+    }	    
+	SPI_Write(data,(1 + size));
+}
+/***************************************************************************//**
+ * @brief  Waits for RDY pin to go low.
+ *
+ * @return None.
+*******************************************************************************/
+void MS5192T_WaitRdyGoLow(void)
+{
+/*  
+    while( MS5192T_RDY_STATE )
+    {
+        ;
+    }
+*/    
+}
+
+/***************************************************************************//**
+ * @brief Sets the operating mode of MS5192T.
+ *
+ * @param mode - Mode of operation.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetMode(unsigned long mode)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_MODE,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_MODE_SEL(0xFF);
+    command |= MS5192T_MODE_SEL(mode);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_MODE,
+            command,
+            2, 
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Selects the channel of MS5192T.
+ *
+ * @param  channel - ADC channel selection.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetChannel(unsigned long channel)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_CHAN(0xFF);
+    command |= MS5192T_CONF_CHAN(channel);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief  Sets the gain of the In-Amp.
+ *
+ * @param  gain - Gain.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetGain(unsigned long gain)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_GAIN(0xFF);
+    command |= MS5192T_CONF_GAIN(gain);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Sets the reference source for the ADC.
+ *
+ * @param type - Type of the reference.
+ *               Example: AD7793_REFSEL_EXT	- External Reference Selected
+ *                        AD7793_REFSEL_INT	- Internal Reference Selected.
+ *
+ * @return None.    
+*******************************************************************************/
+void MS5192T_SetIntReference(unsigned char type)
+{
+    unsigned long command = 0;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_REFSEL(MS5192T_REFSEL_INT);
+    command |= MS5192T_CONF_REFSEL(type);
+    MS5192T_SetRegisterValue(MS5192T_REG_CONF,
+							command,
+							2,
+                            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief Performs the given calibration to the specified channel.
+ *
+ * @param mode - Calibration type.
+ * @param channel - Channel to be calibrated.
+ *
+ * @return none.
+*******************************************************************************/
+void MS5192T_Calibrate(unsigned char mode, unsigned char channel)
+{
+    unsigned short oldRegValue = 0x0;
+    unsigned short newRegValue = 0x0;
+    
+    MS5192T_SetChannel(channel);
+    oldRegValue &= MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1); // CS is modified by SPI read/write functions.
+    oldRegValue &= ~MS5192T_MODE_SEL(0x7);
+    newRegValue = oldRegValue | MS5192T_MODE_SEL(mode);
+    MS5192T_CS_LOW; 
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE, newRegValue, 2, 0); // CS is not modified by SPI read/write functions.
+    MS5192T_WaitRdyGoLow();
+    MS5192T_CS_HIGH;
+    
+}
+
+/***************************************************************************//**
+ * @brief Returns the result of a single conversion.
+ *
+ * @return regData - Result of a single analog-to-digital conversion.
+*******************************************************************************/
+unsigned long MS5192T_SingleConversion(void)
+{
+    unsigned long command = 0x0;
+    unsigned long regData = 0x0;
+    
+    command  = MS5192T_MODE_SEL(MS5192T_MODE_SINGLE);
+    MS5192T_CS_LOW;
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE, 
+                            command,
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    MS5192T_WaitRdyGoLow();
+    regData = MS5192T_GetRegisterValue(MS5192T_REG_DATA, 3, 0); // CS is not modified by SPI read/write functions.
+    MS5192T_CS_HIGH;
+
+    return(regData);
+}
+
+/***************************************************************************//**
+ * @brief Returns the average of several conversion results.
+ *
+ * @return samplesAverage - The average of the conversion results.
+*******************************************************************************/
+unsigned long MS5192T_ContinuousReadAvg(unsigned char sampleNumber)
+{
+    unsigned long samplesAverage = 0x0;
+    unsigned long command        = 0x0;
+    unsigned char count          = 0x0;
+    
+    command = MS5192T_MODE_SEL(MS5192T_MODE_CONT);
+    MS5192T_CS_LOW;
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE,
+                            command, 
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    for(count = 0;count < sampleNumber;count ++)
+    {
+        MS5192T_WaitRdyGoLow();
+        samplesAverage += MS5192T_GetRegisterValue(MS5192T_REG_DATA, 3, 0);  // CS is not modified by SPI read/write functions.
+    }
+    MS5192T_CS_HIGH;
+    samplesAverage = samplesAverage / sampleNumber;
+    
+    return(samplesAverage);
+}

+ 5 - 0
fw/modules/adc/Communication.c

@@ -0,0 +1,5 @@
+#include "at32f403a_407.h"
+#include "Communication.h"
+
+
+

+ 22 - 0
fw/modules/adc/Communication.h

@@ -0,0 +1,22 @@
+#ifndef __COMMUNICATION_H__
+#define __COMMUNICATION_H__
+
+#include "at32f403a_407.h"
+
+
+
+#if 0
+#define ADI_PAR_CS_PIN         (1 << 1)
+#define ADI_PART_CS_PIN_OUT    PM7 &= ~(ADI_PAR_CS_PIN);
+#define ADI_PART_CS_LOW        P7 &= ~ADI_PAR_CS_PIN;
+#define ADI_PART_CS_HIGH       P7 |=  ADI_PAR_CS_PIN;
+#define GPIO1_PIN              (1 << 3)
+#define GPIO1_STATE            (P0 & GPIO1_PIN)
+#endif
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+
+
+#endif	// __COMMUNICATION_H__

+ 313 - 0
fw/modules/adc/adc_transport.c

@@ -0,0 +1,313 @@
+#include "at32f403a_407.h"
+#include "ms5192t.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "settings_api.h"
+#include "io_utils.h"
+#include "adc_transport.h"
+#include <stdio.h>
+
+
+
+//
+void adc_gpio_init(void)
+{
+#if 0  
+    gpio_init_type gpio_initstructure;
+        
+    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_NONE;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_11 | GPIO_PINS_12 | 
+                                             GPIO_PINS_13 | GPIO_PINS_14;
+    
+    gpio_init(GPIOE, &gpio_initstructure); 
+#endif    
+    
+    gpio_init_type gpio_initstructure;
+    spi_init_type spi_init_struct;
+  
+    crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
+    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
+    
+    gpio_pin_remap_config(SPI4_GMUX_0001, TRUE);
+  
+    // SCK
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_DOWN;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_11;
+    gpio_init(GPIOE, &gpio_initstructure);
+  
+    // MISO
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_INPUT;  
+    gpio_initstructure.gpio_pins           = GPIO_PINS_13;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    // MOSI
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX; 
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+     
+    // CS
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_12;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    
+    MS5192T_CS_HIGH;
+
+    crm_periph_clock_enable(CRM_SPI4_PERIPH_CLOCK, TRUE);
+    
+    spi_default_para_init(&spi_init_struct);
+    spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
+    spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
+    spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_32; //SPI_MCLK_DIV_2;
+    spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
+    spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
+    spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;
+    spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
+    spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
+    
+    spi_init(MS5192T_SPI, &spi_init_struct);
+ 
+    //spi_hardware_cs_output_enable(SPI3, TRUE);
+    
+    //adc_mosi_to_spi();
+    
+    spi_enable(MS5192T_SPI, TRUE);
+    
+    
+}
+
+//
+void adc_mosi_high(void)
+{
+    gpio_init_type gpio_initstructure;
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    gpio_bits_set(GPIOE, GPIO_PINS_14);
+}
+
+//
+void adc_mosi_to_spi(void)
+{
+    gpio_init_type gpio_initstructure;
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+}
+
+
+/***************************************************************************//**
+ * @brief Initializes the SPI communication peripheral.
+ *
+ * @param lsbFirst - Transfer format (0 or 1).
+ *                   Example: 0x0 - MSB first.
+ *                            0x1 - LSB first.
+ * @param clockFreq - SPI clock frequency (Hz).
+ *                    Example: 1000 - SPI clock frequency is 1 kHz.
+ * @param clockPol - SPI clock polarity (0 or 1).
+ *                   Example: 0x0 - idle state for SPI clock is low.
+ *	                          0x1 - idle state for SPI clock is high.
+ * @param clockPha - SPI clock phase (0 or 1).
+ *                   Example: 0x0 - data is latched on the leading edge of SPI
+ *                                  clock and data changes on trailing edge.
+ *                            0x1 - data is latched on the trailing edge of SPI
+ *                                  clock and data changes on the leading edge.
+ *
+ * @return 0 - Initialization failed, 1 - Initialization succeeded.
+*******************************************************************************/
+unsigned char SPI_Init(unsigned char lsbFirst,
+                       unsigned long clockFreq,
+                       unsigned char clockPol,
+                       unsigned char clockPha)
+{
+/*  
+    ST7579_CS_PIN_OUT;
+    ST7579_CS_HIGH;
+    ADI_PART_CS_PIN_OUT;
+    ADI_PART_CS_HIGH;
+    R_CSI10_Start();
+*/
+    return(1);
+}
+
+/***************************************************************************//**
+ * @brief Writes data to SPI.
+ *
+ * @param data - Write data buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Write(unsigned char* data,
+                        unsigned char bytesNumber)
+{
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    
+    for (int i = 0; i < bytesNumber; i++)
+    {
+        while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_TDBE_FLAG) == RESET);
+        MS5192T_SPI->dt = data[i];
+  
+        while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_RDBF_FLAG) == RESET);
+        readData[i] = MS5192T_SPI->dt;
+    }  
+#if 0  
+  	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]  = {0, 0, 0, 0};
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    unsigned char byte          = 0;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        writeData[byte] = data[byte + 1];
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_CSI10_Send_Receive((uint8_t *)&writeData[byte], 
+                             1,
+                             (uint8_t *)readData);
+	    while(CSIIF10 == 0);
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_HIGH;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_HIGH;
+    }
+
+	return(bytesNumber);
+#endif    
+}
+
+/***************************************************************************//**
+ * @brief Reads data from SPI.
+ *
+ * @param data - As an input parameter, data represents the write buffer:
+ *               - first byte is the chip select number;
+ *               - from the second byte onwards are located data bytes to write.
+ *               As an output parameter, data represents the read buffer:
+ *               - from the first byte onwards are located the read data bytes. 
+ * @param bytesNumber - Number of bytes to write.
+ *
+ * @return Number of written bytes.
+*******************************************************************************/
+unsigned char SPI_Read(unsigned char* data,
+                       unsigned char bytesNumber)
+{
+    unsigned char writeData[4]  = {0, 0, 0, 0};
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    unsigned char byte          = 0;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        writeData[byte] = data[byte + 1];
+        data[byte + 1] = 0;
+    }
+    
+    MS5192T_CS_LOW;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_TDBE_FLAG) == RESET);
+        MS5192T_SPI->dt = writeData[byte];
+  
+        while (spi_i2s_flag_get(MS5192T_SPI, SPI_I2S_RDBF_FLAG) == RESET);
+        readData[byte] = MS5192T_SPI->dt;
+    }
+    
+    MS5192T_CS_HIGH;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        data[byte] = readData[byte];
+    }  
+      
+    return(bytesNumber);  
+      
+#if 0  
+  	unsigned char chipSelect    = data[0];
+	unsigned char writeData[4]  = {0, 0, 0, 0};
+    unsigned char readData[4]	= {0, 0, 0, 0};
+    unsigned char byte          = 0;
+    
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        writeData[byte] = data[byte + 1];
+        data[byte + 1] = 0;
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_LOW;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_LOW;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        R_CSI10_Send_Receive((uint8_t *)&writeData[byte], 
+                             1,
+                             (uint8_t *)&readData[byte]);
+	    while(CSIIF10 == 0);
+    }
+    if(chipSelect == 1)
+    {
+        ADI_PART_CS_HIGH;
+    }
+    if(chipSelect == 2)
+    {
+        ST7579_CS_HIGH;
+    }
+    for(byte = 0;byte < bytesNumber;byte ++)
+    {
+        data[byte] = readData[byte];
+    }
+    
+	return(bytesNumber);
+#endif    
+}
+
+//
+void adc_test(void)
+{
+    vTaskDelay(100);
+}
+
+
+
+
+

+ 34 - 0
fw/modules/adc/adc_transport.h

@@ -0,0 +1,34 @@
+#ifndef __ADC_TRANSPORT_H
+#define __ADC_TRANSPORT_H
+
+#define MS5192T_SPI     SPI4
+
+#define MS5192T_CS_HIGH     gpio_bits_set(GPIOE, GPIO_PINS_12)
+#define MS5192T_CS_LOW      gpio_bits_reset(GPIOE, GPIO_PINS_12)
+
+
+//
+void adc_gpio_init(void);
+
+//
+void adc_test(void);
+
+//
+void adc_mosi_high(void);
+
+//
+void adc_mosi_to_spi(void);
+
+
+// Initializes the SPI communication peripheral.
+unsigned char SPI_Init(unsigned char lsbFirst, unsigned long clockFreq,
+                       unsigned char clockPol, unsigned char clockPha);
+
+// Writes data to SPI.
+unsigned char SPI_Write(unsigned char* data, unsigned char bytesNumber);
+
+// Reads data from SPI. 
+unsigned char SPI_Read(unsigned char* data, unsigned char bytesNumber);
+
+#endif  // __ADC_TRANSPORT_H
+

+ 272 - 110
fw/modules/adc/ms5192t.c

@@ -1,110 +1,272 @@
-#include "at32f403a_407.h"
-#include "ms5192t.h"
-#include "FreeRTOS.h"
-#include "task.h"
-#include "settings_api.h"
-#include "io_utils.h"
-#include "spi_common.h"
-#include <stdio.h>
-
-
-
-#define ADC_SPI         SPI4
-
-#define ADC_CS_HIGH     gpio_bits_set(GPIOE, GPIO_PINS_12)
-#define ADC_CS_LOW      gpio_bits_reset(GPIOE, GPIO_PINS_12)
-
-
-//
-void adc_gpio_init(void)
-{
-#if 0  
-    gpio_init_type gpio_initstructure;
-        
-    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
-    
-    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
-    gpio_initstructure.gpio_pull           = GPIO_PULL_NONE;  
-    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
-    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
-    gpio_initstructure.gpio_pins           = GPIO_PINS_11 | GPIO_PINS_12 | 
-                                             GPIO_PINS_13 | GPIO_PINS_14;
-    
-    gpio_init(GPIOE, &gpio_initstructure); 
-#endif    
-    
-    gpio_init_type gpio_initstructure;
-    spi_init_type spi_init_struct;
-  
-    crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
-    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
-    
-    gpio_pin_remap_config(SPI4_GMUX_0001, TRUE);
-  
-    // SCK
-    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
-    gpio_initstructure.gpio_pull           = GPIO_PULL_DOWN;  
-    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX;  
-    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
-    gpio_initstructure.gpio_pins           = GPIO_PINS_11;
-    gpio_init(GPIOE, &gpio_initstructure);
-  
-    // MISO
-    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
-    gpio_initstructure.gpio_mode           = GPIO_MODE_INPUT;  
-    gpio_initstructure.gpio_pins           = GPIO_PINS_13;
-    gpio_init(GPIOE, &gpio_initstructure);
-    
-    // MOSI
-    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
-    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX; 
-    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
-    gpio_init(GPIOE, &gpio_initstructure);
-     
-    // CS
-    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
-    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
-    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
-    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
-    gpio_initstructure.gpio_pins           = GPIO_PINS_12;
-    gpio_init(GPIOE, &gpio_initstructure);
-    
-    
-    ADC_CS_HIGH;
-
-    crm_periph_clock_enable(CRM_SPI4_PERIPH_CLOCK, TRUE);
-    
-    spi_default_para_init(&spi_init_struct);
-    spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
-    spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
-    spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_32; //SPI_MCLK_DIV_2;
-    spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
-    spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
-    spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;
-    spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
-    spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
-    
-    spi_init(SPI4, &spi_init_struct);
- 
-    //spi_hardware_cs_output_enable(SPI3, TRUE);
-    
-    spi_enable(SPI4, TRUE);
-    
-    
-}
-
-//
-void adc_test(void)
-{
-/*  
-    gpio_bits_set(GPIOE, GPIO_PINS_11 | GPIO_PINS_12 | GPIO_PINS_13 | GPIO_PINS_14);
-    vTaskDelay(100);
-    gpio_bits_reset(GPIOE, GPIO_PINS_11 | GPIO_PINS_12 | GPIO_PINS_13 | GPIO_PINS_14);
-    vTaskDelay(100);    
-*/
-    ADC_CS_LOW;
-    common_spi_send(ADC_SPI, 0x03);
-    ADC_CS_HIGH;
-    vTaskDelay(100);
-}
-
+#include "ms5192t.h"
+#include "at32f403a_407.h"
+#include "adc_transport.h"
+
+
+
+/***************************************************************************//**
+ * @brief Initializes the MS5192T and checks if the device is present.
+ *
+ * @return status - Result of the initialization procedure.
+ *                  Example: 1 - if initialization was successful (ID is 0x0B).
+ *                           0 - if initialization was unsuccessful.
+*******************************************************************************/
+unsigned char MS5192T_Init(void)
+{ 
+	unsigned char status = 0x1;
+    
+    if((MS5192T_GetRegisterValue(MS5192T_REG_ID, 1, 1) & 0x0F) != MS5192T_ID)
+	{
+		status = 0x0;
+	}
+    
+	return(status);
+}
+
+/***************************************************************************//**
+ * @brief Sends 32 consecutive 1's on SPI in order to reset the part.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_Reset(void)
+{
+	unsigned char dataToSend[5] = {0xff, 0xff, 0xff, 0xff};
+	
+    MS5192T_CS_LOW;	    
+	SPI_Write(dataToSend,4);
+	MS5192T_CS_HIGH;	
+}
+/***************************************************************************//**
+ * @brief Reads the value of the selected register
+ *
+ * @param regAddress - The address of the register to read.
+ * @param size - The size of the register to read.
+ *
+ * @return data - The value of the selected register register.
+*******************************************************************************/
+unsigned long MS5192T_GetRegisterValue(unsigned char regAddress, 
+                                      unsigned char size,
+                                      unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};
+	unsigned long receivedData = 0x00;
+    unsigned char i            = 0x00; 
+    
+	data[0] = 0x01 * modifyCS;
+	data[1] = MS5192T_COMM_READ | MS5192T_COMM_ADDR(regAddress); 
+	SPI_Read(data,(1 + size));
+	for(i = 1;i < size + 1;i ++)
+    {
+        receivedData = (receivedData << 8) + data[i];
+    }
+    
+    return (receivedData);
+}
+/***************************************************************************//**
+ * @brief Writes the value to the register
+ *
+ * @param -  regAddress - The address of the register to write to.
+ * @param -  regValue - The value to write to the register.
+ * @param -  size - The size of the register to write.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetRegisterValue(unsigned char regAddress,
+                             unsigned long regValue, 
+                             unsigned char size,
+                             unsigned char modifyCS)
+{
+	unsigned char data[5]      = {0x00, 0x00, 0x00, 0x00, 0x00};	
+	unsigned char* dataPointer = (unsigned char*)&regValue;
+    unsigned char bytesNr      = size + 1;
+    
+    data[0] = 0x01 * modifyCS;
+    data[1] = MS5192T_COMM_WRITE |  MS5192T_COMM_ADDR(regAddress);
+    while(bytesNr > 1)
+    {
+        data[bytesNr] = *dataPointer;
+        dataPointer ++;
+        bytesNr --;
+    }	    
+	SPI_Write(data,(1 + size));
+}
+/***************************************************************************//**
+ * @brief  Waits for RDY pin to go low.
+ *
+ * @return None.
+*******************************************************************************/
+void MS5192T_WaitRdyGoLow(void)
+{
+/*  
+    while( MS5192T_RDY_STATE )
+    {
+        ;
+    }
+*/    
+}
+
+/***************************************************************************//**
+ * @brief Sets the operating mode of MS5192T.
+ *
+ * @param mode - Mode of operation.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetMode(unsigned long mode)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_MODE,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_MODE_SEL(0xFF);
+    command |= MS5192T_MODE_SEL(mode);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_MODE,
+            command,
+            2, 
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Selects the channel of MS5192T.
+ *
+ * @param  channel - ADC channel selection.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetChannel(unsigned long channel)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_CHAN(0xFF);
+    command |= MS5192T_CONF_CHAN(channel);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief  Sets the gain of the In-Amp.
+ *
+ * @param  gain - Gain.
+ *
+ * @return  None.    
+*******************************************************************************/
+void MS5192T_SetGain(unsigned long gain)
+{
+    unsigned long command;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_GAIN(0xFF);
+    command |= MS5192T_CONF_GAIN(gain);
+    MS5192T_SetRegisterValue(
+            MS5192T_REG_CONF,
+            command,
+            2,
+            1); // CS is modified by SPI read/write functions.
+}
+/***************************************************************************//**
+ * @brief Sets the reference source for the ADC.
+ *
+ * @param type - Type of the reference.
+ *               Example: AD7793_REFSEL_EXT	- External Reference Selected
+ *                        AD7793_REFSEL_INT	- Internal Reference Selected.
+ *
+ * @return None.    
+*******************************************************************************/
+void MS5192T_SetIntReference(unsigned char type)
+{
+    unsigned long command = 0;
+    
+    command = MS5192T_GetRegisterValue(MS5192T_REG_CONF,
+                                      2,
+                                      1); // CS is modified by SPI read/write functions.
+    command &= ~MS5192T_CONF_REFSEL(MS5192T_REFSEL_INT);
+    command |= MS5192T_CONF_REFSEL(type);
+    MS5192T_SetRegisterValue(MS5192T_REG_CONF,
+							command,
+							2,
+                            1); // CS is modified by SPI read/write functions.
+}
+
+/***************************************************************************//**
+ * @brief Performs the given calibration to the specified channel.
+ *
+ * @param mode - Calibration type.
+ * @param channel - Channel to be calibrated.
+ *
+ * @return none.
+*******************************************************************************/
+void MS5192T_Calibrate(unsigned char mode, unsigned char channel)
+{
+    unsigned short oldRegValue = 0x0;
+    unsigned short newRegValue = 0x0;
+    
+    MS5192T_SetChannel(channel);
+    oldRegValue &= MS5192T_GetRegisterValue(MS5192T_REG_MODE, 2, 1); // CS is modified by SPI read/write functions.
+    oldRegValue &= ~MS5192T_MODE_SEL(0x7);
+    newRegValue = oldRegValue | MS5192T_MODE_SEL(mode);
+    MS5192T_CS_LOW; 
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE, newRegValue, 2, 0); // CS is not modified by SPI read/write functions.
+    MS5192T_WaitRdyGoLow();
+    MS5192T_CS_HIGH;
+    
+}
+
+/***************************************************************************//**
+ * @brief Returns the result of a single conversion.
+ *
+ * @return regData - Result of a single analog-to-digital conversion.
+*******************************************************************************/
+unsigned long MS5192T_SingleConversion(void)
+{
+    unsigned long command = 0x0;
+    unsigned long regData = 0x0;
+    
+    command  = MS5192T_MODE_SEL(MS5192T_MODE_SINGLE);
+    MS5192T_CS_LOW;
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE, 
+                            command,
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    MS5192T_WaitRdyGoLow();
+    regData = MS5192T_GetRegisterValue(MS5192T_REG_DATA, 3, 0); // CS is not modified by SPI read/write functions.
+    MS5192T_CS_HIGH;
+
+    return(regData);
+}
+
+/***************************************************************************//**
+ * @brief Returns the average of several conversion results.
+ *
+ * @return samplesAverage - The average of the conversion results.
+*******************************************************************************/
+unsigned long MS5192T_ContinuousReadAvg(unsigned char sampleNumber)
+{
+    unsigned long samplesAverage = 0x0;
+    unsigned long command        = 0x0;
+    unsigned char count          = 0x0;
+    
+    command = MS5192T_MODE_SEL(MS5192T_MODE_CONT);
+    MS5192T_CS_LOW;
+    MS5192T_SetRegisterValue(MS5192T_REG_MODE,
+                            command, 
+                            2,
+                            0);// CS is not modified by SPI read/write functions.
+    for(count = 0;count < sampleNumber;count ++)
+    {
+        MS5192T_WaitRdyGoLow();
+        samplesAverage += MS5192T_GetRegisterValue(MS5192T_REG_DATA, 3, 0);  // CS is not modified by SPI read/write functions.
+    }
+    MS5192T_CS_HIGH;
+    samplesAverage = samplesAverage / sampleNumber;
+    
+    return(samplesAverage);
+}

+ 150 - 14
fw/modules/adc/ms5192t.h

@@ -1,14 +1,150 @@
-#ifndef __MS5192T_H
-#define __MS5192T_H
-
-
-//
-void adc_gpio_init(void);
-
-//
-void adc_test(void);
-
-
-
-#endif  // __MS5192T_H
-
+#ifndef __MS5192T_H__
+#define __MS5192T_H__
+
+
+/* MS5192T GPIO */
+#define MS5192T_RDY_STATE       GPIO1_STATE
+
+/*MS5192T Registers*/
+#define MS5192T_REG_COMM		0 /* Communications Register(WO, 8-bit) */
+#define MS5192T_REG_STAT	    0 /* Status Register	    (RO, 8-bit) */
+#define MS5192T_REG_MODE	    1 /* Mode Register	     	(RW, 16-bit */
+#define MS5192T_REG_CONF	    2 /* Configuration Register (RW, 16-bit)*/
+#define MS5192T_REG_DATA	    3 /* Data Register	     	(RO, 16-/24-bit) */
+#define MS5192T_REG_ID	        4 /* ID Register	     	(RO, 8-bit) */
+#define MS5192T_REG_IO	        5 /* IO Register	     	(RO, 8-bit) */
+#define MS5192T_REG_OFFSET      6 /* Offset Register	    (RW, 24-bit */
+#define MS5192T_REG_FULLSALE	7 /* Full-Scale Register	(RW, 24-bit */
+
+/* Communications Register Bit Designations (AD7793_REG_COMM) */
+#define MS5192T_COMM_WEN		(1 << 7) 			/* Write Enable */
+#define MS5192T_COMM_WRITE	    (0 << 6) 			/* Write Operation */
+#define MS5192T_COMM_READ       (1 << 6) 			/* Read Operation */
+#define MS5192T_COMM_ADDR(x)	(((x) & 0x7) << 3)	/* Register Address */
+#define MS5192T_COMM_CREAD	    (1 << 2) 			/* Continuous Read of Data Register */
+
+/* Status Register Bit Designations (AD7793_REG_STAT) */
+#define MS5192T_STAT_RDY		(1 << 7) /* Ready */
+#define MS5192T_STAT_ERR		(1 << 6) /* Error (Overrange, Underrange) */
+#define MS5192T_STAT_CH3		(1 << 2) /* Channel 3 */
+#define MS5192T_STAT_CH2		(1 << 1) /* Channel 2 */
+#define MS5192T_STAT_CH1		(1 << 0) /* Channel 1 */
+
+/* Mode Register Bit Designations (MS5192T_REG_MODE) */
+#define MS5192T_MODE_SEL(x)		(((x) & 0x7) << 13)	/* Operation Mode Select */
+#define MS5192T_MODE_CLKSRC(x)	(((x) & 0x3) << 6) 	/* ADC Clock Source Select */
+#define MS5192T_MODE_RATE(x)		((x) & 0xF) 		/* Filter Update Rate Select */
+
+/* AD7793_MODE_SEL(x) options */
+#define MS5192T_MODE_CONT       0 /* Continuous Conversion Mode */
+#define MS5192T_MODE_SINGLE		1 /* Single Conversion Mode */
+#define MS5192T_MODE_IDLE		2 /* Idle Mode */
+#define MS5192T_MODE_PWRDN      3 /* Power-Down Mode */
+#define MS5192T_MODE_CAL_INT_ZERO 4 /* Internal Zero-Scale Calibration */
+#define MS5192T_MODE_CAL_INT_FULL 5 /* Internal Full-Scale Calibration */
+#define MS5192T_MODE_CAL_SYS_ZERO 6 /* System Zero-Scale Calibration */
+#define MS5192T_MODE_CAL_SYS_FULL 7 /* System Full-Scale Calibration */
+
+/* MS5192T_MODE_CLKSRC(x) options */
+#define MS5192T_CLK_INT		    0 /* Internal 64 kHz Clk not available at the CLK pin */
+#define MS5192T_CLK_INT_CO	    1 /* Internal 64 kHz Clk available at the CLK pin */
+#define MS5192T_CLK_EXT		    2 /* External 64 kHz Clock */
+#define MS5192T_CLK_EXT_DIV2	3 /* External Clock divided by 2 */
+
+/* Configuration Register Bit Designations (MS5192T_REG_CONF) */
+#define MS5192T_CONF_VBIAS(x)   (((x) & 0x3) << 14) 	/* Bias Voltage Generator Enable */
+#define MS5192T_CONF_BO_EN	    (1 << 13) 			/* Burnout Current Enable */
+#define MS5192T_CONF_UNIPOLAR   (1 << 12) 			/* Unipolar/Bipolar Enable */
+#define MS5192T_CONF_BOOST	    (1 << 11) 			/* Boost Enable */
+#define MS5192T_CONF_GAIN(x)	(((x) & 0x7) << 8) 	/* Gain Select */
+#define MS5192T_CONF_REFSEL(x)  (((x) & 0x1) << 7) 	/* INT/EXT Reference Select */
+#define MS5192T_CONF_BUF		(1 << 4) 				/* Buffered Mode Enable */
+#define MS5192T_CONF_CHAN(x)	((x) & 0x7) 			/* Channel select */
+
+/* MS5192T_CONF_GAIN(x) options */
+#define MS5192T_GAIN_1          0
+#define MS5192T_GAIN_2          1
+#define MS5192T_GAIN_4          2
+#define MS5192T_GAIN_8          3
+#define MS5192T_GAIN_16         4
+#define MS5192T_GAIN_32         5
+#define MS5192T_GAIN_64         6
+#define MS5192T_GAIN_128        7
+
+/* MS5192T_CONF_REFSEL(x) options */
+#define MS5192T_REFSEL_INT      1	/* Internal Reference Selected. */
+#define MS5192T_REFSEL_EXT      0	/* External Reference Applied between REFIN(+) and REFIN(–). */
+
+/* MS5192T_CONF_CHAN(x) options */
+#define MS5192T_CH_AIN1P_AIN1M	0 /* AIN1(+) - AIN1(-) */
+#define MS5192T_CH_AIN2P_AIN2M	1 /* AIN2(+) - AIN2(-) */
+#define MS5192T_CH_AIN3P_AIN3M	2 /* AIN3(+) - AIN3(-) */
+#define MS5192T_CH_AIN1M_AIN1M	3 /* AIN1(-) - AIN1(-) */
+#define MS5192T_CH_TEMP			6 /* Temp Sensor */
+#define MS5192T_CH_AVDD_MONITOR	7 /* AVDD Monitor */
+
+/* ID Register Bit Designations (AD7793_REG_ID) */
+#define MS5192T_ID			    0xA
+#define MS5192T_ID_MASK		    0xF
+
+/* IO (Excitation Current Sources) Register Bit Designations (MS5192T_REG_IO) */
+#define MS5192T_IEXCDIR(x)	    (((x) & 0x3) << 2)
+#define MS5192T_IEXCEN(x)	    (((x) & 0x3) << 0)
+
+/* MS5192T_IEXCDIR(x) options*/
+#define MS5192T_DIR_IEXC1_IOUT1_IEXC2_IOUT2	0  /* IEXC1 connect to IOUT1, IEXC2 connect to IOUT2 */
+#define MS5192T_DIR_IEXC1_IOUT2_IEXC2_IOUT1	1  /* IEXC1 connect to IOUT2, IEXC2 connect to IOUT1 */
+#define MS5192T_DIR_IEXC1_IEXC2_IOUT1		2  /* Both current sources IEXC1,2 connect to IOUT1  */
+#define MS5192T_DIR_IEXC1_IEXC2_IOUT2		3  /* Both current sources IEXC1,2 connect to IOUT2 */
+
+/* MS5192T_IEXCEN(x) options*/
+#define MS5192T_EN_IXCEN_10uA				1  /* Excitation Current 10uA */
+#define MS5192T_EN_IXCEN_210uA				2  /* Excitation Current 210uA */
+#define MS5192T_EN_IXCEN_1mA			    3  /* Excitation Current 1mA */
+
+/******************************************************************************/
+/* Functions Prototypes                                                       */
+/******************************************************************************/
+
+/* Initialize MS5192T and check if the device is present*/
+unsigned char MS5192T_Init(void);
+
+/* Sends 32 consecutive 1's on SPI in order to reset the part. */
+void MS5192T_Reset(void);
+
+/* Reads the value of the selected register. */
+unsigned long MS5192T_GetRegisterValue(unsigned char regAddress, 
+									  unsigned char size,
+                                      unsigned char modifyCS);
+
+/* Writes a value to the register. */
+void MS5192T_SetRegisterValue(unsigned char regAddress,
+							 unsigned long regValue, 
+							 unsigned char size,
+                             unsigned char modifyCS);
+
+/* Waits for RDY pin to go low. */
+void MS5192T_WaitRdyGoLow(void);
+
+/* Sets the operating mode of MS5192T. */
+void MS5192T_SetMode(unsigned long mode);     
+
+/* Selects the channel of MS5192T. */
+void MS5192T_SetChannel(unsigned long channel);
+
+/* Sets the gain of the In-Amp. */
+void MS5192T_SetGain(unsigned long gain);
+
+/* Sets the reference source for the ADC. */
+void MS5192T_SetIntReference(unsigned char type);
+
+/* Performs the given calibration to the specified channel. */
+void MS5192T_Calibrate(unsigned char mode, unsigned char channel);
+
+/* Returns the result of a single conversion. */
+unsigned long MS5192T_SingleConversion(void);
+
+/* Returns the average of several conversion results. */
+unsigned long MS5192T_ContinuousReadAvg(unsigned char sampleNumber);
+
+#endif	// _AD7793_H_

+ 151 - 0
fw/modules/adc/ms5192t_old.c

@@ -0,0 +1,151 @@
+#include "at32f403a_407.h"
+#include "ms5192t.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "settings_api.h"
+#include "io_utils.h"
+#include "spi_common.h"
+#include "Communication.h"
+#include <stdio.h>
+
+
+
+
+
+#define ADC_GET_STATUS_REG  0x40
+
+//
+void adc_gpio_init(void)
+{
+#if 0  
+    gpio_init_type gpio_initstructure;
+        
+    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_NONE;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_11 | GPIO_PINS_12 | 
+                                             GPIO_PINS_13 | GPIO_PINS_14;
+    
+    gpio_init(GPIOE, &gpio_initstructure); 
+#endif    
+    
+    gpio_init_type gpio_initstructure;
+    spi_init_type spi_init_struct;
+  
+    crm_periph_clock_enable(CRM_IOMUX_PERIPH_CLOCK, TRUE);
+    crm_periph_clock_enable(CRM_GPIOE_PERIPH_CLOCK, TRUE);
+    
+    gpio_pin_remap_config(SPI4_GMUX_0001, TRUE);
+  
+    // SCK
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_DOWN;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_11;
+    gpio_init(GPIOE, &gpio_initstructure);
+  
+    // MISO
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_INPUT;  
+    gpio_initstructure.gpio_pins           = GPIO_PINS_13;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    // MOSI
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX; 
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+     
+    // CS
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_12;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    
+    MS5192T_CS_HIGH;
+
+    crm_periph_clock_enable(CRM_SPI4_PERIPH_CLOCK, TRUE);
+    
+    spi_default_para_init(&spi_init_struct);
+    spi_init_struct.transmission_mode = SPI_TRANSMIT_FULL_DUPLEX;
+    spi_init_struct.master_slave_mode = SPI_MODE_MASTER;
+    spi_init_struct.mclk_freq_division = SPI_MCLK_DIV_32; //SPI_MCLK_DIV_2;
+    spi_init_struct.first_bit_transmission = SPI_FIRST_BIT_MSB;
+    spi_init_struct.frame_bit_num = SPI_FRAME_8BIT;
+    spi_init_struct.clock_polarity = SPI_CLOCK_POLARITY_HIGH;
+    spi_init_struct.clock_phase = SPI_CLOCK_PHASE_2EDGE;
+    spi_init_struct.cs_mode_selection = SPI_CS_SOFTWARE_MODE;
+    
+    spi_init(MS5192T_SPI, &spi_init_struct);
+ 
+    //spi_hardware_cs_output_enable(SPI3, TRUE);
+    
+    //adc_mosi_to_spi();
+    
+    spi_enable(MS5192T_SPI, TRUE);
+    
+    
+}
+
+//
+void adc_mosi_high(void)
+{
+    gpio_init_type gpio_initstructure;
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_OUTPUT;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+    
+    gpio_bits_set(GPIOE, GPIO_PINS_14);
+}
+
+//
+void adc_mosi_to_spi(void)
+{
+    gpio_init_type gpio_initstructure;
+    
+    gpio_initstructure.gpio_out_type       = GPIO_OUTPUT_PUSH_PULL;  
+    gpio_initstructure.gpio_pull           = GPIO_PULL_UP;  
+    gpio_initstructure.gpio_mode           = GPIO_MODE_MUX;  
+    gpio_initstructure.gpio_drive_strength = GPIO_DRIVE_STRENGTH_STRONGER;
+    gpio_initstructure.gpio_pins           = GPIO_PINS_14;
+    gpio_init(GPIOE, &gpio_initstructure);
+}
+
+//
+void adc_test(void)
+{
+    uint8_t tx = 0;
+    uint8_t rx = 0;
+    
+/*  
+    gpio_bits_set(GPIOE, GPIO_PINS_11 | GPIO_PINS_12 | GPIO_PINS_13 | GPIO_PINS_14);
+    vTaskDelay(100);
+    gpio_bits_reset(GPIOE, GPIO_PINS_11 | GPIO_PINS_12 | GPIO_PINS_13 | GPIO_PINS_14);
+    vTaskDelay(100);    
+*/
+    MS5192T_CS_LOW;
+    adc_mosi_to_spi();
+    //common_spi_send(MS5192T_SPI, ADC_GET_STATUS_REG);
+    //rx =  common_spi_receive(MS5192T_SPI);
+    rx = common_spi_tx_rx(MS5192T_SPI, ADC_GET_STATUS_REG);
+    rx = common_spi_tx_rx(MS5192T_SPI, 0);
+    MS5192T_CS_HIGH;
+    adc_mosi_high();
+    vTaskDelay(100);
+}
+
+
+
+
+

+ 18 - 0
fw/modules/adc/ms5192t_old.h

@@ -0,0 +1,18 @@
+#ifndef __MS5192T_H
+#define __MS5192T_H
+
+
+//
+void adc_gpio_init(void);
+
+//
+void adc_test(void);
+
+//
+void adc_mosi_high(void);
+
+//
+void adc_mosi_to_spi(void);
+
+#endif  // __MS5192T_H
+

+ 304 - 299
fw/user/main.c

@@ -1,299 +1,304 @@
-#include "main.h"
-
-
-void init_task(void *argument);
-void test_hw_task(void *argument);
-void soft_wdt(void *params);
-void test_gpio(void *params);
-void misc_task(void *params);   // TODO перенести в другой модуль
-
-void usb_clock48m_select(usb_clk48_s clk_s);
-
-//
-int main(void)
-{
-    __disable_irq();
-    nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x08021000);
-    nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
-	__enable_irq();
-  
-    extend_SRAM();
-  
-    system_clock_config();
-
-    delay_init();
-
-    // -------------------------------------------------------------------------
-    // Debug
-    uart_print_init(115200);
-
-    
-    //usb_clock48m_select(USB_CLK_HEXT);
-    
-    crm_periph_clock_enable(CRM_USB_PERIPH_CLOCK, TRUE);
-          
-    
-    //printf("\n\n\n\nModule universal IO [FW %s] loading....\r\n\n", VERSION);
-        
-    //
-    //usb_init();
-    
-    adc_gpio_init();
-        
-#if 1
-    taskENTER_CRITICAL();      
-    
-    xTaskCreate(soft_wdt, "soft_wdt", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);    
-    
-    xTaskCreate(init_task, "init_task", 10*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    xTaskCreate(test_hw_task, "hw_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    xTaskCreate(test_gpio, "gpio_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    //xTaskCreate(input_task, "input_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    xTaskCreate(misc_task, "misc_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    xTaskCreate(button_task, "button_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
-    
-    taskEXIT_CRITICAL();
-    
-    vTaskStartScheduler();
-#endif    
-    
-    while (1) {}
-}
-
-
-void init_task(void *argument)
-{
-    // Для теста
-    //sys_clear();
-    
-// -------------------------------------------------------------------------- //    
-// Загрузка и проверка настроек
-
-    crm_periph_clock_enable(CRM_CRC_PERIPH_CLOCK, TRUE);
-  
-    // Мьютекс для работы с настройками
-    init_settings(); 
-    
-    // Системные настройки
-    sys_settings_load(&sys_settings);
-    
-    // Основные настройки
-    settings_load(&settings);
-    
-#if 0    
-    settings_set_all_default();
-    settings_save(&settings);
-#endif      
-// -------------------------------------------------------------------------- //    
-// Безопасный режим, входы, выходы
-
-    save_mode_init();
-    // TODO Для теста отключаем безопасный режим работы
-    save_mode_set(false);   
-  
-    io_port_init();
-    
-    //in_exint_init();    
-
-    gpio_wdt_init();
-    gpio_mbaddr_init();
-    
-// -------------------------------------------------------------------------- //
-// Кнопки  
-    
-    button_init();
-    
-// -------------------------------------------------------------------------- //
-// Uptime    
-    
-    uptime_init();
-
-// -------------------------------------------------------------------------- //
-// RTC    
-    
-    TM_RTC_Init();
-    
-// -------------------------------------------------------------------------- //    
-// Мультиплексор
-    
-    mux_gpio_init();
-    
-// -------------------------------------------------------------------------- //        
-// Modbus    
-    
-    mb_init();
-    
-// -------------------------------------------------------------------------- //            
-// Базовая инициализация входов/выходов
-// TODO потом брать значения из настроек
-
-    //io_init();
-    
-// -------------------------------------------------------------------------- //        
-// Сброс счетчика попыток загрузок
-    
-    update_reset_boot_try();    
-    
-// -------------------------------------------------------------------------- //    
-// Тесты
-    //pwm_test(); // тесы PWM
-    gpio_get_rev();
-    
-    
-      
-// -------------------------------------------------------------------------- //    
-// RNDIS
-    
-    //usb_eth_init();
-        
-    // Тесты таймеров
-    //mux_led_test_init();
-    
-#if 0    
-    // Тесты SPI flash
-    common_spi_init();
-    InitFS(PRIM_DRIVE);
-    spi_flash_test();
-#endif     
-    
-    // Тесты USB
-    //usb_eth_init();
-     
-      
-    //vTaskDelete(NULL);
-            
-    for (;;)
-    {
-        mux_led_proc();
-    }
-
-// -----------------------------------------------------------------------------              
-    
-    //taskYIELD();
-}
-
-
-void test_hw_task(void *argument)
-{
-    for (;;)
-    {
-#if 0      
-        vTaskDelay(100);
-        
-        mux_led_blink();
-#endif
-
-        adc_test();
-    }
-}
-
-
-//
-void soft_wdt(void *params)
-{
-    (void)params;
-    
-    for (;;)
-    {
-        extern_wdt_togle(); // extern WDT
-        vTaskDelay(100);
-    }
-}
-
-//
-void test_gpio(void *params)
-{
-    (void)params;
-    
-    for (;;)
-    {
-        vTaskDelay(1000);
-        //io_test();
-        //out_test();
-        //load_test();
-        
-        //printf("HW rev: %u\r\n", cm_gpio_get_rev());
-        //printf("Save mode: %u\r\n", save_mode_get());
-    }
-}
-
-//
-void misc_task(void *params)
-{
-    (void)params;
-    
-    for (;;)
-    {
-        vTaskDelay(1000);
-        eMBSetSlaveAddr(gpio_get_mbaddr());
-    }
-}
-
-//
-void usb_clock48m_select(usb_clk48_s clk_s)
-{
-  if(clk_s == USB_CLK_HICK)
-  {
-    crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_HICK);
-
-    /* enable the acc calibration ready interrupt */
-    crm_periph_clock_enable(CRM_ACC_PERIPH_CLOCK, TRUE);
-
-    /* update the c1\c2\c3 value */
-    acc_write_c1(7980);
-    acc_write_c2(8000);
-    acc_write_c3(8020);
-
-    /* open acc calibration */
-    acc_calibration_mode_enable(ACC_CAL_HICKTRIM, TRUE);
-  }
-  else
-  {
-    switch(system_core_clock)
-    {
-      /* 48MHz */
-      case 48000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_1);
-        break;
-
-      /* 72MHz */
-      case 72000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_1_5);
-        break;
-
-      /* 96MHz */
-      case 96000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_2);
-        break;
-
-      /* 120MHz */
-      case 120000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_2_5);
-        break;
-
-      /* 144MHz */
-      case 144000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_3);
-        break;
-
-      /* 168MHz */
-      case 168000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_3_5);
-        break;
-
-      /* 192MHz */
-      case 192000000:
-        crm_usb_clock_div_set(CRM_USB_DIV_4);
-        break;
-
-      default:
-        break;
-
-    }
-  }
-}
+#include "main.h"
+
+
+void init_task(void *argument);
+void test_hw_task(void *argument);
+void soft_wdt(void *params);
+void test_gpio(void *params);
+void misc_task(void *params);   // TODO перенести в другой модуль
+
+void usb_clock48m_select(usb_clk48_s clk_s);
+
+//
+int main(void)
+{
+    __disable_irq();
+    nvic_vector_table_set(NVIC_VECTTAB_FLASH, 0x08021000);
+    nvic_priority_group_config(NVIC_PRIORITY_GROUP_4);
+	__enable_irq();
+  
+    extend_SRAM();
+  
+    system_clock_config();
+
+    delay_init();
+
+    // -------------------------------------------------------------------------
+    // Debug
+    uart_print_init(115200);
+
+    
+    //usb_clock48m_select(USB_CLK_HEXT);
+    
+    crm_periph_clock_enable(CRM_USB_PERIPH_CLOCK, TRUE);
+          
+    
+    //printf("\n\n\n\nModule universal IO [FW %s] loading....\r\n\n", VERSION);
+        
+    //
+    //usb_init();
+    
+    adc_gpio_init();
+        
+#if 1
+    taskENTER_CRITICAL();      
+    
+    xTaskCreate(soft_wdt, "soft_wdt", configMINIMAL_STACK_SIZE, NULL, configMAX_PRIORITIES - 1, NULL);    
+    
+    xTaskCreate(init_task, "init_task", 10*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    xTaskCreate(test_hw_task, "hw_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    xTaskCreate(test_gpio, "gpio_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    //xTaskCreate(input_task, "input_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    xTaskCreate(misc_task, "misc_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    xTaskCreate(button_task, "button_task", 2*configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY, NULL);
+    
+    taskEXIT_CRITICAL();
+    
+    vTaskStartScheduler();
+#endif    
+    
+    while (1) {}
+}
+
+
+void init_task(void *argument)
+{
+    // Для теста
+    //sys_clear();
+    
+// -------------------------------------------------------------------------- //    
+// Загрузка и проверка настроек
+
+    crm_periph_clock_enable(CRM_CRC_PERIPH_CLOCK, TRUE);
+  
+    // Мьютекс для работы с настройками
+    init_settings(); 
+    
+    // Системные настройки
+    sys_settings_load(&sys_settings);
+    
+    // Основные настройки
+    settings_load(&settings);
+    
+#if 0    
+    settings_set_all_default();
+    settings_save(&settings);
+#endif      
+// -------------------------------------------------------------------------- //    
+// Безопасный режим, входы, выходы
+
+    save_mode_init();
+    // TODO Для теста отключаем безопасный режим работы
+    save_mode_set(false);   
+  
+    io_port_init();
+    
+    //in_exint_init();    
+
+    gpio_wdt_init();
+    gpio_mbaddr_init();
+    
+// -------------------------------------------------------------------------- //
+// Кнопки  
+    
+    button_init();
+    
+// -------------------------------------------------------------------------- //
+// Uptime    
+    
+    uptime_init();
+
+// -------------------------------------------------------------------------- //
+// RTC    
+    
+    TM_RTC_Init();
+    
+// -------------------------------------------------------------------------- //    
+// Мультиплексор
+    
+    mux_gpio_init();
+    
+// -------------------------------------------------------------------------- //        
+// Modbus    
+    
+    mb_init();
+    
+// -------------------------------------------------------------------------- //            
+// Базовая инициализация входов/выходов
+// TODO потом брать значения из настроек
+
+    //io_init();
+    
+// -------------------------------------------------------------------------- //        
+// Сброс счетчика попыток загрузок
+    
+    update_reset_boot_try();    
+    
+// -------------------------------------------------------------------------- //    
+// Тесты
+    //pwm_test(); // тесы PWM
+    gpio_get_rev();
+    
+    
+      
+// -------------------------------------------------------------------------- //    
+// RNDIS
+    
+    //usb_eth_init();
+        
+    // Тесты таймеров
+    //mux_led_test_init();
+    
+#if 0    
+    // Тесты SPI flash
+    common_spi_init();
+    InitFS(PRIM_DRIVE);
+    spi_flash_test();
+#endif     
+    
+    // Тесты USB
+    //usb_eth_init();
+     
+      
+    //vTaskDelete(NULL);
+            
+    for (;;)
+    {
+        mux_led_proc();
+    }
+
+// -----------------------------------------------------------------------------              
+    
+    //taskYIELD();
+}
+
+
+void test_hw_task(void *argument)
+{
+    MS5192T_Reset();
+	
+  
+    for (;;)
+    {
+        vTaskDelay(100);
+        MS5192T_Init();
+#if 0      
+        vTaskDelay(100);
+        
+        mux_led_blink();
+#endif
+
+        //adc_test();
+    }
+}
+
+
+//
+void soft_wdt(void *params)
+{
+    (void)params;
+    
+    for (;;)
+    {
+        extern_wdt_togle(); // extern WDT
+        vTaskDelay(100);
+    }
+}
+
+//
+void test_gpio(void *params)
+{
+    (void)params;
+    
+    for (;;)
+    {
+        vTaskDelay(1000);
+        //io_test();
+        //out_test();
+        //load_test();
+        
+        //printf("HW rev: %u\r\n", cm_gpio_get_rev());
+        //printf("Save mode: %u\r\n", save_mode_get());
+    }
+}
+
+//
+void misc_task(void *params)
+{
+    (void)params;
+    
+    for (;;)
+    {
+        vTaskDelay(1000);
+        eMBSetSlaveAddr(gpio_get_mbaddr());
+    }
+}
+
+//
+void usb_clock48m_select(usb_clk48_s clk_s)
+{
+  if(clk_s == USB_CLK_HICK)
+  {
+    crm_usb_clock_source_select(CRM_USB_CLOCK_SOURCE_HICK);
+
+    /* enable the acc calibration ready interrupt */
+    crm_periph_clock_enable(CRM_ACC_PERIPH_CLOCK, TRUE);
+
+    /* update the c1\c2\c3 value */
+    acc_write_c1(7980);
+    acc_write_c2(8000);
+    acc_write_c3(8020);
+
+    /* open acc calibration */
+    acc_calibration_mode_enable(ACC_CAL_HICKTRIM, TRUE);
+  }
+  else
+  {
+    switch(system_core_clock)
+    {
+      /* 48MHz */
+      case 48000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_1);
+        break;
+
+      /* 72MHz */
+      case 72000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_1_5);
+        break;
+
+      /* 96MHz */
+      case 96000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_2);
+        break;
+
+      /* 120MHz */
+      case 120000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_2_5);
+        break;
+
+      /* 144MHz */
+      case 144000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_3);
+        break;
+
+      /* 168MHz */
+      case 168000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_3_5);
+        break;
+
+      /* 192MHz */
+      case 192000000:
+        crm_usb_clock_div_set(CRM_USB_DIV_4);
+        break;
+
+      default:
+        break;
+
+    }
+  }
+}

+ 40 - 40
fw/user/main.h

@@ -1,41 +1,41 @@
-#ifndef __MAIN_H
-#define __MAIN_H
-
-#include "at32f403a_407.h"
-#include "at32f403a_407_board.h"
-#include "at32f403a_407_clock.h"
-#include "common_config.h"
-#include "FreeRTOS.h"
-#include "task.h"
-#include "queue.h"
-#include "semphr.h"
-#include "usb_eth.h"
-#include "mux.h"
-#include "misc.h"
-#include "spi_common.h"
-#include "user_fatfs.h"
-#include "spi_flash.h"
-#include "usb_eth.h"
-#include "extended_sram.h"
-#include "modbus.h"
-#include "common_gpio.h"
-#include "io.h"
-#include "input.h"
-#include "output.h"
-#include "sys_api.h"
-#include "settings_api.h"
-#include "update.h"
-#include "uptime.h"
-#include "rtc.h"
-#include "mb.h"
-#include "io_utils.h"
-#include "buttons.h"
-#include "ms5192t.h"
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-
-
-
-
+#ifndef __MAIN_H
+#define __MAIN_H
+
+#include "at32f403a_407.h"
+#include "at32f403a_407_board.h"
+#include "at32f403a_407_clock.h"
+#include "common_config.h"
+#include "FreeRTOS.h"
+#include "task.h"
+#include "queue.h"
+#include "semphr.h"
+#include "usb_eth.h"
+#include "mux.h"
+#include "misc.h"
+#include "spi_common.h"
+#include "user_fatfs.h"
+#include "spi_flash.h"
+#include "usb_eth.h"
+#include "extended_sram.h"
+#include "modbus.h"
+#include "common_gpio.h"
+#include "io.h"
+#include "input.h"
+#include "output.h"
+#include "sys_api.h"
+#include "settings_api.h"
+#include "update.h"
+#include "uptime.h"
+#include "rtc.h"
+#include "mb.h"
+#include "io_utils.h"
+#include "buttons.h"
+#include "ms5192t.h"
+#include <stdio.h>
+#include <stdbool.h>
+#include <string.h>
+
+
+
+
 #endif

BIN
output/fw.bin


Fichier diff supprimé car celui-ci est trop grand
+ 362 - 364
project/ewarm/iap/iap.dep


Fichier diff supprimé car celui-ci est trop grand
+ 828 - 794
project/ewarm/module_universal_io.dep


+ 3 - 0
project/ewarm/module_universal_io.ewp

@@ -2157,6 +2157,9 @@
             <name>modules</name>
             <group>
                 <name>adc</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\fw\modules\adc\adc_transport.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\fw\modules\adc\ms5192t.c</name>
                 </file>

+ 3 - 0
project/ewarm/module_universal_io.ewt

@@ -2375,6 +2375,9 @@
             <name>modules</name>
             <group>
                 <name>adc</name>
+                <file>
+                    <name>$PROJ_DIR$\..\..\fw\modules\adc\adc_transport.c</name>
+                </file>
                 <file>
                     <name>$PROJ_DIR$\..\..\fw\modules\adc\ms5192t.c</name>
                 </file>

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff