Opencv 3.1 project on GR-PEACH board

Fork of gr-peach-opencv-project by the do

Committer:
thedo
Date:
Tue Jul 04 06:23:13 2017 +0000
Revision:
170:54ff26da7eb6
Parent:
166:3a9487d57a5c
project opencv 3.1 on GR PEACH board, no use SD card.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
thedo 166:3a9487d57a5c 1 /*******************************************************************************
thedo 166:3a9487d57a5c 2 * DISCLAIMER
thedo 166:3a9487d57a5c 3 * This software is supplied by Renesas Electronics Corporation and is only
thedo 166:3a9487d57a5c 4 * intended for use with Renesas products. No other uses are authorized. This
thedo 166:3a9487d57a5c 5 * software is owned by Renesas Electronics Corporation and is protected under
thedo 166:3a9487d57a5c 6 * all applicable laws, including copyright laws.
thedo 166:3a9487d57a5c 7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
thedo 166:3a9487d57a5c 8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
thedo 166:3a9487d57a5c 9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
thedo 166:3a9487d57a5c 10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
thedo 166:3a9487d57a5c 11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
thedo 166:3a9487d57a5c 12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
thedo 166:3a9487d57a5c 13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
thedo 166:3a9487d57a5c 14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
thedo 166:3a9487d57a5c 15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
thedo 166:3a9487d57a5c 16 * Renesas reserves the right, without notice, to make changes to this software
thedo 166:3a9487d57a5c 17 * and to discontinue the availability of this software. By using this software,
thedo 166:3a9487d57a5c 18 * you agree to the additional terms and conditions found by accessing the
thedo 166:3a9487d57a5c 19 * following link:
thedo 166:3a9487d57a5c 20 * http://www.renesas.com/disclaimer
thedo 166:3a9487d57a5c 21 * Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
thedo 166:3a9487d57a5c 22 *******************************************************************************/
thedo 166:3a9487d57a5c 23 /**************************************************************************//**
thedo 166:3a9487d57a5c 24 * @file lvds_pll_main.c
thedo 166:3a9487d57a5c 25 * @version 1.00
thedo 166:3a9487d57a5c 26 * $Rev: 199 $
thedo 166:3a9487d57a5c 27 * $Date:: 2014-05-23 16:33:52 +0900#$
thedo 166:3a9487d57a5c 28 * @brief lvds pll setting value
thedo 166:3a9487d57a5c 29 ******************************************************************************/
thedo 166:3a9487d57a5c 30
thedo 166:3a9487d57a5c 31 /******************************************************************************
thedo 166:3a9487d57a5c 32 Includes <System Includes> , "Project Includes"
thedo 166:3a9487d57a5c 33 ******************************************************************************/
thedo 166:3a9487d57a5c 34 #include <stdio.h>
thedo 166:3a9487d57a5c 35 #include <stdlib.h>
thedo 166:3a9487d57a5c 36 #include <math.h>
thedo 166:3a9487d57a5c 37
thedo 166:3a9487d57a5c 38 #include "r_typedefs.h"
thedo 166:3a9487d57a5c 39 #include "lvds_pll_calc.h"
thedo 166:3a9487d57a5c 40
thedo 166:3a9487d57a5c 41 /******************************************************************************
thedo 166:3a9487d57a5c 42 Macro definitions
thedo 166:3a9487d57a5c 43 ******************************************************************************/
thedo 166:3a9487d57a5c 44 /* FIN: LVDS PLL input frequency */
thedo 166:3a9487d57a5c 45 #define FIN_MIN (9.0) /*!< The lower limit of the FIN */
thedo 166:3a9487d57a5c 46 #define FIN_MAX (30.0) /*!< The upper limit of the FIN */
thedo 166:3a9487d57a5c 47 /* FREF */
thedo 166:3a9487d57a5c 48 #define FREF_MIN (2.5) /*!< The lower limit of the FREF */
thedo 166:3a9487d57a5c 49 #define FREF_MAX (30.0) /*!< The upper limit of the FREF */
thedo 166:3a9487d57a5c 50 /* FVCO: VCO output frequency */
thedo 166:3a9487d57a5c 51 #define FVCO_MIN (750.0) /*!< The lower limit of the FVCO */
thedo 166:3a9487d57a5c 52 #define FVCO_MAX (1630.0) /*!< The upper limit of the FVCO */
thedo 166:3a9487d57a5c 53 /* FOUT: LVDS PLL output frequency */
thedo 166:3a9487d57a5c 54 #define FOUT_MIN (0.0) /*!< The lower limit of the FOUT */
thedo 166:3a9487d57a5c 55 #define FOUT_MAX (609.0) /*!< The upper limit of the FOUT */
thedo 166:3a9487d57a5c 56
thedo 166:3a9487d57a5c 57 #define DIVIDER_3 (7.0) /*!< The frequency dividing value for frequency divider 3 */
thedo 166:3a9487d57a5c 58
thedo 166:3a9487d57a5c 59
thedo 166:3a9487d57a5c 60 /******************************************************************************
thedo 166:3a9487d57a5c 61 Typedef definitions
thedo 166:3a9487d57a5c 62 ******************************************************************************/
thedo 166:3a9487d57a5c 63
thedo 166:3a9487d57a5c 64
thedo 166:3a9487d57a5c 65 /******************************************************************************
thedo 166:3a9487d57a5c 66 Variable Externs
thedo 166:3a9487d57a5c 67 ******************************************************************************/
thedo 166:3a9487d57a5c 68 extern const double NIDIV_data[];
thedo 166:3a9487d57a5c 69 extern const double NRD_data[];
thedo 166:3a9487d57a5c 70 extern const double NFD_data[];
thedo 166:3a9487d57a5c 71 extern const double NOD_data[];
thedo 166:3a9487d57a5c 72 extern const double NODIV_data[];
thedo 166:3a9487d57a5c 73
thedo 166:3a9487d57a5c 74
thedo 166:3a9487d57a5c 75 /******************************************************************************
thedo 166:3a9487d57a5c 76 Private global variables and functions
thedo 166:3a9487d57a5c 77 ******************************************************************************/
thedo 166:3a9487d57a5c 78 static double InputClock;
thedo 166:3a9487d57a5c 79 static double OutputClock;
thedo 166:3a9487d57a5c 80 static int LvdsUsed;
thedo 166:3a9487d57a5c 81
thedo 166:3a9487d57a5c 82
thedo 166:3a9487d57a5c 83
thedo 166:3a9487d57a5c 84 /**************************************************************************//**
thedo 166:3a9487d57a5c 85 * @brief
thedo 166:3a9487d57a5c 86 * @param [in,out]param
thedo 166:3a9487d57a5c 87 * @param [in]fout
thedo 166:3a9487d57a5c 88 * @retval int
thedo 166:3a9487d57a5c 89 *****************************************************************************/
thedo 166:3a9487d57a5c 90 static int compare_nodiv (pll_parameter_t * param, double fout)
thedo 166:3a9487d57a5c 91 {
thedo 166:3a9487d57a5c 92 int change;
thedo 166:3a9487d57a5c 93 const double * nodiv_list;
thedo 166:3a9487d57a5c 94 double diff_freq;
thedo 166:3a9487d57a5c 95
thedo 166:3a9487d57a5c 96 change = 0;
thedo 166:3a9487d57a5c 97 nodiv_list = NODIV_data;
thedo 166:3a9487d57a5c 98 while (*nodiv_list != 0.0) {
thedo 166:3a9487d57a5c 99 diff_freq = fabs(OutputClock - (fout / *nodiv_list));
thedo 166:3a9487d57a5c 100 if (param->comparison_freq > diff_freq) {
thedo 166:3a9487d57a5c 101 param->comparison_freq = diff_freq;
thedo 166:3a9487d57a5c 102 param->output_freq = fout / *nodiv_list;
thedo 166:3a9487d57a5c 103 param->nodiv = *nodiv_list;
thedo 166:3a9487d57a5c 104 change = 1;
thedo 166:3a9487d57a5c 105 }
thedo 166:3a9487d57a5c 106 nodiv_list++;
thedo 166:3a9487d57a5c 107 }
thedo 166:3a9487d57a5c 108 return change;
thedo 166:3a9487d57a5c 109 }
thedo 166:3a9487d57a5c 110
thedo 166:3a9487d57a5c 111 /**************************************************************************//**
thedo 166:3a9487d57a5c 112 * @brief
thedo 166:3a9487d57a5c 113 * @param [in,out]param
thedo 166:3a9487d57a5c 114 * @param [in]fout
thedo 166:3a9487d57a5c 115 * @retval int
thedo 166:3a9487d57a5c 116 *****************************************************************************/
thedo 166:3a9487d57a5c 117 static int compare_div3 (pll_parameter_t * param, double fout)
thedo 166:3a9487d57a5c 118 {
thedo 166:3a9487d57a5c 119 double diff_freq;
thedo 166:3a9487d57a5c 120 int change;
thedo 166:3a9487d57a5c 121
thedo 166:3a9487d57a5c 122 change = 0;
thedo 166:3a9487d57a5c 123 diff_freq = fabs(OutputClock - (fout / DIVIDER_3));
thedo 166:3a9487d57a5c 124
thedo 166:3a9487d57a5c 125 if (param->comparison_freq > diff_freq) {
thedo 166:3a9487d57a5c 126 param->comparison_freq = diff_freq;
thedo 166:3a9487d57a5c 127 param->output_freq = fout / DIVIDER_3;
thedo 166:3a9487d57a5c 128 change = 1;
thedo 166:3a9487d57a5c 129 }
thedo 166:3a9487d57a5c 130 return change;
thedo 166:3a9487d57a5c 131 }
thedo 166:3a9487d57a5c 132
thedo 166:3a9487d57a5c 133 /**************************************************************************//**
thedo 166:3a9487d57a5c 134 * @brief
thedo 166:3a9487d57a5c 135 * @param [out]param
thedo 166:3a9487d57a5c 136 * @retval None
thedo 166:3a9487d57a5c 137 *****************************************************************************/
thedo 166:3a9487d57a5c 138 static void SeekValue (pll_parameter_t * param)
thedo 166:3a9487d57a5c 139 {
thedo 166:3a9487d57a5c 140 const double * nidiv_list;
thedo 166:3a9487d57a5c 141 const double * nrd_list;
thedo 166:3a9487d57a5c 142 const double * nfd_list;
thedo 166:3a9487d57a5c 143 const double * nod_list;
thedo 166:3a9487d57a5c 144
thedo 166:3a9487d57a5c 145 double fin;
thedo 166:3a9487d57a5c 146 double fref;
thedo 166:3a9487d57a5c 147 double fvco;
thedo 166:3a9487d57a5c 148 double fout;
thedo 166:3a9487d57a5c 149 int ret;
thedo 166:3a9487d57a5c 150
thedo 166:3a9487d57a5c 151 nidiv_list = NIDIV_data;
thedo 166:3a9487d57a5c 152 while (*nidiv_list != 0.0) {
thedo 166:3a9487d57a5c 153 fin = InputClock / *nidiv_list;
thedo 166:3a9487d57a5c 154 if ((fin < FIN_MIN) || (FIN_MAX < fin)) {
thedo 166:3a9487d57a5c 155 nidiv_list++;
thedo 166:3a9487d57a5c 156 continue;
thedo 166:3a9487d57a5c 157 }
thedo 166:3a9487d57a5c 158 nrd_list = NRD_data;
thedo 166:3a9487d57a5c 159 while (*nrd_list != 0.0) {
thedo 166:3a9487d57a5c 160 fref = fin / *nrd_list;
thedo 166:3a9487d57a5c 161 if ((fref < FREF_MIN) || (FREF_MAX < fref)) {
thedo 166:3a9487d57a5c 162 nrd_list++;
thedo 166:3a9487d57a5c 163 continue;
thedo 166:3a9487d57a5c 164 }
thedo 166:3a9487d57a5c 165 nfd_list = NFD_data;
thedo 166:3a9487d57a5c 166 while (*nfd_list != 0.0) {
thedo 166:3a9487d57a5c 167 fvco = fref * (*nfd_list);
thedo 166:3a9487d57a5c 168 if ((fvco < FVCO_MIN) || (FVCO_MAX < fvco)) {
thedo 166:3a9487d57a5c 169 nfd_list++;
thedo 166:3a9487d57a5c 170 continue;
thedo 166:3a9487d57a5c 171 }
thedo 166:3a9487d57a5c 172 nod_list = NOD_data;
thedo 166:3a9487d57a5c 173 while (*nod_list != 0.0) {
thedo 166:3a9487d57a5c 174 fout = fvco / *nod_list;
thedo 166:3a9487d57a5c 175 if ((fout < FOUT_MIN) || (FOUT_MAX < fout)) {
thedo 166:3a9487d57a5c 176 nod_list++;
thedo 166:3a9487d57a5c 177 continue;
thedo 166:3a9487d57a5c 178 }
thedo 166:3a9487d57a5c 179
thedo 166:3a9487d57a5c 180 if (LvdsUsed == 0) {
thedo 166:3a9487d57a5c 181 ret = compare_nodiv(param, fout);
thedo 166:3a9487d57a5c 182 } else {
thedo 166:3a9487d57a5c 183 ret = compare_div3(param, fout);
thedo 166:3a9487d57a5c 184 }
thedo 166:3a9487d57a5c 185 if (ret != 0) {
thedo 166:3a9487d57a5c 186 param->nidiv = *nidiv_list;
thedo 166:3a9487d57a5c 187 param->nrd = *nrd_list;
thedo 166:3a9487d57a5c 188 param->nfd = *nfd_list;
thedo 166:3a9487d57a5c 189 param->nod = *nod_list;
thedo 166:3a9487d57a5c 190 }
thedo 166:3a9487d57a5c 191 nod_list++;
thedo 166:3a9487d57a5c 192 }
thedo 166:3a9487d57a5c 193 nfd_list++;
thedo 166:3a9487d57a5c 194 }
thedo 166:3a9487d57a5c 195 nrd_list++;
thedo 166:3a9487d57a5c 196 }
thedo 166:3a9487d57a5c 197 nidiv_list++;
thedo 166:3a9487d57a5c 198 }
thedo 166:3a9487d57a5c 199 }
thedo 166:3a9487d57a5c 200 /**************************************************************************//**
thedo 166:3a9487d57a5c 201 * @brief PLL value Calculation function
thedo 166:3a9487d57a5c 202 * @param[in] InClock : Input clock frequency [MHz]
thedo 166:3a9487d57a5c 203 * @param[in] OuClock : Output clock frequency [MHz]
thedo 166:3a9487d57a5c 204 * @param[in] Lvds : The LVDS output interface is used (=1) or not (=0)
thedo 166:3a9487d57a5c 205 * @param[out] result : pll_parameter_t
thedo 166:3a9487d57a5c 206 * @retval error (-1)
thedo 166:3a9487d57a5c 207 ******************************************************************************/
thedo 166:3a9487d57a5c 208 int32_t lvds_pll_calc(
thedo 166:3a9487d57a5c 209 const double InClock,
thedo 166:3a9487d57a5c 210 const double OuClock,
thedo 166:3a9487d57a5c 211 const uint32_t Lvds,
thedo 166:3a9487d57a5c 212 pll_parameter_t * result )
thedo 166:3a9487d57a5c 213 {
thedo 166:3a9487d57a5c 214 result->comparison_freq = 1000.0;
thedo 166:3a9487d57a5c 215 result->output_freq = 0.0;
thedo 166:3a9487d57a5c 216 result->nidiv = 0.0;
thedo 166:3a9487d57a5c 217 result->nrd = 0.0;
thedo 166:3a9487d57a5c 218 result->nfd = 0.0;
thedo 166:3a9487d57a5c 219 result->nod = 0.0;
thedo 166:3a9487d57a5c 220 result->nodiv = 0.0;
thedo 166:3a9487d57a5c 221
thedo 166:3a9487d57a5c 222 InputClock = InClock;
thedo 166:3a9487d57a5c 223 OutputClock = OuClock;
thedo 166:3a9487d57a5c 224 LvdsUsed = Lvds;
thedo 166:3a9487d57a5c 225
thedo 166:3a9487d57a5c 226 /* Calculation */
thedo 166:3a9487d57a5c 227 SeekValue(result);
thedo 166:3a9487d57a5c 228
thedo 166:3a9487d57a5c 229 result->nidiv = result->nidiv/2;
thedo 166:3a9487d57a5c 230 result->nodiv = result->nodiv/2;
thedo 166:3a9487d57a5c 231 if( result->nod <= 4 ) {
thedo 166:3a9487d57a5c 232 result->nod = result->nod/2;
thedo 166:3a9487d57a5c 233 } else if( result->nod == 8 ) {
thedo 166:3a9487d57a5c 234 result->nod = 3;
thedo 166:3a9487d57a5c 235 } else {
thedo 166:3a9487d57a5c 236 }
thedo 166:3a9487d57a5c 237 result->nrd -=1; /* nrd-1 */
thedo 166:3a9487d57a5c 238 return 0;
thedo 166:3a9487d57a5c 239 }