comparison OtherSources/data_exchange_main_mini.c @ 5:e65d01b6a17e

MOVE files for other applications
author JeanDo
date Fri, 15 Dec 2017 01:45:20 +0100
parents
children 7801c5d8a562
comparison
equal deleted inserted replaced
4:89a87ddc2e47 5:e65d01b6a17e
1 /**
2 ******************************************************************************
3 * @file data_exchange_main.c
4 * @author heinrichs/weikamp, Christian Weikamp
5 * @date 13-Oct-2014
6 * @version V0.0.2
7 * @since 27-May-2015
8
9 * @brief Communication with the second CPU == RTE system
10 *
11 @verbatim
12 ==============================================================================
13 ##### How to use #####
14 ==============================================================================
15
16 ==============================================================================
17 ##### Device Data #####
18 ==============================================================================
19
20 main CPU always sends the device data info that it has at the moment
21
22 on start it is INT32_MIN, INT32_MAX and 0
23 as initialized in data_central.c variable declaration
24
25 second small CPU gets request to send its device data
26
27 on receiption the data is merged with the data in externLogbookFlash,
28 stored on the externLogbookFlash and from now on send to small CPU
29
30 @endverbatim
31 ******************************************************************************
32 * @attention
33 *
34 * <h2><center>&copy; COPYRIGHT(c) 2014 heinrichs weikamp</center></h2>
35 *
36 ******************************************************************************
37 */
38
39 /* Includes ------------------------------------------------------------------*/
40 #include <string.h> // for memcopy
41 #include "stm32f4xx_hal.h"
42 #include "stdio.h"
43 #include "ostc.h"
44 #include "data_central.h"
45 #include "data_exchange_main.h"
46 #include "base.h"
47 #include "externLogbookFlash.h"
48
49
50 /* Expoted variables --------------------------------------------------------*/
51
52 /* Private variables ---------------------------------------------------------*/
53
54 SDataReceiveFromMaster dataOut;
55 SDataExchangeSlaveToMaster dataIn;
56
57 uint8_t data_old__lost_connection_to_slave_counter_temp = 0;
58 /* Private types -------------------------------------------------------------*/
59
60 uint8_t DataEX_check_header_and_footer_ok(void);
61 void DataEX_control_connection_while_asking_for_sleep(void);
62
63 /* Exported functions --------------------------------------------------------*/
64
65 uint8_t DataEX_call(void)
66 {
67 DataEX_control_connection_while_asking_for_sleep();
68
69 for(int i=0;i<EXCHANGE_BUFFERSIZE;i++)
70 *(uint8_t *)(((uint32_t)&dataOut) + i) = 0;
71
72 dataOut.mode = MODE_SHUTDOWN;
73
74 dataOut.header.checkCode[0] = 0xBB;
75 dataOut.header.checkCode[1] = 0x01;
76 dataOut.header.checkCode[2] = 0x01;
77 dataOut.header.checkCode[3] = 0xBB;
78
79 dataOut.footer.checkCode[0] = 0xF4;
80 dataOut.footer.checkCode[1] = 0xF3;
81 dataOut.footer.checkCode[2] = 0xF2;
82 dataOut.footer.checkCode[3] = 0xF1;
83
84 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_SET);
85 delayMicros(10);
86
87 if(data_old__lost_connection_to_slave_counter_temp >= 3)
88 {
89 data_old__lost_connection_to_slave_counter_temp = 0;
90 }
91 else
92 {
93 HAL_GPIO_WritePin(SMALLCPU_CSB_GPIO_PORT,SMALLCPU_CSB_PIN,GPIO_PIN_RESET);
94 }
95
96 HAL_SPI_TransmitReceive_DMA(&cpu2DmaSpi, (uint8_t *)&dataOut, (uint8_t *)&dataIn, EXCHANGE_BUFFERSIZE+1);
97 return 1;
98 }
99
100
101 void DataEX_control_connection_while_asking_for_sleep(void)
102 {
103 if(!DataEX_check_header_and_footer_ok())
104 {
105 data_old__lost_connection_to_slave_counter_temp += 1;
106 }
107 }
108
109 uint8_t DataEX_check_header_and_footer_ok(void)
110 {
111 if(dataIn.header.checkCode[0] != 0xA1)
112 return 0;
113 if(dataIn.header.checkCode[1] != 0xA2)
114 return 0;
115 if(dataIn.header.checkCode[2] != 0xA3)
116 return 0;
117 if(dataIn.header.checkCode[3] != 0xA4)
118 return 0;
119 if(dataIn.footer.checkCode[0] != 0xE1)
120 return 0;
121 if(dataIn.footer.checkCode[1] != 0xE2)
122 return 0;
123 if(dataIn.footer.checkCode[2] != 0xE3)
124 return 0;
125 if(dataIn.footer.checkCode[3] != 0xE4)
126 return 0;
127
128 return 1;
129 }
130