Paparazzi UAS  v5.10_stable-5-g83a0da5-dirty
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) 2015 The Paparazzi Team
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 "mt9v117.h"
34 #include "mt9f002.h"
35 #include "mcu.h"
36 #include "boards/bebop.h"
37 
38 static int kill_gracefull(char *process_name)
39 {
40  /* "pidof" always in /bin on Bebop firmware tested 1.98, 2.0.57, no need for "which" */
41  char pidof_commandline[200] = "/bin/pidof ";
42  strcat(pidof_commandline, process_name);
43  /* Bebop Busybox a
44  $ cat /proc/sys/kernel/pid_max
45  Gives max 32768, makes sure it never kills existing other process
46  */
47  char pid[7] = "";
48  int ret = 0; /* Return code of kill system call */
49  FILE *fp;
50 
51  while (ret == 0) {
52  fp = popen(pidof_commandline, "r");
53  if (fp != NULL) { /* Could open the pidof with line */
54  if (fgets(pid, sizeof(pid) - 1, fp) != NULL) {
55  //printf("Process ID deducted: \"%s\"\n", pid);
56  if (atoi(pid) > 0) { /* To make sure we end 0 > There is a real process id found */
57  char kill_command_and_process[200] = "kill -9 "; /* BTW there is no pkill on this Busybox */
58  strcat(kill_command_and_process, pid);
59  ret = system(kill_command_and_process);
60  /* No need to wait, since if it is not closed the next pidof scan still will still find it and try to kill it */
61  }
62  } else {
63  ret = 256; /* Could not get handle */
64  pclose(fp);
65  }
66  } else {
67  ret = 256; /* fp NULL, so no process, just return */
68  return 0;
69  }
70  } /* end while */
71  return 0;
72 }
73 
74 void board_init(void)
75 {
76  /*
77  * Process running by default for firmware >= v1.98
78  *
79  * - /bin/sh - /usr/bin/DragonStarter.sh -out2null
80  * - //usr/bin/dragon-prog
81  *
82  * Thus two process to kill, the DragonStarter first
83  * This to make sure OEM program does not get re-started
84  *
85  */
86  int ret __attribute__((unused)) = system("killall -q -15 DragonStarter.sh");
87  usleep(50000); /* Give DragonStarter 50ms time to end on a busy system */
88  kill_gracefull("dragon-prog");
89 }
90 
91 void board_init2(void)
92 {
93  /* Initialize MT9V117 chipset (Bottom camera) */
94  struct mt9v117_t mt9v117 = {
95  // Initial values
96 
97  // I2C connection port
98  .i2c_periph = &i2c0
99  };
100  mt9v117_init(&mt9v117);
101 
102  /* Initialize MT9F002 chipset (Front camera) */
103  struct mt9f002_t mt9f002 = {
104  // Precomputed values to go from InputCLK of (26/2)MHz to 96MH
106  .input_clk_freq = (26 / 2),
107  .vt_pix_clk_div = 7,
108  .vt_sys_clk_div = 1,
109  .pre_pll_clk_div = 1,
110  .pll_multiplier = 59,
111  .op_pix_clk_div = 8,
112  .op_sys_clk_div = 1,
114  .rowSpeed_2_0 = 1,
115  .row_speed_10_8 = 1,
116 
117  // Initial values
120  .gain_green1 = 2.0,
121  .gain_blue = 2.0,
122  .gain_red = 2.0,
123  .gain_green2 = 2.0,
129 
130  // I2C connection port
131  .i2c_periph = &i2c0
132  };
133 
134  mt9f002_init(&mt9f002);
135 }
#define MT9F002_TARGET_EXPOSURE
Exposure of the front camera of the bebop.
Definition: bebop.h:75
uint16_t output_height
Output height.
Definition: mt9f002.h:69
uint16_t op_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:49
#define MT9F002_TARGET_FPS
Definition: bebop.h:79
uint8_t rowSpeed_2_0
Fixed PLL config from calculator tool.
Definition: mt9f002.h:51
uint16_t vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:44
Initialization and configuration of the MT9V117 CMOS Chip.
uint16_t pll_multiplier
Fixed PLL config from calculator tool.
Definition: mt9f002.h:47
#define MT9F002_OUTPUT_WIDTH
Definition: bebop.h:36
float gain_blue
Gain for the Blue pixels [1.5 -> 63.50].
Definition: mt9f002.h:64
uint16_t offset_x
Offset from left in pixels.
Definition: mt9f002.h:73
uint16_t vt_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:45
void mt9f002_init(struct mt9f002_t *mt)
Initialisation of the Aptina MT9F002 CMOS sensor (front camera)
Definition: mt9f002.c:788
void board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: board.c:91
float output_scaler
Output scale.
Definition: mt9f002.h:70
uint8_t shift_vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:50
uint8_t row_speed_10_8
Fixed PLL config from calculator tool.
Definition: mt9f002.h:52
enum mt9f002_interface interface
Interface used to connect.
Definition: mt9f002.h:42
#define MT9F002_OUTPUT_HEIGHT
Definition: bebop.h:32
float gain_green1
Gain for the GreenR pixels [1.5 -> 63.50].
Definition: mt9f002.h:63
uint16_t output_width
Output width.
Definition: mt9f002.h:68
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:58
void mt9v117_init(struct mt9v117_t *mt)
Initialisation of the Aptina MT9V117 CMOS sensor (1/6 inch VGA, bottom camera)
Definition: mt9v117.c:363
float gain_red
Gain for the Red pixels [1.5 -> 63.50].
Definition: mt9f002.h:65
float gain_green2
Gain for the GreenB pixels [1.5 -> 63.50].
Definition: mt9f002.h:66
Initialization and configuration of the MT9F002 CMOS Chip.
uint16_t offset_y
Offset from top in pixels.
Definition: mt9f002.h:74
#define MT9F002_INITIAL_OFFSET_Y
Definition: bebop.h:44
I2C peripheral structure.
Definition: i2c.h:138
Arch independent mcu ( Micro Controller Unit ) utilities.
#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: bebop.h:66
uint16_t op_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:48
#define MT9F002_INITIAL_OFFSET_X
Definition: bebop.h:40
uint16_t pre_pll_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:46
Parallel type connection.
Definition: mt9f002.h:37
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition: mt9v117.h:36
float target_exposure
Target exposure time in ms.
Definition: mt9f002.h:60
static int kill_gracefull(char *process_name)
Definition: board.c:38
Architecture independent I2C (Inter-Integrated Circuit Bus) API.