IRPyro messaging application
Communications program between IRPyro and IRPyro evaluation tool
main.c
Go to the documentation of this file.
1 /**
2 ******************************************************************************
3 * @file main.c
4 * @author _KEMET, Ltd
5 * @date March 2018
6 * @version Release 1.0.0
7 * @copyright (c) 2018 _KEMET, Ltd
8 * @brief IRPyro messaging application to communicate with the IRPyro evaluation tool
9 *
10 * @verbatim
11  ===============================================================================
12  ##### Description #####
13  ===============================================================================
14  [..]
15  Main function of IRPyro evaluation tool firmware
16  - Initialize micro-controller and board
17  - Detect sensors present
18  - Configure sensors
19  - Stream sampling data via UART to the IRPyro evaluation tool GUI
20  [..]
21  @endverbatim
22  ******************************************************************************
23  @attention <h2><center>&copy; COPYRIGHT 2018 _KEMET, Ltd</center></h2>
24  @verbatim
25  Copyright (c) 2018, _KEMET, Ltd
26  All rights reserved.
27 
28  THIS SOFTWARE IS PROVIDED BY _KEMET, Ltd ''AS IS'' AND ANY
29  EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
30  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
31  DISCLAIMED. IN NO EVENT SHALL _KEMET, Ltd BE LIABLE FOR ANY
32  DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
33  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
34  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38  @endverbatim
39  ******************************************************************************
40  */
41 /* Includes ------------------------------------------------------------------*/
42 #include "main.h"
43 typedef enum
44 {
51 }
53 uint8_t mode_sleeping ; // capture
54 uint8_t mode_lowPower ; // capture
55 uint8_t UnitID[2] = {0xda,0xde};
56 uint8_t BoardType = 0x47;
57 uint8_t DarkPixelState = 0x00;
58 uint8_t FailureFlags = 0x00; // coded test result
59 /**
60 * bit 0 : external emitter in use
61 * bit 1 : internal emitter in use
62 * bit 2 : internal emitter currently ON
63 * bit 3 : internal emitter in use but permanently OFF
64 * bit 7 : 0 = normal1 state, = status changed by external command */
65 uint8_t EmitterStatus = 0 ; //
66 uint16_t EmitterONTime = 50 ; //
67 uint16_t EmitterOFFTime = 50 ; // this means 10Hz with 1:1 mark/space by default
68 // uint16_t EmitterTimer = 0; //
69 
70 uint8_t isStreaming = 0;
71 uint8_t isStatus = 1;
72 uint8_t status_need_to_send = 1;
73 uint8_t error_flag = 0;
74 uint8_t num_of_IRPyro_on_demo_board = NUMBER_IRPyro; // number of devices on a demo board
75 
76 IRPyro_devices IRPyro_device = {0}; // IRPyro sensors main structure
77 IRPyro_cmd_type IRPyro_device_cmd = {0}; //
78 IRPyro_arg_type IRPyro_device_arg = {0}; //
79 uint8_t ChannelConfiguration[NUMBER_OF_SCOPES_IN_THE_GUI] = {0,0x03,0x08,0x0D,0x12,0,0} ; // order of the package for the scope on the GUI
80 
82 static void eevt(MainState_type state);
83 static void fn_sampling_data_get(void);
84 static void fn_apply_parameters(void);
85 
88 TIM_callback pointer_to_status_function = NULL;
89 /** @defgroup eevt_main IRPyro messaging application
90  * @brief main and support functions for state machine
91  * @{
92  */
93 /** @defgroup eevt main IRPyro messaging application
94  * @{
95  */
96 /**
97  * @brief point of entry for the evaluation tool software
98  */
99 int main(void)
100 {
101  while (1)
102  {
103  eevt(state);
104  }
105 }
106 /**
107 * @brief sensor array population
108 */
109 static void sensor_configuration(IRPyro_devices this_list)
110 {
111  /*--------------------------- INITIALIZE CONFIGURATION -------------------*/
112  const AFE_reg_type IRPyro_AFE_Master =
113  {
114  .S7_S0 = 0, // Sets the sampling rate to 1,000 samples per second.
115  .LP = LOW_POWER_DISABLE, // Low power sets the sampling rate to 166 samples per second.
116  .HP = HP_DISABLE, // High pass filter enabled
117  .C_LP = LOW_PASS_180, // Low pass filter set at 180Hz
118  .CLK_OUT = CLK_ENABLE, // Clock output enabled to synchronize other IRPyro sensors
119  .SYNC = MASTER, // IRPyro set as Master issues the synchronization to SLAVE
120  .TEMP = TEMP_DISABLE, //
121  .INT = INT_ENABLE // IRPyro indicates data ready enable
122  };
123  const AFE_reg_type IRPyro_AFE_Slave =
124  {
125  .S7_S0 = 0, // Sets the sampling rate to 1,000 samples per second.
126  .LP = LOW_POWER_DISABLE, // Low power sets the sampling rate to 166 samples per second.
127  .HP = HP_DISABLE, // High pass filter enabled
128  .C_LP = LOW_PASS_180, // Low pass filter set at 180Hz
129  .CLK_OUT = CLK_DISABLE, // Clock output enabled to synchronize other IRPyro sensors
130  .SYNC = SLAVE, // IRPyro set as Slave receiver synchronization from Master
131  .TEMP = TEMP_DISABLE, //
132  .INT = INT_ENABLE // IRPyro indicates data ready enable
133  };
134 
135  const CCP_reg_type IRPyro_Ch_Cfg =
136  {
137  .Feedback_cap = FEEDBACK_200_80, // Feedback capacitance
138  .High_pass_filter_setting = HIGH_PASS_1HZ, // High pass filter set at 1Hz
139  .Feedback_transconductance = TCONDUCT_0_15T, // Time constant selection
140  .status_bit = CH_ENABLE // Channel ready to collect data
141  };
142 
143  const WUP_reg_type IRPyro_WUP_Cfg =
144  {
145  .UHT = MAX_WUP_THRESHOLD, // Upper High Threshold = 255 events
146  .ULT = SAFE_WUP_THRESHOLD, // Upper Low Threshold = 180 events
147  .LHT = MIN_WUP_THRESHOLD, // Low High Threshold = 0 events
148  .LLT = MIN_WUP_THRESHOLD, // Low Low Threshold = 0 events
149  .WT_Threshold = DEFAULT_NO_EVENTS, // Wake up time Threshold = 10 events
150  .DP0_DP2 = NOT_IN_USE_VALUE, // Active pixel channel
151  .CH0_CH2 = SEL_CH_2, // Reference channel
152  .ST = SLEEP_MODE_ONE_CH // Sleep mode type
153  };
154  /*----------------- ADDRESS ASSIGNMENT ---------------------------------*/
155  /* Assuming four sensors on an IRPyro Break out board or demo board*/
156  this_list[0].CS_Port = 2;
157  this_list[0].CS_Pin = 1;
158  this_list[0].INT_Port = 1;
159  this_list[0].INT_Pin = 4;
160  this_list[0].address = 0x70;
161 
162  this_list[1].CS_Port = 2;
163  this_list[1].CS_Pin = 5;
164  this_list[1].INT_Port = 1;
165  this_list[1].INT_Pin = 5;
166  this_list[1].address = 0x69;
167 
168  this_list[2].CS_Port = 2;
169  this_list[2].CS_Pin = 4;
170  this_list[2].INT_Port = 1;
171  this_list[2].INT_Pin = 6;
172  this_list[2].address = 0x68;
173 
174  this_list[3].CS_Port = 2;
175  this_list[3].CS_Pin = 3;
176  this_list[3].INT_Port = 1;
177  this_list[3].INT_Pin = 7;
178  this_list[3].address = 0x67;
179 
180  /*----------------- COMMIT CONFIGURATION ------------*/
181  this_list[0].number_of_active_channels = 1;
182  this_list[0].AFE_register = IRPyro_AFE_Master; // MASTER, INT, CLK ENABLED
183  this_list[0].CCP_register[2] = IRPyro_Ch_Cfg;
184  this_list[0].WUP_register = IRPyro_WUP_Cfg;
185 
186  this_list[1].number_of_active_channels = 1;
187  this_list[1].AFE_register = IRPyro_AFE_Slave; // SLAVE, INT, CLK DISABLED
188  this_list[1].CCP_register[2] = IRPyro_Ch_Cfg;
189  this_list[1].WUP_register = IRPyro_WUP_Cfg;
190 
191  this_list[2].number_of_active_channels = 1;
192  this_list[2].AFE_register = IRPyro_AFE_Slave; // SLAVE, INT, CLK DISABLED
193  this_list[2].CCP_register[2] = IRPyro_Ch_Cfg;
194  this_list[2].WUP_register = IRPyro_WUP_Cfg;
195 
196  this_list[3].number_of_active_channels = 1;
197  this_list[3].AFE_register = IRPyro_AFE_Slave; // SLAVE, INT, CLK DISABLED
198  this_list[3].CCP_register[2] = IRPyro_Ch_Cfg;
199  this_list[3].WUP_register = IRPyro_WUP_Cfg;
200 }
201 /**
202  * @brief Detect IRPyro sensors present in the demo board
203  * @param this_list IRPyro sensor array
204  * @param list_size number of sensors in the array
205 */
206 static void IRPyro_sensor_population(IRPyro_devices this_list, uint8_t * list_size)
207 {
208  uint8_t num_of_IRPyro = *list_size;
209  uint8_t devices_present =0;
210  const uint8_t types[]= {0x00, 0x7F, 0x77, 0x67, 0x47};
211 
212  for(uint8_t current=0 ; current < num_of_IRPyro; ++ current)
213  {
214  if (IRPyro_open(&this_list[current]) == 1)
215  {
216  ++ devices_present;
217  }
218  }
219  *list_size = devices_present;
220  BoardType = types[devices_present];
221  uint8_t calc01 = (uint8_t)( GPIO_ReadInputData( GPIOA ) >> 8 ) & 1 ;
222  uint8_t calc02 = (uint8_t)( GPIO_ReadInputData( GPIOA ) >> 10 ) & 6 ;
223  uint8_t calc03 = (uint8_t)( GPIO_ReadInputData( GPIOA ) >> 2 ) & 0x38;
224  BoardType = calc01;
225  BoardType |= calc02;
226  BoardType |= calc03;
227  BoardType |= 0x40 ;
228  if ( devices_present > 1 )
229  {
230  BoardType &= 0xf7 ;
231  }
232  if ( devices_present > 2 )
233  {
234  BoardType &= 0xef ;
235  }
236  if ( devices_present > 3 )
237  {
238  BoardType &= 0xdf ;
239  }
240 }
241 /**
242  * @brief Changes the state of all the CS lines as used on the IRPyro backplane board
243  * @param state 0 off / 1 on
244  */
246 {
247  CS_pin_set(2,1,state);
248  CS_pin_set(2,3,state);
249  CS_pin_set(2,4,state);
250  CS_pin_set(2,5,state);
251 }
252 /**
253  * @brief power cycles the sensors on the board to assure stability
254 */
256 {
257  // toggle all CS lines
259  Micro_controller_delay_ms(30);
261  Micro_controller_delay_ms(30);
263 }
264 /**
265  * @brief assigns read and status functions interrupts
266 */
267 static void callback_setup()
268 {
270  EXTernal_Callback_Setup(pointer_to_read_function);
271  TIM_Callback_Setup(pointer_to_status_function);
272 }
273 /**
274  * @brief Initializes board and populates sensors
275 */
276 static void fn_eevt_initialize(void)
277 {
278  uint8_t LED_ready = 0;
279  /*-------------------------- board setup ---------------------------------*/
280  Micro_controller_template_init();
283  /*-------- test the open_list, read_list and close_list functions --------*/
285  /*-------------------------- open_list ---------------------------------*/
286  LED_ready = IRPyro_open_devices(IRPyro_device, num_of_IRPyro_on_demo_board);
287  LED_READY(LED_ready);
288  Micro_controller_timeout_set(SEND_STATUS_TIME);
289 
290  callback_setup();
292 }
293 /**
294 * @brief decodes a command from the USART.
295 */
296 uint8_t cmd_decoded = 0;
297 uint8_t sensor_destination = 0;
298 static void fn_command_decode(void)
299 {
300  uint8_t decode_result = 0;
301  const MainState_type next_state[]=
302  {
305  };
307  state = next_state[decode_result];
308 }
309 /**
310  * @brief Sends collected data from configured sensors
311 */
312 static void fn_sampling_data_get(void)
313 {
314  if (isStreaming)
315  {
316  IRPyro_read_devices(IRPyro_device, num_of_IRPyro_on_demo_board);
317  }
318 }
319 /**
320 * @brief changes parameters from one or more sensors
321 */
322 static void fn_apply_parameters(void)
323 {
324  mode_lowPower = IRPyro_device[0].AFE_register.LP;
326  state = contact_gui;
327 }
328 /**
329 * @brief changes parameters from one or more sensors
330 */
331 static void fn_contact_gui(void)
332 {
335 }
336 /**
337 * @brief configures and control the emitter
338 */
339 static void fn_emitter_control(void)
340 {
341  Emitter_control(&EmitterStatus, EmitterONTime, EmitterOFFTime);
342 }
343 /**
344  * @brief IRPyro evaluation tool state machine
345  * @param state indicates next state in the machine
346  */
348 {
349  static void (* const pf[6])(void) =
350  {
357  };
358  (*pf[state])();
359  (*pf[sampling_data_get])();
360  (*pf[emitter_control])();
361 }
362 /** end of eevt
363  * @}
364  */
365 /** end of eevt_main
366  * @}
367  */
368 /* ********** Copyright (c) 2018 _KEMET, Ltd. **********END OF FILE************/
fn_contact_gui
static void fn_contact_gui(void)
changes parameters from one or more sensors
Definition: main.c:331
fn_eevt_initialize
static void fn_eevt_initialize(void)
Initializes board and populates sensors.
Definition: main.c:276
pointer_to_status_function
TIM_callback pointer_to_status_function
Definition: main.c:88
message_generator
void message_generator(uint8_t cmd_to_gui, uint8_t destination)
prepares packet to GUI
Definition: message_generator.c:617
eevt
static void eevt(MainState_type state)
IRPyro evaluation tool state machine.
Definition: main.c:347
main
int main(void)
point of entry for the evaluation tool software
Definition: main.c:99
pointer_to_wakeup_function
EXTernal_callback pointer_to_wakeup_function
Definition: main.c:87
error_flag
uint8_t error_flag
Definition: main.c:73
cmd_decoded
uint8_t cmd_decoded
decodes a command from the USART.
Definition: main.c:296
ChannelConfiguration
uint8_t ChannelConfiguration[NUMBER_OF_SCOPES_IN_THE_GUI]
Definition: main.c:79
contact_gui
@ contact_gui
Definition: main.c:49
mode_lowPower
uint8_t mode_lowPower
Definition: main.c:54
sensor_destination
uint8_t sensor_destination
Definition: main.c:297
eevt_initialize
@ eevt_initialize
Definition: main.c:45
EmitterStatus
uint8_t EmitterStatus
Definition: main.c:65
next_state
decode_state_type next_state
Definition: message_unpack.c:154
EmitterOFFTime
uint16_t EmitterOFFTime
Definition: main.c:67
IRPyro_sensor_population
static void IRPyro_sensor_population(IRPyro_devices this_list, uint8_t *list_size)
Detect IRPyro sensors present in the demo board.
Definition: main.c:206
num_of_IRPyro_on_demo_board
uint8_t num_of_IRPyro_on_demo_board
Definition: main.c:74
fn_emitter_control
static void fn_emitter_control(void)
configures and control the emitter
Definition: main.c:339
SEND_STATUS_TIME
#define SEND_STATUS_TIME
Definition: externals.h:31
FailureFlags
uint8_t FailureFlags
Definition: main.c:58
UnitID
uint8_t UnitID[2]
Definition: main.c:55
mode_sleeping
uint8_t mode_sleeping
Definition: main.c:53
status_need_to_send
uint8_t status_need_to_send
Definition: main.c:72
IRPyro_device_arg
IRPyro_arg_type IRPyro_device_arg
Definition: main.c:78
fn_command_decode
static void fn_command_decode(void)
Definition: main.c:298
queue_handle_enable
void queue_handle_enable(void)
Definition: queue_handle.c:102
fn_apply_parameters
static void fn_apply_parameters(void)
changes parameters from one or more sensors
Definition: main.c:322
message_interpreter
execute_next_state_type message_interpreter(uint8_t *cmd_code, uint8_t *destination)
Recovers the next message from the GUI to the sensor If the message is valid, is passed to the corres...
Definition: message_interpreter.c:422
sampling_data_get
@ sampling_data_get
Definition: main.c:47
sensor_power_stabilize
static void sensor_power_stabilize()
power cycles the sensors on the board to assure stability
Definition: main.c:255
NUMBER_OF_SCOPES_IN_THE_GUI
#define NUMBER_OF_SCOPES_IN_THE_GUI
Definition: externals.h:30
state
static MainState_type state
Definition: main.c:81
demo_board_sensor_control
static void demo_board_sensor_control(int state)
Changes the state of all the CS lines as used on the IRPyro backplane board.
Definition: main.c:245
IRPyro_device_cmd
IRPyro_cmd_type IRPyro_device_cmd
Definition: main.c:77
EmitterONTime
uint16_t EmitterONTime
Definition: main.c:66
pointer_to_read_function
EXTernal_callback pointer_to_read_function
Definition: main.c:86
apply_parameters
@ apply_parameters
Definition: main.c:48
isStreaming
uint8_t isStreaming
Definition: main.c:70
main.h
Includes for eevt state machine.
sensor_configuration
static void sensor_configuration(IRPyro_devices this_list)
sensor array population
Definition: main.c:109
emitter_control
@ emitter_control
Definition: main.c:50
isStatus
uint8_t isStatus
Definition: main.c:71
DarkPixelState
uint8_t DarkPixelState
Definition: main.c:57
fn_sampling_data_get
static void fn_sampling_data_get(void)
Sends collected data from configured sensors.
Definition: main.c:312
callback_setup
static void callback_setup()
assigns read and status functions interrupts
Definition: main.c:267
MainState_type
MainState_type
Definition: main.c:44
NUMBER_IRPyro
#define NUMBER_IRPyro
Definition: externals.h:32
IRPyro_device
IRPyro_devices IRPyro_device
Definition: main.c:76
BoardType
uint8_t BoardType
Definition: main.c:56
command_decode
@ command_decode
Definition: main.c:46