Paparazzi UAS  v5.14.0_stable-0-g3f680d1
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
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,
51  .rowSpeed_2_0 = 1,
52  .row_speed_10_8 = 1,
53 
54  // Initial values
66 
69 
70  // I2C connection port
71  .i2c_periph = &i2c0
72 };
73 
74 static int kill_gracefull(char *process_name)
75 {
76  /* TODO: "pidof" always in /bin on Disco firmware tested 1.4.1, no need for "which" */
77  char pidof_commandline[200] = "/bin/pidof ";
78  strcat(pidof_commandline, process_name);
79  /* On Disco 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.0.5
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  /* Initialize Front camera) */
139  //WIP mt9f002_init(&mt9f002);
140 }
#define MT9F002_Y_ODD_INC_VAL
Definition: mt9f002.h:103
uint8_t x_odd_inc
X increment for subsampling (1,3,7,15,31 accepted)
Definition: mt9f002.h:166
uint16_t output_height
Output height.
Definition: mt9f002.h:159
uint16_t op_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:139
uint8_t rowSpeed_2_0
Fixed PLL config from calculator tool.
Definition: mt9f002.h:141
#define MT9F002_OUTPUT_HEIGHT
Definition: mt9f002.h:35
uint16_t vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:134
#define MT9F002_INITIAL_OFFSET_X
Definition: mt9f002.h:43
Initialization and configuration of the MT9V117 CMOS Chip.
uint16_t pll_multiplier
Fixed PLL config from calculator tool.
Definition: mt9f002.h:137
#define MT9F002_GAIN_GREEN2
Definition: mt9f002.h:84
#define MT9F002_INITIAL_OFFSET_Y
Definition: mt9f002.h:47
float gain_blue
Gain for the Blue pixels [1.5 -> 63.50].
Definition: mt9f002.h:154
#define MT9F002_OUTPUT_SCALER
Our output is only OUTPUT_SCALER of the pixels we take of the sensor It is programmable in 1/16 steps...
Definition: mt9f002.h:62
float offset_y
Offset from top in pixels.
Definition: mt9f002.h:164
uint8_t y_odd_inc
Y increment for subsampling (1,3,7 accepted)
Definition: mt9f002.h:167
uint16_t vt_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:135
#define MT9F002_GAIN_GREEN1
Definition: mt9f002.h:80
float offset_x
Offset from left in pixels.
Definition: mt9f002.h:163
void board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: board.c:129
float output_scaler
Output scale.
Definition: mt9f002.h:160
uint8_t shift_vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:140
uint8_t row_speed_10_8
Fixed PLL config from calculator tool.
Definition: mt9f002.h:142
enum mt9f002_interface interface
Interface used to connect.
Definition: mt9f002.h:132
#define MT9F002_TARGET_EXPOSURE
Exposure of the front camera of the bebop.
Definition: mt9f002.h:71
#define MT9F002_X_ODD_INC_VAL
Definition: mt9f002.h:98
float gain_green1
Gain for the GreenR pixels [1.5 -> 63.50].
Definition: mt9f002.h:153
uint16_t output_width
Output width.
Definition: mt9f002.h:158
void board_init(void)
Optional board init function called at the start of mcu_init().
Definition: board.c:130
float target_fps
FPS wanted.
Definition: mt9f002.h:148
void mt9v117_init(struct mt9v117_t *mt)
Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera)
Definition: mt9v117.c:368
float gain_red
Gain for the Red pixels [1.5 -> 63.50].
Definition: mt9f002.h:155
#define MT9F002_OUTPUT_WIDTH
Definition: mt9f002.h:39
static int kill_gracefull(char *process_name)
Definition: board.c:74
float gain_green2
Gain for the GreenB pixels [1.5 -> 63.50].
Definition: mt9f002.h:156
Initialization and configuration of the MT9F002 CMOS Chip.
I2C peripheral structure.
Definition: i2c.h:138
Arch independent mcu ( Micro Controller Unit ) utilities.
struct mt9f002_t mt9f002
Definition: board.c:39
uint16_t op_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:138
#define MT9F002_GAIN_RED
Definition: mt9f002.h:88
uint16_t pre_pll_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:136
Parallel type connection.
Definition: mt9f002.h:127
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition: mt9v117.h:56
#define MT9F002_GAIN_BLUE
Definition: mt9f002.h:92
#define MT9F002_TARGET_FPS
Definition: mt9f002.h:75
float target_exposure
Target exposure time in ms.
Definition: mt9f002.h:150
Architecture independent I2C (Inter-Integrated Circuit Bus) API.