annotate OtherSources/data_exchange_main_mini.c @ 460:2effe85f1a9b minor_improvments

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