Paparazzi UAS  v5.12_stable-4-g9b43e9b
Paparazzi is a free software Unmanned Aircraft System.
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
board.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2017 Gautier Hattenberger <gautier.hattenberger@enac.fr>
3  *
4  * This file is part of paparazzi.
5  *
6  * paparazzi is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2, or (at your option)
9  * any later version.
10  *
11  * paparazzi is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with paparazzi; see the file COPYING. If not, see
18  * <http://www.gnu.org/licenses/>.
19  */
20 
28 #include <stdlib.h>
29 #include <stdio.h>
30 #include <string.h>
31 #include <unistd.h>
32 #include "mcu_periph/i2c.h"
33 #include "mcu.h"
34 #include "boards/disco.h"
35 // Reusing bebop video driver
36 #include "boards/bebop/mt9v117.h"
37 #include "boards/bebop/mt9f002.h"
38 
39 /* Initialize MT9F002 chipset (Front camera) */
40 //struct mt9f002_t mt9f002 = {
41 // // Precomputed values to go from InputCLK of (26/2)MHz to 96MH
42 // .interface = MT9F002_PARALLEL,
43 // .input_clk_freq = (26 / 2),
44 // .vt_pix_clk_div = 7,
45 // .vt_sys_clk_div = 1,
46 // .pre_pll_clk_div = 1,
47 // .pll_multiplier = 59,
48 // .op_pix_clk_div = 8,
49 // .op_sys_clk_div = 1,
50 // .shift_vt_pix_clk_div = 1,
51 // .rowSpeed_2_0 = 1,
52 // .row_speed_10_8 = 1,
53 //
54 // // Initial values
55 // .target_fps = MT9F002_TARGET_FPS,
56 // .target_exposure = MT9F002_TARGET_EXPOSURE,
57 // .gain_green1 = MT9F002_GAIN_GREEN1,
58 // .gain_blue = MT9F002_GAIN_BLUE,
59 // .gain_red = MT9F002_GAIN_RED,
60 // .gain_green2 = MT9F002_GAIN_GREEN2,
61 // .output_width = MT9F002_OUTPUT_WIDTH,
62 // .output_height = MT9F002_OUTPUT_HEIGHT,
63 // .output_scaler = MT9F002_OUTPUT_SCALER,
64 // .offset_x = MT9F002_INITIAL_OFFSET_X,
65 // .offset_y = MT9F002_INITIAL_OFFSET_Y,
66 //
67 // .x_odd_inc = MT9F002_X_ODD_INC_VAL,
68 // .y_odd_inc = MT9F002_Y_ODD_INC_VAL,
69 //
70 // // I2C connection port
71 // .i2c_periph = &i2c0
72 //};
73 
74 static int kill_gracefull(char *process_name)
75 {
76  /* "pidof" always in /bin on Bebop firmware tested 1.98, 2.0.57, no need for "which" */
77  char pidof_commandline[200] = "/bin/pidof ";
78  strcat(pidof_commandline, process_name);
79  /* Bebop Busybox a
80  $ cat /proc/sys/kernel/pid_max
81  Gives max 32768, makes sure it never kills existing other process
82  */
83  char pid[7] = "";
84  int ret = 0; /* Return code of kill system call */
85  FILE *fp;
86 
87  while (ret == 0) {
88  fp = popen(pidof_commandline, "r");
89  if (fp != NULL) { /* Could open the pidof with line */
90  if (fgets(pid, sizeof(pid) - 1, fp) != NULL) {
91  //printf("Process ID deducted: \"%s\"\n", pid);
92  if (atoi(pid) > 0) { /* To make sure we end 0 > There is a real process id found */
93  char kill_command_and_process[200] = "kill -9 "; /* BTW there is no pkill on this Busybox */
94  strcat(kill_command_and_process, pid);
95  ret = system(kill_command_and_process);
96  /* No need to wait, since if it is not closed the next pidof scan still will still find it and try to kill it */
97  }
98  } else {
99  ret = 256; /* Could not get handle */
100  pclose(fp);
101  }
102  } else {
103  ret = 256; /* fp NULL, so no process, just return */
104  return 0;
105  }
106  } /* end while */
107  return 0;
108 }
109 
110 void board_init(void)
111 {
112  /*
113  * Process running by default for firmware >= v1.98
114  *
115  * - /bin/sh - /usr/bin/DragonStarter.sh -out2null
116  * - //usr/bin/dragon-prog
117  *
118  * Thus two process to kill, the DragonStarter first
119  * This to make sure OEM program does not get re-started
120  *
121  */
122  int ret __attribute__((unused)) = system("killall -q -15 DragonStarter.sh");
123  usleep(50000); /* Give DragonStarter 50ms time to end on a busy system */
124  kill_gracefull("dragon-prog");
125 }
126 
127 void board_init2(void)
128 {
129  /* Initialize MT9V117 chipset (Bottom camera) */
130  //struct mt9v117_t mt9v117 = {
131  // // Initial values
132 
133  // // I2C connection port
134  // .i2c_periph = &i2c0
135  //};
136  //mt9v117_init(&mt9v117);
137 
138  //mt9f002_init(&mt9f002);
139 }
Initialization and configuration of the MT9V117 CMOS Chip.
void board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: board.c:126
void board_init(void)
Optional board init function called at the start of mcu_init().
Definition: board.c:130
static int kill_gracefull(char *process_name)
Definition: board.c:74
Initialization and configuration of the MT9F002 CMOS Chip.
Arch independent mcu ( Micro Controller Unit ) utilities.
Architecture independent I2C (Inter-Integrated Circuit Bus) API.