diff options
| author | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-12-19 18:01:18 +0200 |
|---|---|---|
| committer | Roy Ben-Shabat <Roy@Twine-s.com> | 2019-12-19 18:01:18 +0200 |
| commit | 60be180a3736bf15e89f51f65bc1d7eda7b6cfae (patch) | |
| tree | b8331374188ee35815b4340f5d93ee8244dcf401 /Software | |
| parent | 1208554e06da8aec1b074932df488769572ffcfb (diff) | |
| parent | 935b82a27fb385a68edc9ef4184614862324b304 (diff) | |
| download | Tango-60be180a3736bf15e89f51f65bc1d7eda7b6cfae.tar.gz Tango-60be180a3736bf15e89f51f65bc1d7eda7b6cfae.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software')
46 files changed, 5110 insertions, 1193 deletions
diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.c b/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.c index aa61cd30e..4e7244306 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.c +++ b/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.c @@ -52,42 +52,9 @@ void continue_thread_loading_response__free_unpacked assert(message->base.descriptor == &continue_thread_loading_response__descriptor); protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator); } -static const ProtobufCFieldDescriptor continue_thread_loading_response__field_descriptors[2] = -{ - { - "State", - 1, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_ENUM, - offsetof(ContinueThreadLoadingResponse, has_state), - offsetof(ContinueThreadLoadingResponse, state), - &thread_loading_state__descriptor, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, - { - "ErrorReason", - 2, - PROTOBUF_C_LABEL_OPTIONAL, - PROTOBUF_C_TYPE_STRING, - 0, /* quantifier_offset */ - offsetof(ContinueThreadLoadingResponse, errorreason), - NULL, - NULL, - 0, /* flags */ - 0,NULL,NULL /* reserved1,reserved2, etc */ - }, -}; -static const unsigned continue_thread_loading_response__field_indices_by_name[] = { - 1, /* field[1] = ErrorReason */ - 0, /* field[0] = State */ -}; -static const ProtobufCIntRange continue_thread_loading_response__number_ranges[1 + 1] = -{ - { 1, 0 }, - { 0, 2 } -}; +#define continue_thread_loading_response__field_descriptors NULL +#define continue_thread_loading_response__field_indices_by_name NULL +#define continue_thread_loading_response__number_ranges NULL const ProtobufCMessageDescriptor continue_thread_loading_response__descriptor = { PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC, @@ -96,10 +63,10 @@ const ProtobufCMessageDescriptor continue_thread_loading_response__descriptor = "ContinueThreadLoadingResponse", "", sizeof(ContinueThreadLoadingResponse), - 2, + 0, continue_thread_loading_response__field_descriptors, continue_thread_loading_response__field_indices_by_name, - 1, continue_thread_loading_response__number_ranges, + 0, continue_thread_loading_response__number_ranges, (ProtobufCMessageInit) continue_thread_loading_response__init, NULL,NULL,NULL /* reserved[123] */ }; diff --git a/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.h b/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.h index ae83a671f..8d9a98326 100644 --- a/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.h +++ b/Software/Embedded_SW/Embedded/Communication/PMR/ThreadLoading/ContinueThreadLoadingResponse.pb-c.h @@ -14,7 +14,6 @@ PROTOBUF_C__BEGIN_DECLS # error This file was generated by an older version of protoc-c which is incompatible with your libprotobuf-c headers. Please regenerate this file with a newer version of protoc-c. #endif -#include "ThreadLoadingState.pb-c.h" typedef struct _ContinueThreadLoadingResponse ContinueThreadLoadingResponse; @@ -27,13 +26,10 @@ typedef struct _ContinueThreadLoadingResponse ContinueThreadLoadingResponse; struct _ContinueThreadLoadingResponse { ProtobufCMessage base; - protobuf_c_boolean has_state; - ThreadLoadingState state; - char *errorreason; }; #define CONTINUE_THREAD_LOADING_RESPONSE__INIT \ { PROTOBUF_C_MESSAGE_INIT (&continue_thread_loading_response__descriptor) \ - , 0, THREAD_LOADING_STATE__None, NULL } + } /* ContinueThreadLoadingResponse methods */ diff --git a/Software/Embedded_SW/Embedded/DataDef.h b/Software/Embedded_SW/Embedded/DataDef.h index 0fd48c037..e514817c0 100644 --- a/Software/Embedded_SW/Embedded/DataDef.h +++ b/Software/Embedded_SW/Embedded/DataDef.h @@ -7,6 +7,8 @@ #include <driverlib/gpio.h> #include "common/report/report.h" + + //#define EVALUATION_BOARD // to use the LCD only when using the evaluation board //#define USE_USB #define Stub_Mode 1 diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.c index f290a8ef3..7efa8c65f 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.c @@ -12,7 +12,7 @@ #include "Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h" -uint8_t Main_Mux_Flag = UNKNOWN; +//uint8_t Main_Mux_Flag = UNKNOWN; uint32_t Select_Main_Head_Mux_Channel() { diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c index 5134c0712..b29e901d0 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.c @@ -18,6 +18,7 @@ #include "driverlib/i2c.h" +uint8_t Main_Mux_Flag = UNKNOWN; void InitI2C2() { diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.h index b0da72345..f8407268a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/I2C.h @@ -25,4 +25,6 @@ uint32_t I2C_Read(uint32_t I2C_ID, uint32_t Slave_Add, uint32_t *I2C_Read_buf, u void Trigger_Heater_Current_Read(void); void Trigger_MidTank_Pressure_Read(void); +extern uint8_t Main_Mux_Flag ; + #endif /* DRIVERS_I2C_COMMUNICATION_I2C_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.c new file mode 100644 index 000000000..c4d5c0887 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.c @@ -0,0 +1,393 @@ +/* + * MAX11614_Driver.c + * + * Created on: Nov 28, 2019 + * Author: Shai + */ + +#include "include.h" +#include <Drivers/I2C_Communication/I2C.h> +#include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> +#include <Drivers/I2C_Communication/HEAD_Card/I2C_Head_Mux.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include <Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.h> + + +//uint8_t AD5272_Read_Buf[16] = {0}; +AD5272 U40_AD5272; + + +uint32_t AD5272_WriteRdac(uint16_t value) +{ + uint32_t status= OK; + uint8_t Write_Buf[2]; + + Write_Buf[0] = ((value & 0xff00)>>8); + Write_Buf[1] = (value & 0x00FF); + //status |= Block_Main_Head_Mux_Channel(); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(U40_AD5272.AD5272_I2CBUS, U40_AD5272.AD5272_I2CADDR, Write_Buf, 2); + + return status; +} + + +//uint32_t MAX11615_Read_allADC() +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// uint8_t command_regAddress = 0; +// +// Write_Buf[0] = command_regAddress; +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// +// status |= I2C_Read(I2C_ID_WHS_CARD, I2CDAC_ADDRESS + 1, MAX11614_Read_Buf, 16); +// +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +//uint32_t AD5272_Init () +//{ +// uint32_t status= OK; +// +// U40_AD5272.bits.REG = 0; +// U40_AD5272.setup.bits.SEL2 = 1; +// U40_AD5272.setup.bits.SEL1 = 0; +// U40_AD5272.setup.bits.SEL0 = 1; +// U40_AD5272.setup.bits.CLK = 0; +// U40_AD5272.setup.bits.BIP_UNIn = 0; +// U40_AD5272.setup.bits.RSTn = 1; +// U40_AD5272.setup.bits.Dont_care = 0; +// +// U40_AD5272.configuration.bits.REG = 1; +// U40_AD5272.configuration.bits.SCAN1 = 0; +// U40_AD5272.configuration.bits.SCAN0 = 0; +// U40_AD5272.configuration.bits.CS3 = 0; +// U40_AD5272.configuration.bits.CS2 = 1; +// U40_AD5272.configuration.bits.CS1 = 1; +// U40_AD5272.configuration.bits.CS0 = 1; +// U40_AD5272.configuration.bits.SGL_DIFn = 1; +// +// U40_AD5272.MAX11614_I2CADDR = I2CADC_ADDRESS; +// U40_AD5272.MAX11614_I2CBUS = I2C_ID_WHS_CARD; +// +// +// +// +// status = MAX11615_Setup(U20_MAX11614.MAX11614_I2CBUS, U20_MAX11614.MAX11614_I2CADDR, U20_MAX11614.setup.uchar); +// status |= MAX11615_Configuration(U20_MAX11614.MAX11614_I2CBUS, U20_MAX11614.MAX11614_I2CADDR, U20_MAX11614.configuration.uchar); +// +// return status; +// +//} + +//uint32_t MAX11615_Setup (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// Write_Buf[0] = value; +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +//uint32_t MAX11615_Configuration(uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// +// Write_Buf[0] = value; +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// return status; +//} + + + + +//uint32_t MAX11615_Write8 (MAX11615*, uint8_t, uint8_t) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// Write_Buf[0] = command_regAddress; +// Write_Buf[1] = (uint8_t)(regValue >> 8); +// Write_Buf[2] = (uint8_t)( regValue & 0x00FF ); +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CADC_ADDRESS, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// return status; +//} +//uint32_t MAX11615_ADC_Read (MAX11615*, uint8_t, uint16_t*) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +//uint32_t MAX11615_Scan (MAX11615*, uint16_t*) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +///*----------------------------------------------------------------*/ +// +//int32_t i2c_smbus_write_word_data(int i2cFileDescriptor, uint8_t command_regAddress, uint16_t regValue) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// Write_Buf[0] = command_regAddress; +// Write_Buf[1] = (uint8_t)(regValue >> 8); +// Write_Buf[2] = (uint8_t)( regValue & 0x00FF ); +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 3); +// +// delayUs(10);//TODO - check the delay +// return status; +//} +// +//int32_t i2c_smbus_read_word_data(int i2cFileDescriptor, uint8_t command_regAddress) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// +// Write_Buf[0] = command_regAddress; +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// +// status |= I2C_Read(I2C_ID_WHS_CARD, I2CDAC_ADDRESS + 1, Read_Buf, 2); +// +// return status; +//} +// +//int32_t read_Max5805_device_ID() +//{ +// int32_t status = OK; +// +// status = MAX5805_DEVICEID(); +// if ((Read_Buf[0] == 0x50) && (Read_Buf[1] == 0x82)) +// { +// ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID OK -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); +// } +// else +// { +// ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID NOT OK !!!! -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); +// } +// return status; +//} +// +// +//int32_t Write_Max5805_AUXn(bool value) +//{ +// int32_t status = OK; +// +// +// Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_AUXn = value; +// status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); +// return status; +//} +// +//int16_t Write_Max5805_LDACn(bool value) +//{ +// int32_t status = OK; +// +// +// Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_LDACn = value; +// status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); +// return status; +//} +// +// +//void Write_Volt_Blower_Control(uint16_t volt) +//{ +// MAX5805_CODE_LOAD( volt); +//} +// +//void Write_MAX5805_REF(MAX5805_REF_enum_t value) +//{ +// MAX5805_REF(value) ; //REF_OUT_AlwaysOn_2V500 +//} +// +//int32_t init_5805() +//{ +// int32_t ret = OK; +// MAX5805_REF_enum_t ref_value = REF_OUT_AlwaysOn_2V500; +// MAX5805_CONFIG_enum_t confug_value = CONFIG_0000_0000_0011_1000_NONE; +// bool LDACn_value = true; +// bool AUXn_value = true; +// +// Write_MAX5805_REF( ref_value); +// MAX5805_CONFIG(confug_value); +// Write_Max5805_LDACn( LDACn_value); +// Write_Max5805_AUXn( AUXn_value); +// return ret; +//} +// +// +// +// +// +// +///* source */ +///** +// * @note STILL IN DEVELOPMENT +// * @file max11615.c +// * @author Simon Burkhardt github.com/mnemocron +// * @copyright MIT license +// * @date 06.2018 +// * @brief C library for the MAX11615EEE+ I2C ADC for STM32 HAL. +// * @details +// * @see github.com/mnemocron +// * @see https://datasheets.maximintegrated.com/en/ds/MAX11612-MAX11617.pdf +// * @see https://github.com/AllAboutEE/MAX11609EEE-Breakout-Board/tree/master/Software/Arduino/AllAboutEE-MAX11609-Library +// */ +//#include "max11615.h" +//#include "main.h" +// +///** +// * @brief writes a single value into a MAX11615 register +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param reg, the destination register's address +// * @param val, the value for the destination register +// */ +//uint8_t MAX11615_Write8(MAX11615 *chip, uint8_t reg, uint8_t val){ +// if(HAL_I2C_Mem_Write(chip->wireIface, chip->devAddress, reg, 1, &val, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * @brief reads a single value from a MAX11615 register +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param reg, the destination register's address +// * @param val, pointer to the location where the value shall be stored +// * @return 0 on success, 1 on transmission error +// */ +//uint8_t MAX11615_Read8(MAX11615 *chip, uint8_t reg, uint8_t *val){ +// if(HAL_I2C_Mem_Read(chip->wireIface, chip->devAddress, reg, 1, val, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * @brief sets up the MAX11615 chip with the provided Vref setting +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param *wireIface a pointer to a HAL I2C_HandleTypeDef +// * @param address of the chip on the I2C bus +// */ +//uint8_t MAX11615_Init(MAX11615* chip, I2C_HandleTypeDef* wireIface, uint16_t address, uint8_t vRef){ +// chip->wireIface = wireIface; +// chip->devAddress = address; +// uint8_t ret = 0; +// // 0 - don't care +// // 1 - reset configuration register to default +// // 2 - unipolar +// // 3 - internal clock +// // 4 - SEL0 (vRef) +// // 5 - SEL1 (vRef) +// // 6 - SEL2 (vRef) +// vRef = (vRef<<4) & 0xf0; +// vRef |= 2; // do not reset the setup register +// ret += MAX11615_Setup(chip, vRef); +// // 0 - Single Ended +// // 1 to 4 - Channel Select: 7 +// // 5 to 6 - Scan Mode: read channels up to selected channel +// uint8_t config_byte = 0x00; +// config_byte |= 1; // single ended mode +// config_byte |= ((1<<5) & (1<<6)); // SCAN bits: convert only the channel selected by CS bits +// ret += MAX11615_Configuration(chip, config_byte); +// return ret; +//} +// +//uint8_t MAX11615_Setup(MAX11615* chip, uint8_t data){ +// data = data | 0x80; // make REG bit 7 = 1 (setup byte) +// if(HAL_I2C_Master_Transmit(chip->wireIface, chip->devAddress, &data, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +//uint8_t MAX11615_Configuration(MAX11615* chip, uint8_t data){ +// data = data & (~0x80); // make REG bit 7 = 0 (configuration byte) +// if(HAL_I2C_Master_Transmit(chip->wireIface, chip->devAddress, &data, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * Reads one channel. +// * @author Miguel (5/24/2015) +// * @param channel The channel to convert or read. Alternatively +// * if a channel was set already leave null. +// * @param val Pointer to where the return value should be stored. +// * @return uint8_t +// */ +//uint8_t MAX11615_ADC_Read(MAX11615* chip, uint8_t channel, uint16_t* val){ +// uint8_t result[2] = {0,0}; +// +// uint8_t configurationByte = ( (channel<<1) & 0x0e) | 0x61; +// MAX11615_Configuration(chip, configurationByte); +// // the conversion consists of two bytes per channel +// if(HAL_I2C_Master_Receive(chip->wireIface, chip->devAddress, &result[0], 2, 10) != HAL_OK){ +// return 1; +// } +// uint16_t value = 0; +// // cast to uint16_t is necessary to not loose the values by the left shift +// value = (((uint16_t)result[0] & 0x000f) << 8); // MSB is returned first +// value += ((uint16_t)result[1] & 0x00ff); // read LSB +// *val = value; +// return 0; +//} +// +///** +// * Reads all channels conversion into a buffer/array. +// * +// * @author Miguel (5/24/2015) +// * +// * @param buffer an array where the channel read values are put. +// */ +//uint8_t MAX11615_Scan(MAX11615* chip, uint16_t* buffer){ +// uint8_t ret = 0; +// uint8_t configurationByte = 0xf0; +// ret += MAX11615_Configuration(chip, configurationByte); +// // 2 bytes per channel. There are 8 channels +// for(uint8_t i = 0;i<8;i++){ +// ret += MAX11615_ADC_Read(chip, i, buffer+i); +// } +// return ret; +//} + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.h new file mode 100644 index 000000000..b6c6cdab5 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_AD5272/AD5272_Driver.h @@ -0,0 +1,61 @@ + + + +#ifndef AD5272_H_ +#define AD5272_H_ + +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +/* Table 6 */ +/* use to config sel(2,1,0) */ +#define AD5272_WriteRDAC 0x00 +#define AD5272_ReadRDAC 0x01 +#define AD5272_StorWiper 0x03 +#define AD5272_SW_ShutDown 0x09 + + + +typedef union +{ + struct + { + bool DontCare1 : 1; //P00 + bool DontCare0 : 1; //P01 + bool C3 : 1; //P02 + bool C2 : 1; //P03 + bool C1 : 1; //P04 + bool C0 : 1; //P05 + bool D9 : 1; //P06 + bool D8 : 1; //P07 + + bool D7 : 1; //P00 + bool D6 : 1; //P01 + bool D5 : 1; //P02 + bool D4 : 1; //P03 + bool D3 : 1; //P04 + bool D2 : 1; //P05 + bool D1 : 1; //P06 + bool D0 : 1; //P07 + }bits; + unsigned char uchar[2]; +}AD5272_Write_Byte; + + + +typedef struct { + uint8_t AD5272_I2CBUS; + WHS_chip_address AD5272_I2CADDR; +// AD5272_Write_Byte configuration; +// AD5272_Setup_Byte setup; +}AD5272; + +//extern AD5272 U40_AD5272; + +uint32_t AD5272_WriteRdac(uint16_t value); +/* + +uint32_t AD5272_Init (); +uint32_t AD5272_Setup (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value); +uint32_t AD5272_Configuration (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value); +*/ + +#endif diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.c new file mode 100644 index 000000000..691b04d2f --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.c @@ -0,0 +1,524 @@ +/* + * ADS122X04_Driver.c + * + * Created on: Dec 9, 2019 + * Author: Shai + */ + + + +#include "include.h" +#include <DataDef.h> +#include <Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +#include "drivers/I2C_Communication/I2C.h" + + +D_ADS122C04_TempSensConfigStruc ADS122_Conf; + +bool ADS122_Reset(uint8_t i2cbus, WHS_chip_address i2cadd) +{ + bool status = OK; + // uint8_t i; + uint8_t Write_Buf[1]; + + //Reset the device + Write_Buf[0] = ADS122X_RESET_CMD; + status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + SysCtlDelay(100); // Must delay after hard reset + + return status; +} + + +bool ADS122_StartSync(uint8_t i2cbus, WHS_chip_address i2cadd) +{ + bool Status = OK; + uint8_t Write_Buf[1]; + + Write_Buf[0] = ADS122X_START_CMD; + + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + return Status; +} + +bool ADS122_PowerDown(uint8_t i2cbus, WHS_chip_address i2cadd) +{ + bool Status = OK; + uint8_t Write_Buf[1]; + + Write_Buf[0] = ADS122X_POWERDOWN_CMD; + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + return Status; +} + + +bool ADS122_ReadDataCommand(uint8_t i2cbus, WHS_chip_address i2cadd, uint32_t* p_Data_ADS122X ) +{ + bool Status = OK; + uint8_t Write_Buf[1]; + uint32_t Data_ADS122X; + + uint32_t temp; + + Write_Buf[0] = ADS122X_RDATA_CMD; + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + Status |= I2C_Read(i2cbus, i2cadd, &temp, 3); + Data_ADS122X = (temp & 0xFF0000) >> 16 | (temp & 0xFF00) | (temp & 0x0000FF) << 16;//First send the MSB so we need to reorder the bytes + *p_Data_ADS122X = CalculateTemperatures(Data_ADS122X); +#warning what to do with the data ??????? + return Status; +} + +bool ADS122_WriteReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t writeValue) +{ + bool Status = OK; + uint8_t Write_Buf[2]; + + Write_Buf[0] = ADS122X_WRITE_CMD(reg); + Write_Buf[1] = writeValue; + + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 2); + + return Status; +} + +bool ADS122_WriteAllReg(uint8_t i2cbus, WHS_chip_address i2cadd, D_ADS122C04_TempSensConfigStruc *p_writeValue) +{ + bool Status = OK; + uint8_t Write_Buf[9]; + //uint8_t i =0 ; + + + Write_Buf[0] = ADS122X_WRITE_CMD(0); + Write_Buf[1] = p_writeValue->Reg0.Byte; + Write_Buf[2] = ADS122X_WRITE_CMD(1); + Write_Buf[3] = p_writeValue->Reg1.Byte; + Write_Buf[4] = ADS122X_WRITE_CMD(2); + Write_Buf[5] = p_writeValue->Reg2.Byte; + Write_Buf[6] = ADS122X_WRITE_CMD(3); + Write_Buf[7] = p_writeValue->Reg3.Byte; + + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 8); + + return Status; +} + + +bool ADS122_ReadReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t *p_readValue) +{ + bool Status = OK; + uint8_t Write_Buf[1]; + + Write_Buf[0] = ADS122X_READ_CMD(reg); + + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + delayUs(1); // delayUs(50); + Status |= I2C_Read(i2cbus, i2cadd, p_readValue, 1); + + return Status; +} + +uint32_t WHS_Test_ADS122X_Internal_Temperature_Sensor(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t *p_readValue ) +{ + bool Status = OK; + uint32_t Data = 0; + uint8_t Write_Buf[2]; + + ADS122_Conf.Reg1.bits.TS = ADS122X_TEMP_SENSOR_ON;//Bit 1 Enables the Internal temperature sensor + + Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_1_REG<<2); + Write_Buf[1] = ADS122_Conf.Reg1.Byte; + Status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 2); + + ADS122_StartSync(i2cbus, i2cadd); + SysCtlDelay(3000); + + ADS122_ReadDataCommand( i2cbus, i2cadd, &Data ); + + //Data = Data_ADC_Head; + + Data = Data & 0xFFFFFF;//24bit + + Data = Data >> 10;//need the 14 left bits // According to ADS1220 data sheet page 31 8.3.13 + + Data*=0.03125;// According to ADS1220 data sheet page 31 8.3.13 + + return Data;//Temperature_C + +} + +uint32_t ADS122_Calc_Resistance(uint32_t Data_ADS122X) +{ + + #define Rref 1650 //ohm + + uint32_t ADS122_Resistance; + + uint32_t Factor_2Rref_E_H; + uint32_t Factor_2Rref_E_L; + + //Resistance = Measurement / (2^23) *4 * Rref / Gain //---------------------- is it *4 ???? + + Factor_2Rref_E_H = 400 * Rref; // 200 to calculate Resistance*100 + +//avi: Factor_2Rref_E_L = 8388608 * (2<<(TempSensConfig[SensorId].Reg0.bits.GAIN -1));//2^23*Gain + Factor_2Rref_E_L = 8388608 * (1<<ADS122_Conf.Reg0.bits.GAIN);//2^23*Gain + +/* why to use "float" */ //to do + ADS122_Resistance = (float)Data_ADS122X / (float)Factor_2Rref_E_L * (float)Factor_2Rref_E_H; + + return ADS122_Resistance; +} + + +bool ADS122_InitConfigReg() +{ + bool Status = OK; + // - - - - - - - - - - Reg0 - - - - - - - - - - + ADS122_Conf.Reg0.bits.PGA_BYPASS = ADS122X_PGA_ENABLE ;//Bit 0 + ADS122_Conf.Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 + ADS122_Conf.Reg0.bits.MUX = ADS122X_MUX_AIN1_AIN0 ;//Bits 4-7 + + // - - - - - - - - - - Reg1 - - - - - - - - - - + + ADS122_Conf.Reg1.bits.TS = ADS122X_TEMP_SENSOR_OFF ;//Bit 0 + ADS122_Conf.Reg1.bits.VREF = ADS122X_VREF_INTERNAL ;//Bits 1-2 + ADS122_Conf.Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 + ADS122_Conf.Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 + ADS122_Conf.Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 + + // - - - - - - - - - - Reg2 - - - - - - - - - - + + ADS122_Conf.Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_500_UA ;//Bits 0-2 + ADS122_Conf.Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 + ADS122_Conf.Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 + ADS122_Conf.Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 + ADS122_Conf.Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 + + // - - - - - - - - - - Reg3 - - - - - - - - - - + ADS122_Conf.Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 + ADS122_Conf.Reg3.bits.I2MUX = ADS122X_IDAC2_DISABLED ;//Bits 2-4 + ADS122_Conf.Reg3.bits.I1MUX = ADS122X_IDAC1_AIN3 ;//Bits 5-7 + + return Status; +} + + + +//uint32_t ADS122_I2C_Write_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Write_buf, uint32_t No_BytesToWrite ) +//{ +// uint32_t status = OK; +// +// I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); +// status |= I2C_Write(I2C_ID, I2C_ADC_ADS122C04_SLAVE_ADD, I2C_Write_buf, No_BytesToWrite); +// +// return status; +//} + +//uint32_t I2C_Read_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Read_buf, uint32_t No_BytesToRead ) +//{ +// uint32_t status = OK; +// +// //HeadADCPT100_ControlMux_Brfore_Reading(SensorId); +// //TODO Choose TEMP1 sensor by I/O +// I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); +// status |= I2C_Read(I2C_ID, I2C_ADC_ADS122C04_SLAVE_ADD + 1, I2C_Read_buf, No_BytesToRead); +// +// return status; +//} + + +//uint32_t HeadADCPT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// +// uint8_t Write_Buf[2]; +// +// if(SensorId % 2) +// HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x03; // TBD +// else +// HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x04; // TBD +// +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// +// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// +// return Status; +//} + + + + + +//uint32_t HeadADCPT100_Config_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t Stage) +//{ +// uint32_t Status = OK; +// +// #ifndef EVALUATION_BOARD +// +// uint8_t Write_Buf[2]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// return ERROR; +// +// if(HeadTempSensConfig[SensorId].Config == DONE) +// return Status; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +// switch(Stage) +// { +// case SENSOR_CONFIG_REG0: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// break; +// case SENSOR_CONFIG_REG1: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_1_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg1.Byte; +// break; +// case SENSOR_CONFIG_REG2: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_2_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg2.Byte; +// break; +// case SENSOR_CONFIG_REG3: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_3_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg3.Byte; +// break; +// default: +// Status = ERROR; +// } +// +// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// +// switch(SensorId) +// { +// case HEAD_PT100_ZONE_1_0X80_0: +// case HEAD_PT100_ZONE_2_0X80_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_1_0X80_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_2_0X80_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_3_0X82_0: +// case HEAD_PT100_ZONE_4_0X82_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_3_0X82_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_4_0X82_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_5_0X84_0: +// case HEAD_PT100_ZONE_6_0X84_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_5_0X84_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_6_0X84_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_7_0X86_0: +// case HEAD_PT100_ZONE_8_0X86_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_7_0X86_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_8_0X86_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_9_0X88_0: +// case HEAD_PT100_ZONE_10_0X88_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_9_0X88_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_10_0X88_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_11_0X8A_0: +// case HEAD_PT100_ZONE_12_0X8A_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_11_0X8A_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_12_0X8A_1].Config = DONE; +// break; +// case HEAD_PT100_AIR_HEATER_1_0X8C_0: +// case HEAD_PT100_AIR_HEATER_2_0X8C_1: +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_1_0X8C_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_2_0X8C_1].Config = DONE; +// break; +// case HEAD_PT100_MIXER_0X8E_0: +// case HEAD_PT100_RESERVE_0X8E_1: +// HeadTempSensConfig[HEAD_PT100_MIXER_0X8E_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_RESERVE_0X8E_1].Config = DONE; +// break; +// default: +// break; +// } +// +// #endif +// +// return Status; +//} + +//void HeadADCPT100_SensorInitConfig() +//{ +// int Sensor=0,Register = 0; +// +// HeadADCPT100_InitConfigReg(); // Initial the configuration registers +// +// for(Register=0;Register<=SENSOR_CONFIG_REG3;Register++) +// { +// for(Sensor=HEAD_PT100_ZONE_1_0X80_0;Sensor<MAX_HEAD_CARD_TEMP_SENS_ID; Sensor++) +// { +// HeadADCPT100_Config_callback( (TEMPERATURE_SENSOR_ID_ENUM)(Sensor), Register); +// } +// SysCtlDelay(1000); +// } +//} + +//uint32_t HeadCard_Toggle_PT100(bool Odd_OR_Even)//ODD/EVEN +//{ +// uint32_t status = OK; +// uint8_t i=0; +// uint8_t Write_Buf[2]; +// +// HeadCard_Toggle_PT100_SEL(Odd_OR_Even); +// +// if(Odd_OR_Even == EVEN) +// { +// for(i=HEAD_PT100_ZONE_2_0X80_1;i < MAX_HEAD_CARD_TEMP_SENS_ID;i=i+2) +// { +// HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_EVEN_PT100_MUX;//Reg0 Bits 4-7 +// +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[i].Reg0.Byte; +// +// status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 2); +// } +// } +// else +// { +// for(i=HEAD_PT100_ZONE_1_0X80_0;i < MAX_HEAD_CARD_TEMP_SENS_ID;i=i+2) +// { +// HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_ODD_PT100_MUX;//Reg0 Bits 4-7 +// +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[i].Reg0.Byte; +// +// status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 2); +// } +// } +// +// return status; +//} + + +//uint32_t HeadCard_Toggle_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t status = OK; +// uint8_t Write_Buf[2]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// return ERROR; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +// if(Save_Sel_Status != HeadTempSensConfig[SensorId].SEL) +// { +// HeadCard_Toggle_PT100_SEL(HeadTempSensConfig[SensorId].SEL); +// Save_Sel_Status = HeadTempSensConfig[SensorId].SEL; +// } +// +// if(HeadTempSensConfig[SensorId].MUX_Status != HeadTempSensConfig[SensorId].Reg0.bits.MUX) +// { +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// +// status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// +// switch(SensorId) +// { +// case HEAD_PT100_ZONE_1_0X80_0: +// case HEAD_PT100_ZONE_2_0X80_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_1_0X80_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_2_0X80_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_3_0X82_0: +// case HEAD_PT100_ZONE_4_0X82_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_3_0X82_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_4_0X82_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_5_0X84_0: +// case HEAD_PT100_ZONE_6_0X84_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_5_0X84_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_6_0X84_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_7_0X86_0: +// case HEAD_PT100_ZONE_8_0X86_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_7_0X86_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_8_0X86_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_9_0X88_0: +// case HEAD_PT100_ZONE_10_0X88_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_9_0X88_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_10_0X88_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_11_0X8A_0: +// case HEAD_PT100_ZONE_12_0X8A_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_11_0X8A_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_12_0X8A_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_AIR_HEATER_1_0X8C_0: +// case HEAD_PT100_AIR_HEATER_2_0X8C_1: +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_1_0X8C_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_2_0X8C_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_MIXER_0X8E_0: +// case HEAD_PT100_RESERVE_0X8E_1: +// HeadTempSensConfig[HEAD_PT100_MIXER_0X8E_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_RESERVE_0X8E_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// default: +// break; +// } +// } +// return status; +//} + + + + +//uint8_t Test_Read_Buf[4] = {0,0,0,0}; +// +//uint32_t Test_HeadCard_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// uint8_t i = 0; +// +// #ifdef Test_headCard_With_DispCard_I2C4_Add0xE2_DispID_0 +// Select_Main_Head_Mux_Channel_test(); +// #else +// Select_Main_Head_Mux_Channel(); +// #endif +// +// //HeadADCPT100_Reset(); +// HeadADCPT100_InitConfigReg(); +// +// +// HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG0); +// HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG1); +// HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG2); +// HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG3); +// +// HeadADCPT100_StartSync(SensorId); +// +// +// +// uint8_t Write_Buf[4] = {SENSOR_CONFIG_REG0,SENSOR_CONFIG_REG1,SENSOR_CONFIG_REG2,SENSOR_CONFIG_REG3}; +// +// for(i=0; i<4; i++) +// { +// HeadADCPT100_ReadReg(SensorId, Write_Buf[i], &Test_Read_Buf[i]); +// +// } +// +// HeadADCPT100_SendReadDataCommand(SensorId); +// +// +// return Status; +//} + + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/ADS122X04.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.h index 114e6db24..7d5d694bb 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/ADS122X04.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.h @@ -1,5 +1,5 @@ -#ifndef ADS122X04_H_ -#define ADS122X04_H_ +#ifndef ADS122X04_Driver_H_ +#define ADS122X04_Driver_H_ /*************************************************************************************************************************************************/ /*! ADS122U04.h * ADS122C04.h @@ -35,7 +35,7 @@ extern "C" { #endif - +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> //#include "driverlib.h" // ADS122U04, Table 15 and C04 Datasheets @@ -92,21 +92,21 @@ extern "C" { #define ADS122X_MUX_AVDDmAVSS (0xd << ADS122X_MUX_SHIFT) #define ADS122X_MUX_SHORTED (0xe << ADS122X_MUX_SHIFT) */ -#define ADS122X_MUX_AIN0_AIN1 0x0 //default -#define ADS122X_MUX_AIN0_AIN2 0x1 -#define ADS122X_MUX_AIN0_AIN3 0x2 -#define ADS122X_MUX_AIN1_AIN0 0x3 -#define ADS122X_MUX_AIN1_AIN2 0x4 -#define ADS122X_MUX_AIN1_AIN3 0x5 -#define ADS122X_MUX_AIN2_AIN3 0x6 -#define ADS122X_MUX_AIN3_AIN2 0x7 -#define ADS122X_MUX_AIN0_AVSS 0x8 -#define ADS122X_MUX_AIN1_AVSS 0x9 -#define ADS122X_MUX_AIN2_AVSS 0xa -#define ADS122X_MUX_AIN3_AVSS 0xb -#define ADS122X_MUX_REFPmREFN 0xc -#define ADS122X_MUX_AVDDmAVSS 0xd -#define ADS122X_MUX_SHORTED 0xe +#define ADS122X_MUX_AIN0_AIN1 0x00 //default +#define ADS122X_MUX_AIN0_AIN2 0x01 +#define ADS122X_MUX_AIN0_AIN3 0x02 +#define ADS122X_MUX_AIN1_AIN0 0x03 +#define ADS122X_MUX_AIN1_AIN2 0x04 +#define ADS122X_MUX_AIN1_AIN3 0x05 +#define ADS122X_MUX_AIN2_AIN3 0x06 +#define ADS122X_MUX_AIN3_AIN2 0x07 +#define ADS122X_MUX_AIN0_AVSS 0x08 +#define ADS122X_MUX_AIN1_AVSS 0x09 +#define ADS122X_MUX_AIN2_AVSS 0x0A +#define ADS122X_MUX_AIN3_AVSS 0x0B +#define ADS122X_MUX_REFPmREFN 0x0C +#define ADS122X_MUX_AVDDmAVSS 0x0D +#define ADS122X_MUX_SHORTED 0x0E #define ADS122X_GAIN_MASK 0xe #ifdef __BIT_FIELD__ @@ -126,18 +126,18 @@ extern "C" { #define ADS122X_GAIN_128 (0x7 << ADS122X_GAIN_SHIFT) */ -#define ADS122X_GAIN_1 0x0 -#define ADS122X_GAIN_2 0x1 -#define ADS122X_GAIN_4 0x2 -#define ADS122X_GAIN_8 0x3 -#define ADS122X_GAIN_16 0x4 -#define ADS122X_GAIN_32 0x5 -#define ADS122X_GAIN_64 0x6 -#define ADS122X_GAIN_128 0x7 +#define ADS122X_GAIN_1 0x00 +#define ADS122X_GAIN_2 0x01 +#define ADS122X_GAIN_4 0x02 +#define ADS122X_GAIN_8 0x03 +#define ADS122X_GAIN_16 0x04 +#define ADS122X_GAIN_32 0x05 +#define ADS122X_GAIN_64 0x06 +#define ADS122X_GAIN_128 0x07 -#define ADS122X_PGA_BYPASS 1 -#define ADS122X_USE_PGA 0 +#define ADS122X_PGA_DISABLE 1 +#define ADS122X_PGA_ENABLE 0 #ifdef _ADS122U04_ #define ADS122X_AUTO_READ 1 @@ -163,13 +163,13 @@ extern "C" { #define ADS122X_DATA_RATE_600SPS (5 << ADS122X_DATA_RATE_SHIFT) #define ADS122X_DATA_RATE_1000SPS (6 << ADS122X_DATA_RATE_SHIFT) */ -#define ADS122X_DATA_RATE_20SPS 0 -#define ADS122X_DATA_RATE_45SPS 1 -#define ADS122X_DATA_RATE_90SPS 2 -#define ADS122X_DATA_RATE_175SPS 3 -#define ADS122X_DATA_RATE_330SPS 4 -#define ADS122X_DATA_RATE_600SPS 5 -#define ADS122X_DATA_RATE_1000SPS 6 +#define ADS122X_DATA_RATE_20SPS 0x00 +#define ADS122X_DATA_RATE_45SPS 0x01 +#define ADS122X_DATA_RATE_90SPS 0x02 +#define ADS122X_DATA_RATE_175SPS 0x03 +#define ADS122X_DATA_RATE_330SPS 0x04 +#define ADS122X_DATA_RATE_600SPS 0x05 +#define ADS122X_DATA_RATE_1000SPS 0x06 #define ADS122X_OP_MODE_MASK 0x10 @@ -183,30 +183,32 @@ extern "C" { #define ADS122X_OP_MODE_NORMAL (0 << ADS122X_OP_MODE_SHIFT) #define ADS122X_OP_MODE_TURBO (1 << ADS122X_OP_MODE_SHIFT) */ -#define ADS122X_OP_MODE_NORMAL 0 -#define ADS122X_OP_MODE_TURBO 1 +#define ADS122X_OP_MODE_NORMAL 0x00 +#define ADS122X_OP_MODE_TURBO 0x01 -#define ADS122X_CONVERSION_MODE_MASK 0x4 -#define ADS122X_CONVERSION_SINGLE_SHOT 0x0 +#define ADS122X_CONVERSION_MODE_MASK 0x04 +#define ADS122X_CONVERSION_SINGLE_SHOT 0x00 #ifdef __BIT_FIELD__ -#define ADS122X_CONVERSION_CONTINUOUS 0x1 +#define ADS122X_CONVERSION_CONTINUOUS 0x01 #else #define ADS122X_CONVERSION_CONTINUOUS 0x4 #endif //__BIT_FIELD__ -#define ADS122X_TEMP_SENSOR_MASK 0x2 +#define ADS122X_TEMP_SENSOR_MASK 0x02 #ifdef __BIT_FIELD__ -#define ADS122X_TEMP_SENSOR_ON 0x1 +#define ADS122X_TEMP_SENSOR_ON 0x01 #else -#define ADS122X_TEMP_SENSOR_ON 0x2 +#define ADS122X_TEMP_SENSOR_ON 0x02 #endif //__BIT_FIELD__ -#define ADS122X_TEMP_SENSOR_OFF 0x0 +#define ADS122X_TEMP_SENSOR_OFF 0x00 +#define ADS122X_TEMP_SENSOR_DISABLE 0x00 +#define ADS122X_TEMP_SENSOR_ENABLE 0x01 -#define ADS122X_BURN_OUT_MASK 0x1 -#define ADS122X_BURN_OUT_CURRENT_ON 0x1 -#define ADS122X_BURN_OUT_CURRENT_OFF 0x0 +#define ADS122X_BURN_OUT_MASK 0x01 +#define ADS122X_BURN_OUT_CURRENT_ON 0x01 +#define ADS122X_BURN_OUT_CURRENT_OFF 0x00 // Configuration Register 2 Settings 02h @@ -223,10 +225,11 @@ extern "C" { #define ADS122X_VREF_EXT_REF1_PINS (2 << ADS122X_VREF_SHIFT) //Analog Supply AVDD and AVSS #define ADS122X_VREF_AVDD (3 << ADS122X_VREF_SHIFT) //Analog Supply AVDD and AVSS */ -#define ADS122X_VREF_INTERNAL 0 //2.048V internal -#define ADS122X_VREF_EXT_REF0_PINS 1 //REFp and REFn external -#define ADS122X_VREF_EXT_REF1_PINS 2 //Analog Supply AVDD and AVSS -#define ADS122X_VREF_AVDD 3 //Analog Supply AVDD and AVSS +#define ADS122X_VREF_INTERNAL 0x00 //2.048V internal +#define ADS122X_VREF_EXT_REF0_PINS 0x01 //REFp and REFn external +#define ADS122X_VREF_EXT 0x01 //REFp and REFn external +#define ADS122X_VREF_EXT_REF1_PINS 0x02 //Analog Supply AVDD and AVSS +#define ADS122X_VREF_AVDD 0x03 //Analog Supply AVDD and AVSS //28.9.17 fix PSW and rest of bit fields @@ -256,14 +259,14 @@ extern "C" { #define ADS122X_IDAC_CURRENT_1000_UA (6 << ADS122X_IDAC_CURRENT_SHIFT) #define ADS122X_IDAC_CURRENT_1500_UA (7 << ADS122X_IDAC_CURRENT_SHIFT) */ -#define ADS122X_IDAC_CURRENT_OFF 0 -#define ADS122X_IDAC_CURRENT_10_UA 1 -#define ADS122X_IDAC_CURRENT_50_UA 2 -#define ADS122X_IDAC_CURRENT_100_UA 3 -#define ADS122X_IDAC_CURRENT_250_UA 4 -#define ADS122X_IDAC_CURRENT_500_UA 5 -#define ADS122X_IDAC_CURRENT_1000_UA 6 -#define ADS122X_IDAC_CURRENT_1500_UA 7 +#define ADS122X_IDAC_CURRENT_OFF 0x00 +#define ADS122X_IDAC_CURRENT_10_UA 0x01 +#define ADS122X_IDAC_CURRENT_50_UA 0x02 +#define ADS122X_IDAC_CURRENT_100_UA 0x03 +#define ADS122X_IDAC_CURRENT_250_UA 0x04 +#define ADS122X_IDAC_CURRENT_500_UA 0x05 +#define ADS122X_IDAC_CURRENT_1000_UA 0x06 +#define ADS122X_IDAC_CURRENT_1500_UA 0x07 // Configuration Register 3 Settings 03h @@ -275,16 +278,16 @@ extern "C" { #endif //__BIT_FIELD__ -#define ADS122X_BCS_CURRENT_SOURCES_OFF 0 -#define ADS122X_BCS_CURRENT_SOURCES_ON 1 +#define ADS122X_BCS_CURRENT_SOURCES_OFF 0x00 +#define ADS122X_BCS_CURRENT_SOURCES_ON 0x01 -#define ADS122X_CRC_DISABLED 0 +#define ADS122X_CRC_DISABLED 0x00 -#define ADS122X_DCNT_CONVERSION_COUNTER_DISABLED 0 +#define ADS122X_DCNT_CONVERSION_COUNTER_DISABLED 0x00 -#define ADS122X_DRDY_NO_NEW_CONVERSION 0 +#define ADS122X_DRDY_NO_NEW_CONVERSION 0x00 -#define ADS122X_RESERVED_WRITE_0 0 +#define ADS122X_RESERVED_WRITE_0 0x00 /* #define ADS122X_IDAC1_DISABLED (0 << ADS122X_IDAC1_MUX_SHIFT) #define ADS122X_IDAC1_AIN0 (1 << ADS122X_IDAC1_MUX_SHIFT) @@ -319,13 +322,13 @@ extern "C" { #define ADS122X_IDAC2_REFP0 (5 << ADS122X_IDAC2_MUX_SHIFT) #define ADS122X_IDAC2_REFN0 (6 << ADS122X_IDAC2_MUX_SHIFT) */ -#define ADS122X_IDAC2_DISABLED 0 -#define ADS122X_IDAC2_AIN0 1 -#define ADS122X_IDAC2_AIN1 2 -#define ADS122X_IDAC2_AIN2 3 -#define ADS122X_IDAC2_AIN3 4 -#define ADS122X_IDAC2_REFP0 5 -#define ADS122X_IDAC2_REFN0 6 +#define ADS122X_IDAC2_DISABLED 0x00 +#define ADS122X_IDAC2_AIN0 0x01 +#define ADS122X_IDAC2_AIN1 0x02 +#define ADS122X_IDAC2_AIN2 0x03 +#define ADS122X_IDAC2_AIN3 0x04 +#define ADS122X_IDAC2_REFP0 0x05 +#define ADS122X_IDAC2_REFN0 0x06 #define ADS122X_DOUT_DRDY_MASK 0x2 @@ -343,6 +346,79 @@ extern "C" { #define ADS122X_GPIO_DRDY 3 // when configure as an output #endif + + typedef union + { + struct + { + unsigned char PGA_BYPASS:1; // + unsigned char GAIN :3; // + unsigned char MUX :4; // + }bits; + unsigned char Byte; + }D_ADS122C04_CONFIG_REGISTER_0; + + +typedef union +{ + struct + { + unsigned char TS :1; // + unsigned char VREF:2; // + unsigned char CM :1; // + unsigned char MODE:1; // + unsigned char DR :3; // + }bits; + unsigned char Byte; +}D_ADS122C04_CONFIG_REGISTER_1; + +typedef union +{ + struct + { + unsigned char IDAC:3; // + unsigned char BCS :1; // + unsigned char CRC :2; // + unsigned char DCNT:1; // + unsigned char DRDY:1; // + }bits; + unsigned char Byte; +}D_ADS122C04_CONFIG_REGISTER_2; + +typedef union +{ + struct + { + unsigned char Always_write_0:2; // + unsigned char I2MUX:3; // + unsigned char I1MUX:3; // + }bits; + unsigned char Byte; +}D_ADS122C04_CONFIG_REGISTER_3; + +typedef struct +{ + D_ADS122C04_CONFIG_REGISTER_0 Reg0; // + D_ADS122C04_CONFIG_REGISTER_1 Reg1;// + D_ADS122C04_CONFIG_REGISTER_2 Reg2; + D_ADS122C04_CONFIG_REGISTER_3 Reg3; + //uint8_t SEL; + bool Config; //true for done + unsigned char MUX_Status; + +}D_ADS122C04_TempSensConfigStruc; + + +bool ADS122_Reset(uint8_t i2cbus, WHS_chip_address i2cadd); +bool ADS122_StartSync(uint8_t i2cbus, WHS_chip_address i2cadd); +bool ADS122_PowerDown(uint8_t i2cbus, WHS_chip_address i2cadd); +bool ADS122_ReadDataCommand(uint8_t i2cbus, WHS_chip_address i2cadd, uint32_t* p_Data_ADS122X ); +bool ADS122_WriteReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t writeValue); +bool ADS122_WriteAllReg(uint8_t i2cbus, WHS_chip_address i2cadd, D_ADS122C04_TempSensConfigStruc *p_writeValue); +bool ADS122_ReadReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t *p_readValue); +uint32_t WHS_Test_ADS122X_Internal_Temperature_Sensor(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t *p_readValue ); +uint32_t ADS122_Calc_Resistance(uint32_t Data_ADS122X); +bool ADS122_InitConfigReg(); /* // Bit field type register configuration // Configuration Map register ADS122x04 diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.c new file mode 100644 index 000000000..a63f89654 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.c @@ -0,0 +1,875 @@ +/* + * WHS_PT100_ADC.c + * + * Created on: Jun 30, 2019 + * Author: Shai Frieder + */ + +/* +PT100 ADS122C04IRTE +ADDR 0x80 +ADDR 0x82 +*/ + +#include "include.h" +#include <DataDef.h> +#include <Drivers/I2C_Communication/WHS_Card/D_ADS122/ADS122X04_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> + +#include "modules/control/millisecTask.h" +#include "Modules/AlarmHandling/AlarmHandling.h" +#include "drivers/Heater/TemperatureSensor.h" +#include "../I2C_WHS_Mux.h" +#include "drivers/I2C_Communication/I2C.h" +//#include "drivers/I2C_Communication/Head_Card/IO_Ports/Head_IO.h" +//#include "Drivers/I2C_Communication/Head_Card/PT100/Head_PT100_ADC.h" + + +D_ADS122C04_TempSensConfigStruc PT100_Conf[2]; + +#define PT100_RST 0 +#define PT100_notRST 1 + +bool WHS_PT100_setRST(bool RST_value); +uint32_t temp_WHS_PT100_1_0X80_0 = 0; +uint32_t temp_WHS_PT100_2_0X80_1 = 0; +uint32_t temp_WHS_PT100_3_0X82_0 = 0; +uint32_t temp_WHS_PT100_4_0X82_1 = 0; + +bool WHS_PT100_setRST(bool RST_value) +{ + bool Status = OK; + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_PT_RSTn != RST_value) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_PT_RSTn = RST_value; + Status |= WHS_Write_IO(I2CExp1_ADDRESS,TCA9555_PORT_0); + } + return Status; +} + +bool WHS_PT100_InitConfigReg() +{ + bool Status = OK; + /* --- config PT100 U18 I2CExp1_ADDRESS= 0x40 --- */ + // - - - - - - - - - - Reg0 - - - - - - - - - - + PT100_Conf[0].Reg0.bits.PGA_BYPASS = ADS122X_PGA_ENABLE ;//Bit 0 + PT100_Conf[0].Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 + PT100_Conf[0].Reg0.bits.MUX = ADS122X_MUX_AIN0_AIN1 ;//Bits 4-7 + + // - - - - - - - - - - Reg1 - - - - - - - - - - + + PT100_Conf[0].Reg1.bits.TS = ADS122X_TEMP_SENSOR_DISABLE ;//Bit 0 + PT100_Conf[0].Reg1.bits.VREF = ADS122X_VREF_EXT ;//Bits 1-2 + PT100_Conf[0].Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 + PT100_Conf[0].Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 + PT100_Conf[0].Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 + + // - - - - - - - - - - Reg2 - - - - - - - - - - + + PT100_Conf[0].Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_1000_UA ;//Bits 0-2 + PT100_Conf[0].Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 + PT100_Conf[0].Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 + PT100_Conf[0].Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 + PT100_Conf[0].Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 + + // - - - - - - - - - - Reg3 - - - - - - - - - - + PT100_Conf[0].Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 + PT100_Conf[0].Reg3.bits.I2MUX = ADS122X_IDAC2_AIN3 ;//Bits 2-4 + PT100_Conf[0].Reg3.bits.I1MUX = ADS122X_IDAC2_AIN0 ;//Bits 5-7 + + /* --- config PT100 U21 I2CExp2_ADDRESS= 0x42 --- */ + // - - - - - - - - - - Reg0 - - - - - - - - - - + PT100_Conf[1].Reg0.bits.PGA_BYPASS = ADS122X_PGA_ENABLE ;//Bit 0 + PT100_Conf[1].Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 + PT100_Conf[1].Reg0.bits.MUX = ADS122X_MUX_AIN0_AIN1 ;//Bits 4-7 + + // - - - - - - - - - - Reg1 - - - - - - - - - - + + PT100_Conf[1].Reg1.bits.TS = ADS122X_TEMP_SENSOR_DISABLE ;//Bit 0 + PT100_Conf[1].Reg1.bits.VREF = ADS122X_VREF_EXT ;//Bits 1-2 + PT100_Conf[1].Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 + PT100_Conf[1].Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 + PT100_Conf[1].Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 + + // - - - - - - - - - - Reg2 - - - - - - - - - - + + PT100_Conf[1].Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_1000_UA ;//Bits 0-2 + PT100_Conf[1].Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 + PT100_Conf[1].Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 + PT100_Conf[1].Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 + PT100_Conf[1].Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 + + // - - - - - - - - - - Reg3 - - - - - - - - - - + PT100_Conf[1].Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 + PT100_Conf[1].Reg3.bits.I2MUX = ADS122X_IDAC2_AIN3 ;//Bits 2-4 + PT100_Conf[1].Reg3.bits.I1MUX = ADS122X_IDAC2_AIN0 ;//Bits 5-7 + + WHS_PT100_setRST(PT100_notRST); + Status |= ADS122_WriteAllReg(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS, &PT100_Conf[0]); + Status |= ADS122_WriteAllReg(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS, &PT100_Conf[1]); + return Status; +} + + + +/* +WHS_PT100_1_0X80_0, +WHS_PT100_2_0X80_1, +WHS_PT100_3_0X82_0, +WHS_PT100_4_0X82_1, + +TEMPERATURE_SENSOR_ID_ENUM +*/ +#define SELECT_B0 0 // WHS_PT100_1_0X80_0(J11) , WHS_PT100_3_0X82_0(J12) +#define SELECT_B1 1 // WHS_PT100_2_0X80_1(J20) , WHS_PT100_4_0X82_1(J21) + +bool WHS_PT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId) +{ + bool Status = OK; + + switch (SensorId) + { + case WHS_PT100_1_0X80_0: + case WHS_PT100_3_0X82_0: + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PT_SEL == SELECT_B1) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PT_SEL = SELECT_B0; + Status |= WHS_Write_IO(I2CExp1_ADDRESS,TCA9555_PORT_0); + } + break; + case WHS_PT100_2_0X80_1: + case WHS_PT100_4_0X82_1: + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PT_SEL == SELECT_B0) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PT_SEL = SELECT_B1; + Status |= WHS_Write_IO(I2CExp1_ADDRESS,TCA9555_PORT_0); + } + break; + default: + Status = ERROR; + break; + } + return Status; +} + +bool WHS_PT100_config(TEMPERATURE_SENSOR_ID_ENUM SensorId) +{ + /* 0x40 (reg0), 0x06(J11,J12), 0x76(J20,J21) + * 0x44 (reg1), 0x0A, + * 0x48 (reg2), 0x06, + * 0x4C (reg2), 0x30 */ + bool Status = OK; + + switch (SensorId) + { + case WHS_PT100_1_0X80_0: + if (PT100_Conf[0].Reg0.bits.MUX == ADS122X_MUX_AIN3_AIN2) + { + PT100_Conf[0].Reg0.bits.MUX = ADS122X_MUX_AIN0_AIN1; + Status |= ADS122_WriteReg(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS, 0, PT100_Conf[0].Reg0.Byte); + } + break; + case WHS_PT100_3_0X82_0: + if (PT100_Conf[1].Reg0.bits.MUX == ADS122X_MUX_AIN3_AIN2) + { + PT100_Conf[1].Reg0.bits.MUX = ADS122X_MUX_AIN0_AIN1; + Status |= ADS122_WriteReg(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS, 0, PT100_Conf[1].Reg0.Byte); + } + break; + case WHS_PT100_2_0X80_1: + if (PT100_Conf[0].Reg0.bits.MUX == ADS122X_MUX_AIN0_AIN1) + { + PT100_Conf[0].Reg0.bits.MUX = ADS122X_MUX_AIN3_AIN2; + Status |= ADS122_WriteReg(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS, 0, PT100_Conf[0].Reg0.Byte); + } + break; + case WHS_PT100_4_0X82_1: + if (PT100_Conf[1].Reg0.bits.MUX == ADS122X_MUX_AIN0_AIN1) + { + PT100_Conf[1].Reg0.bits.MUX = ADS122X_MUX_AIN3_AIN2; + Status |= ADS122_WriteReg(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS, 0, PT100_Conf[1].Reg0.Byte); + } + break; + default: + Status = ERROR; + break; + } + // - - - - - - - - - - Reg0 - - - - - - - - - - + PT100_Conf[0].Reg0.bits.MUX = ADS122X_MUX_AIN0_AIN1 ;//Bits 4-7 ADS122_WriteReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t writeValue); + PT100_Conf[0].Reg0.bits.MUX = ADS122X_MUX_AIN3_AIN2 ;//Bits 4-7 ADS122_WriteReg(uint8_t i2cbus, WHS_chip_address i2cadd, uint8_t reg, uint8_t writeValue); + return Status; + + //ADS122_WriteAllReg(uint8_t i2cbus, WHS_chip_address i2cadd, D_ADS122C04_TempSensConfigStruc *p_writeValue); +} + +bool WHS_PT100_Read(TEMPERATURE_SENSOR_ID_ENUM SensorId) +{ + bool Status = OK; + + WHS_PT100_config( SensorId); + WHS_PT100_ControlMux_Brfore_Reading( SensorId); + switch (SensorId) + { + case WHS_PT100_1_0X80_0: + Status |= ADS122_StartSync(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS); + Status |= ADS122_ReadDataCommand(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS, &temp_WHS_PT100_1_0X80_0 ); + break; + case WHS_PT100_2_0X80_1: + Status |= ADS122_StartSync(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS); + Status |= ADS122_ReadDataCommand(I2C_ID_WHS_CARD, I2CTemp1_ADDRESS, &temp_WHS_PT100_2_0X80_1 ); + break; + case WHS_PT100_3_0X82_0: + Status |= ADS122_StartSync(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS); + Status |= ADS122_ReadDataCommand(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS, &temp_WHS_PT100_3_0X82_0 ); + break; + case WHS_PT100_4_0X82_1: + Status |= ADS122_StartSync(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS); + Status |= ADS122_ReadDataCommand(I2C_ID_WHS_CARD, I2CTemp2_ADDRESS, &temp_WHS_PT100_4_0X82_1 ); + break; + default: + Status = ERROR; + break; + } + + return Status; +} + + +D_ADS122C04_TempSensConfigStruc HeadTempSensConfig[MAX_HEAD_CARD_TEMP_SENS_ID];//using only from HEAD_PT100_ZONE_1_0X80_0 + +uint32_t was_I2C_ADC_ADS122C04_SLAVE_ADD = 0x80; //A0-GND A1-GND 4-Bit, 4-Channel, 2-kSPS, ADC ------ PT100 ADC – 0x80 … 0x87. + +uint8_t was_Save_Sel_Status = UNKNOWN; + +//uint32_t SensorId_To_SlaveAdd(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// switch(SensorId) +// { +// case HEAD_PT100_ZONE_1_0X80_0: +// case HEAD_PT100_ZONE_2_0X80_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x80; +// break; +// case HEAD_PT100_ZONE_3_0X82_0: +// case HEAD_PT100_ZONE_4_0X82_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x82; +// break; +// case HEAD_PT100_ZONE_5_0X84_0: +// case HEAD_PT100_ZONE_6_0X84_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x84; +// break; +// case HEAD_PT100_ZONE_7_0X86_0: +// case HEAD_PT100_ZONE_8_0X86_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x86; +// break; +// case HEAD_PT100_ZONE_9_0X88_0: +// case HEAD_PT100_ZONE_10_0X88_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x88; +// break; +// case HEAD_PT100_ZONE_11_0X8A_0: +// case HEAD_PT100_ZONE_12_0X8A_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x8A; +// break; +// case HEAD_PT100_AIR_HEATER_1_0X8C_0: +// case HEAD_PT100_AIR_HEATER_2_0X8C_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x8C; +// break; +// case HEAD_PT100_MIXER_0X8E_0: +// case HEAD_PT100_RESERVE_0X8E_1: +// I2C_ADC_ADS122C04_SLAVE_ADD = 0x8E; +// break; +// default: +// break; +// } +// +// return I2C_ADC_ADS122C04_SLAVE_ADD; +//} + +//uint32_t I2C_Write_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Write_buf, uint32_t No_BytesToWrite ) +//{ +// uint32_t status = OK; +// +// I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); +// status |= I2C_Write(I2C_ID, I2C_ADC_ADS122C04_SLAVE_ADD, I2C_Write_buf, No_BytesToWrite); +// +// return status; +//} + +//uint32_t HeadADCPT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// +// uint8_t Write_Buf[2]; +// +// if(SensorId % 2) +// HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x03; // TBD +// else +// HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x04; // TBD +// +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// +// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// +// return Status; +//} + + +//uint32_t was_I2C_Read_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Read_buf, uint32_t No_BytesToRead ) +//{ +// uint32_t status = OK; +// +// //HeadADCPT100_ControlMux_Brfore_Reading(SensorId); +// //TODO Choose TEMP1 sensor by I/O +// was_I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); +// status |= I2C_Read(I2C_ID, was_I2C_ADC_ADS122C04_SLAVE_ADD + 1, I2C_Read_buf, No_BytesToRead); +// +// return status; +//} + +//uint32_t was_HeadADCPT100_Reset(void) +//{ +// uint32_t status = OK; +// #ifndef EVALUATION_BOARD +// uint8_t i; +// uint8_t Write_Buf[1]; +// +// for(i=HEAD_PT100_ZONE_1_0X80_0;i<MAX_HEAD_CARD_TEMP_SENS_ID; i++) +// { +// //Reset the device +// Write_Buf[0] = ADS122X_RESET_CMD; +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +//// status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 1); +// //status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); +// //Wait at least (50 us + 32 · t(CLK)) after the RESET command is sent before sending any other command. +// +// } +// #endif +// SysCtlDelay(100); // Must delay after hard reset +// +// return status; +//} + + +//uint32_t was_HeadADCPT100_StartSync(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// uint8_t Write_Buf[1]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// Status = ERROR; +// +// Write_Buf[0] = ADS122X_START_CMD; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); +// +// return Status; +//} + +//uint32_t was_HeadADCPT100_PowerDown(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// uint8_t Write_Buf[1]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// Status = ERROR; +// +// Write_Buf[0] = ADS122X_POWERDOWN_CMD; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); +// +// return Status; +//} + +//uint32_t was_Data_ADC_Head = 0; +//uint32_t was_HeadADCPT100_SendReadDataCommand(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// uint8_t Write_Buf[1]; +// +// uint32_t temp; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// Status = ERROR; +// +// //Write_Buf[0] = ADS122X_RDATA_CMD; +// Write_Buf[0] = ADS122X_RDATA_CMD; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); +// +//// Status |= I2C_Read_SensorId(I2C_ID_HEAD_CARD, SensorId, &temp, 3); +// was_Data_ADC_Head = (temp & 0xFF0000) >> 16 | (temp & 0xFF00) | (temp & 0x0000FF) << 16;//First send the MSB so we need to reorder the bytes +// +// CalculateTemperatures(SensorId, was_Data_ADC_Head); +// +// +// return Status; +//} + +//uint32_t was_HeadADCPT100_WriteReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t writeValue) +//{ +// uint32_t Status = OK; +// uint8_t Write_Buf[2]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// Status = ERROR; +// +// Write_Buf[0] = ADS122X_WRITE_CMD(reg); +// Write_Buf[1] = writeValue; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 2); +// +// return Status; +//} + + + +//#ifdef Use_Head_Card +// +//uint8_t was_HeadADCPT100_InitConfigReg() +//{ +// uint8_t i; +// +// for(i=HEAD_PT100_ZONE_1_0X80_0;i < MAX_HEAD_CARD_TEMP_SENS_ID;i++) // for now we are using the same configuration to all of them +// { +// // - - - - - - - - - - Reg0 - - - - - - - - - - +// HeadTempSensConfig[i].Reg0.bits.PGA_BYPASS = ADS122X_USE_PGA ;//Bit 0 +// HeadTempSensConfig[i].Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 +// //HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_ODD_PT100_MUX ;//Bits 4-7 +// +// // - - - - - - - - - - Reg1 - - - - - - - - - - +// +// HeadTempSensConfig[i].Reg1.bits.TS = ADS122X_TEMP_SENSOR_OFF ;//Bit 0 +// HeadTempSensConfig[i].Reg1.bits.VREF = ADS122X_VREF_INTERNAL ;//Bits 1-2 +// HeadTempSensConfig[i].Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 +// HeadTempSensConfig[i].Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 +// HeadTempSensConfig[i].Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 +// +// // - - - - - - - - - - Reg2 - - - - - - - - - - +// +// HeadTempSensConfig[i].Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_1000_UA ;//Bits 0-2 +// HeadTempSensConfig[i].Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 +// HeadTempSensConfig[i].Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 +// HeadTempSensConfig[i].Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 +// HeadTempSensConfig[i].Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 +// +// // - - - - - - - - - - Reg3 - - - - - - - - - - +// HeadTempSensConfig[i].Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 +// HeadTempSensConfig[i].Reg3.bits.I2MUX = ADS122X_IDAC2_AIN3 ;//Bits 2-4 +// HeadTempSensConfig[i].Reg3.bits.I1MUX = ADS122X_IDAC1_AIN0 ;//Bits 5-7 +// +// } +// +// for(i=HEAD_PT100_ZONE_1_0X80_0;i < MAX_HEAD_CARD_TEMP_SENS_ID_0;i++) +// { +// HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_ODD_PT100_MUX ;//Bits 4-7 +// HeadTempSensConfig[i].SEL = ODD; +// } +// +// for(i=HEAD_PT100_ZONE_2_0X80_1;i < MAX_HEAD_CARD_TEMP_SENS_ID_1;i++) +// { +// HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_EVEN_PT100_MUX ;//Bits 4-7 +// HeadTempSensConfig[i].SEL = EVEN; +// } +// +// HeadTempSensConfig[i].Config = 0; +// +// HeadTempSensConfig[i].MUX_Status = UNKNOWN; +// +// return OK; +//} +//#else +// uint8_t was_HeadADCPT100_InitConfigReg() +// { +// uint8_t i; +// +// for(i=HEAD_PT100_ZONE_1_0X80_0;i<MAX_HEAD_CARD_TEMP_SENS_ID; i++) +// { +// // - - - - - - - - - - Reg0 - - - - - - - - - - +// HeadTempSensConfig[i].Reg0.bits.PGA_BYPASS = ADS122X_PGA_ENABLE ;//Bit 0 +// HeadTempSensConfig[i].Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 +// HeadTempSensConfig[i].Reg0.bits.MUX = ADS122X_MUX_AIN1_AIN0 ;//Bits 4-7 +// +// // - - - - - - - - - - Reg1 - - - - - - - - - - +// +// HeadTempSensConfig[i].Reg1.bits.TS = ADS122X_TEMP_SENSOR_OFF ;//Bit 0 +// HeadTempSensConfig[i].Reg1.bits.VREF = ADS122X_VREF_INTERNAL ;//Bits 1-2 +// HeadTempSensConfig[i].Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 +// HeadTempSensConfig[i].Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 +// HeadTempSensConfig[i].Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 +// +// // - - - - - - - - - - Reg2 - - - - - - - - - - +// +// HeadTempSensConfig[i].Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_500_UA ;//Bits 0-2 +// HeadTempSensConfig[i].Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 +// HeadTempSensConfig[i].Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 +// HeadTempSensConfig[i].Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 +// HeadTempSensConfig[i].Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 +// +// // - - - - - - - - - - Reg3 - - - - - - - - - - +// HeadTempSensConfig[i].Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 +// HeadTempSensConfig[i].Reg3.bits.I2MUX = ADS122X_IDAC2_DISABLED ;//Bits 2-4 +// HeadTempSensConfig[i].Reg3.bits.I1MUX = ADS122X_IDAC1_AIN3 ;//Bits 5-7 +// +// } +// +// return OK; +// } +//#endif + +//uint32_t was_HeadADCPT100_Config_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t Stage) +//{ +// uint32_t Status = OK; +// +// #ifndef EVALUATION_BOARD +// +// uint8_t Write_Buf[2]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// return ERROR; +// +// if(HeadTempSensConfig[SensorId].Config == DONE) +// return Status; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +// switch(Stage) +// { +// case SENSOR_CONFIG_REG0: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// break; +// case SENSOR_CONFIG_REG1: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_1_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg1.Byte; +// break; +// case SENSOR_CONFIG_REG2: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_2_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg2.Byte; +// break; +// case SENSOR_CONFIG_REG3: +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_3_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg3.Byte; +// break; +// default: +// Status = ERROR; +// } +// +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// +// switch(SensorId) +// { +// case HEAD_PT100_ZONE_1_0X80_0: +// case HEAD_PT100_ZONE_2_0X80_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_1_0X80_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_2_0X80_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_3_0X82_0: +// case HEAD_PT100_ZONE_4_0X82_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_3_0X82_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_4_0X82_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_5_0X84_0: +// case HEAD_PT100_ZONE_6_0X84_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_5_0X84_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_6_0X84_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_7_0X86_0: +// case HEAD_PT100_ZONE_8_0X86_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_7_0X86_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_8_0X86_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_9_0X88_0: +// case HEAD_PT100_ZONE_10_0X88_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_9_0X88_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_10_0X88_1].Config = DONE; +// break; +// case HEAD_PT100_ZONE_11_0X8A_0: +// case HEAD_PT100_ZONE_12_0X8A_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_11_0X8A_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_ZONE_12_0X8A_1].Config = DONE; +// break; +// case HEAD_PT100_AIR_HEATER_1_0X8C_0: +// case HEAD_PT100_AIR_HEATER_2_0X8C_1: +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_1_0X8C_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_2_0X8C_1].Config = DONE; +// break; +// case HEAD_PT100_MIXER_0X8E_0: +// case HEAD_PT100_RESERVE_0X8E_1: +// HeadTempSensConfig[HEAD_PT100_MIXER_0X8E_0].Config = DONE; +// HeadTempSensConfig[HEAD_PT100_RESERVE_0X8E_1].Config = DONE; +// break; +// default: +// break; +// } +// +// #endif +// +// return Status; +//} + +//void was_HeadADCPT100_SensorInitConfig() +//{ +// int Sensor=0,Register = 0; +// +// HeadADCPT100_InitConfigReg(); // Initial the configuration registers +// +// for(Register=0;Register<=SENSOR_CONFIG_REG3;Register++) +// { +// for(Sensor=HEAD_PT100_ZONE_1_0X80_0;Sensor<MAX_HEAD_CARD_TEMP_SENS_ID; Sensor++) +// { +// HeadADCPT100_Config_callback( (TEMPERATURE_SENSOR_ID_ENUM)(Sensor), Register); +// } +// SysCtlDelay(1000); +// } +//} +/* +uint32_t was_HeadCard_Toggle_PT100(bool Odd_OR_Even)//ODD/EVEN +{ + uint32_t status = OK; + uint8_t i=0; + uint8_t Write_Buf[2]; + + was_HeadCard_Toggle_PT100_SEL(Odd_OR_Even); + + if(Odd_OR_Even == EVEN) + { + for(i=HEAD_PT100_ZONE_2_0X80_1;i < MAX_HEAD_CARD_TEMP_SENS_ID;i=i+2) + { + HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_EVEN_PT100_MUX;//Reg0 Bits 4-7 + + Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); + Write_Buf[1] = HeadTempSensConfig[i].Reg0.Byte; + + status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 2); + } + } + else + { + for(i=HEAD_PT100_ZONE_1_0X80_0;i < MAX_HEAD_CARD_TEMP_SENS_ID;i=i+2) + { + HeadTempSensConfig[i].Reg0.bits.MUX = HEAD_CONFIG_ODD_PT100_MUX;//Reg0 Bits 4-7 + + Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); + Write_Buf[1] = HeadTempSensConfig[i].Reg0.Byte; + + status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 2); + } + } + + return status; +} +*/ + +//uint32_t was_HeadCard_Toggle_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t status = OK; +// uint8_t Write_Buf[2]; +// +// if((SensorId < HEAD_PT100_ZONE_1_0X80_0) || (SensorId > MAX_HEAD_CARD_TEMP_SENS_ID)) +// return ERROR; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +//// if(was_Save_Sel_Status != HeadTempSensConfig[SensorId].SEL) +//// { +//// was_HeadCard_Toggle_PT100_SEL(HeadTempSensConfig[SensorId].SEL); +//// was_Save_Sel_Status = HeadTempSensConfig[SensorId].SEL; +//// } +// +// if(HeadTempSensConfig[SensorId].MUX_Status != HeadTempSensConfig[SensorId].Reg0.bits.MUX) +// { +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; +// +//// status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// +// switch(SensorId) +// { +// case HEAD_PT100_ZONE_1_0X80_0: +// case HEAD_PT100_ZONE_2_0X80_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_1_0X80_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_2_0X80_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_3_0X82_0: +// case HEAD_PT100_ZONE_4_0X82_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_3_0X82_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_4_0X82_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_5_0X84_0: +// case HEAD_PT100_ZONE_6_0X84_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_5_0X84_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_6_0X84_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_7_0X86_0: +// case HEAD_PT100_ZONE_8_0X86_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_7_0X86_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_8_0X86_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_9_0X88_0: +// case HEAD_PT100_ZONE_10_0X88_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_9_0X88_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_10_0X88_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_ZONE_11_0X8A_0: +// case HEAD_PT100_ZONE_12_0X8A_1: +// HeadTempSensConfig[HEAD_PT100_ZONE_11_0X8A_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_ZONE_12_0X8A_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_AIR_HEATER_1_0X8C_0: +// case HEAD_PT100_AIR_HEATER_2_0X8C_1: +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_1_0X8C_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_AIR_HEATER_2_0X8C_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// case HEAD_PT100_MIXER_0X8E_0: +// case HEAD_PT100_RESERVE_0X8E_1: +// HeadTempSensConfig[HEAD_PT100_MIXER_0X8E_0].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// HeadTempSensConfig[HEAD_PT100_RESERVE_0X8E_1].MUX_Status = TempSensConfig[SensorId].Reg0.bits.MUX; +// break; +// default: +// break; +// } +// } +// return status; +//} + + +//uint32_t was_HeadADCPT100_ReadReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t *readValue) +//{ +// uint32_t Status = OK; +// +// uint8_t Write_Buf[1]; +// +// #ifdef Use_Head_Card +// Select_Main_Head_Mux_Channel(); +// #endif +// +// Write_Buf[0] = ADS122X_READ_CMD(reg); +// +//// Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); +// delayUs(1); // delayUs(50); +//// Status |= I2C_Read_SensorId(I2C_ID_HEAD_CARD, SensorId, readValue, 1); +// +// return Status; +//} + +//uint8_t was_Test_Read_Buf[4] = {0,0,0,0}; + +//uint32_t was_Test_HeadCard_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Status = OK; +// uint8_t i = 0; +// +// #ifdef Test_headCard_With_DispCard_I2C4_Add0xE2_DispID_0 +// Select_Main_Head_Mux_Channel_test(); +// #else +// Select_Main_Head_Mux_Channel(); +// #endif +// +// //HeadADCPT100_Reset(); +// HeadADCPT100_InitConfigReg(); +// +// +// was_HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG0); +// was_HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG1); +// was_HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG2); +// was_HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG3); +// +// was_HeadADCPT100_StartSync(SensorId); +// +// +// +// uint8_t Write_Buf[4] = {SENSOR_CONFIG_REG0,SENSOR_CONFIG_REG1,SENSOR_CONFIG_REG2,SENSOR_CONFIG_REG3}; +// +// for(i=0; i<4; i++) +// { +// was_HeadADCPT100_ReadReg(SensorId, Write_Buf[i], &was_Test_Read_Buf[i]); +// +// } +// +// was_HeadADCPT100_SendReadDataCommand(SensorId); +// +// +// return Status; +//} + +//uint32_t was_HeadADCPT100_Calc_Resistance(TEMPERATURE_SENSOR_ID_ENUM SensorId, unsigned int Current_Measurement) +//{ +// +// #define Rref 1650 //ohm +// +// uint32_t HeadADCPT100_Resistance_100; +// +// unsigned int Factor_2Rref_E_H; +// unsigned int Factor_2Rref_E_L; +// +// //Resistance = Measurement / (2^23) *4 * Rref / Gain //---------------------- is it *4 ???? +// +// Factor_2Rref_E_H = 400 * Rref; // 200 to calculate Resistance*100 +// +// Factor_2Rref_E_L = 8388608 * (2<<(TempSensConfig[SensorId].Reg0.bits.GAIN -1));//2^23*Gain +// +// HeadADCPT100_Resistance_100 = (float)Current_Measurement / (float)Factor_2Rref_E_L * (float)Factor_2Rref_E_H; +// +// return HeadADCPT100_Resistance_100; +//} + +//uint32_t was_Test_ADS122X_Internal_Temperature_Sensor(TEMPERATURE_SENSOR_ID_ENUM SensorId) +//{ +// uint32_t Data = 0; +// +// uint8_t Write_Buf[2]; +// +// Select_Main_Head_Mux_Channel(); +// +// SysCtlDelay(5000); +// HeadTempSensConfig[SensorId].Reg1.bits.TS = ADS122X_TEMP_SENSOR_ON;//Bit 1 Enables the Internal temperature sensor +// +// Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_1_REG<<2); +// Write_Buf[1] = HeadTempSensConfig[SensorId].Reg1.Byte; +//// I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); +// +// was_HeadCard_Toggle_PT100(SensorId); +// +// SysCtlDelay(5000); +// +// was_HeadADCPT100_StartSync(SensorId); +// SysCtlDelay(3000); +// +// was_HeadADCPT100_SendReadDataCommand(SensorId); +// +// Data = was_Data_ADC_Head; +// +// Data = Data & 0xFFFFFF;//24bit +// +// Data = Data >> 10;//need the 14 left bits // According to ADS1220 data sheet page 31 8.3.13 +// +// Data*=0.03125;// According to ADS1220 data sheet page 31 8.3.13 +// +// return Data;//Temperature_C +// +//} diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.h new file mode 100644 index 000000000..2cedac166 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_ADS122/WHS_PT100_ADC.h @@ -0,0 +1,52 @@ +/* + * WHS_PT100_ADC.h + * + * Created on: Jun 30, 2019 + * Author: avi + */ + +#ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_PT100_PT100_ADC_H_ +#define DRIVERS_I2C_COMMUNICATION_WHS_CARD_PT100_PT100_ADC_H_ + +extern uint32_t was_Data_ADC_Head; + +#define WHS_CONFIG_GAIN ADS122X_GAIN_8 +#define WHS_CONFIG_IDAC ADS122X_IDAC_CURRENT_1000_UA +#define WHS_CONFIG_I1MUX ADS122X_IDAC2_AIN0 +#define WHS_CONFIG_I2MUX ADS122X_IDAC1_AIN3 + +#define WHS_CONFIG_ODD_PT100_MUX ADS122X_MUX_AIN0_AIN1 //0x0 +#define WHS_CONFIG_EVEN_PT100_MUX ADS122X_MUX_AIN3_AIN2 //0x7 + +#define WHS_CONFIG_EVEN_PT100_PT_SEL 0X01 +#define WHS_CONFIG_ODD_PT100_PT_SEL 0X00 + + + +bool WHS_PT100_InitConfigReg(); +bool WHS_PT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId); + + +extern HeadBoardTempSensConfigStruc HeadTempSensConfig[MAX_TEMPERATURE_SENSOR_ID]; + + +//uint32_t SensorId_To_SlaveAdd(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t I2C_Write_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Write_buf, uint32_t No_BytesToWrite ); +//uint32_t was_HeadADCPT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t was_I2C_Read_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Read_buf, uint32_t No_BytesToRead ); +//uint32_t was_HeadADCPT100_Reset(void); +//uint32_t was_HeadADCPT100_StartSync(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t was_HeadADCPT100_PowerDown(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t was_HeadADCPT100_SendReadDataCommand(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t was_HeadADCPT100_WriteReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t writeValue); +//uint8_t was_HeadADCPT100_InitConfigReg(); +//uint32_t was_HeadADCPT100_Config_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t Stage); +//uint32_t was_HeadADCPT100_ReadReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t *readValue); +//void was_HeadADCPT100_SensorInitConfig(); +//uint32_t was_HeadADCPT100_Calc_Resistance(TEMPERATURE_SENSOR_ID_ENUM SensorId, unsigned int Current_Measurement); +//uint32_t was_HeadCard_Toggle_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId); +//uint32_t was_Test_ADS122X_Internal_Temperature_Sensor(TEMPERATURE_SENSOR_ID_ENUM SensorId); + +//uint32_t Test_HeadCard_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId); + +#endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_PT100_PT100_ADC_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.c index abb62531c..cca6be426 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.c @@ -16,16 +16,17 @@ #include "../I2C_WHS_Mux.h" #include <Drivers/I2C_Communication/I2C.h> #include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h> -#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.h> +#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h> +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" -uint8_t D_Fan_PWM_Output_Config (uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr); -uint8_t D_Fan_Setting (uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan); -uint8_t D_Fan_Read_Tacho (uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan); -uint8_t D_fan_click_productID (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); -uint8_t D_fan_click_manufactuerID (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); -uint8_t D_fan_click_revision (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); -uint8_t D_Read_Config_Reg (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); -uint8_t D_Fan_config (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_Fan_PWM_Output_Config (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_Fan_Setting (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr, bool Fan); +//uint8_t D_Fan_Read_Tacho (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr, bool Fan); +//uint8_t D_fan_productID (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_fan_manufactuerID (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_fan_revision (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_Read_Config_Reg (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); +//uint8_t D_Fan_config (uint8_t EMC2302_I2C_bus_number , uint8_t EMC2302_I2C_addr); /****************************************************************************** @@ -38,7 +39,7 @@ uint8_t writebuffer[2]; //uint32_t I2C_FAN_SLAVE_ADD = 0x5C; -FAN_CLICK_INFO Fan_Click_Info; + uint16_t Fan_Tach[2] = {0,0}; uint8_t D_Fan_PWM_Command[2] = {0,0}; @@ -46,15 +47,12 @@ uint8_t D_Fan_PWM_Command[2] = {0,0}; EMC2302_READ EMC2302_Read; - - - EMC2302_WRITE EMC2302_Write; -uint8_t D_EMC2302_Reg_Add[EMC2302_Size] = { -0x20,0x24,0x25,0x26,0x27,0x29,0x2A,0x2B,0x2D, -0x30,0x40,0x31,0x41,0x32,0x42,0x33,0x43,0x35,0x45,0x36,0x46,0x37,0x47,0x38,0x48,0x39,0x49,0x3A,0x4A,0x3B,0x4B,0x3C,0x4C,0x3D,0x4D,0x3E,0x4E,0x3F,0x4F, -0xEF,0xFD,0xFE,0xFF}; +//uint8_t D_EMC2302_Reg_Add[EMC2302_Size] = { +//0x20,0x24,0x25,0x26,0x27,0x29,0x2A,0x2B,0x2D, +//0x30,0x40,0x31,0x41,0x32,0x42,0x33,0x43,0x35,0x45,0x36,0x46,0x37,0x47,0x38,0x48,0x39,0x49,0x3A,0x4A,0x3B,0x4B,0x3C,0x4C,0x3D,0x4D,0x3E,0x4E,0x3F,0x4F, +//0xEF,0xFD,0xFE,0xFF}; /****************************************************************************** * Function Definitions @@ -63,18 +61,7 @@ uint8_t D_EMC2302_Reg_Add[EMC2302_Size] = { -//uint8_t D_Fan_PWM_Polarity_Config() -//{ -// uint8_t status = ERROR; -// -// if(EMC2302_Write.Reg.PWM_Polarity_Config <=0x03)//Bit0 invert PWM1, Bit2 invert PWM2 -// { -// writebuffer[0] = EMC2301_PWM_POLARITY; -// writebuffer[1] = EMC2302_Write.Reg.PWM_Polarity_Config;; -// status = I2C_Write(I2C_ID_WHS_CARD, I2C_WHS_FAN_SLAVE_ADD, writebuffer, 2); -// } -// return status; -//} + @@ -99,52 +86,20 @@ uint8_t D_EMC2302_Reg_Add[EMC2302_Size] = { ******************************************/ -uint8_t D_fan_click_productID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr) -{ - uint8_t status = OK; - writebuffer[0] = EMC2301_PRODUCT_ID; - readbuffer[0] = 0; - status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); - delayUs(10);//TODO - check the delay - status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); - Fan_Click_Info.Product_ID = readbuffer[0]; - return status; -} -uint8_t D_fan_click_manufactuerID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr) -{ - uint8_t status = OK; - writebuffer[0] = EMC2301_MANUFACTUERE_ID; - status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); - delayUs(10);//TODO - check the delay - status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); - Fan_Click_Info.Product_ID = readbuffer[0]; - return status; -} -uint8_t D_fan_click_revision(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr) -{ - uint8_t status = OK; - writebuffer[0] = EMC2301_REVISION; - status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); - delayUs(10);//TODO - check the delay - status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); - Fan_Click_Info.Product_ID = readbuffer[0]; - return status; -} - -uint8_t D_Read_Config_Reg(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr) -{ - uint8_t status = OK; - writebuffer[0] = EMC2301_CONFIGURATION; - status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); - delayUs(10);//TODO - check the delay - status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); - - EMC2302_Read.Reg.Configuration = readbuffer[0]; - - return status; -} +//uint8_t D_Read_Config_Reg(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr) +//{ +// uint8_t status = OK; +// writebuffer[0] = EMC2301_CONFIGURATION; +// status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); +// delayUs(10);//TODO - check the delay +// status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); +// +// EMC2302_Read.Reg.Configuration = readbuffer[0]; +// +// return status; +//} //uint8_t WHS_Fan_Read_Register(uint8_t Reg) //{ @@ -178,94 +133,164 @@ uint8_t D_Read_Config_Reg(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_ad -uint8_t D_Fan_config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr) - -{ - uint8_t status = OK; +//uint8_t D_Fan_config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr) +// +//{ +// uint8_t status = OK; +// +// //EMC2302_Write.Reg.PWM_Polarity_Config = 0x0;//Bit0 invert PWM1, Bit2 invert PWM2 +// //WHS_Fan_PWM_Polarity_Config(); +// +// //Output is configured as a push-pull output +// EMC2302_Write.Reg.PWM_Output_Config = 0x3;//Bit0 Output PWM1, Bit2 Output PWM2, 0 open drain, 1 push-pull +// D_Fan_PWM_Output_Config(EMC2302_I2C_bus_number ,EMC2302_I2C_addr); +// +//// //Max Freq. +//// EMC2302_Write.Reg.PWM_Base_Freq = (FAN_FREQ_26KHZ << 2) | FAN_FREQ_26KHZ; +//// WHS_Fan_PWM_Base_Frequency(); +//// +//// +//// WHS_Read_Config_Reg(); +//// if (EMC2302_Read.Reg.PWM_Output_Config != EMC2302_Write.Reg.PWM_Output_Config) +//// status |= ERROR ; +// +// EMC2302_Write.Reg.Fan_Setting[0] = D_Fan_PWM_Command[0]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP +// D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 0); +// delayms(5);//TODO - check the delay +// D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 0); +// +// EMC2302_Write.Reg.Fan_Setting[1] = D_Fan_PWM_Command[1]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP +// D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 1); +// delayms(5);//TODO - check the delay +// D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 1); +// +// return status; +//} - //EMC2302_Write.Reg.PWM_Polarity_Config = 0x0;//Bit0 invert PWM1, Bit2 invert PWM2 - //WHS_Fan_PWM_Polarity_Config(); - //Output is configured as a push-pull output - EMC2302_Write.Reg.PWM_Output_Config = 0x3;//Bit0 Output PWM1, Bit2 Output PWM2, 0 open drain, 1 push-pull - D_Fan_PWM_Output_Config(EMC2302_I2C_bus_number ,EMC2302_I2C_addr); +//void Test_WHS_fan_Click(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr) +//{ +// static uint8_t once = 1; +// uint8_t data; +// if (once) +// { +// #ifdef Test_WHSCard_With_DispCard_I2C4_Add0xE2_DispID_0 +// Select_Main_WHS_Mux_Channel_test(); +// #else +// Select_Main_WHS_Mux_Channel(); +// #endif +// +// //once = 0; +// } +// D_fan_productID(EMC2302_I2C_bus_number , EMC2302_I2C_addr, &data); +// D_fan_manufactuerID(EMC2302_I2C_bus_number , EMC2302_I2C_addr, &data); +// D_fan_revision(EMC2302_I2C_bus_number , EMC2302_I2C_addr, &data); +// D_Read_Config_Reg(EMC2302_I2C_bus_number , EMC2302_I2C_addr); +// //WHS_Fan_Read_Registers(); +// D_Fan_config( EMC2302_I2C_bus_number , EMC2302_I2C_addr); +//} -// //Max Freq. -// EMC2302_Write.Reg.PWM_Base_Freq = (FAN_FREQ_26KHZ << 2) | FAN_FREQ_26KHZ; -// WHS_Fan_PWM_Base_Frequency(); +//uint8_t D_Fan_PWM_Control(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, uint8_t Fan_ID, uint8_t PWM) +//{ +// uint8_t status = OK; +// +// // Select_Main_WHS_Mux_Channel(); // +// if(Fan_ID < 0x02) +// { +// D_Fan_PWM_Command[Fan_ID] = PWM; +// } +// else +// status |= ERROR; +// +// +// EMC2302_Write.Reg.PWM_Output_Config |= (0x1 << Fan_ID);//Bit0 Output PWM1, Bit2 Output PWM2, 0 open drain, 1 push-pull +// status |= D_Fan_PWM_Output_Config( EMC2302_I2C_bus_number , EMC2302_I2C_addr); // -// WHS_Read_Config_Reg(); -// if (EMC2302_Read.Reg.PWM_Output_Config != EMC2302_Write.Reg.PWM_Output_Config) -// status |= ERROR ; +// EMC2302_Write.Reg.Fan_Setting[Fan_ID] = D_Fan_PWM_Command[Fan_ID]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP +// status |= D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, Fan_ID); +// delayms(5);//TODO - check the delay +// status |= D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, Fan_ID); +// +// return status; +//} - EMC2302_Write.Reg.Fan_Setting[0] = D_Fan_PWM_Command[0]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP - D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 0); - delayms(5);//TODO - check the delay - D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 0); +/* ***** use only the next func: ***/ +/* ***** use only the next func: ***/ +/* ***** use only the next func: ***/ +/* ***** use only the next func: ***/ - EMC2302_Write.Reg.Fan_Setting[1] = D_Fan_PWM_Command[1]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP - D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 1); - delayms(5);//TODO - check the delay - D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, 1); +uint8_t D_fan_productID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *productID) +{ + uint8_t status = OK; + writebuffer[0] = EMC2301_PRODUCT_ID; + readbuffer[0] = 0; + status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); + delayUs(10);//TODO - check the delay + status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1,productID , 1);// readbuffer + //Fan_Info.Product_ID = readbuffer[0]; + return status; +} +uint8_t D_fan_manufactuerID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *manufactuerID) +{ + uint8_t status = OK; + writebuffer[0] = EMC2301_MANUFACTUERE_ID; + status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); + delayUs(10);//TODO - check the delay + status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, manufactuerID, 1); + //Fan_Info.Product_ID = readbuffer[0]; return status; } +uint8_t D_fan_revision(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *revision) +{ + uint8_t status = OK; + writebuffer[0] = EMC2301_REVISION; + status |= I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 1); + delayUs(10);//TODO - check the delay + status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, revision, 1); + //Fan_Info.Product_ID = readbuffer[0]; + return status; +} -void Test_WHS_fan_Click(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr) +uint8_t D_Fan_PWM_Polarity_Config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan_ID, bool polarity_config) { - static uint8_t once = 1; - if (once) - { - #ifdef Test_WHSCard_With_DispCard_I2C4_Add0xE2_DispID_0 - Select_Main_WHS_Mux_Channel_test(); - #else - Select_Main_WHS_Mux_Channel(); - #endif + uint8_t status = ERROR; + EMC2302_Write.Reg.PWM_Polarity_Config |= (polarity_config << Fan_ID); - //once = 0; - } - D_fan_click_productID(EMC2302_I2C_bus_number , EMC2302_I2C_addr); - D_fan_click_manufactuerID(EMC2302_I2C_bus_number , EMC2302_I2C_addr); - D_fan_click_revision(EMC2302_I2C_bus_number , EMC2302_I2C_addr); - D_Read_Config_Reg(EMC2302_I2C_bus_number , EMC2302_I2C_addr); - //WHS_Fan_Read_Registers(); - D_Fan_config( EMC2302_I2C_bus_number , EMC2302_I2C_addr); -} + writebuffer[0] = EMC2301_PWM_POLARITY; + writebuffer[1] = EMC2302_Write.Reg.PWM_Polarity_Config; + status = I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 2); -/* ***** use only the next func: ***/ -/* ***** use only the next func: ***/ -/* ***** use only the next func: ***/ -/* ***** use only the next func: ***/ + return status; +} -uint8_t D_Fan_PWM_Output_Config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr) +uint8_t D_Fan_PWM_Output_Config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan_ID, bool output_config) { uint8_t status = ERROR; + EMC2302_Write.Reg.PWM_Output_Config |= (output_config << Fan_ID); - if(EMC2302_Write.Reg.PWM_Output_Config <=0x03)//Bit0 Output PWM1, Bit2 Output PWM2, 0 open drain, 1 push-pull - { writebuffer[0] = EMC2301_PWM_OUTPUT_CONFIG; - writebuffer[1] = EMC2302_Write.Reg.PWM_Output_Config;; + writebuffer[1] = EMC2302_Write.Reg.PWM_Output_Config; // status = I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 2); - } - return status; + return status; } -uint8_t D_Fan_Setting(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan) +uint8_t D_Fan_Setting(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan, uint8_t fan_speed) { uint8_t status = ERROR; if(Fan == 0) { writebuffer[0] = EMC2301_FAN_1_SETTING; - writebuffer[1] = EMC2302_Write.Reg.Fan_Setting[0]; + writebuffer[1] = fan_speed; //EMC2302_Write.Reg.Fan_Setting[0] } else { writebuffer[0] = EMC2301_FAN_2_SETTING; - writebuffer[1] = EMC2302_Write.Reg.Fan_Setting[1]; + writebuffer[1] = fan_speed; //EMC2302_Write.Reg.Fan_Setting[1]; } status = I2C_Write(EMC2302_I2C_bus_number, EMC2302_I2C_addr, writebuffer, 2); @@ -273,7 +298,7 @@ uint8_t D_Fan_Setting(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, return status; } -uint8_t D_Fan_Read_Tacho(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan) +uint8_t D_Fan_Read_Tacho(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan, uint16_t *data) { uint8_t status = ERROR; @@ -291,7 +316,8 @@ uint8_t D_Fan_Read_Tacho(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_add status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); EMC2302_Read.Reg.TACHReading_Low[0] = readbuffer[0]; - Fan_Tach[0] = (EMC2302_Read.Reg.TACHReading_High[0] << 8) | EMC2302_Read.Reg.TACHReading_Low[0]; + *data = (EMC2302_Read.Reg.TACHReading_High[0] << 8) | EMC2302_Read.Reg.TACHReading_Low[0]; + //*data = Fan_Tach[0]; } else { @@ -307,37 +333,15 @@ uint8_t D_Fan_Read_Tacho(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_add status |= I2C_Read(EMC2302_I2C_bus_number, EMC2302_I2C_addr + 1, readbuffer, 1); EMC2302_Read.Reg.TACHReading_Low[1] = readbuffer[0]; - Fan_Tach[1] = (EMC2302_Read.Reg.TACHReading_High[1] << 8) | EMC2302_Read.Reg.TACHReading_Low[1]; + //Fan_Tach[1] = (EMC2302_Read.Reg.TACHReading_High[1] << 8) | EMC2302_Read.Reg.TACHReading_Low[1]; + *data = (EMC2302_Read.Reg.TACHReading_High[1] << 8) | EMC2302_Read.Reg.TACHReading_Low[1]; } return status; } -uint8_t D_Fan_PWM_Control(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, uint8_t Fan_ID, uint8_t PWM) -{ - uint8_t status = OK; - - // Select_Main_WHS_Mux_Channel(); - if(Fan_ID < 0x02) - { - D_Fan_PWM_Command[Fan_ID] = PWM; - } - else - status |= ERROR; - - - EMC2302_Write.Reg.PWM_Output_Config |= (0x1 << Fan_ID);//Bit0 Output PWM1, Bit2 Output PWM2, 0 open drain, 1 push-pull - status |= D_Fan_PWM_Output_Config( EMC2302_I2C_bus_number , EMC2302_I2C_addr); - - EMC2302_Write.Reg.Fan_Setting[Fan_ID] = D_Fan_PWM_Command[Fan_ID]; //Fan 1 Setting - 0xFF Full PWM 0x80 = 50% FF = 100% 0 - STOP - status |= D_Fan_Setting( EMC2302_I2C_bus_number , EMC2302_I2C_addr, Fan_ID); - delayms(5);//TODO - check the delay - status |= D_Fan_Read_Tacho( EMC2302_I2C_bus_number , EMC2302_I2C_addr, Fan_ID); - - return status; -} /* control by: diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h index c4b0b6ba7..a227e25d7 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h @@ -775,7 +775,7 @@ void fan_click_lock_registers( bool lock ); * * @return Product ID */ -uint8_t fan_click_productID( void ); +uint8_t D_fan_productID( uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *productID); /** * @brief fan_click_manufactuerID @@ -784,7 +784,7 @@ uint8_t fan_click_productID( void ); * * @return Manufacturer ID */ -uint8_t fan_click_manufactuerID( void ); +uint8_t D_fan_manufactuerID( uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *manufactuerID ); /** @@ -795,7 +795,20 @@ uint8_t fan_click_manufactuerID( void ); * * @return Revision number */ -uint8_t fan_click_revision( void ); +uint8_t D_fan_revision( uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *revision ); + +//uint8_t D_Fan_PWM_Control(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, uint8_t Fan_ID, uint8_t PWM); + + + +uint8_t D_fan_productID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *productID); +uint8_t D_fan_manufactuerID(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *manufactuerID); +uint8_t D_fan_revision(uint8_t EMC2302_I2C_bus_number, uint8_t EMC2302_I2C_addr, uint8_t *revision); +uint8_t D_Fan_PWM_Polarity_Config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan_ID, bool polarity_config); +uint8_t D_Fan_PWM_Output_Config(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan_ID, bool output_config); +uint8_t D_Fan_Setting(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan, uint8_t fan_speed); +uint8_t D_Fan_Read_Tacho(uint8_t EMC2302_I2C_bus_number ,uint8_t EMC2302_I2C_addr, bool Fan, uint16_t *data); + #ifdef __cplusplus } // extern "C" diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.c deleted file mode 100644 index c18dc3be3..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Head_Fan.c - * - * Created on: Jul 2, 2019 - * Author: avi - */ -#include "include.h" - -/* - - EMC2301 / EMC2302 - -https://github.com/MicrochipTech/gcp-iot-core-examples/blob/master/src/devices/fan_click.c -https://github.com/MikroElektronika/HEXIWEAR/blob/master/SW/Click%20Examples%20mikroC/examples/iqRF/fan_click.h - -https://github.com/TekkaTim/esp32_learning/blob/master/lib/EMC2302.py - -*/ - -//FAN EMC2302-1-AIZL - - - diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.c new file mode 100644 index 000000000..cd78a0aa5 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.c @@ -0,0 +1,223 @@ +/* + * Head_Fan.c + * + * Created on: Jul 2, 2019 + * Author: avi + */ +#include "include.h" +#include "Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h" +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include <Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_EMC2302_fan.h> +#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h> + +FAN_DRIVER_INFO Fan_Driver_Info[maxFAN-1]; +#define FAN_SPEED_OFF 0x00 +#define PUSH_PULL 1 +uint8_t Fan_Mux_Channel = UNKNOWN; + +bool Select_WHS_Fan_Mux_Channel(WHS_fan_num fan_number); + + +/* + + EMC2301 / EMC2302 + +https://github.com/MicrochipTech/gcp-iot-core-examples/blob/master/src/devices/fan_click.c +https://github.com/MikroElektronika/HEXIWEAR/blob/master/SW/Click%20Examples%20mikroC/examples/iqRF/fan_click.h + +https://github.com/TekkaTim/esp32_learning/blob/master/lib/EMC2302.py + +*/ + +//FAN EMC2302-1-AIZL + + + + +bool Select_WHS_Fan_Mux_Channel(WHS_fan_num fan_number) +{ + bool status = OK; + + if (Fan_Mux_Channel == fan_number) + { + return status; + } + switch (fan_number) + { + case FAN1: + case FAN2: + status |= D_TCA9546_Select_Channel(I2C_ID_WHS_CARD ,I2CSwitch_ADDRESS ,TCA9546A_chnl_OPEN, TCA9546A_chnl0); + break; + case FAN3: + case FAN4: + status |= D_TCA9546_Select_Channel(I2C_ID_WHS_CARD ,I2CSwitch_ADDRESS ,TCA9546A_chnl_OPEN, TCA9546A_chnl1); + break; + case FAN5: + case FAN6: + status |= D_TCA9546_Select_Channel(I2C_ID_WHS_CARD ,I2CSwitch_ADDRESS ,TCA9546A_chnl_OPEN, TCA9546A_chnl2); + break; + default: + status = ERROR; + } + if (status == OK ) Fan_Mux_Channel = fan_number; + return status; +} + +bool WHS_set_fan_speed(WHS_fan_num fan_number, uint8_t fan_speed) +{ + bool status = OK; + + Select_WHS_Fan_Mux_Channel(fan_number); + status |= D_Fan_Setting(I2C_ID_WHS_CARD ,I2CFanViaSwitch_ADDRESS, !(fan_number & 0x01), fan_speed); + + return status; +} + +bool WHS_Read_fan_tach(WHS_fan_num fan_number, uint16_t *fan_tacho) +{ + bool status = OK; + + Select_WHS_Fan_Mux_Channel(fan_number); + //status |= D_Fan_Setting(I2C_ID_WHS_CARD ,I2CFanViaSwitch_ADDRESS, !(fan_number & 0x01), fan_speed); + status |= D_Fan_Read_Tacho(I2C_ID_WHS_CARD ,I2CFanViaSwitch_ADDRESS, !(fan_number & 0x01), &fan_tacho); + + return status; +} + +#define FAN_BREAK BIT0 +#define FAN_ALERT_12 BIT1 +#define FAN_ALERT_34 BIT2 +#define FAN_ALERT_56 BIT3 + + +bool WHS_Get_fan_ALERT(WHS_fan_num fan_number, bool *fan_alert) +{ + bool status = OK; + uint8_t fan_number_bit = 0; + + switch (fan_number) + { + case 0: + fan_number_bit = FAN_BREAK; + break; + case 1: + case 2: + fan_number_bit = FAN_ALERT_12; + break; + case 3: + case 4: + fan_number_bit = FAN_ALERT_34; + break; + case 5: + case 6: + fan_number_bit = FAN_ALERT_56; + break; + default : + status = ERROR; + return status; + } + status |= WHS_Get_IO_Reg(I2CExp1_ADDRESS, TCA9555_PORT_1, fan_number_bit, &fan_alert); + return status; +} + +bool init_WHS_fan() +{ + bool status = OK; + WHS_fan_num fan_number; + + Select_Main_WHS_Mux_Channel(); + status |= WHS_IO_Init(); + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_PT_RSTn = 1; //P00 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FANS_ON = 1; //P04 + status |= WHS_Write_IO(I2CExp1_ADDRESS,TCA9555_PORT_0); + + for (fan_number = FAN1 ; fan_number < maxFAN; fan_number++) + { + Select_WHS_Fan_Mux_Channel(fan_number); + status |= D_Fan_PWM_Output_Config(I2C_ID_WHS_CARD ,I2CFanViaSwitch_ADDRESS, !(fan_number & 0x01), PUSH_PULL ); + status |= D_Fan_Setting(I2C_ID_WHS_CARD ,I2CFanViaSwitch_ADDRESS, !(fan_number & 0x01), FAN_SPEED_OFF); + } + + + return status; +} + + + +bool Read_WHS_fan_info(WHS_fan_num fan_number) +{ + bool status = OK; + + Select_Main_WHS_Mux_Channel(); + + Select_WHS_Fan_Mux_Channel(fan_number); + status |= D_fan_productID (I2C_ID_WHS_CARD, I2CFanViaSwitch_ADDRESS, &(Fan_Driver_Info[fan_number-1].Product_ID) ); + status |= D_fan_manufactuerID(I2C_ID_WHS_CARD, I2CFanViaSwitch_ADDRESS, &(Fan_Driver_Info[fan_number-1].Manufactuere_ID)); + status |= D_fan_revision (I2C_ID_WHS_CARD, I2CFanViaSwitch_ADDRESS, &(Fan_Driver_Info[fan_number-1].Revision) ); + return status; +} + +bool WHS_Read_fan_ALERT(WHS_fan_num fan_number, uint16_t *fan_alert) +{ + bool status = OK; + uint8_t data=0; + + status = Select_Main_WHS_Mux_Channel(); + status |= Select_WHS_Fan_Mux_Channel(fan_number); + status |= WHS_Read_IO_Reg(I2C_ID_WHS_CARD, TCA9555_PORT_1, &data); + + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_12 = ((data & 0x02)? 1:0); + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_34 = ((data & 0x04)? 1:0); + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_56 = ((data & 0x08)? 1:0); + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FANS_BREAK = ((data & 0x01)? 1:0); + + return status; +} + + +bool Test_WHS_Fan() +{ + bool status = OK; + WHS_fan_num fan_number=0; + + init_WHS_fan(); + uint16_t fan_tacho; + + for (fan_number = FAN1 ; fan_number < maxFAN; fan_number++) + { + status |= Read_WHS_fan_info(fan_number); + + if (Fan_Driver_Info[fan_number-1].Manufactuere_ID != 0x5D) + { + status|= ERROR; + } + if (Fan_Driver_Info[fan_number-1].Product_ID != 0x36) + { + status|= ERROR; + } + if (Fan_Driver_Info[fan_number-1].Revision != 0x80) + { + status|= ERROR; + } + WHS_set_fan_speed(fan_number, 0x20); + delayms(4000); + WHS_Read_fan_tach(fan_number, fan_tacho); + delayms(1000); + WHS_set_fan_speed(fan_number, 0x80); + delayms(4000); + WHS_Read_fan_tach(fan_number, fan_tacho); + delayms(1000); + WHS_set_fan_speed(fan_number, 0xFF); + delayms(4000); + WHS_set_fan_speed(fan_number, FAN_SPEED_OFF); + delayms(4000); + WHS_Read_fan_tach(fan_number, fan_tacho); + delayms(1000); + + } + + + return status; +} + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h index 5956e3d08..fb6d6fedd 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/D_Fan.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h @@ -45,13 +45,47 @@ typedef struct }EMC2302_Register; #define EMC2302_Size sizeof(EMC2302_Register)//43 +#define number_of_EMC2302 3 +typedef enum +{ + noFAN = 0, + FAN1 , + FAN2 , + FAN3 , + FAN4 , + FAN5 , + FAN6 , + maxFAN +}WHS_fan_num; + +typedef enum +{ + FAN1chanel = 0, + FAN2chanel = 0, + FAN3chanel = 1, + FAN4chanel = 1, + FAN5chanel = 2, + FAN6chanel = 2 +}WHS_fan_mux; + +#define PORT0 0 +#define PORT1 1 + + +#define FAN1_PORT PORT0 +#define FAN3_PORT PORT0 +#define FAN5_PORT PORT0 + +#define FAN2_PORT PORT1 +#define FAN4_PORT PORT1 +#define FAN6_PORT PORT1 typedef struct { uint8_t Product_ID; uint8_t Manufactuere_ID; uint8_t Revision; -}FAN_CLICK_INFO; +}FAN_DRIVER_INFO; typedef union { @@ -65,11 +99,16 @@ typedef union uint8_t Buf[EMC2302_Size]; }EMC2302_WRITE; -void Test_fan_Click(); +bool Read_WHS_fan_info(WHS_fan_num fan_number); +bool Test_WHS_Fan(void); +bool init_WHS_fan(void); +bool WHS_set_fan_speed(WHS_fan_num fan_number, uint8_t fan_speed); +bool WHS_Read_fan_tach(WHS_fan_num fan_number, uint16_t *fan_tacho); +bool WHS_Read_fan_ALERT(WHS_fan_num fan_number, uint16_t *fan_alert); -extern FAN_CLICK_INFO Fan_Click_Info; +//extern FAN_INFO Fan_Info; extern EMC2302_READ EMC2302_Read; -uint8_t Head_Fan_PWM_Control(uint8_t Fan_ID, uint8_t PWM); +//uint8_t D_Fan_PWM_Control(WHS_fan_num Fan_ID, uint8_t PWM); #endif /* DRIVERS_I2C_COMMUNICATION_HEAD_CARD_FAN_HEAD_FAN_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.c new file mode 100644 index 000000000..c8d3e745b --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.c @@ -0,0 +1,377 @@ +/* + * MAX11614_Driver.c + * + * Created on: Nov 28, 2019 + * Author: Shai + */ + +#include "include.h" +#include <Drivers/I2C_Communication/I2C.h> +#include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> +#include <Drivers/I2C_Communication/HEAD_Card/I2C_Head_Mux.h> +#include <Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> + +uint8_t MAX11614_Read_Buf[16] = {0}; +MAX11614 U20_MAX11614 ; + + + +uint32_t MAX11615_Read_allADC() +{ + uint32_t status= OK; + uint8_t Write_Buf[1]; + uint8_t command_regAddress = 0; + + Write_Buf[0] = command_regAddress; + status |= Block_Main_Head_Mux_Channel(); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 1); + + delayUs(10);//TODO - check the delay + + status |= I2C_Read(I2C_ID_WHS_CARD, I2CDAC_ADDRESS + 1, MAX11614_Read_Buf, 16); + + delayUs(10);//TODO - check the delay + return status; + +} +uint32_t MAX11615_Init () +{ + uint32_t status= OK; + + U20_MAX11614.setup.bits.REG = 0; + U20_MAX11614.setup.bits.SEL2 = 1; + U20_MAX11614.setup.bits.SEL1 = 0; + U20_MAX11614.setup.bits.SEL0 = 1; + U20_MAX11614.setup.bits.CLK = 0; + U20_MAX11614.setup.bits.BIP_UNIn = 0; + U20_MAX11614.setup.bits.RSTn = 1; + U20_MAX11614.setup.bits.Dont_care = 0; + + U20_MAX11614.configuration.bits.REG = 1; + U20_MAX11614.configuration.bits.SCAN1 = 0; + U20_MAX11614.configuration.bits.SCAN0 = 0; + U20_MAX11614.configuration.bits.CS3 = 0; + U20_MAX11614.configuration.bits.CS2 = 1; + U20_MAX11614.configuration.bits.CS1 = 1; + U20_MAX11614.configuration.bits.CS0 = 1; + U20_MAX11614.configuration.bits.SGL_DIFn = 1; + + U20_MAX11614.MAX11614_I2CADDR = I2CADC_ADDRESS; + U20_MAX11614.MAX11614_I2CBUS = I2C_ID_WHS_CARD; + + + + + status = MAX11615_Setup(U20_MAX11614.MAX11614_I2CBUS, U20_MAX11614.MAX11614_I2CADDR, U20_MAX11614.setup.uchar); + status |= MAX11615_Configuration(U20_MAX11614.MAX11614_I2CBUS, U20_MAX11614.MAX11614_I2CADDR, U20_MAX11614.configuration.uchar); + + return status; + +} + +uint32_t MAX11615_Setup (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value) +{ + uint32_t status= OK; + uint8_t Write_Buf[1]; + + Write_Buf[0] = value; + status |= Block_Main_Head_Mux_Channel(); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + delayUs(10);//TODO - check the delay + delayUs(10);//TODO - check the delay + return status; + +} + +uint32_t MAX11615_Configuration(uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value) +{ + uint32_t status= OK; + uint8_t Write_Buf[1]; + + + Write_Buf[0] = value; + status |= Block_Main_Head_Mux_Channel(); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(i2cbus, i2cadd, Write_Buf, 1); + + delayUs(10);//TODO - check the delay + return status; +} + + + + +//uint32_t MAX11615_Write8 (MAX11615*, uint8_t, uint8_t) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// Write_Buf[0] = command_regAddress; +// Write_Buf[1] = (uint8_t)(regValue >> 8); +// Write_Buf[2] = (uint8_t)( regValue & 0x00FF ); +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CADC_ADDRESS, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// return status; +//} +//uint32_t MAX11615_ADC_Read (MAX11615*, uint8_t, uint16_t*) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +//uint32_t MAX11615_Scan (MAX11615*, uint16_t*) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// delayUs(10);//TODO - check the delay +// return status; +// +//} + +///*----------------------------------------------------------------*/ +// +//int32_t i2c_smbus_write_word_data(int i2cFileDescriptor, uint8_t command_regAddress, uint16_t regValue) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[3]; +// +// Write_Buf[0] = command_regAddress; +// Write_Buf[1] = (uint8_t)(regValue >> 8); +// Write_Buf[2] = (uint8_t)( regValue & 0x00FF ); +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 3); +// +// delayUs(10);//TODO - check the delay +// return status; +//} +// +//int32_t i2c_smbus_read_word_data(int i2cFileDescriptor, uint8_t command_regAddress) +//{ +// uint32_t status= OK; +// uint8_t Write_Buf[1]; +// +// +// Write_Buf[0] = command_regAddress; +// status |= Block_Main_Head_Mux_Channel(); +// status |= Select_Main_WHS_Mux_Channel(); +// status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 1); +// +// delayUs(10);//TODO - check the delay +// +// status |= I2C_Read(I2C_ID_WHS_CARD, I2CDAC_ADDRESS + 1, Read_Buf, 2); +// +// return status; +//} +// +//int32_t read_Max5805_device_ID() +//{ +// int32_t status = OK; +// +// status = MAX5805_DEVICEID(); +// if ((Read_Buf[0] == 0x50) && (Read_Buf[1] == 0x82)) +// { +// ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID OK -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); +// } +// else +// { +// ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID NOT OK !!!! -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); +// } +// return status; +//} +// +// +//int32_t Write_Max5805_AUXn(bool value) +//{ +// int32_t status = OK; +// +// +// Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_AUXn = value; +// status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); +// return status; +//} +// +//int16_t Write_Max5805_LDACn(bool value) +//{ +// int32_t status = OK; +// +// +// Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_LDACn = value; +// status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); +// return status; +//} +// +// +//void Write_Volt_Blower_Control(uint16_t volt) +//{ +// MAX5805_CODE_LOAD( volt); +//} +// +//void Write_MAX5805_REF(MAX5805_REF_enum_t value) +//{ +// MAX5805_REF(value) ; //REF_OUT_AlwaysOn_2V500 +//} +// +//int32_t init_5805() +//{ +// int32_t ret = OK; +// MAX5805_REF_enum_t ref_value = REF_OUT_AlwaysOn_2V500; +// MAX5805_CONFIG_enum_t confug_value = CONFIG_0000_0000_0011_1000_NONE; +// bool LDACn_value = true; +// bool AUXn_value = true; +// +// Write_MAX5805_REF( ref_value); +// MAX5805_CONFIG(confug_value); +// Write_Max5805_LDACn( LDACn_value); +// Write_Max5805_AUXn( AUXn_value); +// return ret; +//} +// +// +// +// +// +// +///* source */ +///** +// * @note STILL IN DEVELOPMENT +// * @file max11615.c +// * @author Simon Burkhardt github.com/mnemocron +// * @copyright MIT license +// * @date 06.2018 +// * @brief C library for the MAX11615EEE+ I2C ADC for STM32 HAL. +// * @details +// * @see github.com/mnemocron +// * @see https://datasheets.maximintegrated.com/en/ds/MAX11612-MAX11617.pdf +// * @see https://github.com/AllAboutEE/MAX11609EEE-Breakout-Board/tree/master/Software/Arduino/AllAboutEE-MAX11609-Library +// */ +//#include "max11615.h" +//#include "main.h" +// +///** +// * @brief writes a single value into a MAX11615 register +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param reg, the destination register's address +// * @param val, the value for the destination register +// */ +//uint8_t MAX11615_Write8(MAX11615 *chip, uint8_t reg, uint8_t val){ +// if(HAL_I2C_Mem_Write(chip->wireIface, chip->devAddress, reg, 1, &val, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * @brief reads a single value from a MAX11615 register +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param reg, the destination register's address +// * @param val, pointer to the location where the value shall be stored +// * @return 0 on success, 1 on transmission error +// */ +//uint8_t MAX11615_Read8(MAX11615 *chip, uint8_t reg, uint8_t *val){ +// if(HAL_I2C_Mem_Read(chip->wireIface, chip->devAddress, reg, 1, val, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * @brief sets up the MAX11615 chip with the provided Vref setting +// * @param *chip, pointer to the MAX11615 typedef struct +// * @param *wireIface a pointer to a HAL I2C_HandleTypeDef +// * @param address of the chip on the I2C bus +// */ +//uint8_t MAX11615_Init(MAX11615* chip, I2C_HandleTypeDef* wireIface, uint16_t address, uint8_t vRef){ +// chip->wireIface = wireIface; +// chip->devAddress = address; +// uint8_t ret = 0; +// // 0 - don't care +// // 1 - reset configuration register to default +// // 2 - unipolar +// // 3 - internal clock +// // 4 - SEL0 (vRef) +// // 5 - SEL1 (vRef) +// // 6 - SEL2 (vRef) +// vRef = (vRef<<4) & 0xf0; +// vRef |= 2; // do not reset the setup register +// ret += MAX11615_Setup(chip, vRef); +// // 0 - Single Ended +// // 1 to 4 - Channel Select: 7 +// // 5 to 6 - Scan Mode: read channels up to selected channel +// uint8_t config_byte = 0x00; +// config_byte |= 1; // single ended mode +// config_byte |= ((1<<5) & (1<<6)); // SCAN bits: convert only the channel selected by CS bits +// ret += MAX11615_Configuration(chip, config_byte); +// return ret; +//} +// +//uint8_t MAX11615_Setup(MAX11615* chip, uint8_t data){ +// data = data | 0x80; // make REG bit 7 = 1 (setup byte) +// if(HAL_I2C_Master_Transmit(chip->wireIface, chip->devAddress, &data, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +//uint8_t MAX11615_Configuration(MAX11615* chip, uint8_t data){ +// data = data & (~0x80); // make REG bit 7 = 0 (configuration byte) +// if(HAL_I2C_Master_Transmit(chip->wireIface, chip->devAddress, &data, 1, 10) != HAL_OK) +// return 1; +// return 0; +//} +// +///** +// * Reads one channel. +// * @author Miguel (5/24/2015) +// * @param channel The channel to convert or read. Alternatively +// * if a channel was set already leave null. +// * @param val Pointer to where the return value should be stored. +// * @return uint8_t +// */ +//uint8_t MAX11615_ADC_Read(MAX11615* chip, uint8_t channel, uint16_t* val){ +// uint8_t result[2] = {0,0}; +// +// uint8_t configurationByte = ( (channel<<1) & 0x0e) | 0x61; +// MAX11615_Configuration(chip, configurationByte); +// // the conversion consists of two bytes per channel +// if(HAL_I2C_Master_Receive(chip->wireIface, chip->devAddress, &result[0], 2, 10) != HAL_OK){ +// return 1; +// } +// uint16_t value = 0; +// // cast to uint16_t is necessary to not loose the values by the left shift +// value = (((uint16_t)result[0] & 0x000f) << 8); // MSB is returned first +// value += ((uint16_t)result[1] & 0x00ff); // read LSB +// *val = value; +// return 0; +//} +// +///** +// * Reads all channels conversion into a buffer/array. +// * +// * @author Miguel (5/24/2015) +// * +// * @param buffer an array where the channel read values are put. +// */ +//uint8_t MAX11615_Scan(MAX11615* chip, uint16_t* buffer){ +// uint8_t ret = 0; +// uint8_t configurationByte = 0xf0; +// ret += MAX11615_Configuration(chip, configurationByte); +// // 2 bytes per channel. There are 8 channels +// for(uint8_t i = 0;i<8;i++){ +// ret += MAX11615_ADC_Read(chip, i, buffer+i); +// } +// return ret; +//} + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.h new file mode 100644 index 000000000..6e6276107 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_MAX11614/MAX11614_Driver.h @@ -0,0 +1,72 @@ + + + +#ifndef MAX11614_H_ +#define MAX11614_H_ + +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +/* Table 6 */ +/* use to config sel(2,1,0) */ +#define MAX11615_REF_VDD 0x00 +#define MAX11615_REF_EXTERNAL 0x02 +#define MAX11615_REF_INTERNAL 0x04 +#define MAX11615_ANANLOG_IN 0x00 +#define MAX11615_REF_OUT 0x02 +#define MAX11615_INT_REF_ON 0x01 + +//#define I2CADC_ADDRESS 0x66 + +typedef union +{ + struct + { + bool REG : 1; //P00 + bool SEL2 : 1; //P01 + bool SEL1 : 1; //P02 + bool SEL0 : 1; //P03 + bool CLK : 1; //P04 + bool BIP_UNIn : 1; //P05 + bool RSTn : 1; //P06 + bool Dont_care : 1; //P07 + }bits; + unsigned char uchar; +}MAX11614_Setup_Byte; + +typedef union +{ + struct + { + bool REG : 1; //P00 + bool SCAN1 : 1; //P01 + bool SCAN0 : 1; //P02 + bool CS3 : 1; //P03 + bool CS2 : 1; //P04 + bool CS1 : 1; //P05 + bool CS0 : 1; //P06 + bool SGL_DIFn : 1; //P07 + }bits; + unsigned char uchar; +}MAX11614_Configuration_Byte; + +typedef struct { + uint8_t MAX11614_I2CBUS; + uint8_t MAX11614_I2CADDR; + MAX11614_Configuration_Byte configuration; + MAX11614_Setup_Byte setup; +} MAX11614; + +extern MAX11614 U20_MAX11614; + +uint32_t MAX11615_Read_allADC (); +uint32_t MAX11615_Init (); +uint32_t MAX11615_Setup (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value); +uint32_t MAX11615_Configuration (uint8_t i2cbus, WHS_chip_address i2cadd,uint8_t value); + + + + +//uint8_t MAX11615_Write8 (MAX11615*, uint8_t, uint8_t); +//uint32_t MAX11615_ADC_Read (uint8_t* read_buf ); +//uint32_t MAX11615_Scan (uint16_t* read_buf); + +#endif diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.c new file mode 100644 index 000000000..fd8d14df1 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.c @@ -0,0 +1,155 @@ +/* + * Head_Heaters.c + * + * Created on: Jul 2, 2019 + * Author: avi + */ + +#include "include.h" +#include <Drivers/I2C_Communication/I2C.h> +#include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> +#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.h> +#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h> +#include <Drivers/I2C_Communication/HEAD_Card/I2C_Head_Mux.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> + +bool Read_Max5805_device_ID(); + +uint8_t Read_Buf[2] = {0}; + +int32_t i2c_smbus_write_word_data(int i2cFileDescriptor, uint8_t command_regAddress, uint16_t regValue) +{ + int32_t status= OK; + uint8_t Write_Buf[3]; + + Write_Buf[0] = command_regAddress; + Write_Buf[1] = (uint8_t)(regValue >> 8); + Write_Buf[2] = (uint8_t)( regValue & 0x00FF ); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 3); + + delayUs(10);//TODO - check the delay + return status; +} + +int32_t i2c_smbus_read_word_data(int i2cFileDescriptor, uint8_t command_regAddress) +{ + uint32_t status= OK; + uint8_t Write_Buf[1]; + + + Write_Buf[0] = command_regAddress; + status |= Block_Main_Head_Mux_Channel(); + status |= Select_Main_WHS_Mux_Channel(); + status |= I2C_Write(I2C_ID_WHS_CARD, I2CDAC_ADDRESS, Write_Buf, 1); + + delayUs(10);//TODO - check the delay + + status |= I2C_Read(I2C_ID_WHS_CARD, I2CDAC_ADDRESS + 1, Read_Buf, 2); + + return status; +} + +bool Read_Max5805_device_ID() +{ + bool status = OK; + + status = MAX5805_DEVICEID(); + if ((Read_Buf[0] == 0x50) && (Read_Buf[1] == 0x82)) + { + ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID OK -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); + status |= OK; + } + else + { + ReportWithPackageFilter(GeneralFilter,"------------ max5805 ID NOT OK !!!! -----------------", __FILE__,__LINE__,(Read_Buf[0]), RpMessage,(Read_Buf[1]), 0); + status |= ERROR; + } + return status; +} + + +int32_t Write_Max5805_AUXn(bool value) +{ + int32_t status = OK; + + + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_AUXn != value) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_AUXn = value; + status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); + } + return status; +} + +int16_t Write_Max5805_LDACn(bool value) +{ + int32_t status = OK; + + + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_LDACn != value) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_LDACn = value; + status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); + } + return status; +} + + +void Write_Volt_Blower_Control(uint16_t volt) +{ + MAX5805_CODE_LOAD( volt); +} + +bool Write_MAX5805_REF() +{ + bool status = OK; + status = MAX5805_REF(REF_OUT_AlwaysOn_2V500) ; //REF_OUT_AlwaysOn_2V500 + return status; +} + +bool WHS_init_5805() +{ + bool status = OK; +// MAX5805_REF_enum_t ref_value = REF_OUT_AlwaysOn_2V500; +// MAX5805_CONFIG_enum_t config_value = CONFIG_0000_0000_0011_1000_NONE; + bool LDACn_value = true; + bool AUXn_value = true; + + /* ---- select the WHS card mux channel ----*/ + Select_Main_WHS_Mux_Channel(); + + + /* ---- config the WHS card 9555 configuration ----*/ + status |= WHS_IO_Init(); + status |= Write_Max5805_LDACn( LDACn_value); + status |= Write_Max5805_AUXn( AUXn_value); + + +// status |= Read_Max5805_device_ID(); + status |= Write_MAX5805_REF( ); +// status |= MAX5805_CONFIG(config_value); + return status; +} + + +bool Test_WHS_blower() +{ + bool status = OK; + + WHS_init_5805(); + Write_Volt_Blower_Control(0x0fff); //12 bit 5.0v + delayms(4000); + Write_Volt_Blower_Control(0x0c00); //12 bit 3.77v + delayms(4000); + Write_Volt_Blower_Control(0x0800); //12 bit 2.5v + delayms(4000); + Write_Volt_Blower_Control(0x0400);//12 bit 1.25v + delayms(4000); + Write_Volt_Blower_Control(0x0000); //12 bit 0.0v + delayms(4000); + + return status; +} diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.h new file mode 100644 index 000000000..c96d68af5 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.h @@ -0,0 +1,33 @@ +/* + * I2C_Head_Mux.h + * + * Created on: Jul 2, 2019 + * Author: avi + */ + + +#ifndef WHS_CARS_MAX5805_H_ +#define WHS_CARS_MAX5805_H_ + +#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h> + +int32_t Write_Max5805_AUXn(bool value); +int16_t Write_Max5805_LDACn(bool value); + +void Write_Volt_Blower_Control(uint16_t volt); +bool Write_MAX5805_REF(); +bool init_5805(); +bool Test_WHS_blower(); + +/* from Blower.h + * +uint32_t Turn_the_Blower_On(); +uint32_t Control_Voltage_To_Blower(uint32_t mV); +uint32_t Turn_the_Blower_Off(); +uint32_t getBlowerState(void); +uint32_t Gradual_Increase_Blower(uint32_t Initial_mV,uint32_t Target_mV); +uint32_t Cancel_Gradual_Increase_Blower(uint32_t Initial_mV); + * + * */ + +#endif /* WHS_CARS_MAX5805_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.c new file mode 100644 index 000000000..17dbed8db --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.c @@ -0,0 +1,741 @@ +/* + * Max_5805_Driver.c + * + * Created on: 11 11, 2019 + * Author: Shai + */ + + + + +// /******************************************************************************* +// * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved. +// * * This software is protected by copyright laws of the United States and +// * of foreign countries. This material may also be protected by patent laws +// * and technology transfer regulations of the United States and of foreign +// * countries. This software is furnished under a license agreement and/or a +// * nondisclosure agreement and may only be used or reproduced in accordance +// * with the terms of those agreements. Dissemination of this information to +// * any party or parties not specified in the license agreement and/or +// * nondisclosure agreement is expressly prohibited. +// * +// * The above copyright notice and this permission notice shall be included +// * in all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +// * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// * OTHER DEALINGS IN THE SOFTWARE. +// * +// * Except as contained in this notice, the name of Maxim Integrated +// * Products, Inc. shall not be used except as stated in the Maxim Integrated +// * Products, Inc. Branding Policy. +// * +// * The mere transfer of this software does not imply any licenses +// * of trade secrets, proprietary technology, copyrights, patents, +// * trademarks, maskwork rights, or any other form of intellectual +// * property whatsoever. Maxim Integrated Products, Inc. retains all +// * ownership rights. +// ******************************************************************************* +// */ +// Device Driver file +// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. +// generated by XMLSystemOfDevicesToSETRegisterDescriptors.py +// System Name = ExampleSystem +// System Description = Device driver example + +//#include "MAX5805.h" +#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h> +// Device Name = MAX5805 +// Device Description = Ultra-Small, 12-Bit, 1-Channel, Buffered Output Voltage DAC with Internal Reference and I2C Interface +// Device Manufacturer = Maxim Integrated +// Device PartNumber = MAX5805AAUB+ +// Device RegValue_Width = DataWidth16bit_HL +// +// DAC NumChannels = 1 +// DAC ResolutionBits = 12 +// +// I2C SCLMaxkHz = 400 +// I2C SCLMinkHz = 0 +// I2C AddressSelectionPins = ADDR +// +// I2CDeviceAddress Value = 0011011 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011011 when ADDR pin = VDD +// +// I2CDeviceAddress Value = 0011010 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011010 when ADDR pin = N.C +// +// I2CDeviceAddress Value = 0011000 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011000 when ADDR pin = GND +// +// I2CDeviceAddress Value = 0011001 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011001 (master write only) broadcast +// +// InputPin Name = AUX# +// InputPin Description = Active-Low Auxilliary Asynchronous Input. +// User Configurable, see Table 7. +// Software-selectable CLR#, GATE#, or no operation. +// If not using the AUX functions, connect this input to VDDIO. +// If AUX is unconnected, the CODE, LOAD, and CODELOAD commands fail (NACK), +// indicating a busy condition, because AUX low gates the device output. +// InputPin Function = Trigger +// +// InputPin Name = LDAC# +// InputPin Description = Dedicated Active-Low Asynchronous Load DAC. +// InputPin Function = Trigger +// +// InputPin Name = ADDR +// InputPin Description = I2C Interface Address Selection. +// See Table 1 I2C Slave Address LSBs. +// InputPin Function = Address +// +// InputPin Name = REF +// InputPin Description = Reference Voltage Input/Output. +// Software selectable to be external reference or internal 2.048V, 2.500V, or 4.096V reference. +// Default is external reference mode. +// InputPin Function = Reference +// +// OutputPin Name = OUT +// OutputPin Description = Buffered DAC Output +// OutputPin Function = Analog +// +// SupplyPin Name = VDD +// SupplyPin Description = Supply Voltage Input. Bypass VDD with a 0.1uF capacitor to GND. +// SupplyPin VinMax = 5.5 +// SupplyPin VinMin = 2.7 (unless configured DAC VRefInternal = 4.096V, then VinMin = 4.5V) +// SupplyPin Function = Analog +// +// SupplyPin Name = VDDIO +// SupplyPin Description = Digital Interface Power-Supply Input +// SupplyPin VinMax = 5.5 +// SupplyPin VinMin = 1.8 +// SupplyPin Function = Digital +// + +//---------------------------------------- +// Possible I2C device addresses for MAX5805 +// I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// List is terminated by 0 element. +int g_MAX5805_i2cDeviceAddress7bits_list[] = { + 0x1b, //!< 8-bit i2c address 0x36: 0011011 when ADDR pin = VDD + 0x1a, //!< 8-bit i2c address 0x34: 0011010 when ADDR pin = N.C + 0x18, //!< 8-bit i2c address 0x30: 0011000 when ADDR pin = GND + 0x19, //!< 8-bit i2c address 0x32: 0011001 (master write only) broadcast + 0 //<! end of list +}; + +//---------------------------------------- +// Global Device Object +MAX5805_device_t g_MAX5805_device; + +//---------------------------------------- +// Initialize device +// Search the i2c address list for possible devices +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_Init(void) +{ + + //---------------------------------------- + // Search the i2c address list for possible devices + uint8_t i2cAddressIndex = 0; + // + //---------------------------------------- + // default i2c device address + g_MAX5805_device.i2cDeviceAddress7bits = g_MAX5805_i2cDeviceAddress7bits_list[0]; // shai : we use 0x30 [2] + // + //---------------------------------------- + // open I2C adapter file descriptor +#if 1 + // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. + //g_MAX5805_device.i2cFileDescriptor = i2c_open_adapter(1); +#else + // suggested equivalent code. NOT TESTED. + // locate i2c adapter by scanning /dev/i2c-0, /dev/i2c-1, /dev/i2c-2, ... + for (adapter_nr = 0; adapter_nr <= adapter_nr_MAX; adapter_nr++) + { + snprintf(filename, sizeof(filename)-1, "/dev/i2c-%d", adapter_nr); + g_MAX5805_device.i2cFileDescriptor = open(filename, O_RDWR); + if (g_MAX5805_device.i2cFileDescriptor < 0) { + /* ERROR HANDLING; you can check errno to see what went wrong */ + //~ exit(1); + //~ return errno; + continue; + } + break; // stop searching adapter_nr + } + if (g_MAX5805_device.i2cFileDescriptor < 0) { + /* ERROR HANDLING; you can check errno to see what went wrong */ + //~ exit(1); + return errno; + } +#endif + //---------------------------------------- + // Search the i2c address list for possible devices + while (g_MAX5805_i2cDeviceAddress7bits_list[i2cAddressIndex] != 0) + { + g_MAX5805_device.i2cDeviceAddress7bits = g_MAX5805_i2cDeviceAddress7bits_list[i2cAddressIndex]; + // + //~ Serial.print(F("i2cDeviceAddress7bits_list[")); + //~ Serial.print(i2cAddressIndex); + //~ Serial.print(F("]=0x")); + //~ Serial.println( (g_MAX5805_device.i2cDeviceAddress7bits & 0xFF), HEX); +//#if 1 +// // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. +// if (i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(g_MAX5805_device.i2cFileDescriptor, g_MAX5805_device.i2cDeviceAddress7bits) < 0) +//#else +// // suggested equivalent code. NOT TESTED. +// if (ioctl(g_MAX5805_device.i2cFileDescriptor, I2C_SLAVE, global_max7311_device_data.i2cDeviceAddress7bits) < 0) +//#endif + { + /* ERROR HANDLING; you can check errno to see what went wrong */ + // i2cdetect: if (errno == EBUSY) { printf("UU "); continue; } + //~ exit(1); + //~ return errno; + //~ Serial.println(F(" -NACK")); + if (i2cAddressIndex > 100) { + break; // too many tries; fail + } + i2cAddressIndex++; // try next device address + continue; + } + // + // we set the i2c device address but haven't attempted to commmunicate yet + // +//#if 1 +// // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. +// //---------------------------------------- +// // I2C file descriptor for I2C device access +// // on linux systems, fd is obtained by open("/dev/i2c-1", O_RDWR); +// // not used on smaller bare-metal embedded systems +// // if i2cFileDescriptor < 0 then the device is not open +// // In this bare metal system, file descriptor is i2cDeviceAddress7bits +// g_MAX5805_device.i2cFileDescriptor = g_MAX5805_device.i2cDeviceAddress7bits; +//#endif + // + // Device ACK + // Issue DeviceID command and test whether correct device type + // +// TODO1: Device ID Validation + int16_t DeviceID_Actual = MAX5805_DEVICEID(); + //~ Serial.print(F(" DEVICEID=0x")); + //~ Serial.print(DeviceID_Actual, HEX); + // Decode MAX5805 Device ID + int PARTID = ((DeviceID_Actual >> 0) & 0x00FF); + //~ Serial.print(F(" PARTID=0x")); + //~ Serial.print(PARTID, HEX); + switch (PARTID) + { + case 0x8A: // PARTID is 0x8A for MAX5803 + case 0x92: // PARTID is 0x92 for MAX5804 + case 0x82: // PARTID is 0x82 for MAX5805 +// TODO1: Device ID Validation + // Success + // + // perform INIT functions on newly discovered device + // + //---------------------------------------- + // Perform Software Reset + if (!MAX5805_SW_RESET()) { + g_MAX5805_device.i2cFileDescriptor = -1; // device is not open + return 0; // failure + } + //---------------------------------------- + // Turn on the reference output pin + MAX5805_REF(REF_OUT_AlwaysOn_2V500); + // + //~ Serial.println(F(" success")); + //~ return; + return 1; // success + } + // device ACK but did not give a valid DeviceID value + //~ Serial.println(F(" bad DeviceId")); + i2cAddressIndex++; // try next device address + } // Continue searching the i2c address list + // + // FAIL - device not attached + g_MAX5805_device.i2cDeviceAddress7bits = 0; +#if 1 + // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. + //i2c_close(g_MAX5805_device.i2cFileDescriptor); +#else + // suggested equivalent code. NOT TESTED. + close(g_MAX5805_device.i2cFileDescriptor); +#endif + g_MAX5805_device.i2cFileDescriptor = -1; + //~ Serial.println(F("failure")); + //~ return; + return 0; // failure +} + +//---------------------------------------- +// Return the DAC register value corresponding to physical voltage. +// Does not perform any offset or gain correction. +// +// @pre g_MAX5805_device.VRef = Voltage of REF input, in Volts +// @param[in] voltage = physical voltage in Volts +// @returns raw 12-bit MAX5805 code (right justified). +uint16_t MAX5805_DACCodeOfVoltage(double voltageV) +{ + + //---------------------------------------- + // Linear map min and max endpoints + const double MaxScaleVoltage = g_MAX5805_device.VRef; // voltage of maximum code 0x0fff + const double MinScaleVoltage = 0.0; // voltage of minimum code 0x000 + const uint16_t FULL_SCALE_CODE_12BIT = 0x0fff; + const uint16_t MaxCode = FULL_SCALE_CODE_12BIT; + const uint16_t MinCode = 0x000; + double codeFraction = (voltageV - MinScaleVoltage) / (MaxScaleVoltage - MinScaleVoltage); + double dacRegValueIdeal = ((codeFraction * (double)(MaxCode - MinCode + 1)) + MinCode + 0.5); + uint16_t dacRegValue = (uint16_t)dacRegValueIdeal; + if (dacRegValueIdeal > MaxCode) + { + dacRegValue = MaxCode; + } else if (dacRegValueIdeal < MinCode) + { + dacRegValue = MinCode; + } + return dacRegValue; +} + +//---------------------------------------- +// Return the physical voltage corresponding to DAC register. +// Does not perform any offset or gain correction. +// +// @pre g_MAX5805_device.VRef = Voltage of REF input, in Volts +// @param[in] value_u12: raw 12-bit MAX5805 code (right justified). +// @Returns physical voltage corresponding to MAX5805 code. +double MAX5805_VoltageOfCode(uint16_t value_u12) +{ + + //---------------------------------------- + // Linear map min and max endpoints + double MaxScaleVoltage = g_MAX5805_device.VRef; // voltage of maximum code 0x0fff + double MinScaleVoltage = 0.0; // voltage of minimum code 0x000 + const uint16_t FULL_SCALE_CODE_12BIT = 0x0fff; + const uint16_t MaxCode = FULL_SCALE_CODE_12BIT; + const uint16_t MinCode = 0x000; + double codeFraction = ((double)value_u12 - MinCode) / (MaxCode - MinCode + 1); + return MinScaleVoltage + ((MaxScaleVoltage - MinScaleVoltage) * codeFraction); +} + +//---------------------------------------- +// Read device status from register 0001_0000 +// @return CLR_LOAD_GATE_1_REF[3:0]_PD[1:0]_AB[2:0]_DF[2:0] +// int CLR = ((STATUS >> 15) & 0x0001); +// int LOAD = ((STATUS >> 14) & 0x0001); +// int GATE = ((STATUS >> 13) & 0x0001); +// int REF = ((STATUS >> 8) & 0x000F); +// int PD = ((STATUS >> 6) & 0x0003); +// int AB = ((STATUS >> 3) & 0x0007); +// int DF = ((STATUS >> 0) & 0x0007); +int16_t MAX5805_STATUS(void) +{ + + //---------------------------------------- + // ReadWord_10 --> CLR_LOAD_GATE_1_REF[3:0]_PD[1:0]_AB[2:0]_DF[2:0] + uint8_t command_regAddress = 0x10; + return i2c_smbus_read_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress); +} + +//---------------------------------------- +// Read device ID from register 0000_0000 +// @return 0101_0_REVID[2:0]_PARTID[7:0] +// int REVID = ((DEVICEID >> 8) & 0x0007); +// int PARTID = ((DEVICEID >> 0) & 0x00FF); +// PARTID is 0x8A for MAX5803 +// PARTID is 0x92 for MAX5804 +// PARTID is 0x82 for MAX5805 + +int16_t MAX5805_DEVICEID(void) +{ + + //---------------------------------------- + // ReadWord_00 --> 0101_0_REVID[2:0]_PARTID[7:0] + uint8_t command_regAddress = 0x00; + return i2c_smbus_read_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress); +} + +//---------------------------------------- +// Writes data to the CODE register +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_CODE(uint16_t dacCodeLsbs) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_1000_0000_dddd_dddd_dddd_0000_CODE; + uint16_t regValue = (dacCodeLsbs << 4); // left-align dddd_dddd_dddd_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.CODE = dacCodeLsbs; + g_MAX5805_device.Shadow_1000_CODE = regValue; + } +} + +//---------------------------------------- +// Simultaneously writes data to the CODE register while updating DAC register +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_CODE_LOAD(uint16_t dacCodeLsbs) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_1010_0000_dddd_dddd_dddd_0000_CODE_LOAD; + uint16_t regValue = (dacCodeLsbs << 4); // left-align dddd_dddd_dddd_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.CODE = dacCodeLsbs; + g_MAX5805_device.Shadow_1000_CODE = regValue; + } +} + +//---------------------------------------- +// Updates the function of the AUX input +void MAX5805_CONFIG(MAX5805_CONFIG_enum_t value) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0101_0000_0000_0000_00aa_a000_CONFIG; + uint16_t regValue = ((value & 0xFF) << 0); // align field 0000_0000_00aa_a000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register CONFIG 0000_0000_00aa_a000 + g_MAX5805_device.Shadow_0101_CONFIG = regValue; + } +} + +//---------------------------------------- +// Sets the default value for the DAC +void MAX5805_DEFAULT(MAX5805_DEFAULT_enum_t value) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0110_0000_0000_0000_ddd0_0000_DEFAULT; + uint16_t regValue = ((value & 0xFF) << 0); // align field 0000_0000_ddd0_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register DEFAULT 0000_0000_ddd0_0000 + g_MAX5805_device.Shadow_0110_DEFAULT = regValue; + } +} + +//---------------------------------------- +// Transfers data from the CODE register to the DAC register +void MAX5805_LOAD(void) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_1001_0000_0000_0000_0000_0000_LOAD; + uint16_t regValue = 0; // 0000_0000_0000_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success +} + +//---------------------------------------- +// Sets the Power mode +void MAX5805_POWER(MAX5805_POWER_enum_t value) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0100_0000_0000_0000_pp00_0000_POWER; + uint16_t regValue = ((value & 0xFF) << 0); // align field 0000_0000_pp00_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register POWER 0000_0000_pp00_0000 + g_MAX5805_device.Shadow_0100_POWER = regValue; + } +} + +//---------------------------------------- +// Sets the reference operating mode. +int32_t MAX5805_REF(MAX5805_REF_enum_t value) +{ + + //---------------------------------------- + // select command_regAddress based on condition + uint8_t command_regAddress = CMD_0010_1110_0000_0000_0000_0000_REF_OUT_AlwaysOn_2V048; // diagnostic + uint16_t regValue = 0; // 0000_0000_0000_0000 + // select command_regAddress from list of 14 values, based on condition + if (value == REF_OUT_4V096) { + command_regAddress = CMD_0010_1011_0000_0000_0000_0000_REF_OUT_4V096; + g_MAX5805_device.VRef = 4.096; + } + if (value == REF_OUT_2V500) { + command_regAddress = CMD_0010_1001_0000_0000_0000_0000_REF_OUT_2V500; + g_MAX5805_device.VRef = 2.500; + } + if (value == REF_AlwaysOn_EXT) { + command_regAddress = CMD_0010_0100_0000_0000_0000_0000_REF_AlwaysOn_EXT; + } + if (value == REF_OUT_2V048) { + command_regAddress = CMD_0010_1010_0000_0000_0000_0000_REF_OUT_2V048; + g_MAX5805_device.VRef = 2.048; + } + if (value == REF_AlwaysOn_2V500) { + command_regAddress = CMD_0010_0101_0000_0000_0000_0000_REF_AlwaysOn_2V500; + g_MAX5805_device.VRef = 2.500; + } + if (value == REF_OUT_AlwaysOn_2V048) { + command_regAddress = CMD_0010_1110_0000_0000_0000_0000_REF_OUT_AlwaysOn_2V048; + g_MAX5805_device.VRef = 2.048; + } + if (value == REF_AlwaysOn_4V096) { + command_regAddress = CMD_0010_0111_0000_0000_0000_0000_REF_AlwaysOn_4V096; + g_MAX5805_device.VRef = 4.096; + } + if (value == REF_AlwaysOn_2V048) { + command_regAddress = CMD_0010_0110_0000_0000_0000_0000_REF_AlwaysOn_2V048; + g_MAX5805_device.VRef = 2.048; + } + if (value == REF_OUT_AlwaysOn_2V500) { + command_regAddress = CMD_0010_1101_0000_0000_0000_0000_REF_OUT_AlwaysOn_2V500; + g_MAX5805_device.VRef = 2.500; + } + if (value == REF_OUT_AlwaysOn_4V096) { + command_regAddress = CMD_0010_1111_0000_0000_0000_0000_REF_OUT_AlwaysOn_4V096; + g_MAX5805_device.VRef = 4.096; + } + if (value == REF_2V048) { + command_regAddress = CMD_0010_0010_0000_0000_0000_0000_REF_2V048; + g_MAX5805_device.VRef = 2.048; + } + if (value == REF_4V096) { + command_regAddress = CMD_0010_0011_0000_0000_0000_0000_REF_4V096; + g_MAX5805_device.VRef = 4.096; + } + if (value == REF_EXT) { + command_regAddress = CMD_0010_0000_0000_0000_0000_0000_REF_EXT; + } + if (value == REF_2V500) { + command_regAddress = CMD_0010_0001_0000_0000_0000_0000_REF_2V500; + g_MAX5805_device.VRef = 2.500; + } + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register REF CMD_0010_rrrr + g_MAX5805_device.Shadow_0010_REF = regValue; + } + return g_MAX5805_device.i2cResult; +} + +//---------------------------------------- +// Updates the RETURN register contents for the DAC +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_RETURN(uint16_t dacCodeLsbs) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0111_0000_dddd_dddd_dddd_0000_RETURN; + uint16_t regValue = (dacCodeLsbs << 4); // left-align dddd_dddd_dddd_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.RETURN = dacCodeLsbs; + g_MAX5805_device.Shadow_0111_RETURN = regValue; + } +} + +//---------------------------------------- +// All CODE and DAC contents will be cleared to their DEFAULT selected values. +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_SW_CLEAR(void) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0011_0100_0000_0000_0000_0000_SW_CLEAR; + uint16_t regValue = 0; // 0000_0000_0000_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + + //---------------------------------------- + // after successful SW_RESET, update shadow registers + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register REF CMD_0010_rrrr + //g_MAX5805_device.Shadow_0010_REF = REF_EXT; // 8'b00000000 + // + // shadow of write-only register POWER 0000_0000_pp00_0000 + //g_MAX5805_device.Shadow_0100_POWER = POWER_0000_0000_0000_0000_Normal; + // + // shadow of write-only register CONFIG 0000_0000_00aa_a000 + // Note: CONFIG has a non-zero POR default value + // AUXB mode = 110 CLEAR + //g_MAX5805_device.Shadow_0101_CONFIG = CONFIG_0000_0000_0011_0000_CLEAR; + // + // shadow of write-only register DEFAULT 0000_0000_ddd0_0000 + //g_MAX5805_device.Shadow_0110_DEFAULT = DEFAULT_0000_0000_0000_0000_POR; + // + // shadow of write-only register RETURN dddd_dddd_dddd_0000 + //g_MAX5805_device.Shadow_0111_RETURN = 0x0000; + // + // shadow of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.Shadow_1000_CODE = 0x0000; + // + // shadow of CODE field of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.CODE = 0x0000; + // + // shadow of RETURN field of write-only register RETURN dddd_dddd_dddd_0000 + //g_MAX5805_device.RETURN = 0x0000; + } + + //---------------------------------------- + // Function return 1 on success; 0 on failure. + // i2cResult is -1 on failure, 0 on success + return (g_MAX5805_device.i2cResult == 0); +} + +//---------------------------------------- +// End any active gate operation, returning to normal operation (default). +void MAX5805_SW_END(void) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0011_0000_0000_0000_0000_0000_SW_END; + uint16_t regValue = 0; // 0000_0000_0000_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success +} + +//---------------------------------------- +// DAC contents will be gated to their DEFAULT selected values +// until the gate condition is removed. +void MAX5805_SW_GATE(void) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0011_0001_0000_0000_0000_0000_SW_GATE; + uint16_t regValue = 0; // 0000_0000_0000_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success +} + +//---------------------------------------- +// Software Reset +// All CODE, DAC, RETURN, and configuration registers reset to their +// power-up defaults (including REF, POWER, and CONFIG settings), +// simulating a power cycle reset. +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_SW_RESET(void) +{ + + //---------------------------------------- + // Define command code + uint8_t command_regAddress = CMD_0011_0101_0000_0000_0000_0000_SW_RESET; + uint16_t regValue = 0; // 0000_0000_0000_0000 + + //---------------------------------------- + // I2C write 8-bit regAddress and 16-bit regValue + g_MAX5805_device.i2cResult = i2c_smbus_write_word_data(g_MAX5805_device.i2cFileDescriptor, command_regAddress, regValue); + // i2cResult is -1 on failure, 0 on success + + //---------------------------------------- + // after successful SW_RESET, update shadow registers + // i2cResult is -1 on failure, 0 on success + if (g_MAX5805_device.i2cResult != -1) + { + // shadow of write-only register REF CMD_0010_rrrr + g_MAX5805_device.Shadow_0010_REF = REF_EXT; // 8'b00000000 + // + // shadow of write-only register POWER 0000_0000_pp00_0000 + g_MAX5805_device.Shadow_0100_POWER = POWER_0000_0000_0000_0000_Normal; + // + // shadow of write-only register CONFIG 0000_0000_00aa_a000 + // Note: CONFIG has a non-zero POR default value + // AUXB mode = 110 CLEAR + g_MAX5805_device.Shadow_0101_CONFIG = CONFIG_0000_0000_0011_0000_CLEAR; + // + // shadow of write-only register DEFAULT 0000_0000_ddd0_0000 + g_MAX5805_device.Shadow_0110_DEFAULT = DEFAULT_0000_0000_0000_0000_POR; + // + // shadow of write-only register RETURN dddd_dddd_dddd_0000 + g_MAX5805_device.Shadow_0111_RETURN = 0x0000; + // + // shadow of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.Shadow_1000_CODE = 0x0000; + // + // shadow of CODE field of write-only register CODE dddd_dddd_dddd_0000 + g_MAX5805_device.CODE = 0x0000; + // + // shadow of RETURN field of write-only register RETURN dddd_dddd_dddd_0000 + g_MAX5805_device.RETURN = 0x0000; + } + + //---------------------------------------- + // Function return 1 on success; 0 on failure. + // i2cResult is -1 on failure, 0 on success + return (g_MAX5805_device.i2cResult == 0); +} + + +// End of file + + + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h new file mode 100644 index 000000000..ed55d5683 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805_Driver.h @@ -0,0 +1,408 @@ +/* + * I2C_Head_Mux.h + * + * Created on: Jul 2, 2019 + * Author: avi + */ + + +// /******************************************************************************* +// * Copyright (C) 2016 Maxim Integrated Products, Inc., All rights Reserved. +// * * This software is protected by copyright laws of the United States and +// * of foreign countries. This material may also be protected by patent laws +// * and technology transfer regulations of the United States and of foreign +// * countries. This software is furnished under a license agreement and/or a +// * nondisclosure agreement and may only be used or reproduced in accordance +// * with the terms of those agreements. Dissemination of this information to +// * any party or parties not specified in the license agreement and/or +// * nondisclosure agreement is expressly prohibited. +// * +// * The above copyright notice and this permission notice shall be included +// * in all copies or substantial portions of the Software. +// * +// * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES +// * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, +// * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +// * OTHER DEALINGS IN THE SOFTWARE. +// * +// * Except as contained in this notice, the name of Maxim Integrated +// * Products, Inc. shall not be used except as stated in the Maxim Integrated +// * Products, Inc. Branding Policy. +// * +// * The mere transfer of this software does not imply any licenses +// * of trade secrets, proprietary technology, copyrights, patents, +// * trademarks, maskwork rights, or any other form of intellectual +// * property whatsoever. Maxim Integrated Products, Inc. retains all +// * ownership rights. +// ******************************************************************************* +// */ +// Header file +// DO NOT EDIT; except areas designated "CUSTOMIZE". Automatically generated file. +// generated by XMLSystemOfDevicesToSETRegisterDescriptors.py +// System Name = ExampleSystem +// System Description = Device driver example + +// Prevent multiple declaration +#ifndef __MAX5805_H__ +#define __MAX5805_H__ + + +#ifdef __cplusplus +extern "C" { +#endif + + +// standard-width integer types uint8_t, int8_t, uint16_t, int16_t, uint32_t, int32_t +// could be <inttypes.h> or <stdint.h> depending on compiler +#include <inttypes.h> + +// Device Name = MAX5805 +// Device Description = Ultra-Small, 12-Bit, 1-Channel, Buffered Output Voltage DAC with Internal Reference and I2C Interface +// Device Manufacturer = Maxim Integrated +// Device PartNumber = MAX5805AAUB+ +// Device RegValue_Width = DataWidth16bit_HL +// +// DAC NumChannels = 1 +// DAC ResolutionBits = 12 +// +// I2C SCLMaxkHz = 400 +// I2C SCLMinkHz = 0 +// I2C AddressSelectionPins = ADDR +// +// I2CDeviceAddress Value = 0011011 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011011 when ADDR pin = VDD +// +// I2CDeviceAddress Value = 0011010 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011010 when ADDR pin = N.C +// +// I2CDeviceAddress Value = 0011000 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011000 when ADDR pin = GND +// +// I2CDeviceAddress Value = 0011001 +// I2CDeviceAddress Align = Left7bit +// I2CDeviceAddress Description = 0011001 (master write only) broadcast +// + +//---------------------------------------- +// Possible I2C device addresses for MAX5805 +// I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// List is terminated by 0 element. +extern int g_MAX5805_i2cDeviceAddress7bits_list[]; + +//---------------------------------------- +// Command Codes (first byte) +typedef enum MAX5805_CMD_enum_t { + CMD_0000_xxxx_xxxx_xxxx_xxxx_xxxx_NOP = 0x00, // 8'b00000000 + CMD_0001_xxxx_xxxx_xxxx_xxxx_xxxx_RESERVED = 0x10, // 8'b00010000 + CMD_0010_0000_0000_0000_0000_0000_REF_EXT = 0x20, // 8'b00100000 + CMD_0010_0001_0000_0000_0000_0000_REF_2V500 = 0x21, // 8'b00100001 + CMD_0010_0010_0000_0000_0000_0000_REF_2V048 = 0x22, // 8'b00100010 + CMD_0010_0011_0000_0000_0000_0000_REF_4V096 = 0x23, // 8'b00100011 + CMD_0010_0100_0000_0000_0000_0000_REF_AlwaysOn_EXT = 0x24, // 8'b00100100 + CMD_0010_0101_0000_0000_0000_0000_REF_AlwaysOn_2V500 = 0x25, // 8'b00100101 + CMD_0010_0110_0000_0000_0000_0000_REF_AlwaysOn_2V048 = 0x26, // 8'b00100110 + CMD_0010_0111_0000_0000_0000_0000_REF_AlwaysOn_4V096 = 0x27, // 8'b00100111 + CMD_0010_1001_0000_0000_0000_0000_REF_OUT_2V500 = 0x29, // 8'b00101001 + CMD_0010_1010_0000_0000_0000_0000_REF_OUT_2V048 = 0x2a, // 8'b00101010 + CMD_0010_1011_0000_0000_0000_0000_REF_OUT_4V096 = 0x2b, // 8'b00101011 + CMD_0010_1101_0000_0000_0000_0000_REF_OUT_AlwaysOn_2V500 = 0x2d, // 8'b00101101 + CMD_0010_1110_0000_0000_0000_0000_REF_OUT_AlwaysOn_2V048 = 0x2e, // 8'b00101110 + CMD_0010_1111_0000_0000_0000_0000_REF_OUT_AlwaysOn_4V096 = 0x2f, // 8'b00101111 + CMD_0011_0000_0000_0000_0000_0000_SW_END = 0x30, // 8'b00110000 + CMD_0011_0001_0000_0000_0000_0000_SW_GATE = 0x31, // 8'b00110001 + CMD_0011_0100_0000_0000_0000_0000_SW_CLEAR = 0x34, // 8'b00110100 + CMD_0011_0101_0000_0000_0000_0000_SW_RESET = 0x35, // 8'b00110101 + CMD_0100_0000_0000_0000_pp00_0000_POWER = 0x40, // 8'b01000000 + CMD_0101_0000_0000_0000_00aa_a000_CONFIG = 0x50, // 8'b01010000 + CMD_0110_0000_0000_0000_ddd0_0000_DEFAULT = 0x60, // 8'b01100000 + CMD_0111_0000_dddd_dddd_dddd_0000_RETURN = 0x70, // 8'b01110000 + CMD_1000_0000_dddd_dddd_dddd_0000_CODE = 0x80, // 8'b10000000 + CMD_1001_0000_0000_0000_0000_0000_LOAD = 0x90, // 8'b10010000 + CMD_1010_0000_dddd_dddd_dddd_0000_CODE_LOAD = 0xa0, // 8'b10100000 + CMD_1011_0000_dddd_dddd_dddd_0000_CODE_LOAD = 0xb0, // 8'b10110000 + CMD_1100_xxxx_xxxx_xxxx_xxxx_xxxx_RESERVED = 0xc0, // 8'b11000000 + CMD_1101_xxxx_xxxx_xxxx_xxxx_xxxx_RESERVED = 0xd0, // 8'b11010000 + CMD_1110_xxxx_xxxx_xxxx_xxxx_xxxx_RESERVED = 0xe0, // 8'b11100000 + CMD_1111_xxxx_xxxx_xxxx_xxxx_xxxx_NOP = 0xf0, // 8'b11110000 +} MAX5805_CMD_enum_t; + +//---------------------------------------- +// 16-bit argument to command CMD_0100_0000_0000_0000_pp00_0000_POWER +typedef enum MAX5805_POWER_enum_t { + POWER_0000_0000_0000_0000_Normal = 0x00, // 8'b00000000 + POWER_0000_0000_0100_0000_PD1k = 0x40, // 8'b01000000 + POWER_0000_0000_1000_0000_PD100k = 0x80, // 8'b10000000 + POWER_0000_0000_1100_0000_PDHiZ = 0xc0, // 8'b11000000 +} MAX5805_POWER_enum_t; + +//---------------------------------------- +// 16-bit argument to command CMD_0101_0000_0000_0000_00aa_a000_CONFIG +typedef enum MAX5805_CONFIG_enum_t { + CONFIG_0000_0000_0001_1000_GATE = 0x18, // 8'b00011000 + CONFIG_0000_0000_0011_0000_CLEAR = 0x30, // 8'b00110000 + CONFIG_0000_0000_0011_1000_NONE = 0x38, // 8'b00111000 +} MAX5805_CONFIG_enum_t; + +//---------------------------------------- +// 16-bit argument to command CMD_0110_0000_0000_0000_ddd0_0000_DEFAULT +typedef enum MAX5805_DEFAULT_enum_t { + DEFAULT_0000_0000_0000_0000_POR = 0x00, // 8'b00000000 + DEFAULT_0000_0000_0010_0000_ZERO = 0x20, // 8'b00100000 + DEFAULT_0000_0000_0100_0000_MID = 0x40, // 8'b01000000 + DEFAULT_0000_0000_0110_0000_FULL = 0x60, // 8'b01100000 + DEFAULT_0000_0000_1000_0000_RETURN = 0x80, // 8'b10000000 +} MAX5805_DEFAULT_enum_t; + +//---------------------------------------- +// Argument to REF function ( external? voltage? always on? drive pin? ) +typedef enum MAX5805_REF_enum_t { + REF_EXT = 0x00, // 8'b00000000 + REF_2V500 = 0x01, // 8'b00000001 + REF_2V048 = 0x02, // 8'b00000010 + REF_4V096 = 0x03, // 8'b00000011 + REF_AlwaysOn_EXT = 0x04, // 8'b00000100 + REF_AlwaysOn_2V500 = 0x05, // 8'b00000101 + REF_AlwaysOn_2V048 = 0x06, // 8'b00000110 + REF_AlwaysOn_4V096 = 0x07, // 8'b00000111 + REF_OUT_2V500 = 0x09, // 8'b00001001 + REF_OUT_2V048 = 0x0a, // 8'b00001010 + REF_OUT_4V096 = 0x0b, // 8'b00001011 + REF_OUT_AlwaysOn_2V500 = 0x0d, // 8'b00001101 + REF_OUT_AlwaysOn_2V048 = 0x0e, // 8'b00001110 + REF_OUT_AlwaysOn_4V096 = 0x0f, // 8'b00001111 +} MAX5805_REF_enum_t; + +//---------------------------------------- +// Device Object Structure +typedef struct MAX5805_device_t { + + // reference voltage, in Volts + double VRef; + + // shadow of write-only register REF CMD_0010_rrrr + int16_t Shadow_0010_REF; + + // shadow of write-only register POWER 0000_0000_pp00_0000 + int16_t Shadow_0100_POWER; + + // shadow of write-only register CONFIG 0000_0000_00aa_a000 + int16_t Shadow_0101_CONFIG; + + // shadow of write-only register DEFAULT 0000_0000_ddd0_0000 + int16_t Shadow_0110_DEFAULT; + + // shadow of write-only register RETURN dddd_dddd_dddd_0000 + int16_t Shadow_0111_RETURN; + + // shadow of write-only register CODE dddd_dddd_dddd_0000 + int16_t Shadow_1000_CODE; + + // shadow of CODE field of write-only register CODE dddd_dddd_dddd_0000 + int16_t CODE; + + // shadow of RETURN field of write-only register RETURN dddd_dddd_dddd_0000 + int16_t RETURN; + + // I2C file descriptor for I2C device access + // on linux systems, fd is obtained by open("/dev/i2c-1", O_RDWR); + // not used on smaller bare-metal embedded systems + // if i2cFileDescriptor < 0 then the device is not open + // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. + int i2cFileDescriptor; + + // I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. + // Trying to make the bare-metal i2c functions behave like in linux sysfs file system. + int i2cDeviceAddress7bits; + + // code generator: keep i2cResult + int32_t i2cResult; +} MAX5805_device_t; + +//---------------------------------------- +// Global Device Object +extern MAX5805_device_t g_MAX5805_device; + +//---------------------------------------- +// User-provided hardware function +// declare user-provided hardware interface function +// I2C interface function for MAX5805 +// Similar to SMBusQuick device-present test function +// Similar to linux/i2c-dev.h interface functions +// ioctl(fileDescriptor, I2C_SLAVE, i2cDeviceAddress7bits) +// +// @param[in] fileDescriptor = file descriptor from i2c_open_adapter +// @param[in] i2cDeviceAddress7bits = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// @return status; error if (fileDescriptor < 0) +// @post I2C device address is associated with fileDescriptor for +// subsequent calls to i2c_smbus_write_word_data, i2c_smbus_read_word_data, and i2c_smbus_write_quick +// +extern int i2c_ioctl_I2C_SLAVE_i2cDeviceAddress7bits(int i2cFileDescriptor, int i2cDeviceAddress7bits); + +//---------------------------------------- +// User-provided hardware function +// declare user-provided hardware interface function +// I2C interface function for MAX5805 +// Similar to linux/i2c-dev.h interface functions +// +// @pre I2C device address was previously set by an ioctl(..., I2C_SLAVE, i2cDeviceAddress7bits) +// @pre g_MAX5805_device.i2cDeviceAddress7bits = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// @param[in] i2cFileDescriptor = I2C file descriptor for I2C device access +// @param[in] command_regAddress = 8-bit register address +// @return -1 on failure, return 0 on success +// +extern int32_t i2c_smbus_write_quick(int i2cFileDescriptor, + uint8_t command_regAddress); + +//---------------------------------------- +// User-provided hardware function +// declare user-provided hardware interface function +// I2C interface function for MAX5805 +// Similar to linux/i2c-dev.h interface functions +// +// @pre I2C device address was previously set by an ioctl(..., I2C_SLAVE, i2cDeviceAddress7bits) +// @pre g_MAX5805_device.i2cDeviceAddress7bits = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// @param[in] i2cFileDescriptor = I2C file descriptor for I2C device access +// @param[in] command_regAddress = 8-bit register address +// @return -1 on failure, return the read value on success +// +extern int32_t i2c_smbus_read_word_data(int i2cFileDescriptor, + uint8_t command_regAddress); + +//---------------------------------------- +// User-provided hardware function +// declare user-provided hardware interface function +// I2C interface function for MAX5805 +// Similar to linux/i2c-dev.h interface functions +// +// @pre I2C device address was previously set by an ioctl(..., I2C_SLAVE, i2cDeviceAddress7bits) +// @pre g_MAX5805_device.i2cDeviceAddress7bits = I2C device address (slave address on I2C bus), 7-bits, RIGHT-justified. +// @param[in] i2cFileDescriptor = I2C file descriptor for I2C device access +// @param[in] command_regAddress = 8-bit register address +// @return -1 on failure, return 0 on success +// +extern int32_t i2c_smbus_write_word_data(int i2cFileDescriptor, + uint8_t command_regAddress, + uint16_t regValue); + +//---------------------------------------- +// Initialize device +// Search the i2c address list for possible devices +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_Init(void); + +//---------------------------------------- +// Return the DAC register value corresponding to physical voltage. +// Does not perform any offset or gain correction. +// +// @pre g_MAX5805_device.VRef = Voltage of REF input, in Volts +// @param[in] voltage = physical voltage in Volts +// @returns raw 12-bit MAX5805 code (right justified). +uint16_t MAX5805_DACCodeOfVoltage(double voltageV); + +//---------------------------------------- +// Return the physical voltage corresponding to DAC register. +// Does not perform any offset or gain correction. +// +// @pre g_MAX5805_device.VRef = Voltage of REF input, in Volts +// @param[in] value_u12: raw 12-bit MAX5805 code (right justified). +// @Returns physical voltage corresponding to MAX5805 code. +double MAX5805_VoltageOfCode(uint16_t value_u12); + +//---------------------------------------- +// Read device status from register 0001_0000 +// @return CLR_LOAD_GATE_1_REF[3:0]_PD[1:0]_AB[2:0]_DF[2:0] +// int CLR = ((STATUS >> 15) & 0x0001); +// int LOAD = ((STATUS >> 14) & 0x0001); +// int GATE = ((STATUS >> 13) & 0x0001); +// int REF = ((STATUS >> 8) & 0x000F); +// int PD = ((STATUS >> 6) & 0x0003); +// int AB = ((STATUS >> 3) & 0x0007); +// int DF = ((STATUS >> 0) & 0x0007); +int16_t MAX5805_STATUS(void); + +//---------------------------------------- +// Read device ID from register 0000_0000 +// @return 0101_0_REVID[2:0]_PARTID[7:0] +// int REVID = ((DEVICEID >> 8) & 0x0007); +// int PARTID = ((DEVICEID >> 0) & 0x00FF); +// PARTID is 0x8A for MAX5803 +// PARTID is 0x92 for MAX5804 +// PARTID is 0x82 for MAX5805 +int16_t MAX5805_DEVICEID(void); + +//---------------------------------------- +// Writes data to the CODE register +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_CODE(uint16_t dacCodeLsbs); + +//---------------------------------------- +// Simultaneously writes data to the CODE register while updating DAC register +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_CODE_LOAD(uint16_t dacCodeLsbs); + +//---------------------------------------- +// Updates the function of the AUX input +void MAX5805_CONFIG(MAX5805_CONFIG_enum_t value); + +//---------------------------------------- +// Sets the default value for the DAC +void MAX5805_DEFAULT(MAX5805_DEFAULT_enum_t value); + +//---------------------------------------- +// Transfers data from the CODE register to the DAC register +void MAX5805_LOAD(void); + +//---------------------------------------- +// Sets the Power mode +void MAX5805_POWER(MAX5805_POWER_enum_t value); + +//---------------------------------------- +// Sets the reference operating mode. +int32_t MAX5805_REF(MAX5805_REF_enum_t value); + +//---------------------------------------- +// Updates the RETURN register contents for the DAC +// @param[in] dacCodeLsbs = 12-bit unsigned code value in LSBs +void MAX5805_RETURN(uint16_t dacCodeLsbs); + +//---------------------------------------- +// All CODE and DAC contents will be cleared to their DEFAULT selected values. +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_SW_CLEAR(void); + +//---------------------------------------- +// End any active gate operation, returning to normal operation (default). +void MAX5805_SW_END(void); + +//---------------------------------------- +// DAC contents will be gated to their DEFAULT selected values +// until the gate condition is removed. +void MAX5805_SW_GATE(void); + +//---------------------------------------- +// Software Reset +// All CODE, DAC, RETURN, and configuration registers reset to their +// power-up defaults (including REF, POWER, and CONFIG settings), +// simulating a power cycle reset. +// +// @return 1 on success; 0 on failure +uint8_t MAX5805_SW_RESET(void); + +/* +#ifdef __cplusplus +}; // extern "C" declaration +#endif +*/ + +#endif // __MAX5805_H__ + +// End of file + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.c index f6fd8e9cd..d59da9343 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.c @@ -17,7 +17,7 @@ bool D_TCA9546_Reset_n(bool reset) return ret; } -bool D_TCA9546_Select_Channel(uint8_t TCA9546A_I2C_bus_number ,uint8_t TCA9546A_I2C_addr ,TCA9546A_chnl_status chnl_status, TCA9546A_chnl chnl_number) +bool D_TCA9546_Select_Channel(uint8_t TCA9546A_I2C_bus_number, uint8_t TCA9546A_I2C_addr, TCA9546A_chnl_status chnl_status, TCA9546A_chnl chnl_number) { bool status= OK; diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.c new file mode 100644 index 000000000..51f0c655e --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.c @@ -0,0 +1,99 @@ +/* + * WHS_EEPROM.c + * + * Created on: Jun 30, 2019 + * Author: avi + */ +#include "include.h" +#include <Drivers/I2C_Communication/I2C.h> +#include <Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.h> +#include "../I2C_WHS_Mux.h" +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" + +//EEPROM M24M01-DFMN6TP +//uint32_t I2C_WHS_EEPROM_SLAVE_ADD = 0xA0; + +uint8_t WHS_Write_Buf[Max_WHS_buf_size +2]; + +uint32_t WHS_I2C_EEprom_Write_Ch() +{ + uint32_t status= OK; + + uint8_t i = 0; + + + status |= Select_Main_WHS_Mux_Channel(); + + WHS_Write_Buf[0] = 0x00; + WHS_Write_Buf[1] = 0x00; + + for(i=0;i<Max_WHS_buf_size;i++) + { + WHS_Write_Buf[i+2] = WHS_struct.Write_WHS_EEPROM.Buf[i]; + } + + status |= I2C_Write(I2C_ID_WHS_CARD, I2CEEPROM_ADDRESS, WHS_Write_Buf, Max_WHS_buf_size+2); + + return status; +} + +uint32_t WHS_I2C_EEprom_Set_for_Read_Ch() +{ + uint32_t status= OK; + + status |= Select_Main_WHS_Mux_Channel(); + + WHS_Write_Buf[0] = 0x00; + WHS_Write_Buf[1] = 0x00; + + status |= I2C_Write(I2C_ID_WHS_CARD, I2CEEPROM_ADDRESS, WHS_Write_Buf, 2); + + return status; +} + +uint32_t WHS_I2C_EEprom_Read_Ch() +{ + uint32_t status= OK; + + status |= Select_Main_WHS_Mux_Channel(); + + status |= I2C_Read(I2C_ID_WHS_CARD, I2CEEPROM_ADDRESS + 1, WHS_struct.Read_WHS_EEPROM.Buf, Max_WHS_buf_size); + + return status; +} + +uint32_t Test_WHS_EEPROM() +{ + uint32_t status= OK; + uint32_t i; + + WHS_struct.Write_WHS_EEPROM.bytes.SN = 0x12345678; + + WHS_struct.Write_WHS_EEPROM.bytes.Uint32_Spare[0] = 0xA123456A; + WHS_struct.Write_WHS_EEPROM.bytes.Uint32_Spare[1] = 0xB123456B; + WHS_struct.Write_WHS_EEPROM.bytes.Uint32_Spare[2] = 0xC123456C; + WHS_struct.Write_WHS_EEPROM.bytes.Uint32_Spare[3] = 0xD123456D; + WHS_struct.Write_WHS_EEPROM.bytes.Uint32_Spare[4] = 0xE123456E; + + WHS_struct.Write_WHS_EEPROM.bytes.Double_Spare[0] = 0xA789012A; + WHS_struct.Write_WHS_EEPROM.bytes.Double_Spare[1] = 0xB789012B; + WHS_struct.Write_WHS_EEPROM.bytes.Double_Spare[2] = 0xC789012C; + WHS_struct.Write_WHS_EEPROM.bytes.Double_Spare[3] = 0xD789012D; + WHS_struct.Write_WHS_EEPROM.bytes.Double_Spare[4] = 0xE789012E; + + status |= WHS_I2C_EEprom_Write_Ch(); + SysCtlDelay(5000000);//Must delay for at least 5 milli. !!! (See data sheet ) + status |= WHS_I2C_EEprom_Set_for_Read_Ch(); + status |= WHS_I2C_EEprom_Read_Ch(); + + if(status == 0) + { + for(i=0;i<Max_WHS_buf_size;i++) + { + if(WHS_struct.Read_WHS_EEPROM.Buf[i]!=WHS_struct.Write_WHS_EEPROM.Buf[i]) + status |= ERROR; + } + } + + return status; +} diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.h new file mode 100644 index 000000000..1a7f895f7 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.h @@ -0,0 +1,40 @@ +/* + * WHS_EEPROM.h + * + * Created on: Jun 30, 2019 + * Author: avi + */ + +#ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_EEPROM_WHS_EEPROM_H_ +#define DRIVERS_I2C_COMMUNICATION_WHS_CARD_EEPROM_WHS_EEPROM_H_ + + +typedef struct +{ + uint32_t SN; + uint32_t Uint32_Spare[5]; + double Double_Spare[5]; +}WHS_EEPROM_BYTES; + +typedef union +{ + WHS_EEPROM_BYTES bytes; + uint8_t Buf[sizeof(WHS_EEPROM_BYTES)]; +}WHS_EEPROM; + +typedef struct +{ + WHS_EEPROM Write_WHS_EEPROM; + WHS_EEPROM Read_WHS_EEPROM; +}WHS_EEPROM_STRUCT; + +WHS_EEPROM_STRUCT WHS_struct; + +#define Max_WHS_buf_size sizeof(WHS_struct.Write_WHS_EEPROM.Buf) + +uint32_t WHS_I2C_EEprom_Write_Ch(); +uint32_t WHS_I2C_EEprom_Set_for_Read_Ch(); +uint32_t WHS_I2C_EEprom_Read_Ch(); +uint32_t Test_WHS_EEPROM(); + +#endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_EEPROM_WHS_EEPROM_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.c index 257b124bb..a6f98195a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.c @@ -13,6 +13,7 @@ #include "Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h" #include "Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.h" #include "Drivers/I2C_Communication/WHS_Card/D_TCA9546/TCA9546_Driver.h" +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" uint32_t Select_Fan_Mux_Channel(TCA9546A_chnl Channel) { @@ -24,7 +25,7 @@ uint32_t Select_Fan_Mux_Channel(TCA9546A_chnl Channel) Write_Buf[0] = Channel; //<< 4;//Channel 4 - status = I2C_Write(I2C_ID_WHS_CARD, Fan_MUX_TCA9546A_0xE8, Write_Buf, 1); + status = I2C_Write(I2C_ID_WHS_CARD, I2CSwitch_ADDRESS, Write_Buf, 1); return status; } diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.h index 4c29e4ea8..020667c50 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Fan_Mux.h @@ -25,8 +25,8 @@ uint32_t Select_Fan_Mux_Channel(TCA9546A_chnl Channel); -#define I2C_ID_WHS_CARD 0x03 -#define I2C3_MAIN_MUX_TCA9548A_0xE0 0xE0 //WHS - SD1, SC1 -#define Fan_MUX_TCA9546A_0xE8 0xE8 +//#define I2C_ID_WHS_CARD 0x03 +//#define I2C3_MAIN_MUX_TCA9548A_0xE0 0xE0 //WHS - SD1, SC1 +//#define Fan_MUX_TCA9546A_0xE8 0xE8 #endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_I2C_WHS_FAN_MUX_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.c index 3690037d8..1bec2079a 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.c @@ -10,8 +10,10 @@ #include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> #include "drivers/I2C_Communication/I2C.h" #include <Drivers/I2C_Communication/Head_Card/I2C_Head_Mux.h> +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" + + -extern uint8_t Main_Mux_Flag; /* uint32_t Select_Main_WHS_Mux_Channel(bool chnl_stats, uint32_t chnl_number) { @@ -81,3 +83,35 @@ uint32_t Block_Main_WHS_Mux_Channel() return status; } + + +/* +uint32_t Select_Main_WHS_Mux_Channel() +{ + uint32_t status= OK; + + uint8_t Write_Buf[1]; + + Block_Main_Head_Mux_Channel(); + + Write_Buf[0] = 0x01 << 1;//Channel 1 + + status = I2C_Write(I2C_ID_WHS_CARD, I2C2_MAIN_MUX_TCA9548A_0xE0, Write_Buf, 1); + + return status; +} + +uint32_t Block_Main_WHS_Mux_Channel() +{ + uint32_t status= OK; + + uint8_t Write_Buf[1]; + + Write_Buf[0] = 0x00;//Block all + + status = I2C_Write(I2C_ID_WHS_CARD, I2C2_MAIN_MUX_TCA9548A_0xE0, Write_Buf, 1); + + return status; +} +*/ + diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h index a949a0ea3..48187791c 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h @@ -38,6 +38,6 @@ uint32_t Reset_n(bool reset); uint32_t Select_Main_WHS_Mux_Channel(); uint32_t Block_Main_WHS_Mux_Channel(); -#define I2C_ID_WHS_CARD 0x03 -#define I2C2_MAIN_MUX_TCA9548A_0xE0 0xE0 //WHS - SD1, SC1 + +//#define I2C2_MAIN_MUX_TCA9548A_0xE0 0xE0 //WHS - SD1, SC1 #endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_I2C_WHS_MUX_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.c index 7f399ff59..840e39eeb 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.c @@ -33,7 +33,7 @@ struct TCA9555_params * @param Config_dir_PORT_1 * @return status - OK or FAIL */ -uint32_t D_TCA9555ConfigDirection(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS ,uint8_t Config_dir_PORT_0 ,uint8_t Config_dir_PORT_1)//Set GPIO +uint32_t D_TCA9555ConfigDirection(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, uint8_t Config_dir_PORT_0, uint8_t Config_dir_PORT_1) { uint32_t status= OK; uint8_t Write_Buf[2]; @@ -49,7 +49,7 @@ uint32_t D_TCA9555ConfigDirection(uint8_t TCA9555_I2C_bus_number, uint8_t TCA955 return status; } -uint32_t D_TCA9555_Read_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t *value) +uint32_t D_TCA9555_Read_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t *read_data) { uint32_t status= OK; uint8_t Write_Buf[1]; @@ -57,17 +57,17 @@ uint32_t D_TCA9555_Read_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRE if (port_num == TCA9555_PORT_0) { - Write_Buf[0] = TCA9555_PORT_0; + Write_Buf[0] = TCA9555_INPUT_PORT_0; } else { - Write_Buf[0] = TCA9555_PORT_1; + Write_Buf[0] = TCA9555_INPUT_PORT_1; } status |= I2C_Write(TCA9555_I2C_bus_number, TCA9555_ADDRESS, Write_Buf, 1); //status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); delayUs(10);//TODO - check the delay status |= I2C_Read(TCA9555_I2C_bus_number, TCA9555_ADDRESS + 1, Read_Buf, 1); - *value = Read_Buf[1]; + *read_data = Read_Buf[0]; return status; } @@ -77,7 +77,10 @@ uint32_t D_TCA9555_Write_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDR uint32_t status= OK; uint8_t Write_Buf[2]; - Write_Buf[0] = port_num; + if (port_num == TCA9555_PORT_0) + Write_Buf[0] = TCA9555_OUTPUT_PORT_0; + else + Write_Buf[0] = TCA9555_OUTPUT_PORT_1; Write_Buf[1] = data; status |= I2C_Write(TCA9555_I2C_bus_number, TCA9555_ADDRESS, Write_Buf, 2); diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h index 9f48c57aa..3ae83eddd 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h @@ -5,15 +5,15 @@ * Author: Shai */ -#ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ -#define DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ +#ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_TCA9555_Driver_H_ +#define DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_TCA9555_Driver_H_ //COMMAND BYTES //#define TCA9555_PORT_0 0x00 //#define TCA9555_PORT_1 0x01 -#define TCA9555_DIR_OUTPUT 0x00 -#define TCA9555_DIR_INPUT 0x01 +//#define TCA9555_DIR_OUTPUT 0x00 +//#define TCA9555_DIR_INPUT 0x01 #define TCA9555_8Pins_INPUT 0xFF #define TCA9555_8Pins_OUPUT 0x00 @@ -33,58 +33,64 @@ typedef enum { + TCA9555_DIR_OUTPUT = 0, + TCA9555_DIR_INPUT +} TCA9555_port_direction; + +typedef enum +{ TCA9555_PORT_0 = 0, TCA9555_PORT_1 } TCA9555_port_num; - -typedef union -{ - struct - { - bool TCA9555_bit0 : 1; //0 - bool TCA9555_bit1 : 1; //1 - bool TCA9555_bit2 : 1; //2 - bool TCA9555_bit3 : 1; //3 - bool TCA9555_bit4 : 1; //4 - bool TCA9555_bit5 : 1; //5 - bool TCA9555_bit6 : 1; //6 - bool TCA9555_bit7 : 1; //7 - - }bits; - uint8_t Uchar; -}TCA9555_union; - - -//I2C expander: U3 0x40 -typedef union -{ - struct - { - bool P00 : 1; //P00 - bool P01 : 1; //P01 - bool P02 : 1; //P02 - bool P03 : 1; //P03 - bool P04 : 1; //P04 - bool P05 : 1; //P05 - bool P06 : 1; //P06 - bool P07 : 1; //P07 - - bool p10 : 1; //p10 - bool p11 : 1; //p11 - bool p12 : 1; //p12 - bool p13 : 1; //p13 - bool p14 : 1; //p14 - bool p15 : 1; //p15 - bool p16 : 1; //p16 - bool p17 : 1; //p17 - }bits; - unsigned char uchar[2]; - unsigned short ushort; -}IO_port_name; - - -extern IO_port_name IO_Port_name; +// +//typedef union +//{ +// struct +// { +// bool TCA9555_bit0 : 1; //0 +// bool TCA9555_bit1 : 1; //1 +// bool TCA9555_bit2 : 1; //2 +// bool TCA9555_bit3 : 1; //3 +// bool TCA9555_bit4 : 1; //4 +// bool TCA9555_bit5 : 1; //5 +// bool TCA9555_bit6 : 1; //6 +// bool TCA9555_bit7 : 1; //7 +// +// }bits; +// uint8_t Uchar; +//}TCA9555_union; +// +// +////I2C expander: U3 0x40 +//typedef union +//{ +// struct +// { +// bool P00 : 1; //P00 +// bool P01 : 1; //P01 +// bool P02 : 1; //P02 +// bool P03 : 1; //P03 +// bool P04 : 1; //P04 +// bool P05 : 1; //P05 +// bool P06 : 1; //P06 +// bool P07 : 1; //P07 +// +// bool p10 : 1; //p10 +// bool p11 : 1; //p11 +// bool p12 : 1; //p12 +// bool p13 : 1; //p13 +// bool p14 : 1; //p14 +// bool p15 : 1; //p15 +// bool p16 : 1; //p16 +// bool p17 : 1; //p17 +// }bits; +// unsigned char uchar[2]; +// unsigned short ushort; +//}IO_port_name; +// +// +//extern IO_port_name IO_Port_name; /* @@ -98,10 +104,10 @@ uint32_t D_TCA9555_Config_Polarity_Port1(uint8_t TCA9555_I2C_bus_number, uint8_t uint32_t D_TCA9555_Write_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t data); uint32_t D_TCA9555_Read_IO(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t *value); -uint32_t D_TCA9555ConfigDirection(uint8_t TCA9555_I2C_bus_number,uint8_t TCA9555_ADDRESS ,uint8_t Config_Reg_PORT_0 ,uint8_t Config_Reg_PORT_1); +uint32_t D_TCA9555ConfigDirection(uint8_t TCA9555_I2C_bus_number, uint8_t TCA9555_ADDRESS, uint8_t Config_dir_PORT_0, uint8_t Config_dir_PORT_1); uint32_t D_TCA9555_IO_Init(); uint8_t D_TCA9555_Test_IO(); //------------------------------ -#endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ */ +#endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_TCA9555_Driver_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.c index 921477f12..a163397ac 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.c +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.c @@ -7,245 +7,264 @@ #include "include.h" //#include "WHS_IO.h" #include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> #include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> #include <Drivers/I2C_Communication/I2C.h> -//#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" +#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h> +//#include "TCA9555_Driver.h" + + /* GPIO TCA9555RTWR ADDR 0x40 ADDR 0x42 */ -WHS_I2C_EXP1_0x40 Whs_I2C_EXP1_0x40; -WHS_I2C_EXP2_0x42 Whs_I2C_EXP2_0x42; +//WHS_I2C_EXP_U3_0x40 Whs_I2C_EXP_U3_0x40; +//WHS_I2C_EXP_U4_0x42 Whs_I2C_EXP_U4_0x42; + +WHS_I2C_EXP_U3_0x40_DIRECTION Whs_I2C_EXP_U3_0x40_DIRECTION; +WHS_I2C_EXP_U4_0x42_DIRECTION Whs_I2C_EXP_U4_0x42_DIRECTION; +WHS_I2C_EXP_U3_0x40_VALUE Whs_I2C_EXP_U3_0x40_VALUE; +WHS_I2C_EXP_U4_0x42_VALUE Whs_I2C_EXP_U4_0x42_VALUE; + + -# define U3_I2C_ADDR 0x40 -# define U4_I2C_ADDR 0x42 -uint32_t WHS_TCA9555Config(uint8_t TCA9555_ADDRESS)//Set GPIO + + +uint32_t WHS_TCA9555Config(uint8_t TCA9555_ADDRESS) { uint32_t status= OK; - uint8_t Config_Reg_PORT_0; - uint8_t Config_Reg_PORT_1; - uint8_t Write_Buf[2]; - TCA9555_union config_bits; + uint8_t Config_Dir_PORT_0; + uint8_t Config_Dir_PORT_1; +// uint8_t Write_Buf[2]; +// TCA9555_union config_bits; switch (TCA9555_ADDRESS) { - case U3_I2C_ADDR: - Config_Reg_PORT_0 = TCA9555_8Pins_OUPUT; - Config_Reg_PORT_1 = TCA9555_8Pins_INPUT; - break; - case U4_I2C_ADDR: - Config_Reg_PORT_0 = TCA9555_8Pins_OUPUT; - Config_Reg_PORT_1 = TCA9555_8Pins_INPUT; - break; - default : - return ERROR; - + case I2CExp1_ADDRESS: + Config_Dir_PORT_0 = Whs_I2C_EXP_U3_0x40_DIRECTION.uchar[0]; // TCA9555_8Pins_OUPUT + Config_Dir_PORT_1 = Whs_I2C_EXP_U3_0x40_DIRECTION.uchar[1]; // TCA9555_8Pins_INPUT + break; + case I2CExp2_ADDRESS: + Config_Dir_PORT_0 = Whs_I2C_EXP_U4_0x42_DIRECTION.uchar[0]; // TCA9555_8Pins_OUPUT + Config_Dir_PORT_1 = Whs_I2C_EXP_U4_0x42_DIRECTION.uchar[1]; // TCA9555_8Pins_OUPUT + break; + default : + return ERROR; } + status = D_TCA9555ConfigDirection(I2C_ID_WHS_CARD, TCA9555_ADDRESS , Config_Dir_PORT_0 ,Config_Dir_PORT_1); -/* if(TCA9555_ADDRESS == 0x40) - { +return status; +} - } - else - if(TCA9555_ADDRESS == 0x42) - { - Config_Reg_PORT_0 = TCA9555_8Pins_OUPUT; - Config_Reg_PORT_1 = TCA9555_8Pins_OUPUT; - } - else - if(TCA9555_ADDRESS == 0x44) - { - Config_Reg_PORT_0 = TCA9555_8Pins_INPUT; - Config_Reg_PORT_1 = TCA9555_8Pins_OUPUT; - } - else - if(TCA9555_ADDRESS == 0x46) - { - config_bits.bits.TCA9555_bit0 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit1 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit2 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit3 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit4 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit5 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit6 = TCA9555_DIR_INPUT; - config_bits.bits.TCA9555_bit7 = TCA9555_DIR_OUTPUT; +bool WHS_Write_IO_AllReg(WHS_chip_address TCA9555_ADDRESS) +{ + bool status= OK; - Config_Reg_PORT_0 = config_bits.Uchar; + status = WHS_Write_IO(TCA9555_ADDRESS, TCA9555_PORT_0); + status |= WHS_Write_IO(TCA9555_ADDRESS, TCA9555_PORT_1); - config_bits.bits.TCA9555_bit0 = TCA9555_DIR_INPUT;//8 - config_bits.bits.TCA9555_bit1 = TCA9555_DIR_INPUT;//9 - config_bits.bits.TCA9555_bit2 = TCA9555_DIR_OUTPUT;//10 - config_bits.bits.TCA9555_bit3 = TCA9555_DIR_OUTPUT;//11 - config_bits.bits.TCA9555_bit4 = TCA9555_DIR_INPUT;//12 - config_bits.bits.TCA9555_bit5 = TCA9555_DIR_INPUT;//13 - config_bits.bits.TCA9555_bit6 = TCA9555_DIR_INPUT;//14 - config_bits.bits.TCA9555_bit7 = TCA9555_DIR_INPUT;//15 + return status; +} - Config_Reg_PORT_1 = config_bits.Uchar; - } +bool WHS_Write_IO(WHS_chip_address TCA9555_ADDRESS, TCA9555_port_num port_num) +{ + bool status = OK; - else - return ERROR; -*/ + switch (TCA9555_ADDRESS) + { + case I2CExp1_ADDRESS: + if (port_num == TCA9555_PORT_0) + { + status = Select_Main_WHS_Mux_Channel(); + status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, TCA9555_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); + } + else + { + status = Select_Main_WHS_Mux_Channel(); + status |= D_TCA9555_Write_IO(I2C_ID_WHS_CARD, TCA9555_ADDRESS, TCA9555_PORT_1, Whs_I2C_EXP_U3_0x40_VALUE.uchar[1]); + } + break; + case I2CExp2_ADDRESS: + if (port_num == TCA9555_PORT_0) + { + status = Select_Main_WHS_Mux_Channel(); + status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, TCA9555_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U4_0x42_VALUE.uchar[0]); + } + else + { + status = Select_Main_WHS_Mux_Channel(); + status |= D_TCA9555_Write_IO(I2C_ID_WHS_CARD, TCA9555_ADDRESS, TCA9555_PORT_1, Whs_I2C_EXP_U4_0x42_VALUE.uchar[1]); + } + break; + default : + return ERROR; + } +return status; +} - Write_Buf[0] = TCA9555_CONFIG_PORT_0; - Write_Buf[1] = Config_Reg_PORT_0; -// status |= Select_Main_WHS_Mux_Channel(); //status |= Select_Main_Head_Mux_Channel(); - status |= I2C_Write(I2C_ID_WHS_CARD, TCA9555_ADDRESS, Write_Buf, 2); //status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); +bool WHS_Read_IO_Reg(uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t *data) +{ + bool status = OK; + status = D_TCA9555_Read_IO(I2C_ID_WHS_CARD, TCA9555_ADDRESS, port_num, &data); + return status; +} - Write_Buf[0] = TCA9555_CONFIG_PORT_1; - Write_Buf[1] = Config_Reg_PORT_1; -// status |= Select_Main_WHS_Mux_Channel(); //status |= Select_Main_Head_Mux_Channel(); - status |= I2C_Write(I2C_ID_WHS_CARD, TCA9555_ADDRESS, Write_Buf, 2); //status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); - return OK; +bool WHS_Get_IO_Reg(uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, bool bit_num, bool *data) +{ + bool status = OK; + switch (TCA9555_ADDRESS) + { + case (I2CExp1_ADDRESS): + *data = ((Whs_I2C_EXP_U3_0x40_VALUE.uchar[port_num] & bit_num) ? 1 : 0); + break; + case (I2CExp2_ADDRESS): + *data = ((Whs_I2C_EXP_U3_0x40_VALUE.uchar[port_num] & bit_num) ? 1 : 0); + break; + default: + status = ERROR; + break; + } + return status; } -uint32_t WHS_IO_Init() + +bool WHS_IO_Init() { - uint32_t status = OK; - uint8_t i = 0; + bool status = OK; - //Set all the active low bits to "1" and all the active high bits to "0" + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_PT_RSTn = 1; //P00 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PT_SEL = 1; //P01 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_AUXn = 1; //P02 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_ACTLOW_LDACn = 1; //P03 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FANS_ON = 0; //P04 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FANS_LATCH_RST = 1; //P05 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_I2CSW_RST = 1; //P06 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PUMP_ON = PUMP_DISABLE; //P07 - for(i=0;i<2;i++) - { - Whs_I2C_EXP1_0x40.uchar[i] = 0x00; -// WHS_I2C_EXP2_0x42.uchar[i] = 0x00; -// Head_I2C_EXP1_0x44.uchar[i] = 0x01; -// Head_I2C_EXP1_0x46.uchar[i] = 0x00; - } + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FANS_BREAK = 1; //p10 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_12 = 1; //p11 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_34 = 1; //p12 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_FAN_ALART_56 = 1; //p13 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_NC_p14 = 1; //p14 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_NC_p15 = 1; //p15 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_NC_p16 = 1; //p16 + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_NC_p17 = 1; //p17 - Whs_I2C_EXP1_0x40.bits.OUTPUT_ACTLOW_PT_RSTn = 0x01; - Whs_I2C_EXP1_0x40.bits.OUTPUT_PT_SEL = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_ACTLOW_AUXn = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_ACTLOW_LDACn = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_FANS_ON = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_FANS_LATCH_RST = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_I2CSW_RST = 1; - Whs_I2C_EXP1_0x40.bits.OUTPUT_PUMP_ON = 1; + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_ACTLOW_PT_RSTn = TCA9555_DIR_OUTPUT; //P00 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_PT_SEL = TCA9555_DIR_OUTPUT; //P01 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_ACTLOW_AUXn = TCA9555_DIR_OUTPUT; //P02 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_ACTLOW_LDACn = TCA9555_DIR_OUTPUT; //P03 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_FANS_ON = TCA9555_DIR_OUTPUT; //P04 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_FANS_LATCH_RST = TCA9555_DIR_OUTPUT; //P05 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_I2CSW_RST = TCA9555_DIR_OUTPUT; //P06 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.OUTPUT_PUMP_ON = TCA9555_DIR_OUTPUT; //P07 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_FANS_BREAK = TCA9555_DIR_INPUT; //p10 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_FAN_ALERT_12 = TCA9555_DIR_INPUT; //p11 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_FAN_ALERT_34 = TCA9555_DIR_INPUT; //p12 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_FAN_ALERT_56 = TCA9555_DIR_INPUT; //p13 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_NC_p14 = TCA9555_DIR_INPUT; //p14 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_NC_p15 = TCA9555_DIR_INPUT; //p15 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_NC_p16 = TCA9555_DIR_INPUT; //p16 + Whs_I2C_EXP_U3_0x40_DIRECTION.bits.INPUT_NC_p17 = TCA9555_DIR_INPUT; //p17 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_ACTLOW_DE_REn = 1; //P00 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_P01 = 1; //P01 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_P02 = 1; //P02 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_RST_100K = 1; //P03 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV1_DIR = 1; //P04 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV1_EN = VALVE_DISABLE; //P05 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV2_DIR = 1; //P06 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV2_EN = VALVE_DISABLE; //P07 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_RST_I2C_485 = 1; //p10 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p11 = 1; //p11 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p12 = 1; //p12 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p13 = 1; //p13 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p14 = 1; //p14 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p15 = 1; //p15 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p16 = 1; //p16 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_NC_p17 = 1; //p17 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_ACTLOW_DE_REn = TCA9555_DIR_OUTPUT; //P00 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_P01 = TCA9555_DIR_OUTPUT; //P01 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_P02 = TCA9555_DIR_OUTPUT; //P02 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_RST_100K = TCA9555_DIR_OUTPUT; //P03 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_VALV1_DIR = TCA9555_DIR_OUTPUT; //P04 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_VALV1_EN = TCA9555_DIR_OUTPUT; //P05 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_VALV2_DIR = TCA9555_DIR_OUTPUT; //P06 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_VALV2_EN = TCA9555_DIR_OUTPUT; //P07 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_RST_I2C_485 = TCA9555_DIR_OUTPUT; //p10 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p11 = TCA9555_DIR_OUTPUT; //p11 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p12 = TCA9555_DIR_OUTPUT; //p12 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p13 = TCA9555_DIR_OUTPUT; //p13 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p14 = TCA9555_DIR_OUTPUT; //p14 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p15 = TCA9555_DIR_OUTPUT; //p15 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p16 = TCA9555_DIR_OUTPUT; //p16 + Whs_I2C_EXP_U4_0x42_DIRECTION.bits.OUTPUT_NC_p17 = TCA9555_DIR_OUTPUT; //p17 - TCA9555Config(0x40); - TCA9555Config(0x42); -// TCA9555Config(0x44); -// TCA9555Config(0x46); + + //*** set port value ***// + WHS_Write_IO_AllReg(I2CExp1_ADDRESS); + WHS_Write_IO_AllReg(I2CExp2_ADDRESS); + + //*** set direction ***// + WHS_TCA9555Config(I2CExp1_ADDRESS); + WHS_TCA9555Config(I2CExp2_ADDRESS); return status; } -uint32_t WHS_Write_IO_Reg(uint8_t TCA9555_ADDRESS) -{ - uint32_t status= OK; - uint8_t Write_Buf[2]; - if(TCA9555_ADDRESS == 0x40) +bool Set_WHS_valve(uint8_t valve_number, bool state, bool direction) +{ + bool status = OK; + if (valve_number == VALVE_0) { -// Write_Buf[0] = TCA9555_OUTPUT_PORT_0; -// Write_Buf[1] = WHS_I2C_EXP1_0x40.uchar[0]; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); -// -// Write_Buf[0] = TCA9555_OUTPUT_PORT_1; -// Write_Buf[1] = Head_I2C_EXP1_0x40.uchar[1]; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV1_DIR = direction; //P04 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV1_EN = state; //P05 } - else - if(TCA9555_ADDRESS == 0x42) + else if(valve_number == VALVE_1) { -// Write_Buf[0] = TCA9555_OUTPUT_PORT_0; -// Write_Buf[1] = WHS_I2C_EXP1_0x42.uchar[0]; -//// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_WHS_CARD, TCA9555_ADDRESS, Write_Buf, 2); -// -// Write_Buf[0] = TCA9555_OUTPUT_PORT_1; -// Write_Buf[1] = WHS_I2C_EXP1_0x42.uchar[1]; -//// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_WHS_CARD, TCA9555_ADDRESS, Write_Buf, 2); + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV2_DIR = direction; //P04 + Whs_I2C_EXP_U4_0x42_VALUE.bits.VALUE_VALV2_EN = state; //P05 } -// else -// if(TCA9555_ADDRESS == 0x46) -// { -// Write_Buf[0] = TCA9555_OUTPUT_PORT_0; -// Write_Buf[1] = WHS_I2C_EXP1_0x46.uchar[0] & BIT7; -//// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_WHS_CARD, TCA9555_ADDRESS, Write_Buf, 2); -// -// Write_Buf[0] = TCA9555_OUTPUT_PORT_1; -// Write_Buf[1] = Head_I2C_EXP1_0x46.uchar[1] & (BIT11 | BIT12) ; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 2); -// } - else - status = ERROR; - - return status; + return status; } -uint32_t WHS_Read_IO_Reg(uint8_t TCA9555_ADDRESS) +bool Write_WHS_Valve_reg() { - uint32_t status= OK; - uint8_t Write_Buf[1] = {0}; - uint8_t Read_Buf[1] = {0}; + bool status = OK; - if(TCA9555_ADDRESS == 0x40) - { -// Write_Buf[0] = TCA9555_INPUT_PORT_0; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 1); -// delayUs(10);//TODO - check the delay -// status |= I2C_Read(I2C_ID_HEAD_CARD, TCA9555_ADDRESS + 1, Read_Buf, 1); -// WHS_I2C_EXP1_0x44.uchar[0] = Read_Buf[0]; -// -// Write_Buf[0] = TCA9555_INPUT_PORT_1; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 1); -// delayUs(10);//TODO - check the delay -// status |= I2C_Read(I2C_ID_HEAD_CARD, TCA9555_ADDRESS + 1, Read_Buf, 1); -// -// Head_I2C_EXP1_0x44.uchar[1] = Read_Buf[0]; - } -// else -// if(TCA9555_ADDRESS == 0x42) -// { -// Write_Buf[0] = TCA9555_INPUT_PORT_0; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 1); -// delayUs(10);//TODO - check the delay -// status |= I2C_Read(I2C_ID_HEAD_CARD, TCA9555_ADDRESS + 1, Read_Buf, 1); -// Head_I2C_EXP1_0x46.uchar[0] = (Read_Buf[0] & ~BIT7); -// -// Write_Buf[0] = TCA9555_INPUT_PORT_1; -// status |= Select_Main_Head_Mux_Channel(); -// status |= I2C_Write(I2C_ID_HEAD_CARD, TCA9555_ADDRESS, Write_Buf, 1); -// delayUs(10);//TODO - check the delay -// status |= I2C_Read(I2C_ID_HEAD_CARD, TCA9555_ADDRESS + 1, Read_Buf, 1); -// -// Head_I2C_EXP1_0x46.uchar[1] |= (Read_Buf[0]& ~(BIT11 | BIT12)) ; -// } - else - status = ERROR; + status = WHS_Write_IO( I2CExp2_ADDRESS, TCA9555_PORT_0); - return status; + return status; } - +bool Write_WHS_pump(bool state) +{ + bool status = OK; + if (Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PUMP_ON != state) + { + Whs_I2C_EXP_U3_0x40_VALUE.bits.VALUE_PUMP_ON = state; + status = WHS_Write_IO( I2CExp1_ADDRESS, TCA9555_PORT_0); + } + return status; +} //------------------------------ uint8_t WHS_Test_IO() @@ -258,8 +277,56 @@ uint8_t WHS_Test_IO() } +bool Test_WHS_valve() +{ + bool status = OK; + +// status = Select_Main_WHS_Mux_Channel(); + Set_WHS_valve(VALVE_0, VALVE_ENABLE, 0); + Set_WHS_valve(VALVE_1, VALVE_DISABLE, 0); + status = Write_WHS_Valve_reg(); + delayms(4000); + Set_WHS_valve(VALVE_0, VALVE_ENABLE, 1); + Set_WHS_valve(VALVE_1, VALVE_DISABLE, 1); + status |= Write_WHS_Valve_reg(); + + delayms(4000); + + Set_WHS_valve(VALVE_0, VALVE_DISABLE, 0); + Set_WHS_valve(VALVE_1, VALVE_ENABLE, 0); + status |= Write_WHS_Valve_reg(); + + delayms(4000); + + Set_WHS_valve(VALVE_0, VALVE_DISABLE, 1); + Set_WHS_valve(VALVE_1, VALVE_ENABLE, 1); + status |= Write_WHS_Valve_reg(); + + delayms(4000); + + Set_WHS_valve(VALVE_0, VALVE_DISABLE, 1); + Set_WHS_valve(VALVE_1, VALVE_DISABLE, 1); + status |= Write_WHS_Valve_reg(); + + delayms(4000); + + return status; +} + +bool Test_WHS_pump() +{ + bool status = OK; + + status = Write_WHS_pump(PUMP_ENABLE); + + delayms(4000); + + status |= Write_WHS_pump(PUMP_DISABLE); + + return status; +} diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h index 381ae8536..e152166cb 100644 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h @@ -8,75 +8,117 @@ #ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ #define DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ -//COMMAND BYTES - - - - - - - - - - - - - +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> +#define VALVE_ENABLE 1 +#define VALVE_DISABLE 0 +#define VALVE_0 0 +#define VALVE_1 1 +#define PUMP_ENABLE 1 +#define PUMP_DISABLE 0 +//typedef union +//{ +// struct +// { +// bool TCA9555_bit0 : 1; //0 +// bool TCA9555_bit1 : 1; //1 +// bool TCA9555_bit2 : 1; //2 +// bool TCA9555_bit3 : 1; //3 +// bool TCA9555_bit4 : 1; //4 +// bool TCA9555_bit5 : 1; //5 +// bool TCA9555_bit6 : 1; //6 +// bool TCA9555_bit7 : 1; //7 +// +// }bits; +// uint8_t Uchar; +//}TCA9555_union; +//I2C expander: U3 0x40 +typedef union +{ + struct + { + bool VALUE_ACTLOW_PT_RSTn : 1; //P00 + bool VALUE_PT_SEL : 1; //P01 + bool VALUE_ACTLOW_AUXn : 1; //P02 + bool VALUE_ACTLOW_LDACn : 1; //P03 + bool VALUE_FANS_ON : 1; //P04 + bool VALUE_FANS_LATCH_RST : 1; //P05 + bool VALUE_I2CSW_RST : 1; //P06 + bool VALUE_PUMP_ON : 1; //P07 + bool VALUE_FANS_BREAK : 1; //p10 + bool VALUE_FAN_ALART_12 : 1; //p11 + bool VALUE_FAN_ALART_34 : 1; //p12 + bool VALUE_FAN_ALART_56 : 1; //p13 + bool VALUE_NC_p14 : 1; //p14 + bool VALUE_NC_p15 : 1; //p15 + bool VALUE_NC_p16 : 1; //p16 + bool VALUE_NC_p17 : 1; //p17 + }bits; + unsigned char uchar[2]; + unsigned short ushort; +}WHS_I2C_EXP_U3_0x40_VALUE; typedef union { struct { - bool TCA9555_bit0 : 1; //0 - bool TCA9555_bit1 : 1; //1 - bool TCA9555_bit2 : 1; //2 - bool TCA9555_bit3 : 1; //3 - bool TCA9555_bit4 : 1; //4 - bool TCA9555_bit5 : 1; //5 - bool TCA9555_bit6 : 1; //6 - bool TCA9555_bit7 : 1; //7 + TCA9555_port_direction OUTPUT_ACTLOW_PT_RSTn : 1; //P00 + TCA9555_port_direction OUTPUT_PT_SEL : 1; //P01 + TCA9555_port_direction OUTPUT_ACTLOW_AUXn : 1; //P02 + TCA9555_port_direction OUTPUT_ACTLOW_LDACn : 1; //P03 + TCA9555_port_direction OUTPUT_FANS_ON : 1; //P04 + TCA9555_port_direction OUTPUT_FANS_LATCH_RST : 1; //P05 + TCA9555_port_direction OUTPUT_I2CSW_RST : 1; //P06 + TCA9555_port_direction OUTPUT_PUMP_ON : 1; //P07 + TCA9555_port_direction INPUT_FANS_BREAK : 1; //p10 + TCA9555_port_direction INPUT_FAN_ALERT_12 : 1; //p11 + TCA9555_port_direction INPUT_FAN_ALERT_34 : 1; //p12 + TCA9555_port_direction INPUT_FAN_ALERT_56 : 1; //p13 + TCA9555_port_direction INPUT_NC_p14 : 1; //p14 + TCA9555_port_direction INPUT_NC_p15 : 1; //p15 + TCA9555_port_direction INPUT_NC_p16 : 1; //p16 + TCA9555_port_direction INPUT_NC_p17 : 1; //p17 }bits; - uint8_t Uchar; -}TCA9555_union; - + unsigned char uchar[2]; + unsigned short ushort; +}WHS_I2C_EXP_U3_0x40_DIRECTION; -//I2C expander: U3 0x40 +//I2C expander: U4 0x42 typedef union { struct { - bool OUTPUT_ACTLOW_PT_RSTn : 1; //P00 - bool OUTPUT_PT_SEL : 1; //P01 - bool OUTPUT_ACTLOW_AUXn : 1; //P02 - bool OUTPUT_ACTLOW_LDACn : 1; //P03 - bool OUTPUT_FANS_ON : 1; //P04 - bool OUTPUT_FANS_LATCH_RST : 1; //P05 - bool OUTPUT_I2CSW_RST : 1; //P06 - bool OUTPUT_PUMP_ON : 1; //P07 + bool VALUE_ACTLOW_DE_REn : 1; //P00 + bool VALUE_NC_P01 : 1; //P01 + bool VALUE_NC_P02 : 1; //P02 + bool VALUE_RST_100K : 1; //P03 + bool VALUE_VALV1_DIR : 1; //P04 + bool VALUE_VALV1_EN : 1; //P05 + bool VALUE_VALV2_DIR : 1; //P06 + bool VALUE_VALV2_EN : 1; //P07 - bool IN_FANS_BREAK : 1; //p10 - bool IN_FAN_ALART_12 : 1; //p11 - bool IN_FAN_ALART_34 : 1; //p12 - bool IN_FAN_ALART_56 : 1; //p13 - bool IN_NC_p14 : 1; //p14 - bool IN_NC_p15 : 1; //p15 - bool IN_NC_p16 : 1; //p16 - bool IN_NC_p17 : 1; //p17 + bool VALUE_RST_I2C_485 : 1; //p10 + bool VALUE_NC_p11 : 1; //p11 + bool VALUE_NC_p12 : 1; //p12 + bool VALUE_NC_p13 : 1; //p13 + bool VALUE_NC_p14 : 1; //p14 + bool VALUE_NC_p15 : 1; //p15 + bool VALUE_NC_p16 : 1; //p16 + bool VALUE_NC_p17 : 1; //p17 }bits; unsigned char uchar[2]; unsigned short ushort; -}WHS_I2C_EXP1_0x40; +}WHS_I2C_EXP_U4_0x42_VALUE; -//I2C expander: U4 0x42 typedef union { struct @@ -101,8 +143,7 @@ typedef union }bits; unsigned char uchar[2]; unsigned short ushort; -}WHS_I2C_EXP2_0x42; - +}WHS_I2C_EXP_U4_0x42_DIRECTION; @@ -110,19 +151,23 @@ typedef union -extern WHS_I2C_EXP1_0x40 Whs_I2C_EXP1_0x40; -extern WHS_I2C_EXP2_0x42 Whs_I2C_EXP2_0x42; +extern WHS_I2C_EXP_U3_0x40_DIRECTION Whs_I2C_EXP_U3_0x40_DIRECTION; +extern WHS_I2C_EXP_U4_0x42_DIRECTION Whs_I2C_EXP_U4_0x42_DIRECTION; +extern WHS_I2C_EXP_U3_0x40_VALUE Whs_I2C_EXP_U3_0x40_VALUE; +extern WHS_I2C_EXP_U4_0x42_VALUE Whs_I2C_EXP_U4_0x42_VALUE; -/* -extern HEAD_I2C_EXP3_0x44 Head_I2C_EXP1_0x44; -extern HEAD_I2C_EXP4_0x46 Head_I2C_EXP1_0x46; -*/ -uint32_t WHS_IO_Init(); -uint32_t WHS_Write_IO_Reg(uint8_t TCA9555_ADDRESS); -uint32_t WHS_Read_IO_Reg(uint8_t TCA9555_ADDRESS); +bool WHS_IO_Init(); +bool WHS_Write_IO_AllReg(uint8_t TCA9555_ADDRESS); +bool WHS_Write_IO(WHS_chip_address TCA9555_ADDRESS, TCA9555_port_num port_num); +bool WHS_Read_IO_Reg(uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, uint8_t *data); +bool WHS_Get_IO_Reg(uint8_t TCA9555_ADDRESS, TCA9555_port_num port_num, bool bit_num, bool *data); +bool Write_WHS_valve(uint8_t valve_number, bool state, bool direction); +bool Write_WHS_pump(bool state); //------------------------------ uint8_t WHS_Test_IO(); +bool Test_WHS_valve(); +bool Test_WHS_pump(); #endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_IO_PORTS_TCA9555_WHS_IO_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.c b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.c deleted file mode 100644 index 1f1b74dec..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - * PT100_ADC.c - * - * Created on: Jun 30, 2019 - * Author: avi - */ - -/* -PT100 ADS122C04IRTE -ADDR 0x80 -ADDR 0x81 -ADDR 0x82 -ADDR 0x83 -ADDR 0x84 -ADDR 0x85 -ADDR 0x86 -ADDR 0x87 -*/ - -#include "include.h" -#include "modules/control/millisecTask.h" -#include "Modules/AlarmHandling/AlarmHandling.h" -#include "PT100_ADC.h" -#include "ADS122X04.h" -//#include "PT100RTD.h" -#include <DataDef.h> -#include "../I2C_Head_Mux.h" -#include "drivers/I2C_Communication/I2C.h" - -uint32_t I2C_ADC_ADS122C04_SLAVE_ADD = 0x80; //A0-GND A1-GND 4-Bit, 4-Channel, 2-kSPS, ADC ------ PT100 ADC – 0x80 … 0x87. - -uint32_t SensorId_To_SlaveAdd(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - switch(SensorId) - { - case TEMP_SENSE_ANALOG_DYEINGH_TEMP1: - case TEMP_SENSE_ANALOG_DYEINGH_TEMP2: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x80; - break; - case TEMP_SENSE_ANALOG_DYEINGH_TEMP3: - case TEMP_SENSE_ANALOG_DYEINGH_TEMP4: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x81; - break; - case TEMP_SENSE_ANALOG_DYEINGH_TEMP5: - //case TEMP_SENSE_ANALOG_DYEINGH_TEMP6: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x82; - break; - /* - case TEMP_SENSE_ANALOG_DYEINGH_TEMP7: - case TEMP_SENSE_ANALOG_DYEINGH_TEMP8: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x83; - break; - case TEMP_SENSE_ANALOG_DYEINGH_TEMP9: - case TEMP_SENSE_ANALOG_DYEINGH_TEMP10: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x84; - break; - case TEMP_SENSE_ANALOG_DYEINGH_TEMP11: - case TEMP_SENSE_ANALOG_DYEINGH_TEMP12: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x85; - break; - case TBD1: - case TBD2: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x86; - break; - case TBD3: - case TBD4: - I2C_ADC_ADS122C04_SLAVE_ADD = 0x87; - break; - */ - default: - break; - } - - return I2C_ADC_ADS122C04_SLAVE_ADD; -} - -uint32_t I2C_Write_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Write_buf, uint32_t No_BytesToWrite ) -{ - uint32_t status = OK; - - I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); - status |= I2C_Write(I2C_ID, I2C_ADC_ADS122C04_SLAVE_ADD, I2C_Write_buf, No_BytesToWrite); - - return status; -} - -uint32_t HeadADCPT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - uint32_t Status = OK; - - uint8_t Write_Buf[2]; - - if(SensorId % 2) - HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x03; // TBD - else - HeadTempSensConfig[SensorId].Reg0.bits.MUX = 0x04; // TBD - - Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); - Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; - - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); - - return Status; -} - - -uint32_t I2C_Read_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Read_buf, uint32_t No_BytesToRead ) -{ - uint32_t status = OK; - - //HeadADCPT100_ControlMux_Brfore_Reading(SensorId); - //TODO Choose TEMP1 sensor by I/O - I2C_ADC_ADS122C04_SLAVE_ADD = SensorId_To_SlaveAdd(SensorId); - status |= I2C_Read(I2C_ID, I2C_ADC_ADS122C04_SLAVE_ADD + 1, I2C_Read_buf, No_BytesToRead); - - return status; -} - -uint32_t HeadADCPT100_Reset(void) -{ - #ifndef EVALUATION_BOARD - uint32_t status = OK; - uint8_t i; - uint8_t Write_Buf[1]; - - for(i=0;i<MAX_TEMPERATURE_SENSOR_ID; i++) - { - //Reset the device - Write_Buf[0] = ADS122X_RESET_CMD; - //Select_Main_Head_Mux_Channel(); - status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, i, Write_Buf, 1); - //status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); - //Wait at least (50 us + 32 · t(CLK)) after the RESET command is sent before sending any other command. - - } - #endif - SysCtlDelay(100); // Must delay after hard reset - - return status; -} - - -uint32_t HeadADCPT100_StartSync(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - uint32_t Status = OK; - uint8_t Write_Buf[1]; - - if(SensorId > MAX_TEMPERATURE_SENSOR_ID) - Status = ERROR; - - Write_Buf[0] = ADS122X_START_CMD; - - //Select_Main_Head_Mux_Channel(); - - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); - //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); - - return Status; -} - -uint32_t HeadADCPT100_PowerDown(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - uint32_t Status = OK; - uint8_t Write_Buf[1]; - - if(SensorId > MAX_TEMPERATURE_SENSOR_ID) - Status = ERROR; - - Write_Buf[0] = ADS122X_POWERDOWN_CMD; - - Select_Main_Head_Mux_Channel(); - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); - //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); - - return Status; -} - -uint32_t Data_ADC_Head = 0; -uint32_t HeadADCPT100_SendReadDataCommand(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - uint32_t Status = OK; - uint8_t Write_Buf[1]; - - uint32_t temp; - - if(SensorId > MAX_TEMPERATURE_SENSOR_ID) - Status = ERROR; - - //Write_Buf[0] = ADS122X_RDATA_CMD; - Write_Buf[0] = ADS122X_RDATA_CMD; - - //Select_Main_Head_Mux_Channel(); - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); - //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 1); - - Status |= I2C_Read_SensorId(I2C_ID_HEAD_CARD, SensorId, &temp, 3); - Data_ADC_Head = (temp & 0xFF0000) >> 16 | (temp & 0xFF00) | (temp & 0x0000FF) << 16;//First send the MSB so we need to reorder the bytes - - CalculateTemperatures(SensorId, Data_ADC_Head); - - - return Status; -} - -uint32_t HeadADCPT100_WriteReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t writeValue) -{ - uint32_t Status = OK; - uint8_t Write_Buf[2]; - - if(SensorId > MAX_TEMPERATURE_SENSOR_ID) - Status = ERROR; - - Write_Buf[0] = ADS122X_WRITE_CMD(reg); - Write_Buf[1] = writeValue; - - Select_Main_Head_Mux_Channel(); - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); - //Status |= I2C_Write(I2C_ID_HEAD_CARD, I2C_ADC_ADS122C04_SLAVE_ADD, Write_Buf, 2); - - return Status; -} - -uint8_t HeadADCPT100_InitConfigReg() -{ - uint8_t i; - - for(i=0;i<MAX_TEMPERATURE_SENSOR_ID;i++) // for now we are using the same configuration to all of them - { - // - - - - - - - - - - Reg0 - - - - - - - - - - - HeadTempSensConfig[i].Reg0.bits.PGA_BYPASS = ADS122X_USE_PGA ;//Bit 0 - HeadTempSensConfig[i].Reg0.bits.GAIN = ADS122X_GAIN_8 ;//Bits 1-3 - HeadTempSensConfig[i].Reg0.bits.MUX = ADS122X_MUX_AIN1_AIN0 ;//Bits 4-7 - - // - - - - - - - - - - Reg1 - - - - - - - - - - - - HeadTempSensConfig[i].Reg1.bits.TS = ADS122X_TEMP_SENSOR_OFF ;//Bit 0 - HeadTempSensConfig[i].Reg1.bits.VREF = ADS122X_VREF_INTERNAL ;//Bits 1-2 - HeadTempSensConfig[i].Reg1.bits.CM = ADS122X_CONVERSION_CONTINUOUS ;//Bit 3 - HeadTempSensConfig[i].Reg1.bits.MODE = ADS122X_OP_MODE_NORMAL ;//Bit 4 - HeadTempSensConfig[i].Reg1.bits.DR = ADS122X_DATA_RATE_20SPS ;//Bits 5-7 - - // - - - - - - - - - - Reg2 - - - - - - - - - - - - HeadTempSensConfig[i].Reg2.bits.IDAC = ADS122X_IDAC_CURRENT_500_UA ;//Bits 0-2 - HeadTempSensConfig[i].Reg2.bits.BCS = ADS122X_BCS_CURRENT_SOURCES_OFF ;//Bit 3 - HeadTempSensConfig[i].Reg2.bits.CRC = ADS122X_CRC_DISABLED ;//BitS 4-5 - HeadTempSensConfig[i].Reg2.bits.DCNT = ADS122X_DCNT_CONVERSION_COUNTER_DISABLED ;//Bit 6 - HeadTempSensConfig[i].Reg2.bits.DRDY = ADS122X_DRDY_NO_NEW_CONVERSION ;//Bit 7 - - // - - - - - - - - - - Reg3 - - - - - - - - - - - HeadTempSensConfig[i].Reg3.bits.Always_write_0 = ADS122X_RESERVED_WRITE_0 ;//BitS 0-1 Always write 0 - HeadTempSensConfig[i].Reg3.bits.I2MUX = ADS122X_IDAC2_DISABLED ;//Bits 2-4 - HeadTempSensConfig[i].Reg3.bits.I1MUX = ADS122X_IDAC1_AIN3 ;//Bits 5-7 - - } - - return OK; -} - - -uint32_t HeadADCPT100_Config_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t Stage) -{ - uint32_t Status = OK; - - #ifndef EVALUATION_BOARD - - uint8_t Write_Buf[2]; - - if (SensorId > MAX_TEMPERATURE_SENSOR_ID) - return ERROR; - - switch(Stage) - { - case SENSOR_CONFIG_REG0: - Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_0_REG<<2); - Write_Buf[1] = HeadTempSensConfig[SensorId].Reg0.Byte; - break; - case SENSOR_CONFIG_REG1: - Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_1_REG<<2); - Write_Buf[1] = HeadTempSensConfig[SensorId].Reg1.Byte; - break; - case SENSOR_CONFIG_REG2: - Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_2_REG<<2); - Write_Buf[1] = HeadTempSensConfig[SensorId].Reg2.Byte; - break; - case SENSOR_CONFIG_REG3: - Write_Buf[0] = ADS122X_WREG_CMD | (ADS122X_CONFIG_3_REG<<2); - Write_Buf[1] = HeadTempSensConfig[SensorId].Reg3.Byte; - break; - default: - Status = ERROR; - } - - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 2); - - #endif - - return Status; -} - -void HeadADCPT100_SensorInitConfig() -{ - int Sensor=0,Register = 0; - - HeadADCPT100_InitConfigReg(); // Initial the configuration registers - - for(Register=0;Register<=SENSOR_CONFIG_REG3;Register++) - { - for(Sensor=0;Sensor<MAX_TEMPERATURE_SENSOR_ID;Sensor++) - { - HeadADCPT100_Config_callback( (TEMPERATURE_SENSOR_ID_ENUM)(Sensor), Register); - } - SysCtlDelay(1000); - } -} - - -uint32_t HeadADCPT100_ReadReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t *readValue) -{ - uint32_t Status = OK; - - uint8_t Write_Buf[1]; - - Write_Buf[0] = ADS122X_READ_CMD(reg); - - Status |= I2C_Write_SensorId(I2C_ID_HEAD_CARD, SensorId, Write_Buf, 1); - delayUs(1); // delayUs(50); - Status |= I2C_Read_SensorId(I2C_ID_HEAD_CARD, SensorId, readValue, 1); - - return Status; -} - -uint8_t Test_Read_Buf[4] = {0,0,0,0}; - -uint32_t Test_HeadCard_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId) -{ - uint32_t Status = OK; - uint8_t i = 0; - - #ifdef Test_headCard_With_DispCard_I2C4_Add0xE2_DispID_0 - Select_Main_Head_Mux_Channel_test(); - #else - Select_Main_Head_Mux_Channel(); - #endif - - //HeadADCPT100_Reset(); - HeadADCPT100_InitConfigReg(); - - - HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG0); - HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG1); - HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG2); - HeadADCPT100_Config_callback(SensorId, SENSOR_CONFIG_REG3); - - HeadADCPT100_StartSync(SensorId); - - - - uint8_t Write_Buf[4] = {SENSOR_CONFIG_REG0,SENSOR_CONFIG_REG1,SENSOR_CONFIG_REG2,SENSOR_CONFIG_REG3}; - - for(i=0; i<4; i++) - { - HeadADCPT100_ReadReg(SensorId, Write_Buf[i], &Test_Read_Buf[i]); - - } - - HeadADCPT100_SendReadDataCommand(SensorId); - - - return Status; -} - -uint32_t HeadADCPT100_Calc_Resistance(TEMPERATURE_SENSOR_ID_ENUM SensorId, unsigned int Current_Measurement) -{ - - #define Rref 1650 //ohm - - uint32_t HeadADCPT100_Resistance_100; - - unsigned int Factor_2Rref_E_H; - unsigned int Factor_2Rref_E_L; - - //Resistance = Measurement / (2^23) *4 * Rref / Gain //---------------------- is it *4 ???? - - Factor_2Rref_E_H = 400 * Rref; // 200 to calculate Resistance*100 - - Factor_2Rref_E_L = 8388608 * (2<<(TempSensConfig[SensorId].Reg0.bits.GAIN -1));//2^23*Gain - - HeadADCPT100_Resistance_100 = (float)Current_Measurement / (float)Factor_2Rref_E_L * (float)Factor_2Rref_E_H; - - return HeadADCPT100_Resistance_100; -} diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.h deleted file mode 100644 index ed204dde5..000000000 --- a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/PT100/PT100_ADC.h +++ /dev/null @@ -1,127 +0,0 @@ -/* - * PT100_ADC.h - * - * Created on: Jun 30, 2019 - * Author: avi - * update to WHS by Shai 12.11.2019 - */ - -#ifndef DRIVERS_I2C_COMMUNICATION_HEAD_CARD_PT100_PT100_ADC_H_ -#define DRIVERS_I2C_COMMUNICATION_HEAD_CARD_PT100_PT100_ADC_H_ - -extern uint32_t I2C_ADC_ADS122C04_SLAVE_ADD; - -extern uint32_t Data_ADC_Head; - -enum -{ - //16 channels for temperature measuring - HEAD_PT100_ZONE_1_0X80_0, //0 - HEAD_PT100_ZONE_2_0X80_1, //1 - HEAD_PT100_ZONE_3_0X82_0, //2 - HEAD_PT100_ZONE_4_0X82_1, //3 - HEAD_PT100_ZONE_5_0X84_0, //4 - HEAD_PT100_ZONE_6_0X84_1, //5 - HEAD_PT100_ZONE_7_0X86_0, //6 - HEAD_PT100_ZONE_8_0X86_1, //7 - HEAD_PT100_ZONE_9_0X88_0, //8 - HEAD_PT100_ZONE_10_0X88_1, //9 - HEAD_PT100_ZONE_11_0X8A_0, //10 - HEAD_PT100_ZONE_12_0X8A_1, //11 - HEAD_PT100_AIR_HEATER_1_0X8C_0, //12 - HEAD_PT100_AIR_HEATER_2_0X8C_1, //13 - HEAD_PT100_MIXER_0X8E_0, //14 - HEAD_PT100_RESERVE_0X8E_1, //15 -}HEAD_PT100; - -#define HEAD_CONFIG_GAIN ADS122X_GAIN_8 -#define HEAD_CONFIG_IDAC ADS122X_IDAC_CURRENT_1000_UA -#define HEAD_CONFIG_I1MUX ADS122X_IDAC2_AIN0 -#define HEAD_CONFIG_I2MUX ADS122X_IDAC1_AIN3 - -#define HEAD_CONFIG_EVEN_PT100_MUX ADS122X_MUX_AIN0_AIN1 -#define HEAD_CONFIG_ODD_PT100_MUX ADS122X_MUX_AIN3_AIN2 - -#define HEAD_CONFIG_EVEN_PT100_PT_SEL 0X00 -#define HEAD_CONFIG_ODD_PT100_PT_SEL 0X01 - -typedef union -{ - struct - { - unsigned char PGA_BYPASS:1; // - unsigned char GAIN :3; // - unsigned char MUX :4; // - }bits; - unsigned char Byte; -}ADS122C04_CONFIG_REGISTER_0; - -typedef union -{ - struct - { - unsigned char TS :1; // - unsigned char VREF:2; // - unsigned char CM :1; // - unsigned char MODE:1; // - unsigned char DR :3; // - }bits; - unsigned char Byte; -}ADS122C04_CONFIG_REGISTER_1; - -typedef union -{ - struct - { - unsigned char IDAC:3; // - unsigned char BCS :1; // - unsigned char CRC :2; // - unsigned char DCNT:1; // - unsigned char DRDY:1; // - }bits; - unsigned char Byte; -}ADS122C04_CONFIG_REGISTER_2; - -typedef union -{ - struct - { - unsigned char Always_write_0:2; // - unsigned char I2MUX:3; // - unsigned char I1MUX:3; // - }bits; - unsigned char Byte; -}ADS122C04_CONFIG_REGISTER_3; - -typedef struct -{ - ADS122C04_CONFIG_REGISTER_0 Reg0; // - ADS122C04_CONFIG_REGISTER_1 Reg1;// - ADS122C04_CONFIG_REGISTER_2 Reg2; - ADS122C04_CONFIG_REGISTER_3 Reg3; - -}HeadBoardTempSensConfigStruc; - -HeadBoardTempSensConfigStruc HeadTempSensConfig[MAX_TEMPERATURE_SENSOR_ID]; - - -uint32_t SensorId_To_SlaveAdd(TEMPERATURE_SENSOR_ID_ENUM SensorId); -uint32_t I2C_Write_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Write_buf, uint32_t No_BytesToWrite ); -uint32_t HeadADCPT100_ControlMux_Brfore_Reading(TEMPERATURE_SENSOR_ID_ENUM SensorId); -uint32_t I2C_Read_SensorId(uint32_t I2C_ID, TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t *I2C_Read_buf, uint32_t No_BytesToRead ); -uint32_t HeadADCPT100_Reset(void); -uint32_t HeadADCPT100_StartSync(TEMPERATURE_SENSOR_ID_ENUM SensorId); -uint32_t HeadADCPT100_PowerDown(TEMPERATURE_SENSOR_ID_ENUM SensorId); -uint32_t HeadADCPT100_SendReadDataCommand(TEMPERATURE_SENSOR_ID_ENUM SensorId); -uint32_t HeadADCPT100_WriteReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t writeValue); -uint8_t HeadADCPT100_InitConfigReg(); -uint32_t HeadADCPT100_Config_callback(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint32_t Stage); -uint32_t HeadADCPT100_ReadReg(TEMPERATURE_SENSOR_ID_ENUM SensorId, uint8_t reg, uint8_t *readValue); -void HeadADCPT100_SensorInitConfig(); -uint32_t HeadADCPT100_Calc_Resistance(TEMPERATURE_SENSOR_ID_ENUM SensorId, unsigned int Current_Measurement); - - - -uint32_t Test_HeadCard_PT100(TEMPERATURE_SENSOR_ID_ENUM SensorId); - -#endif /* DRIVERS_I2C_COMMUNICATION_HEAD_CARD_PT100_PT100_ADC_H_ */ diff --git a/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/WHS_data.h b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/WHS_data.h new file mode 100644 index 000000000..3d6bbc462 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Drivers/I2C_Communication/WHS_Card/WHS_data.h @@ -0,0 +1,33 @@ +/* + * WHD_data.h + * + * Created on: Jun 30, 2019 + * Author: Shai + */ + +#ifndef DRIVERS_I2C_COMMUNICATION_WHS_CARD_DATA_H_ +#define DRIVERS_I2C_COMMUNICATION_WHS_CARD_DATA_H_ + +//#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" + + + +#define I2C_ID_WHS_CARD 0x03 +#define I2C2_MAIN_MUX_TCA9548A_0xE0 0xE0 //WHS - SD1, SC1 + +typedef enum +{ + I2CExp1_ADDRESS = 0x40, + I2CExp2_ADDRESS = 0x42, + I2CSwitch_ADDRESS = 0xE8, + I2CFanViaSwitch_ADDRESS = 0x5C, + I2CTemp1_ADDRESS = 0x80, + I2CTemp2_ADDRESS = 0x82, + I2CDAC_ADDRESS = 0x30, + I2CADC_ADDRESS = 0x66, + I2CEEPROM_ADDRESS = 0xA0, + I2CRheosts_ADDRESS = 0x58 +}WHS_chip_address; + +#endif /* DRIVERS_I2C_COMMUNICATION_WHS_CARD_DATA_H_ */ + diff --git a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c index 5f2046c3e..598c5df8a 100644 --- a/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c +++ b/Software/Embedded_SW/Embedded/Modules/General/GeneralHardware.c @@ -150,7 +150,9 @@ uint32_t HWConfigurationInit(void) //ProcessParamsInit(); Buttons_Init(); WHS_init(); - +#ifdef Use_WHS_Card + newWHS_init(); +#endif ADC_MUX_Init(); GeneralHwReady = true; diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_maint.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_maint.c index c49fd81f0..41452cbad 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_maint.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_maint.c @@ -476,7 +476,7 @@ uint32_t IDS_Dispenser_Alarm_On (uint8_t DispenserId) if (Extended_Motor_Param == true) Power_Step_01_Dispenser_Mode(DispenserId,Voltage); //status |= MotorSetMicroStep(MotorId, KeepMicrostep[DispenserId]); - status |= MotorStop(DispenserId, Hard_Hiz); + status |= MotorStop(MotorId, Hard_Hiz); IDS_Dispenser_Init(DispenserId); JobEndReason = JOB_OUT_OF_DYE; return status; @@ -509,7 +509,6 @@ uint32_t IDS_Check_Pressure_Callback(uint32_t DispenserId, uint32_t ReadValue) if (GetDispenserPressure(DispenserId)>3.0) { Report("Pulling dispenser down to reduce pressure",__FILE__,DispenserId,(int)(GetDispenserPressure(DispenserId)*100),RpWarning,200,0); - MotorMove(HW_Motor_Id,1-MotorsCfg[HW_Motor_Id].directionthreadwize,200*MotorsCfg[HW_Motor_Id].microstep); } return OK; diff --git a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c index 3af6416cb..9fdcaaf1f 100644 --- a/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c +++ b/Software/Embedded_SW/Embedded/Modules/IDS/IDS_print.c @@ -81,7 +81,7 @@ int lInterSegmentLength = 0; uint32_t InterSegmentStartWFCFDispensers; uint32_t WFCF = 80; bool EnableCleaning = true; - +bool JobEndSequence = false; void IDS_Dispenser_SetPreSegmentWFCFValues(double dispenserpresegmentwfcf, double ids_presegment_wfcf_timebeforesegment) { if (ids_presegment_wfcf_timebeforesegment) @@ -228,7 +228,7 @@ JobDescriptionFileBrushStop *FirstBrushStop = NULL; int brushCounter = 0; - GeneralHwReady = false; + //GeneralHwReady = false; for (Dispenser_i = 0;Dispenser_i<MAX_SYSTEM_DISPENSERS;Dispenser_i++) { DispenserUsedInJob[Dispenser_i] = false; @@ -317,7 +317,7 @@ JobDescriptionFileBrushStop *FirstBrushStop = NULL; FreeSegmentFileData(Segment); CloseJobFile(); } - GeneralHwReady = true; + //GeneralHwReady = true; int ActiveDispensers = 0; for (Dispenser_i = 0; Dispenser_i < MAX_DYE_DISPENSERS; Dispenser_i++) { @@ -657,6 +657,7 @@ uint32_t InactiveDispenserHome(uint32_t DispenserId, uint32_t ReadValue) //JobTicket* JobTicket = JobDetails; + JobEndSequence = false; if ((feedertension>0.1)&&(feedertension<1.5)) { Report("Setting pressure from RML feeder tension",__FILE__,__LINE__,(int)(feedertension*100),RpWarning,(int)(DispenserPreparePressure*100),0); @@ -733,7 +734,7 @@ uint32_t InactiveDispenserHome(uint32_t DispenserId, uint32_t ReadValue) } else { - /**/if (AutoHoming_Config >= AutoHoming_JobEnd_PowerOn_off) + if (AutoHoming_Config >= AutoHoming_JobEnd_PowerOn_off) { if ((HomingActive[i] == false)&&(PrimingActive[i] == false)) { @@ -744,26 +745,7 @@ uint32_t InactiveDispenserHome(uint32_t DispenserId, uint32_t ReadValue) { Report("Inactive dispenser already homing",__FILE__,i,HomingActive[i],RpWarning,PrimingActive[i],0); } - }/**/ - /*if ((HomingActive[i] == false)&&(PrimingActive[i] == false)) - { - Report("Inactive dispenser open valve",__FILE__,i,HomingActive[i],RpWarning,PrimingActive[i],0); - Control3WayValvesWithCallback (i, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer - Report("Homing Inactive dispenser",__FILE__,i,HomingActive[i],RpWarning,PrimingActive[i],0); - IDS_HomeDispenser (i, 1000 , NULL); - } - else - { - Report("Inactive dispenser already homing",__FILE__,i,HomingActive[i],RpWarning,PrimingActive[i],0); - } - }*/ - //if ((HomingActive[i] == false)&&(PrimingActive[i] == false)) - //{ - // Report("Inactive dispenser open valve",__FILE__,i,HomingActive[i],RpWarning,PrimingActive[i],0); - // Control3WayValvesWithCallback (i, Dispenser_Mixer, NULL); //direction: MidTank_Dispenser or Dispenser_Mixer - //} - //ControlIdtoInactiveDispenserId[Dispenser_i] = AddControlCallback( IDS_Check_Pressure_Callback, eOneMinute,TemplateDataReadCBFunction ,0, 0, 0 ); - + } } } if (NumOfActiveDispensers) @@ -1401,6 +1383,12 @@ uint32_t IDSBrushStopRestartCallback(uint32_t IfIndex, uint32_t readValue) int n_dispensers = 0; JobSegment* Segment = (void *)IfIndex; + if (JobEndSequence == true) + { + Report("JobEndSequence",__FILE__,__LINE__,(int)JobBrushStopId,RpWarning,(int)SegmentNumOfBrushStops,0); + SafeRemoveControlCallback(BrushStopControlId,IDSBrushStopRestartCallback); + BrushStopControlId = 0Xff; + } if (uploadstrategy == JOB_UPLOAD_STRATEGY__Default) { Dispensers = Segment->brushstops[JobBrushStopId]->dispensers; @@ -1464,10 +1452,10 @@ uint32_t IDSSegmentState(void *SegmentDetails, int SegmentId) #endif IDS_Cleaning_Stop_Cleaning_Solution(NULL); SegmentNumOfBrushStops = Segment->n_brushstops; - BrushStopTime = Segment->length/SegmentNumOfBrushStops; //brushstop in meters + BrushStopTime = Segment->length*1000/(double)SegmentNumOfBrushStops; //brushstop in meters //brushstop in millisecond BrushStopTime = ((BrushStopTime*100)/dyeingspeed);//brushstop in seconds - BrushStopTime *= 1000; //brushstop in millisecond - Report("IDSSegmentState",__FILE__,__LINE__,(int)BrushStopTime,RpWarning,(int)SegmentNumOfBrushStops,0); + //BrushStopTime *= 1000; + Report("IDSSegmentState",__FILE__,__LINE__,(int)(BrushStopTime*1000),RpWarning,(int)SegmentNumOfBrushStops,0); if (uploadstrategy == JOB_UPLOAD_STRATEGY__Default) { Dispensers = Segment->brushstops[JobBrushStopId]->dispensers; @@ -1557,7 +1545,7 @@ uint32_t IDSSegmentState(void *SegmentDetails, int SegmentId) if (FileBrushStop) FreeBrushStopFileData(FileBrushStop); FileBrushStop = NULL; - + JobEndSequence = true; lInterSegmentLength = (dryerbufferCentimeters*1000/dyeingspeed); lInterSegmentLength-=(lInterSegmentLength%100); //round to a 100 multiplication InterSegmentStepsCount = 0; diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c index 373e4bbd9..13b98bcb0 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/ThreadLoad.c @@ -445,7 +445,7 @@ MotorSetMaxSpeed (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1, 500); // MotorMovetoLimitSwitch (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1,MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, 500, Motor_Id_to_LS_IdDown[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1], Thread_Load_HomingCallback,25000); - MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, (2000*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].microstep), Thread_Load_HomingCallback,20000); + MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_LDANCER1, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].directionthreadwize, (5000*MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_LDANCER1].microstep), Thread_Load_HomingCallback,20000); return OK; } @@ -607,7 +607,7 @@ CallbackCounter++; Report("Thread_Load_Dryer_Loading",__FILE__,__LINE__,LoadStages,RpMessage,CallbackCounter,0); MotorMoveWithCallback (HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM, MotorsCfg[HARDWARE_MOTOR_TYPE__MOTO_DRYER_LOADARM].directionthreadwize, - numberOfSteps, Thread_Load_Dryer_Loading_Callback, 100000); + numberOfSteps-400, Thread_Load_Dryer_Loading_Callback, 100000); //Keep Notation How Many Rotations In The Dryer //LoadArmInfo.LoadArmBackLash = 0; @@ -1079,7 +1079,6 @@ uint32_t ThreadLoadingReport(void) MessageContainer responseContainer; bool last = false; StartThreadLoadingResponse response = START_THREAD_LOADING_RESPONSE__INIT; - ContinueThreadLoadingResponse Cresponse = CONTINUE_THREAD_LOADING_RESPONSE__INIT; if (ThreadLoadingToken[0] == 0) return OK; @@ -1093,7 +1092,6 @@ uint32_t ThreadLoadingReport(void) if (LoadStages == THREAD_LOAD_INITIAL_TENSION) { response.state = THREAD_LOADING_STATE__ReadyForLoading; - last = true; } } else @@ -1101,32 +1099,30 @@ uint32_t ThreadLoadingReport(void) response.state = THREAD_LOADING_STATE__PreparationError; response.errorreason = LoadErrorMsg; } - responseContainer = createContainer(MESSAGE_TYPE__StartThreadLoadingResponse, ThreadLoadingToken, last, &response, &start_thread_loading_response__pack, &start_thread_loading_response__get_packed_size); - responseContainer.continuous = true; } else if (MessageState == 2) { - Cresponse.has_state = true; + response.has_state = true; if (LoadStatus == OK) { - Cresponse.state = THREAD_LOADING_STATE__Finalizing; + response.state = THREAD_LOADING_STATE__Finalizing; if (LoadStages >= THREAD_LOAD_JOG_THREAD) { - Cresponse.state = THREAD_LOADING_STATE__Completed; + response.state = THREAD_LOADING_STATE__Completed; last = true; } } else { - Cresponse.state = THREAD_LOADING_STATE__FinalizationError; - Cresponse.errorreason = LoadErrorMsg; + response.state = THREAD_LOADING_STATE__FinalizationError; + response.errorreason = LoadErrorMsg; } - responseContainer = createContainer(MESSAGE_TYPE__ContinueThreadLoadingResponse, ThreadLoadingToken, last, &Cresponse, &continue_thread_loading_response__pack, &continue_thread_loading_response__get_packed_size); - responseContainer.continuous = true; } else return ERROR; //------------------------------------------------------------------------------------------- + responseContainer = createContainer(MESSAGE_TYPE__StartThreadLoadingResponse, ThreadLoadingToken, last, &response, &start_thread_loading_response__pack, &start_thread_loading_response__get_packed_size); + responseContainer.continuous = true; uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); size_t container_size = message_container__pack(&responseContainer, container_buffer); my_free(responseContainer.data.data); @@ -1149,9 +1145,16 @@ uint32_t StartThreadLoadingFunc(MessageContainer* requestContainer) uint32_t ContinueThreadLoadingFunc(MessageContainer* requestContainer) { ContinueThreadLoadingRequest *request = continue_thread_loading_request__unpack(NULL, requestContainer->data.len, requestContainer->data.data); - ustrncpy (ThreadLoadingToken, requestContainer->token,36); + ContinueThreadLoadingResponse Cresponse = CONTINUE_THREAD_LOADING_RESPONSE__INIT; + MessageContainer responseContainer; MessageState = 2; ThreadLoadingReport(); + responseContainer = createContainer(MESSAGE_TYPE__ContinueThreadLoadingResponse, requestContainer->token, true, &Cresponse, &continue_thread_loading_response__pack, &continue_thread_loading_response__get_packed_size); + responseContainer.continuous = false; + uint8_t* container_buffer = my_malloc(message_container__get_packed_size(&responseContainer)); + size_t container_size = message_container__pack(&responseContainer, container_buffer); + my_free(responseContainer.data.data); + SendChars((char*)container_buffer, container_size); return OK; } diff --git a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c index f0331b4bc..dd31e9cda 100644 --- a/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c +++ b/Software/Embedded_SW/Embedded/Modules/Thread/Thread_print.c @@ -722,6 +722,9 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) JobCounter = 0; TotalProcessedLength = 0.0; PoolerTotalProcessedLength = 0.0; + InitialProcess = true; + initialpos = 0xFFFF; + Poolerinitialpos = 0xFFFF; PrepareState = true; AlarmHandlingSetAlarm(EVENT_TYPE__THREAD_BREAK,false); AlarmHandlingSetAlarm(EVENT_TYPE__THREAD_TENSION_CONTROL_FAILURE_PULLER_DANCER,false); @@ -853,9 +856,6 @@ uint32_t ThreadInitialTestStub(HardwareMotor * request) #endif PrepareReady(Module_Thread,ModuleDone); //set 3 dancers to the profile positions - InitialProcess = true; - initialpos = 0xFFFF; - Poolerinitialpos = 0xFFFF; return OK; } diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c index c5c092ae4..65c124cbd 100644 --- a/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c +++ b/Software/Embedded_SW/Embedded/Modules/Waste/Waste_init.c @@ -371,10 +371,10 @@ bool SetValveDirection() U8 CartridgeWasteFilling(bool status) { bool ret = notOK; - SetValveDirection(); + //SetValveDirection(); if ((status == ON) && (WHS_info.active_cartridge != no_waste_cartridge)) { - //SetValveDirection();//Valve_Set(VALVE_WASTE_TANK, WHS_info.active_cartridge); //set the valve direction + SetValveDirection();//Valve_Set(VALVE_WASTE_TANK, WHS_info.active_cartridge); //set the valve direction //Pannel_Leds(PANEL_BUTTON_OR_CRAT_ID Pannel_Led_Id, OPERATION_MODE LED_Mode); //set cartridge led color slow blink SetWastePump(OPEN); //WHS_info.WHS_pump.time = 0; @@ -385,7 +385,7 @@ U8 CartridgeWasteFilling(bool status) else // stop Waste cartridge filling { SetWastePump(CLOSE); - //Valve_Set(VALVE_WASTE_TANK, VALVE_DIR_WAST_CARTRIDGE1); //set the valve direction set to low POWER !!! + Valve_Set(VALVE_WASTE_TANK, VALVE_DIR_WASTE_CARTRIDGE1); //set the valve direction set to low POWER !!! AlarmHandlingSetAlarm( EVENT_TYPE__ALL_WASTE_CARTRIDGES_FULL, true); switch (WHS_info.active_cartridge) @@ -498,7 +498,7 @@ bool initWHS_WasteTank() WHS_info.WHS_sensors.waste_tank_empty_sensor = RdWasteTankEmptySensor(); WHS_info.WHS_sensors.waste_tank_full_sensor = SENSORnotFULL; UpdateStateMachine(); - AddControlCallback(NULL,WasteTankCBFunction, WasteTankCallBackTime , WasteTankCallBackFunction, 0,0,0);//eOneMinute + AddControlCallback("Waste tank",WasteTankCBFunction, WasteTankCallBackTime , WasteTankCallBackFunction, 0,0,0);//eOneMinute return OK; } @@ -569,14 +569,6 @@ WHS_sensor WasteTankCallBackFunction() return ret; } -/* -bool start_WHS_machin() -{ - AddControlCallback( WasteTankCBFunction, eTenMillisecond, WasteTankCallBackFunction, 0,0,0 );// eOneMinute - return OK; -} - */ - bool WasteTankCBFunction() { @@ -744,7 +736,7 @@ bool WasteTankCBFunction() MidTankValvesAction(Cartridge_MidTank_ON); // test the Mid-tank capacity is not at Nadav sequence // Enable_MidTank_Pressure_Reading(IFS_info.Ink.cart_color); - MidTank_Pressure = Read_MidTank_Pressure_Sensor(IFS_info.Ink.cart_color); + MidTank_Pressure = Get_MidTank_Pressure_Sensor(IFS_info.Ink.cart_color); if ( MidTank_Pressure > MidTank_Pressure_EMPTY ) { ReportWithPackageFilter(WasteFilter,"------------ close door MidTank_Pressure > MidTank_Pressure_EMPTY -----------------", __FILE__,__LINE__,(MidTank_Pressure_EMPTY), RpMessage, (int)(MidTank_Pressure*1000), 0); @@ -932,7 +924,7 @@ bool WasteTankCBFunction() REPORT_MSG(WHS_full," ------------ call customer support ----------------- "); Pannel_Leds(CART_1, MODE_ON); cart1.color = fastBILNK; - //IFS_TimeOutAlarm(); + IFS_TimeOutAlarm(true); break; case IFS_MidTankFull: @@ -1172,11 +1164,11 @@ bool InitCartStatus() if (WHS_info.WHS_sensors.cartridge_cover == WHS_CartridgeCoverOPEN) { REPORT_MSG(parameter," ------------ WHS_CartridgeCoverOPEN : add callback for cart1 and cart 2 ----------------- "); - IFS_info.Cartridge_Ink_device_Id = AddControlCallback(NULL, WasteTankCBFunction, eOneSecond, CartridgeInkCallBackFunction, 0,0,0 ); - WHS_info.Cartridge_Waste1_device_Id = AddControlCallback(NULL, WasteTankCBFunction, eOneSecond, CartridgeWaste1CallBackFunction, 0,0,0 ); - WHS_info.Cartridge_Waste2_device_Id = AddControlCallback(NULL, WasteTankCBFunction, eOneSecond, CartridgeWaste2CallBackFunction, 0,0,0 ); + IFS_info.Cartridge_Ink_device_Id = AddControlCallback("Ink Cartridge CB" , WasteTankCBFunction, eOneSecond, CartridgeInkCallBackFunction , 0,0,0 ); + WHS_info.Cartridge_Waste1_device_Id = AddControlCallback("Waste1 Cartridge CB", WasteTankCBFunction, eOneSecond, CartridgeWaste1CallBackFunction, 0,0,0 ); + WHS_info.Cartridge_Waste2_device_Id = AddControlCallback("Waste2 Cartridge CB", WasteTankCBFunction, eOneSecond, CartridgeWaste2CallBackFunction, 0,0,0 ); } - WHS_info.Cartridge_Cover_device_Id = AddControlCallback(NULL, WasteTankCBFunction, eOneSecond, CartridgeCoverCallBackFunction, 0,0,0 ); + WHS_info.Cartridge_Cover_device_Id = AddControlCallback("Cartridge Cover Door", WasteTankCBFunction, eOneSecond, CartridgeCoverCallBackFunction, 0,0,0 ); return OK; } @@ -1216,22 +1208,27 @@ bool SetActiveWastCartridge() uint8_t parameter = 5; bool ret = notOK; - if (( WHS_info.WHS_sensors.waste_cartridge1_precense_sensor == PRECENSE ) && - (WHS_info.cartridge_1.autheticate == PASSED)) + if (( WHS_info.WHS_sensors.waste_cartridge1_precense_sensor == PRECENSE ) + && (WHS_info.cartridge_1.autheticate == PASSED) + && (WHS_info.cartridge_1.status == WasteEmpty)) { REPORT_MSG(parameter," ------------ WHS : active_cartridge = waste_cartridge 1 ----------------- "); WHS_info.active_cartridge = waste_cartridge1; + AlarmHandlingSetAlarm( EVENT_TYPE__NO_WASTE_CARTRIDGE_AVAILABLE, false); } - else if (( WHS_info.WHS_sensors.waste_cartridge2_precense_sensor == PRECENSE) && - (WHS_info.cartridge_2.autheticate == PASSED)) + else if (( WHS_info.WHS_sensors.waste_cartridge2_precense_sensor == PRECENSE) + && (WHS_info.cartridge_2.autheticate == PASSED) + && (WHS_info.cartridge_2.status == WasteEmpty)) { REPORT_MSG(parameter," ------------ WHS : active_cartridge = waste_cartridge 2 ----------------- "); WHS_info.active_cartridge = waste_cartridge2; + AlarmHandlingSetAlarm( EVENT_TYPE__NO_WASTE_CARTRIDGE_AVAILABLE, false); } else { REPORT_MSG(parameter," ------------ WHS : NO active_cartridge ----------------- "); WHS_info.active_cartridge = no_waste_cartridge; + AlarmHandlingSetAlarm( EVENT_TYPE__NO_WASTE_CARTRIDGE_AVAILABLE, true); } return ret; diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.c b/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.c new file mode 100644 index 000000000..d9801f179 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.c @@ -0,0 +1,48 @@ + + + + +#include "include.h" +#include <DataDef.h> +#include <Modules/Waste/newWHS_init.h> + +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/WHS_IO.h> +#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +#include <Drivers/I2C_Communication/WHS_Card/I2C_WHS_Mux.h> +#include <Drivers/I2C_Communication/I2C.h> +#include "Drivers/I2C_Communication/WHS_Card/WHS_data.h" +#include <Drivers/I2C_Communication/WHS_Card/EEPROM/WHS_EEPROM.h> +#include <Drivers/I2C_Communication/WHS_Card/D_EMC2302_Fan/WHS_Fan.h> +#include <Drivers/I2C_Communication/WHS_Card/D_Max5805_ADC/Max_5805.h> +bool test_9555(void); + + +bool newWHS_init(void) +{ + bool status = OK; +// status = Select_Main_WHS_Mux_Channel(); + status |= WHS_IO_Init(); + if (Test_WHS_EEPROM()!= OK) + { + ReportWithPackageFilter(WasteFilter,"------------ Test_WHS_EEPROM U32: test is failed-----------------", __FILE__,__LINE__,0, RpMessage, 0, 0); + } + status = Test_WHS_Fan(); + status = Test_WHS_blower(); + status |= Test_WHS_valve(); + status |= Test_WHS_pump(); + + //test_9555(); + return status; +} + + +bool test_9555(void) +{ + bool status = OK; + + status = D_TCA9555_Write_IO(I2C_ID_WHS_CARD, I2CExp1_ADDRESS, TCA9555_PORT_0, Whs_I2C_EXP_U3_0x40_VALUE.uchar[0]); + + return status; +} + + diff --git a/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.h b/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.h new file mode 100644 index 000000000..ca2894499 --- /dev/null +++ b/Software/Embedded_SW/Embedded/Modules/Waste/newWHS_init.h @@ -0,0 +1,20 @@ +/* + * newWHS_init.h + * + * Created on: Dec 11, 2019 + * Author: Shai + */ + +#ifndef newWHS_init_H_ +#define newWHS_init_H_ + +//#include <Drivers/I2C_Communication/WHS_Card/IO_Ports_TCA9555/TCA9555_Driver.h> +//#include <Drivers/I2C_Communication/WHS_Card/WHS_data.h> + + + + +bool newWHS_init(void); + + +#endif diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs index 15ab21575..facaa358a 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/FlowAnalyser.cs @@ -30,17 +30,36 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers List<DispenserSample> rangeTestValues = csvRows.Where(x => x.Index > pair[0].Index && x.Index < pair[1].Index).ToList(); if (index%2 == 1)//testing Flow-error { - int count_before = rangeTestValues.Count; + + List<DispenserSample> test_data = new List<DispenserSample>{ + new DispenserSample{ Index = 1, Pressure = 1.0 }, + new DispenserSample{ Index = 2, Pressure = 5.0 }, + new DispenserSample{ Index = 3, Pressure = 2.0 }, + new DispenserSample{ Index = 4, Pressure = 4.0 }, + new DispenserSample{ Index = 5, Pressure = 1.0 }, + new DispenserSample{ Index = 6, Pressure = 2.0 }, + new DispenserSample{ Index = 7, Pressure = 1.0 }, + new DispenserSample{ Index = 8, Pressure = 3.0 }, + new DispenserSample{ Index = 9, Pressure = 10.0 }, + new DispenserSample{ Index = 10, Pressure = 1.0 }, + new DispenserSample{ Index = 11, Pressure = 2.0 }, + new DispenserSample{ Index = 12, Pressure = 1.0 }, + new DispenserSample{ Index = 13, Pressure = 2.0 } + }; ProcessOutliers processOutliers = new ProcessOutliers(); List<DispenserSample> peaks = new List<DispenserSample>(); - // processOutliers.RemoveOutliers(rangeTestValues, peaks); - int count_after = rangeTestValues.Count; + processOutliers.RemoveOutliers(rangeTestValues, peaks); + + //HammingFilter filter = new HammingFilter(); + //List<DispenserSample> filteredData = filter.Filtering(rangeTestValues); + //rangeTestValues = filteredData; FlowAnalyzerResult result = new FlowAnalyzerResult(); result.AverageValue = rangeTestValues.Average(t => t.Pressure); result.MinValue = rangeTestValues.Min(t => t.Pressure); result.MaxValue = rangeTestValues.Max(t => t.Pressure); result.TotalValue = result.AverageValue == 0 ? 0 : (result.MaxValue - result.MinValue) * 100 / result.AverageValue; + //local test int startIndex = rangeTestValues.Count > 0 ? rangeTestValues[0].Index :0; int lastIndex = rangeTestValues.Count > 0 ? rangeTestValues[rangeTestValues.Count-1].Index : 0; int delayIndex = (startIndex + 10000) < lastIndex ? startIndex + 10000 : lastIndex; @@ -50,6 +69,7 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers result.FilterMinValue = filterTestValues.Min(t => t.Pressure); result.FilterMaxValue = filterTestValues.Max(t => t.Pressure); result.FilterTotalValue = result.FilterAverageValue == 0 ? 0 : (result.FilterMaxValue - result.FilterMinValue) * 100 / result.FilterAverageValue; + result.Result = (result.FilterTotalValue <= 1.5 && result.TotalValue <= 3) ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; results.Add(result); } @@ -161,6 +181,46 @@ namespace Tango.DispenserAnalyzer.UI.Analyzers } } - + public class HammingFilter + { + public decimal Coeff { get; set; } + public decimal[] CoeffArr { get; set; } + + public HammingFilter() + { + //CreateCoeffArr(2.5m); + CoeffArr = new decimal[]{ 0.008478873m, 0.069751134m, 0.245035116m, 0.353469754m, 0.245035116m, 0.069751134m, 0.008478873m }; + Coeff = 1.0m; + + + } + public List<DispenserSample> Filtering(List<DispenserSample> source) + { + List<DispenserSample> target = new List<DispenserSample>(); + decimal sum = 0.0m; + int index = 0; + + for (; index <= source.Count - CoeffArr.Length; index++) + { + sum = 0.0m; + for (int coeff_index = 0; coeff_index < CoeffArr.Length; coeff_index++) + { + sum += this.CoeffArr[coeff_index] * (decimal)source[index + coeff_index].Pressure; + } + decimal test_newValue = sum / Coeff; + DispenserSample newValue = new DispenserSample() + { + Index = source[index].Index, + Pressure = (double)(sum / Coeff), + }; + target.Add(newValue); + } + for (; index < source.Count; index++) + { + target.Add(source[index]); + } + return target; + } + } } } |
