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) 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 /* Initialize MT9F002 chipset (Front camera) */
39 struct mt9f002_t mt9f002 = {
40  // Precomputed values to go from InputCLK of (26/2)MHz to 96MH
42  .input_clk_freq = (26 / 2),
43  .vt_pix_clk_div = 7,
44  .vt_sys_clk_div = 1,
45  .pre_pll_clk_div = 1,
46  .pll_multiplier = 59,
47  .op_pix_clk_div = 8,
48  .op_sys_clk_div = 1,
50  .rowSpeed_2_0 = 1,
51  .row_speed_10_8 = 1,
52 
53  // Initial values
65 
68 
69  // I2C connection port
70  .i2c_periph = &i2c0
71 };
72 
73 static int kill_gracefull(char *process_name)
74 {
75  /* "pidof" always in /bin on Bebop firmware tested 1.98, 2.0.57, no need for "which" */
76  char pidof_commandline[200] = "/bin/pidof ";
77  strcat(pidof_commandline, process_name);
78  /* Bebop Busybox a
79  $ cat /proc/sys/kernel/pid_max
80  Gives max 32768, makes sure it never kills existing other process
81  */
82  char pid[7] = "";
83  int ret = 0; /* Return code of kill system call */
84  FILE *fp;
85 
86  while (ret == 0) {
87  fp = popen(pidof_commandline, "r");
88  if (fp != NULL) { /* Could open the pidof with line */
89  if (fgets(pid, sizeof(pid) - 1, fp) != NULL) {
90  //printf("Process ID deducted: \"%s\"\n", pid);
91  if (atoi(pid) > 0) { /* To make sure we end 0 > There is a real process id found */
92  char kill_command_and_process[200] = "kill -9 "; /* BTW there is no pkill on this Busybox */
93  strcat(kill_command_and_process, pid);
94  ret = system(kill_command_and_process);
95  /* No need to wait, since if it is not closed the next pidof scan still will still find it and try to kill it */
96  }
97  } else {
98  ret = 256; /* Could not get handle */
99  pclose(fp);
100  }
101  } else {
102  ret = 256; /* fp NULL, so no process, just return */
103  return 0;
104  }
105  } /* end while */
106  return 0;
107 }
108 
109 void board_init(void)
110 {
111  /*
112  * Process running by default for firmware >= v1.98
113  *
114  * - /bin/sh - /usr/bin/DragonStarter.sh -out2null
115  * - //usr/bin/dragon-prog
116  *
117  * Thus two process to kill, the DragonStarter first
118  * This to make sure OEM program does not get re-started
119  *
120  */
121  int ret __attribute__((unused)) = system("killall -q -15 DragonStarter.sh");
122  usleep(50000); /* Give DragonStarter 50ms time to end on a busy system */
123  kill_gracefull("dragon-prog");
124 }
125 
126 void board_init2(void)
127 {
128  /* Initialize MT9V117 chipset (Bottom camera) */
129  struct mt9v117_t mt9v117 = {
130  // Initial values
131 
132  // I2C connection port
133  .i2c_periph = &i2c0
134  };
135  mt9v117_init(&mt9v117);
136 
137  mt9f002_init(&mt9f002);
138 }
#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:149
uint16_t output_height
Output height.
Definition: mt9f002.h:142
uint16_t op_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:122
uint8_t rowSpeed_2_0
Fixed PLL config from calculator tool.
Definition: mt9f002.h:124
#define MT9F002_OUTPUT_HEIGHT
Definition: mt9f002.h:35
uint16_t vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:117
#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:120
#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:137
#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:147
uint8_t y_odd_inc
Y increment for subsampling (1,3,7 accepted)
Definition: mt9f002.h:150
uint16_t vt_sys_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:118
#define MT9F002_GAIN_GREEN1
Definition: mt9f002.h:80
void mt9f002_init(struct mt9f002_t *mt)
Initialisation of the Aptina MT9F002 CMOS sensor (front camera)
Definition: mt9f002.c:856
float offset_x
Offset from left in pixels.
Definition: mt9f002.h:146
void board_init2(void)
Optional board init function called at the end of mcu_init().
Definition: board.c:126
float output_scaler
Output scale.
Definition: mt9f002.h:143
uint8_t shift_vt_pix_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:123
uint8_t row_speed_10_8
Fixed PLL config from calculator tool.
Definition: mt9f002.h:125
enum mt9f002_interface interface
Interface used to connect.
Definition: mt9f002.h:115
#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:136
uint16_t output_width
Output width.
Definition: mt9f002.h:141
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:131
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:138
#define MT9F002_OUTPUT_WIDTH
Definition: mt9f002.h:39
float gain_green2
Gain for the GreenB pixels [1.5 -> 63.50].
Definition: mt9f002.h:139
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:121
#define MT9F002_GAIN_RED
Definition: mt9f002.h:88
uint16_t pre_pll_clk_div
Fixed PLL config from calculator tool.
Definition: mt9f002.h:119
Parallel type connection.
Definition: mt9f002.h:110
struct i2c_periph * i2c_periph
I2C peripheral used to communicate over.
Definition: mt9v117.h:36
#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:133
static int kill_gracefull(char *process_name)
Definition: board.c:73
Architecture independent I2C (Inter-Integrated Circuit Bus) API.