VPU 28.02

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
margadon
Date:
Fri Feb 27 12:13:49 2015 +0000
Commit message:
VPU 28.02

Changed in this revision

IO.h Show annotated file Show diff for this revision Revisions of this file
Package.cpp Show annotated file Show diff for this revision Revisions of this file
Package.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
types.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c645b762b2c0 IO.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/IO.h	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,34 @@
+// B7,6,5,4,C12,11,10,A15,12,11,10,9,8,C9,8,C3
+DigitalIn In1(PB_7);
+DigitalIn In2(PB_6);
+DigitalIn In3(PB_5);
+DigitalIn In4(PB_4);
+DigitalIn In5(PC_12);
+DigitalIn In6(PC_11);
+DigitalIn In7(PC_10);
+DigitalIn In8(PA_15);
+DigitalIn In9(PA_12);
+DigitalIn In10(PA_11);
+DigitalIn In11(PA_10);
+DigitalIn In12(PA_9);
+DigitalIn In13(PA_8);
+DigitalIn In14(PC_9);
+DigitalIn In15(PC_8);
+DigitalIn In16(PC_3);
+//(A0-A7-1-8, B0-B2,B10-9-12, B12-B15-13-16)
+DigitalOut Out1(PA_0);
+DigitalOut Out2(PA_1);
+DigitalOut Out3(PA_2);
+DigitalOut Out4(PA_3);
+DigitalOut Out5(PA_4);
+DigitalOut Out6(PA_5);
+DigitalOut Out7(PA_6);
+DigitalOut Out8(PA_7);
+DigitalOut Out9(PB_0);
+DigitalOut Out10(PB_1);
+DigitalOut Out11(PB_2);
+DigitalOut Out12(PB_10);
+DigitalOut Out13(PB_12);
+DigitalOut Out14(PB_13);
+DigitalOut Out15(PB_14);
+DigitalOut Out16(PB_15);
\ No newline at end of file
diff -r 000000000000 -r c645b762b2c0 Package.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Package.cpp	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,341 @@
+
+#include "mbed.h"
+#include "Package.h"
+
+
+
+FUNCTION_RETURN CheckMarker(PACKAGE_I2C_RX package)
+{
+    if (package.data.marker == DEFAULT_MARKER || 
+            package.data.marker == INIT_MARKER ||
+            package.data.marker == TEST_BLINK_MARKER)
+    {
+        if (package.data.marker == TEST_BLINK_MARKER)
+        {
+            return FUNCTION_TESTBLINK;
+        }
+        return FUNCTION_SUCCESS;
+    }
+    return FUNCTION_ERROR;
+}
+
+FUNCTION_RETURN CheckGroups(PACKAGE_I2C_RX package)
+{
+    if (package.data.group1 <= CONTROL_GROUP_MAX && package.data.group2 <= CONTROL_GROUP_MAX)
+    {
+        return FUNCTION_SUCCESS;
+    }
+    return FUNCTION_ERROR;
+}
+
+BYTE PCKG_CheckSum(BYTE *pByte,int Size)
+{
+    BYTE Sum = 0;
+    int i;
+    for (i=0;i<Size-1;i++)
+    {
+        Sum ^= (*pByte);
+        pByte++;
+    }
+    return Sum;
+}
+
+FUNCTION_RETURN PCKG_Check(PACKAGE_I2C_RX package)
+{
+    BYTE Sum = 0;
+    FUNCTION_RETURN Result = CheckMarker(package);
+    if (IsFunctionError(Result))        return FUNCTION_ERROR;
+
+    Result = CheckGroups(package);
+    if (IsFunctionError(Result))        return FUNCTION_ERROR;
+
+    Sum = PCKG_CheckSum(package.bytes,I2C_SIZEBUF_RX);
+    if (Sum != package.data.checkSum)   return FUNCTION_ERROR;
+    
+    return Result;
+}
+
+// Возврат true если пакеты одинаковые
+COMPARE_STATE ComparePackages(PACKAGE_I2C_RX package1,PACKAGE_I2C_RX package2)
+{
+    int Err = 0;
+    int i;
+    for (i=0;i<I2C_SIZEBUF_RX;i++)
+    {
+        if (package1.bytes[i] != package2.bytes[i])
+        {
+            Err++;
+        }
+    }
+    
+    if (Err) return NOT_EQUAL;
+    return EQUAL;
+}
+
+
+void PCKG_ControlBlink(PACKAGE_I2C_RX *pPackageTest)
+{
+    //SWITCH_STATE Res = SWITCH_NONE;
+    //static PACKAGE_I2C_RX packageTest = {0};
+    
+    //if (pInfo->controlChange == CHANGECONTROL_ACTIVE)
+    
+    if (pPackageTest->data.group1 >= GREEN_FLASH) //CONTROL_GROUP_MAX)
+    {
+        pPackageTest->data.group1 = GREEN;//OFF;
+    }
+    else
+    {
+        //pPackageTest->data.group1=pPackageTest->data.group1+1;
+    }
+    
+    return;
+}
+
+
+SWITCH_STATE PCKG_LightLamp(PACKAGE_I2C_RX *pPackage,PACKAGE_INFO *pInfo)
+{
+    static PACKAGE_I2C_RX packageSave = {
+        0
+    };
+    SWITCH_STATE Res = SWITCH_NONE;
+    
+    switch (pPackage->data.group1)
+    {
+        case OFF:
+        {
+            LED_RED1_OFF;
+            LED_YELLOW1_OFF;
+            LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+            //pInfo->flashGroup1 = FLASH_LIGHT_OFF;
+        } break;
+        
+        case RED_AMBER:
+        {
+            LED_RED1_ON;
+            LED_YELLOW1_ON;
+            LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+            //pInfo->flashGroup1 = FLASH_LIGHT_OFF;
+        } break;
+
+        case RED:
+        {
+            LED_RED1_ON;
+            LED_YELLOW1_OFF;
+            LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+            //pInfo->flashGroup1 = FLASH_LIGHT_OFF;
+        } break;
+
+        case GREEN:
+        {
+            LED_RED1_OFF;
+            LED_YELLOW1_OFF;
+            LED_GREEN1_ON;
+            LED_OUTPUT1_OFF;
+            //pInfo->flashGroup1 = FLASH_LIGHT_OFF;
+        } break;
+
+        case GREEN_FLASH:
+        {
+            LED_RED1_OFF;
+            LED_YELLOW1_OFF;
+            if (pInfo->flashGroup1 == FLASH_LIGHT_ON)  LED_GREEN1_ON;
+            else                                       LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+        } break;
+
+        case AMBER:
+        {
+            LED_RED1_OFF;
+            LED_YELLOW1_ON;
+            LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+            //pInfo->flashGroup1 = FLASH_LIGHT_OFF;
+        } break;
+
+        case AMBER_FLASH:
+        {
+            LED_RED1_OFF;
+            if (pInfo->flashGroup1 == FLASH_LIGHT_ON)  LED_YELLOW1_ON;
+            else                                       LED_YELLOW1_OFF;
+            LED_GREEN1_OFF;
+            LED_OUTPUT1_OFF;
+        } break;
+
+        case ARROW_RED_AMBER:
+        {
+            
+        } break;
+
+        case ARROW_RED:
+        {
+        } break;
+
+        case ARROW_GREEN:
+        {
+        } break;
+
+        case ARROW_GREEN_FLASH:
+        {
+        } break;
+
+        case ARROW_AMBER:
+        {
+        } break;
+
+        case ARROW_AMBER_FLASH:
+        {
+        } break;
+
+        case ARROW_FLASH_RED_AMBER:
+        {
+        } break;
+
+        case ARROW_FLASH_RED:
+        {
+        } break;
+
+        case ARROW_FLASH_GREEN:
+        {
+        } break;
+
+        case ARROW_FLASH_GREEN_FLASH:
+        {
+        } break;
+
+        case ARROW_FLASH_AMBER:
+        {
+        } break;
+
+        case ARROW_FLASH_AMBER_FLASH:
+        {
+        } break;
+    }
+    
+    switch(pPackage->data.group2)
+    {
+        case OFF:
+        {
+            LED_RED2_OFF;
+            LED_YELLOW2_OFF;
+            LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;
+            pInfo->flashGroup2 = FLASH_LIGHT_OFF;
+        } break;
+        
+        case RED_AMBER:
+        {
+            LED_RED2_ON;
+            LED_YELLOW2_ON;
+            LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;
+            pInfo->flashGroup2 = FLASH_LIGHT_OFF;           
+        } break;
+
+        case RED:
+        {
+            LED_RED2_ON;
+            LED_YELLOW2_OFF;
+            LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;
+            pInfo->flashGroup2 = FLASH_LIGHT_OFF;           
+        } break;
+
+        case GREEN:
+        {
+            LED_RED2_OFF;
+            LED_YELLOW2_OFF;
+            LED_GREEN2_ON;
+            LED_OUTPUT2_OFF;
+            pInfo->flashGroup2 = FLASH_LIGHT_OFF;           
+        } break;
+
+        case GREEN_FLASH:
+        {
+            LED_RED2_OFF;
+            LED_YELLOW2_OFF;
+            if (pInfo->flashGroup2 == FLASH_LIGHT_ON)  LED_GREEN2_ON;
+            else                                       LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;                
+        } break;
+
+        case AMBER:
+        {
+            LED_RED2_OFF;
+            LED_YELLOW2_ON;
+            LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;
+            pInfo->flashGroup2 = FLASH_LIGHT_OFF;
+        } break;
+
+        case AMBER_FLASH:
+        {
+            LED_RED2_OFF;
+            if (pInfo->flashGroup2 == FLASH_LIGHT_ON)  LED_YELLOW2_ON;
+            else                                       LED_YELLOW2_OFF;
+            LED_GREEN2_OFF;
+            LED_OUTPUT2_OFF;    
+        } break;
+
+        case ARROW_RED_AMBER:
+        {
+            
+        } break;
+
+        case ARROW_RED:
+        {
+        } break;
+
+        case ARROW_GREEN:
+        {
+        } break;
+
+        case ARROW_GREEN_FLASH:
+        {
+        } break;
+
+        case ARROW_AMBER:
+        {
+        } break;
+
+        case ARROW_AMBER_FLASH:
+        {
+        } break;
+
+        case ARROW_FLASH_RED_AMBER:
+        {
+        } break;
+
+        case ARROW_FLASH_RED:
+        {
+        } break;
+
+        case ARROW_FLASH_GREEN:
+        {
+        } break;
+
+        case ARROW_FLASH_GREEN_FLASH:
+        {
+        } break;
+
+        case ARROW_FLASH_AMBER:
+        {
+        } break;
+
+        case ARROW_FLASH_AMBER_FLASH:
+        {
+        } break;
+    }
+    
+    // Если произошло переключение
+    if (ComparePackages(packageSave,*pPackage) == NOT_EQUAL)
+    {
+        Res = SWITCH_ACTIVE;
+    }
+    
+    packageSave = *pPackage;
+    return Res;
+}
diff -r 000000000000 -r c645b762b2c0 Package.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Package.h	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,6 @@
+#include "types.h"
+
+BYTE PCKG_CheckSum(BYTE *pByte,int Size);
+FUNCTION_RETURN PCKG_Check(PACKAGE_I2C_RX package);
+SWITCH_STATE PCKG_LightLamp(PACKAGE_I2C_RX *pPackage,PACKAGE_INFO *pInfo);
+void PCKG_ControlBlink(PACKAGE_I2C_RX *pPackageTest);
\ No newline at end of file
diff -r 000000000000 -r c645b762b2c0 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,259 @@
+//** An I2C Slave, used for communicating with an I2C Master device 
+// ПО платы ВПУ адрес 0x08 - не изменяется
+#include <mbed.h>
+#include <IO.h>
+//#include <timers.h>
+#include <types.h>
+#include <Package.h>
+#define STATUS_OK       1
+#define STATUS_ERROR    -1
+#define I2C_SLAVE       I2C1
+
+//Serial pc(USBTX, USBRX);  // tx, rx консоль
+Serial pc(PC_6, PC_7);  // tx, rx консоль Serial6
+I2CSlave slave(PB_9, PB_8);
+char readBuffer[5]; // буфер приема
+//char writeBuffer[4]; // буфер передачи
+char writeBuffer[]={0,0,1,1};
+int errorStatus=STATUS_OK; // статус приема пакета от ЦП
+int initMode; // режим инициализации 1 - есть, 0 - нет. 
+
+HAL_I2C_ErrorTypeDef err_I2C;
+HAL_StatusTypeDef    status_I2C;
+    
+I2C_HandleTypeDef      hI2C;
+__IO ITStatus UartReady = RESET;
+
+//SLOT_TABLE slot = {0};
+int slot=0x08;
+int Counter = 0;
+int Error = 0;
+int Reset = 0;
+PACKAGE_I2C_RX puRX = {0};
+PACKAGE_I2C_TX puTX = {0};
+PACKAGE_INFO infoPackage =
+{
+    I2C_SIZEBUF_RX,
+    I2C_SIZEBUF_TX,
+    FLASH_LIGHT_OFF,
+    FLASH_LIGHT_OFF,
+    500,                  // Время мигания
+    CHANGECONTROL_NONE,
+    3000                  // Время переключения
+};
+
+
+// обработчик принятых данных от ЦП к VPU
+  void receiveBufferHandler()
+  {
+    // проверяем ошибки xor всех байт
+    if (readBuffer[3]!=(readBuffer[0]^readBuffer[1]^readBuffer[2]))
+    {
+        errorStatus=STATUS_ERROR; // ошибка если не сошелся xor
+        return;
+    }    
+    else errorStatus=STATUS_OK;
+    
+    // проверяем какой режим - работы или инициализации.
+    if (readBuffer[0]==0xA5)
+    {
+        initMode=0;
+        // состояние данных из пакета выводим в выходы МК 
+        //readBuffer[1]=0xEB;readBuffer[2]=0xff;
+        Out1= readBuffer[1]&1<<0; 
+        Out2= readBuffer[1]&1<<1;
+        Out3= readBuffer[1]&1<<2; 
+        Out4= readBuffer[1]&1<<3;
+        Out5= readBuffer[1]&1<<4; 
+        Out6= readBuffer[1]&1<<5;
+        Out7= readBuffer[1]&1<<6; 
+        Out8= readBuffer[1]&1<<7; 
+        Out9= readBuffer[2]&1<<0; 
+        Out10=readBuffer[2]&1<<1;
+        Out11=readBuffer[2]&1<<2; 
+        Out12=readBuffer[2]&1<<3;
+        Out13=readBuffer[2]&1<<4; 
+        Out14=readBuffer[2]&1<<5;
+        Out15=readBuffer[2]&1<<6; 
+        Out16=readBuffer[2]&1<<7; 
+    }
+    else if (readBuffer[0]==0xAB)initMode=1;
+  }
+
+// формирователь данных прередаваемых от VPU к ЦП 
+  void sendBufferHandler()
+  {
+    writeBuffer[0]=(In1<<0+In2<<1+In3<<2+In4<<3+In5<<4+In6<<5+In7<<6+In8<<7);
+    writeBuffer[1]=(In9<<0+In10<<1+In11<<2+In12<<3+In13<<4+In14<<5+In15<<6+In16<<7);
+    writeBuffer[2]=errorStatus;
+    writeBuffer[3]=writeBuffer[0]^writeBuffer[1]^writeBuffer[2];
+  }
+
+void InitI2C(int Address) {
+    __HAL_I2C_ENABLE(&hI2C);
+
+#ifdef MASTER   
+  hi2c1.Instance = I2C_MASTER;
+#else
+  hI2C.Instance = I2C_SLAVE;
+#endif  
+
+#ifdef HIGH_SPEED_I2C  
+    hI2C.Init.ClockSpeed = 400000;
+  hI2C.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
+#else
+    hI2C.Init.ClockSpeed = 100000;
+  hI2C.Init.DutyCycle = I2C_DUTYCYCLE_2;    
+#endif
+    
+  hI2C.Init.OwnAddress1 = Address;
+  hI2C.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
+  hI2C.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
+  hI2C.Init.OwnAddress2 = 0;
+  hI2C.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
+  hI2C.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
+
+  if (HAL_I2C_Init(&hI2C) != HAL_OK)
+    {
+    /* Initialization Error */
+    pc.printf("Error_init_I2C");
+    }
+    //__HAL_I2C_ENABLE_IT(&hi2c1,I2C_IT_BUF);
+}
+
+
+  int main() 
+  {   
+      STEP_ROUTINE step = STEP_INIT;  
+      FUNCTION_RETURN Result;   
+      slave.frequency(400000);        //частота шины I2C
+      slave.address(0x08);             // адрес в сети i2c для этой платы всегда фиксированный.
+      while (1) 
+      {       Out16=1;
+          //sendBufferHandler(); // формирователь того что надо отправить в ЦП
+          int i = slave.receive();
+          //pc.printf("i= %d",i);
+          
+          switch (step) {
+                //case STEP_INIT:
+                //{
+                //    status_I2C = (HAL_StatusTypeDef)HAL_I2C_GetState(&hI2C);
+                //    PrintStatus(status_I2C);
+                //    HAL_Delay(5000);
+                //} break;
+                    
+                case STEP_RX:
+                {
+                    status_I2C = HAL_I2C_Slave_Receive(&hI2C, (BYTE *)&puRX, infoPackage.sizeRX,100);
+                    if (status_I2C == HAL_OK)
+                    {
+                        Result = PCKG_Check(puRX);
+                        if (!IsFunctionError(Result))   // Если нет ошибки
+                        {
+                            puTX.data.status = PACKAGE_STATUS_SUCCESS;
+                            switch (Result)
+                            {
+                                case FUNCTION_SUCCESS:
+                                {
+                                    //if (PCKG_LightLamp(puRX,&infoPackage) == SWITCH_ACTIVE)    // Управление лампами
+                                    //{
+                                    //    tickLight = HAL_GetTick();   // Обнуляем время, чтобы мигание началось заново
+                                    //}
+                                } break;
+                                
+                                case FUNCTION_TESTBLINK:
+                                {
+                                    //if (PCKG_TestBlink(&infoPackage) == SWITCH_ACTIVE)    // Управление лампами
+                                    //{
+                                    //    tickLight = HAL_GetTick();   // Обнуляем время, чтобы мигание началось заново
+                                    //}
+                                } break;
+                                
+                                default:
+                                {
+                                } break;
+                            }
+                        }
+                        else
+                        {
+                            puTX.data.status = PACKAGE_STATUS_ERROR;
+                        }
+
+                        step = STEP_TX;
+                    }
+                    else
+                    {
+                        step = STEP_RESET;
+                    }
+                } break;
+                
+                case STEP_TX:
+                {
+                    puTX.data.curGroup1.curRed = 10;
+                    puTX.data.curGroup1.curYellow = 20;
+                    puTX.data.curGroup1.curGreen = 30;
+                    puTX.data.curGroup1.curOutput = 40;
+                    puTX.data.curGroup2.curRed = 1111;
+                    puTX.data.curGroup2.curYellow = 2222;
+                    puTX.data.curGroup2.curGreen = 3333;
+                    puTX.data.curGroup2.curOutput = 4444;
+                    puTX.data.checkSum = PCKG_CheckSum(puTX.bytes,infoPackage.sizeTX);
+                    
+                    
+                    status_I2C = HAL_I2C_Slave_Transmit(&hI2C, (BYTE *)&puTX, infoPackage.sizeTX, 100);
+                    if (status_I2C == HAL_OK)
+                    {
+                        //printf("Slave TX = %s\r\n",cBuf);
+                        //printf("OK\r\n");
+                        Counter++;
+                        step = STEP_IDLE;
+                    }
+                    else
+                    {
+                        //printf("Slave TX = %s\r\n",cBuf);
+                        //printf("ERROR\r\n");
+                        Error++;
+                        step = STEP_RESET;
+                    }
+                    //printf("Slave end\r\n");
+                } break;
+                
+                case STEP_RESET:
+                {
+                    //PrintStatus(status);
+                    //PrintErrStatus(err);                  
+                    
+                    HAL_I2C_DeInit(&hI2C);
+                    InitI2C(slot);
+                    //printf("DEINIT Success\r\n");
+                    Reset++;
+                    step = STEP_IDLE;
+                } break;
+                
+                case STEP_IDLE:
+                {
+                    //for (i=0;i<I2C_SIZEBUF_RX;i++)
+                    //{
+                        //printf("%d) 0x%02X\r\n",i,puRX.bytes[1]);
+                    //}
+                    
+                    //pc.printf("Fl = %d\r\n",step );
+                    
+                    memset(&puRX,0,infoPackage.sizeRX);
+                    memset(&puTX,0,infoPackage.sizeTX);
+                    step = STEP_RX;
+                } break;
+                
+                default:
+                {
+                } break;
+            }
+          for(int i = 0; i < 4; i++) {/*writeBuffer[i] = 0;*/ readBuffer[i]=0;} // Clear buffers      
+      //for(int i = 0; i < 10; i++) readBuffer[0] = 0;    // Clear readBufferfer
+      //pc.printf("writeBuffer= %x %x %x %x\r\n",writeBuffer[0],writeBuffer[1],writeBuffer[2],writeBuffer[3]);
+      //pc.printf("sizeof(writeBuffer)= %d\r\n",sizeof(writeBuffer));
+      //pc.printf("readBuffer= %x %x %x %x\r\n",readBuffer[0],readBuffer[1],readBuffer[2],readBuffer[3]);
+      //wait(0.001);
+      Out1=1;
+      }    
+  }
diff -r 000000000000 -r c645b762b2c0 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9ad691361fac
\ No newline at end of file
diff -r 000000000000 -r c645b762b2c0 types.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/types.h	Fri Feb 27 12:13:49 2015 +0000
@@ -0,0 +1,435 @@
+/*
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>     // Для bool, false, true
+#include <stm32f4xx_hal.h>
+#include <stm32f4xx_hal_conf.h>
+*/
+#ifndef TYPESFILE_H
+#define TYPESFILE_H
+
+#define BYTE                unsigned char
+#define WORD                                uint16_t
+#define DWORD                               uint32_t
+#define SIZE(x)                 (sizeof(x) / sizeof(*(x)))
+
+
+typedef enum __FUNCTION_RETURN
+{
+    FUNCTION_ERROR = -1,
+    FUNCTION_NONE = 0,
+    FUNCTION_SUCCESS = 1,
+    FUNCTION_TESTBLINK = 2
+} FUNCTION_RETURN;
+
+typedef enum __STEP_ROUTINE
+{
+    STEP_NONE = -1, 
+    STEP_INIT, //0
+    STEP_RX,    //1
+    STEP_TX,    //2
+    STEP_RESET, //3
+    STEP_IDLE       //4
+} STEP_ROUTINE;
+
+typedef enum __FLASH_LIGHT
+{
+    FLASH_LIGHT_OFF,
+    FLASH_LIGHT_ON
+} FLASH_LIGHT;
+
+typedef enum __CHANGECONTROL_TEST
+{
+    CHANGECONTROL_NONE,
+    CHANGECONTROL_ACTIVE
+} CHANGECONTROL_TEST;
+
+typedef enum __COMPARE_STATE
+{
+    EQUAL,
+    NOT_EQUAL
+} COMPARE_STATE;
+
+typedef enum __SWITCH_STATE
+{
+    SWITCH_NONE,
+    SWITCH_ACTIVE
+} SWITCH_STATE;
+
+typedef enum __INDEX_LIGHT
+{
+    INDEX_RED1,
+    INDEX_RED2,
+    INDEX_YELLOW1,
+    INDEX_YELLOW2,
+    INDEX_GREEN1,
+    INDEX_GREEN2,
+    INDEX_OUTPUT1,
+    INDEX_OUTPUT2
+} INDEX_LIGHT;
+
+//===========================        PACKAGE_RX      ======================================
+//=========================================================================================
+typedef enum __PACKAGE_MARKER
+{
+    DEFAULT_MARKER = 0xA5,
+    INIT_MARKER = 0xAB,
+    TEST_BLINK_MARKER = 0xCD
+} PACKAGE_MARKER;
+
+typedef enum __PACKAGE_CONTROL_GROUP
+{
+    OFF = 0,
+    RED_AMBER = 1,
+    RED = 2,
+    GREEN = 3,
+    GREEN_FLASH = 4,
+    AMBER = 5,
+    AMBER_FLASH = 6,
+    ARROW_RED_AMBER = 7,
+    ARROW_RED = 8,
+    ARROW_GREEN = 9,
+    ARROW_GREEN_FLASH = 10,
+    ARROW_AMBER = 11,
+    ARROW_AMBER_FLASH = 12,
+    ARROW_FLASH_RED_AMBER = 13,
+    ARROW_FLASH_RED = 14,
+    ARROW_FLASH_GREEN = 15,
+    ARROW_FLASH_GREEN_FLASH = 16,
+    ARROW_FLASH_AMBER = 17,
+    ARROW_FLASH_AMBER_FLASH = 18,
+    CONTROL_GROUP_MAX = 18
+} PACKAGE_CONTROL_GROUP;
+
+#pragma pack(push, 1)
+typedef struct __PACKAGE_RX
+{
+    PACKAGE_MARKER marker;
+    PACKAGE_CONTROL_GROUP group1;
+    PACKAGE_CONTROL_GROUP group2;
+    BYTE checkSum;
+} PACKAGE_RX;
+#pragma pack(pop)
+
+#define I2C_SIZEBUF_RX   sizeof(PACKAGE_RX)
+
+typedef union __PACKAGE_I2C_RX
+{
+    BYTE bytes[I2C_SIZEBUF_RX];
+    PACKAGE_RX data;
+} PACKAGE_I2C_RX;
+//=========================================================================================
+
+
+//===========================        PACKAGE_TX      ======================================
+//=========================================================================================
+typedef enum __PACKAGE_STATUS
+{
+    PACKAGE_STATUS_ERROR = -1,
+    PACKAGE_STATUS_NONE = 0,
+    PACKAGE_STATUS_SUCCESS = 1
+} PACKAGE_STATUS;
+
+typedef struct __PACKAGE_CURRENT_GROUP
+{
+    WORD curRed;
+    WORD curYellow;
+    WORD curGreen;
+    WORD curOutput;
+} PACKAGE_CURRENT_GROUP;
+
+#pragma pack(push, 1)
+typedef struct __PACKAGE_TX
+{
+    PACKAGE_CURRENT_GROUP curGroup1;
+    PACKAGE_CURRENT_GROUP curGroup2;
+    PACKAGE_STATUS status;
+    BYTE checkSum;
+} PACKAGE_TX;
+#pragma pack(pop)
+
+#define I2C_SIZEBUF_TX   sizeof(PACKAGE_TX)
+
+typedef union __PACKAGE_I2C_TX
+{
+    BYTE bytes[I2C_SIZEBUF_TX];
+    PACKAGE_TX data;
+} PACKAGE_I2C_TX;
+//=========================================================================================
+
+
+//===========================        PACKAGE_INFO      ====================================
+//=========================================================================================
+typedef struct __PACKAGE_INFO
+{
+    int sizeRX; //I2C_SIZEBUF_RX
+    int sizeTX;
+    FLASH_LIGHT flashGroup1;
+    FLASH_LIGHT flashGroup2;
+    int flashTime_us;
+    CHANGECONTROL_TEST controlChange;
+    int controlTime_us;
+} PACKAGE_INFO;
+//=========================================================================================
+
+//===========================         ADDRESS          ====================================
+//=========================================================================================
+// Адрес платы 5 бит
+/*
+typedef enum __ADDRESS_PLATE_PU
+{
+    ADDRESS_PLATE_PU1  = 0,
+    ADDRESS_PLATE_PU2  = 1,
+    ADDRESS_PLATE_PU3  = 2,
+    ADDRESS_PLATE_PU4  = 3,
+    ADDRESS_PLATE_PU5  = 4,
+    ADDRESS_PLATE_PU6  = 5,
+    ADDRESS_PLATE_PU7  = 6,
+    ADDRESS_PLATE_PU8  = 7,
+    ADDRESS_PLATE_PU9  = 8,
+    ADDRESS_PLATE_PU10 = 9,
+    ADDRESS_PLATE_PU11 = 10,
+    ADDRESS_PLATE_PU12 = 11,
+    ADDRESS_PLATE_PU13 = 12,
+    ADDRESS_PLATE_PU14 = 13,
+    ADDRESS_PLATE_PU15 = 14,
+    ADDRESS_PLATE_PU16 = 15,    
+    ADDRESS_PLATE_PU17 = 16,
+    ADDRESS_PLATE_PU18 = 17,
+    ADDRESS_PLATE_PU19 = 18,
+    ADDRESS_PLATE_PU20 = 19,
+    ADDRESS_PLATE_MAX  = 20
+} ADDRESS_PLATE_PU;
+*/
+// Адрес Рэка 3 бита
+/*
+typedef enum __ADDRESS_RACK_PU
+{
+    ADDRESS_RACK_PU1  = 0x00,
+    ADDRESS_RACK_PU2  = 0x01,
+    ADDRESS_RACK_PU3  = 0x02,
+    ADDRESS_RACK_PU4  = 0x04,
+    ADDRESS_RACK_MAX  = 4
+} ADDRESS_RACK_PU;
+*/
+// Для 1-ого Рэка
+/*
+typedef enum __ADDRESS_I2C_RACK1_PU
+{
+    ADDRESS_I2C_RACK1_NONE = 0,
+    ADDRESS_I2C_RACK1_PU1 = 0x06,
+    ADDRESS_I2C_RACK1_PU2 = 0x07,
+    ADDRESS_I2C_RACK1_PU3 = 0x08,
+    ADDRESS_I2C_RACK1_PU4 = 0x09,
+    ADDRESS_I2C_RACK1_PU5 = 0x0A,
+    ADDRESS_I2C_RACK1_PU6 = 0x0B,
+    ADDRESS_I2C_RACK1_PU7 = 0x0C,
+    ADDRESS_I2C_RACK1_PU8 = 0x0D
+} ADDRESS_I2C_RACK1_PU;
+
+// Для 2-ого Рэка
+typedef enum __ADDRESS_I2C_RACK2_PU
+{
+    ADDRESS_I2C_RACK2_NONE = 0,
+    ADDRESS_I2C_RACK2_PU1  = 0x0F,
+    ADDRESS_I2C_RACK2_PU2  = 0x10,
+    ADDRESS_I2C_RACK2_PU3  = 0x11,
+    ADDRESS_I2C_RACK2_PU4  = 0x12,
+    ADDRESS_I2C_RACK2_PU5  = 0x13,
+    ADDRESS_I2C_RACK2_PU6  = 0x14,
+    ADDRESS_I2C_RACK2_PU7  = 0x15,
+    ADDRESS_I2C_RACK2_PU8  = 0x16,
+    ADDRESS_I2C_RACK2_PU9  = 0x17,
+    ADDRESS_I2C_RACK2_PU10 = 0x18,
+    ADDRESS_I2C_RACK2_PU11 = 0x19,
+    ADDRESS_I2C_RACK2_PU12 = 0x1A,
+    ADDRESS_I2C_RACK2_PU13 = 0x1B,
+    ADDRESS_I2C_RACK2_PU14 = 0x1C,
+    ADDRESS_I2C_RACK2_PU15 = 0x1D,
+    ADDRESS_I2C_RACK2_PU16 = 0x1E,
+    ADDRESS_I2C_RACK2_PU17 = 0x1F,
+    ADDRESS_I2C_RACK2_PU18 = 0x20,
+    ADDRESS_I2C_RACK2_PU19 = 0x21,
+    ADDRESS_I2C_RACK2_PU20 = 0x22
+} ADDRESS_I2C_RACK2_PU;
+
+// Для 3-его Рэка
+typedef enum __ADDRESS_I2C_RACK3_PU
+{
+    ADDRESS_I2C_RACK3_NONE = 0,
+    ADDRESS_I2C_RACK3_PU1  = 0x24,
+    ADDRESS_I2C_RACK3_PU2  = 0x25,
+    ADDRESS_I2C_RACK3_PU3  = 0x26,
+    ADDRESS_I2C_RACK3_PU4  = 0x27,
+    ADDRESS_I2C_RACK3_PU5  = 0x28,
+    ADDRESS_I2C_RACK3_PU6  = 0x29,
+    ADDRESS_I2C_RACK3_PU7  = 0x2A,
+    ADDRESS_I2C_RACK3_PU8  = 0x2B,
+    ADDRESS_I2C_RACK3_PU9  = 0x2C,
+    ADDRESS_I2C_RACK3_PU10 = 0x2D,
+    ADDRESS_I2C_RACK3_PU11 = 0x2E,
+    ADDRESS_I2C_RACK3_PU12 = 0x2F,
+    ADDRESS_I2C_RACK3_PU13 = 0x38,
+    ADDRESS_I2C_RACK3_PU14 = 0x39,
+    ADDRESS_I2C_RACK3_PU15 = 0x3A,
+    ADDRESS_I2C_RACK3_PU16 = 0x3B,
+    ADDRESS_I2C_RACK3_PU17 = 0x3C,
+    ADDRESS_I2C_RACK3_PU18 = 0x3D,
+    ADDRESS_I2C_RACK3_PU19 = 0x3E,
+    ADDRESS_I2C_RACK3_PU20 = 0x3F
+} ADDRESS_I2C_RACK3_PU;
+
+// Для 4-ого Рэка
+typedef enum __ADDRESS_I2C_RACK4_PU
+{
+    ADDRESS_I2C_RACK4_NONE = 0,
+    ADDRESS_I2C_RACK4_PU1  = 0x41,
+    ADDRESS_I2C_RACK4_PU2  = 0x42,
+    ADDRESS_I2C_RACK4_PU3  = 0x43,
+    ADDRESS_I2C_RACK4_PU4  = 0x44,
+    ADDRESS_I2C_RACK4_PU5  = 0x45,
+    ADDRESS_I2C_RACK4_PU6  = 0x46,
+    ADDRESS_I2C_RACK4_PU7  = 0x47,
+    ADDRESS_I2C_RACK4_PU8  = 0x48,
+    ADDRESS_I2C_RACK4_PU9  = 0x49,
+    ADDRESS_I2C_RACK4_PU10 = 0x4A,
+    ADDRESS_I2C_RACK4_PU11 = 0x4B,
+    ADDRESS_I2C_RACK4_PU12 = 0x4C,
+    ADDRESS_I2C_RACK4_PU13 = 0x4D,
+    ADDRESS_I2C_RACK4_PU14 = 0x4E,
+    ADDRESS_I2C_RACK4_PU15 = 0x4F,
+    ADDRESS_I2C_RACK4_PU16 = 0x60,
+    ADDRESS_I2C_RACK4_PU17 = 0x61,
+    ADDRESS_I2C_RACK4_PU18 = 0x62,
+    ADDRESS_I2C_RACK4_PU19 = 0x63,
+    ADDRESS_I2C_RACK4_PU20 = 0x64
+} ADDRESS_I2C_RACK4_PU;
+*/
+#pragma pack(push,1)
+typedef struct __BIT_ADDRESS
+{
+  BYTE plate:5;
+  BYTE rack:3;
+} BIT_ADDRESS;
+#pragma pack(pop)
+
+typedef union __HARDWARE_ADDRESS
+{
+    BIT_ADDRESS bits;
+    BYTE value;
+} HARDWARE_ADDRESS;
+
+typedef struct __ADDRESS
+{
+    HARDWARE_ADDRESS hardware;
+    WORD i2c;
+} ADDRESS;
+
+typedef struct __SLOT_TABLE
+{
+    char name[16];
+    WORD addressI2C;
+} SLOT_TABLE;
+
+//=========================================================================================
+
+
+#define LED_BOARD_PORT      GPIOA
+#define LED_BOARD           GPIO_PIN_2
+#define LED_BOARD_ON        do {HAL_GPIO_WritePin(LED_BOARD_PORT,LED_BOARD,GPIO_PIN_SET);} while(0)
+#define LED_BOARD_OFF       do {HAL_GPIO_WritePin(LED_BOARD_PORT,LED_BOARD,GPIO_PIN_RESET);} while(0)
+
+
+//===========================        LIGHTS       =========================================
+//=========================================================================================
+#define LED_RED1_PORT       GPIOA
+#define LED_RED1            GPIO_PIN_11
+#define LED_RED1_ON         do {HAL_GPIO_WritePin(LED_RED1_PORT,LED_RED1,GPIO_PIN_SET);} while(0)
+#define LED_RED1_OFF        do {HAL_GPIO_WritePin(LED_RED1_PORT,LED_RED1,GPIO_PIN_RESET);} while(0)
+
+#define LED_YELLOW1_PORT    GPIOC
+#define LED_YELLOW1         GPIO_PIN_9
+#define LED_YELLOW1_ON      do {HAL_GPIO_WritePin(LED_YELLOW1_PORT,LED_YELLOW1,GPIO_PIN_SET);} while(0)
+#define LED_YELLOW1_OFF     do {HAL_GPIO_WritePin(LED_YELLOW1_PORT,LED_YELLOW1,GPIO_PIN_RESET);} while(0)
+
+#define LED_GREEN1_PORT     GPIOB
+#define LED_GREEN1          GPIO_PIN_15
+#define LED_GREEN1_ON      do {HAL_GPIO_WritePin(LED_GREEN1_PORT,LED_GREEN1,GPIO_PIN_SET);} while(0)
+#define LED_GREEN1_OFF     do {HAL_GPIO_WritePin(LED_GREEN1_PORT,LED_GREEN1,GPIO_PIN_RESET);} while(0)
+
+#define LED_OUTPUT1_PORT    GPIOB
+#define LED_OUTPUT1         GPIO_PIN_13 
+#define LED_OUTPUT1_ON      do {HAL_GPIO_WritePin(LED_OUTPUT1_PORT,LED_OUTPUT1,GPIO_PIN_SET);} while(0)
+#define LED_OUTPUT1_OFF     do {HAL_GPIO_WritePin(LED_OUTPUT1_PORT,LED_OUTPUT1,GPIO_PIN_RESET);} while(0)
+
+
+#define LED_RED2_PORT       GPIOA
+#define LED_RED2            GPIO_PIN_8
+#define LED_RED2_ON         do {HAL_GPIO_WritePin(LED_RED2_PORT,LED_RED2,GPIO_PIN_SET);} while(0)
+#define LED_RED2_OFF        do {HAL_GPIO_WritePin(LED_RED2_PORT,LED_RED2,GPIO_PIN_RESET);} while(0)
+
+#define LED_YELLOW2_PORT    GPIOC
+#define LED_YELLOW2         GPIO_PIN_8
+#define LED_YELLOW2_ON      do {HAL_GPIO_WritePin(LED_YELLOW2_PORT,LED_YELLOW2,GPIO_PIN_SET);} while(0)
+#define LED_YELLOW2_OFF     do {HAL_GPIO_WritePin(LED_YELLOW2_PORT,LED_YELLOW2,GPIO_PIN_RESET);} while(0)
+
+#define LED_GREEN2_PORT     GPIOB
+#define LED_GREEN2          GPIO_PIN_14
+#define LED_GREEN2_ON       do {HAL_GPIO_WritePin(LED_GREEN2_PORT,LED_GREEN2,GPIO_PIN_SET);} while(0)
+#define LED_GREEN2_OFF      do {HAL_GPIO_WritePin(LED_GREEN2_PORT,LED_GREEN2,GPIO_PIN_RESET);} while(0)
+
+#define LED_OUTPUT2_PORT    GPIOB
+#define LED_OUTPUT2         GPIO_PIN_12
+#define LED_OUTPUT2_ON      do {HAL_GPIO_WritePin(LED_OUTPUT2_PORT,LED_OUTPUT2,GPIO_PIN_SET);} while(0)
+#define LED_OUTPUT2_OFF     do {HAL_GPIO_WritePin(LED_OUTPUT2_PORT,LED_OUTPUT2,GPIO_PIN_RESET);} while(0)
+//=========================================================================================
+
+
+//===========================   ADDRESS PLATE PORT   ======================================
+//=========================================================================================
+#define ADDRESS_PLATE0_PORT  GPIOC
+#define ADDRESS_PLATE0       GPIO_PIN_10
+#define ADDRESS_PLATE1_PORT  GPIOC
+#define ADDRESS_PLATE1       GPIO_PIN_11
+#define ADDRESS_PLATE2_PORT  GPIOC
+#define ADDRESS_PLATE2       GPIO_PIN_12
+#define ADDRESS_PLATE3_PORT  GPIOB
+#define ADDRESS_PLATE3       GPIO_PIN_4
+#define ADDRESS_PLATE4_PORT  GPIOB
+#define ADDRESS_PLATE4       GPIO_PIN_5
+//=========================================================================================
+
+//===========================   ADDRESS RACK PORT   =======================================
+//=========================================================================================
+#define ADDRESS_RACK0_PORT  GPIOB
+#define ADDRESS_RACK0       GPIO_PIN_6
+#define ADDRESS_RACK1_PORT  GPIOB
+#define ADDRESS_RACK1       GPIO_PIN_7
+#define ADDRESS_RACK2_PORT  GPIOC
+#define ADDRESS_RACK2       GPIO_PIN_13
+//=========================================================================================
+
+
+//===========================        ADC          =========================================
+//=========================================================================================
+#define ADC_CHANNELS_COUNT  3
+struct __TYPE_ADC
+{
+    uint16_t wValues[ADC_CHANNELS_COUNT];
+    uint32_t dwSum[ADC_CHANNELS_COUNT];
+    float fVolts[ADC_CHANNELS_COUNT];
+};
+//=========================================================================================
+
+
+static bool IsFunctionError(FUNCTION_RETURN funcRet)
+{
+    if (funcRet > FUNCTION_NONE)
+    {
+        return false;
+    }
+    return true;
+}
+
+#endif