| 1 |
/* |
| 2 |
* Copyright 2018 Martin Ã…berg |
| 3 |
* |
| 4 |
* This file is part of Footag. |
| 5 |
* |
| 6 |
* Footag is free software: you can redistribute it and/or modify it under the |
| 7 |
* terms of the GNU General Public License as published by the Free Software |
| 8 |
* Foundation, either version 3 of the License, or (at your option) any later |
| 9 |
* version. |
| 10 |
* |
| 11 |
* Footag is distributed in the hope that it will be useful, but WITHOUT ANY |
| 12 |
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
| 13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
| 14 |
* details. |
| 15 |
* |
| 16 |
* You should have received a copy of the GNU General Public License along with |
| 17 |
* this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <math.h> |
| 21 |
#include <stddef.h> |
| 22 |
|
| 23 |
#include "priv.h" |
| 24 |
|
| 25 |
/* |
| 26 |
* Calculate Euclidian distance from origin to (a,b,c) |
| 27 |
* |
| 28 |
* NOTE: This is NOT the root mean square as claimed in IPC-7351B. |
| 29 |
*/ |
| 30 |
static double ed3(double a, double b, double c) |
| 31 |
{ |
| 32 |
return sqrt(a * a + b * b + c * c); |
| 33 |
} |
| 34 |
|
| 35 |
static void calc( |
| 36 |
const struct ipcb_comp *comp, |
| 37 |
const struct ipcb_attr *attr, |
| 38 |
struct ipcb_twospec *spec |
| 39 |
) |
| 40 |
{ |
| 41 |
double cl, cs, cw; |
| 42 |
double smax_mod; |
| 43 |
double smin = comp->l.min - 2 * comp->t.max; |
| 44 |
double smax = comp->l.max - 2 * comp->t.min; |
| 45 |
|
| 46 |
{ |
| 47 |
double ltol = footol_range(&comp->l); |
| 48 |
double ttol = footol_range(&comp->t); |
| 49 |
double wtol = footol_range(&comp->w); |
| 50 |
double stol = smax - smin; |
| 51 |
double stol_ed3; |
| 52 |
|
| 53 |
stol_ed3 = ed3(ltol, ttol, ttol); |
| 54 |
smax_mod = smax - (stol - stol_ed3) / 2; |
| 55 |
|
| 56 |
cl = ltol; |
| 57 |
cs = stol_ed3; |
| 58 |
cw = wtol; |
| 59 |
} |
| 60 |
|
| 61 |
spec->smin = smin; |
| 62 |
spec->zmax = comp->l.min + ed3(cl, attr->f, attr->p); |
| 63 |
spec->gmin = smax_mod - ed3(cs, attr->f, attr->p); |
| 64 |
spec->xmax = comp->w.min + ed3(cw, attr->f, attr->p); |
| 65 |
} |
| 66 |
|
| 67 |
static void calcuser( |
| 68 |
const struct ipcbtable *table, |
| 69 |
const struct ipcb_attr *attr, |
| 70 |
struct ipcb_twospec *spec |
| 71 |
) |
| 72 |
{ |
| 73 |
spec->round = table->round; |
| 74 |
spec->cyexc = table->cyexc[attr->density]; |
| 75 |
spec->ref.where = table->ref; |
| 76 |
spec->ref.what = table->desc; |
| 77 |
spec->land.dist = (spec->zmax + spec->gmin) / 2.0; |
| 78 |
spec->land.w = spec->xmax; |
| 79 |
spec->land.h = (spec->zmax - spec->gmin) / 2.0; |
| 80 |
} |
| 81 |
|
| 82 |
static int get_common( |
| 83 |
struct ipcb_twospec *spec, |
| 84 |
const struct ipcb_comp *comp, |
| 85 |
const struct ipcb_attr *attr, |
| 86 |
const struct ipcbtable *table |
| 87 |
) |
| 88 |
{ |
| 89 |
calc(comp, attr, spec); |
| 90 |
spec->zmax += 2 * table->toe [attr->density]; |
| 91 |
spec->gmin -= 2 * table->heel[attr->density]; |
| 92 |
spec->xmax += 2 * table->side[attr->density]; |
| 93 |
calcuser(table, attr, spec); |
| 94 |
return 0; |
| 95 |
} |
| 96 |
|
| 97 |
/* Chip components have two different tables, selected on dimensions. */ |
| 98 |
int ipcb_get_chip( |
| 99 |
struct ipcb_twospec *spec, |
| 100 |
const struct ipcb_comp *comp, |
| 101 |
const struct ipcb_attr *attr |
| 102 |
) |
| 103 |
{ |
| 104 |
if ((comp->l.nom < 1.6) || (comp->w.nom < 0.8)) { |
| 105 |
return get_common(spec, comp, attr, &ipcb_table3_6); |
| 106 |
} else { |
| 107 |
return get_common(spec, comp, attr, &ipcb_table3_5); |
| 108 |
} |
| 109 |
} |
| 110 |
|
| 111 |
int ipcb_get_melf( |
| 112 |
struct ipcb_twospec *spec, |
| 113 |
const struct ipcb_comp *comp, |
| 114 |
const struct ipcb_attr *attr |
| 115 |
) |
| 116 |
{ |
| 117 |
return get_common(spec, comp, attr, &ipcb_table3_7); |
| 118 |
} |
| 119 |
|
| 120 |
/* Molded have lead in opposite direction. */ |
| 121 |
int ipcb_get_molded( |
| 122 |
struct ipcb_twospec *spec, |
| 123 |
const struct ipcb_comp *comp, |
| 124 |
const struct ipcb_attr *attr |
| 125 |
) |
| 126 |
{ |
| 127 |
const struct ipcbtable *table; |
| 128 |
|
| 129 |
calc(comp, attr, spec); |
| 130 |
|
| 131 |
table = &ipcb_table3_13; |
| 132 |
spec->zmax += 2 * table->heel[attr->density]; |
| 133 |
spec->gmin -= 2 * table->toe [attr->density]; |
| 134 |
spec->xmax += 2 * table->side[attr->density]; |
| 135 |
|
| 136 |
calcuser(table, attr, spec); |
| 137 |
|
| 138 |
return 0; |
| 139 |
} |
| 140 |
|
| 141 |
int ipcb_get_sideconcave( |
| 142 |
struct ipcb_twospec *spec, |
| 143 |
const struct ipcb_comp *comp, |
| 144 |
const struct ipcb_attr *attr |
| 145 |
) |
| 146 |
{ |
| 147 |
return get_common(spec, comp, attr, &ipcb_table3_9); |
| 148 |
} |
| 149 |
|
| 150 |
int ipcb_get_concavearray( |
| 151 |
struct ipcb_twospec *spec, |
| 152 |
const struct ipcb_comp *comp, |
| 153 |
const struct ipcb_attr *attr |
| 154 |
) |
| 155 |
{ |
| 156 |
return get_common(spec, comp, attr, &ipcb_table3_9); |
| 157 |
} |
| 158 |
|
| 159 |
int ipcb_get_convexarray( |
| 160 |
struct ipcb_twospec *spec, |
| 161 |
const struct ipcb_comp *comp, |
| 162 |
const struct ipcb_attr *attr |
| 163 |
) |
| 164 |
{ |
| 165 |
return get_common(spec, comp, attr, &ipcb_table3_10); |
| 166 |
} |
| 167 |
|
| 168 |
int ipcb_get_flatarray( |
| 169 |
struct ipcb_twospec *spec, |
| 170 |
const struct ipcb_comp *comp, |
| 171 |
const struct ipcb_attr *attr |
| 172 |
) |
| 173 |
{ |
| 174 |
return get_common(spec, comp, attr, &ipcb_table3_11); |
| 175 |
} |
| 176 |
|
| 177 |
int ipcb_get_gullwing( |
| 178 |
struct ipcb_twospec *spec, |
| 179 |
const struct ipcb_comp *comp, |
| 180 |
const struct ipcb_attr *attr, |
| 181 |
double pitch |
| 182 |
) |
| 183 |
{ |
| 184 |
const struct ipcbtable *table; |
| 185 |
|
| 186 |
calc(comp, attr, spec); |
| 187 |
|
| 188 |
table = &ipcb_table3_2; |
| 189 |
if (pitch <= 0.625) { |
| 190 |
table = &ipcb_table3_3; |
| 191 |
} |
| 192 |
|
| 193 |
double heel = table->heel[attr->density]; |
| 194 |
|
| 195 |
/* |
| 196 |
* NOTE: Table 3-2 and Table 3-3, Note 1 and Note 2 not implemented. |
| 197 |
*/ |
| 198 |
if (0) { |
| 199 |
heel = (double []) { |
| 200 |
[IPCB_DENSITY_M] = 0.25, |
| 201 |
[IPCB_DENSITY_N] = 0.15, |
| 202 |
[IPCB_DENSITY_L] = 0.05 |
| 203 |
}[attr->density]; |
| 204 |
} |
| 205 |
|
| 206 |
spec->zmax += 2 * table->toe [attr->density]; |
| 207 |
spec->gmin -= 2 * heel; |
| 208 |
spec->xmax += 2 * table->side[attr->density]; |
| 209 |
|
| 210 |
calcuser(table, attr, spec); |
| 211 |
|
| 212 |
return 0; |
| 213 |
} |
| 214 |
|
| 215 |
/* "J Leads" have lead in opposite direction. */ |
| 216 |
int ipcb_get_jlead( |
| 217 |
struct ipcb_twospec *spec, |
| 218 |
const struct ipcb_comp *comp, |
| 219 |
const struct ipcb_attr *attr |
| 220 |
) |
| 221 |
{ |
| 222 |
const struct ipcbtable *table; |
| 223 |
|
| 224 |
calc(comp, attr, spec); |
| 225 |
|
| 226 |
table = &ipcb_table3_4; |
| 227 |
spec->zmax += 2 * table->heel[attr->density]; |
| 228 |
spec->gmin -= 2 * table->toe [attr->density]; |
| 229 |
spec->xmax += 2 * table->side[attr->density]; |
| 230 |
|
| 231 |
calcuser(table, attr, spec); |
| 232 |
|
| 233 |
return 0; |
| 234 |
} |
| 235 |
|
| 236 |
/* NOTE: Note 1 not implemented because I don't understand it. */ |
| 237 |
int ipcb_get_son( |
| 238 |
struct ipcb_twospec *spec, |
| 239 |
const struct ipcb_comp *comp, |
| 240 |
const struct ipcb_attr *attr |
| 241 |
) |
| 242 |
{ |
| 243 |
return get_common(spec, comp, attr, &ipcb_table3_16); |
| 244 |
} |
| 245 |
|
| 246 |
/* NOTE: Note 1 not implemented because I don't understand it. */ |
| 247 |
int ipcb_get_qfn( |
| 248 |
struct ipcb_twospec *spec, |
| 249 |
const struct ipcb_comp *comp, |
| 250 |
const struct ipcb_attr *attr |
| 251 |
) |
| 252 |
{ |
| 253 |
return get_common(spec, comp, attr, &ipcb_table3_15); |
| 254 |
} |
| 255 |
|
| 256 |
int ipcb_get_pson( |
| 257 |
struct ipcb_twospec *spec, |
| 258 |
const struct ipcb_comp *comp, |
| 259 |
const struct ipcb_attr *attr, |
| 260 |
double pullback |
| 261 |
) |
| 262 |
{ |
| 263 |
const struct ipcbtable *table; |
| 264 |
/* adjusted for pullback */ |
| 265 |
struct ipcb_comp compx = *comp; |
| 266 |
|
| 267 |
footol_minmax( |
| 268 |
&compx.l, |
| 269 |
comp->l.min - 2 * pullback, |
| 270 |
comp->l.max - 2 * pullback |
| 271 |
); |
| 272 |
|
| 273 |
calc(&compx, attr, spec); |
| 274 |
|
| 275 |
table = &ipcb_table3_18; |
| 276 |
|
| 277 |
spec->zmax += 2 * table->toe [attr->density]; |
| 278 |
spec->gmin -= 2 * table->heel[attr->density]; |
| 279 |
spec->xmax += 2 * table->side[attr->density]; |
| 280 |
|
| 281 |
calcuser(table, attr, spec); |
| 282 |
|
| 283 |
return 0; |
| 284 |
} |
| 285 |
|
| 286 |
int ipcb_get_sodfl( |
| 287 |
struct ipcb_twospec *spec, |
| 288 |
const struct ipcb_comp *comp, |
| 289 |
const struct ipcb_attr *attr |
| 290 |
) |
| 291 |
{ |
| 292 |
return get_common(spec, comp, attr, &ipcb_table3_22); |
| 293 |
} |
| 294 |
|
| 295 |
int ipcb_get_capae( |
| 296 |
struct ipcb_twospec *spec, |
| 297 |
const struct ipcb_comp *comp, |
| 298 |
const struct ipcb_attr *attr, |
| 299 |
double height |
| 300 |
) |
| 301 |
{ |
| 302 |
const struct ipcbtable *const table = &ipcb_table3_20; |
| 303 |
|
| 304 |
calc(comp, attr, spec); |
| 305 |
|
| 306 |
const double *toe = table->toe; |
| 307 |
const double *heel = table->heel; |
| 308 |
const double *side = table->side; |
| 309 |
if (10.0 <= height) { |
| 310 |
static const double hitoe[] = { |
| 311 |
[IPCB_DENSITY_M] = 1.00, |
| 312 |
[IPCB_DENSITY_N] = 0.70, |
| 313 |
[IPCB_DENSITY_L] = 0.40 |
| 314 |
}; |
| 315 |
static const double hiheel[] = { |
| 316 |
[IPCB_DENSITY_M] = 0.00, |
| 317 |
[IPCB_DENSITY_N] = -0.05, |
| 318 |
[IPCB_DENSITY_L] = -0.10 |
| 319 |
}; |
| 320 |
static const double hiside[] = { |
| 321 |
[IPCB_DENSITY_M] = 0.60, |
| 322 |
[IPCB_DENSITY_N] = 0.50, |
| 323 |
[IPCB_DENSITY_L] = 0.40 |
| 324 |
}; |
| 325 |
toe = hitoe; |
| 326 |
heel = hiheel; |
| 327 |
side = hiside; |
| 328 |
} |
| 329 |
|
| 330 |
spec->zmax += 2 * toe [attr->density]; |
| 331 |
spec->gmin -= 2 * heel[attr->density]; |
| 332 |
spec->xmax += 2 * side[attr->density]; |
| 333 |
|
| 334 |
calcuser(table, attr, spec); |
| 335 |
|
| 336 |
return 0; |
| 337 |
} |
| 338 |
|
| 339 |
struct balltoland { double ball; double land; }; |
| 340 |
|
| 341 |
static const struct balltoland BALLTOLAND_COLLAPS[] = { |
| 342 |
{0.75, 0.60}, |
| 343 |
{0.65, 0.55}, |
| 344 |
{0.60, 0.50}, |
| 345 |
{0.55, 0.50}, |
| 346 |
{0.50, 0.45}, |
| 347 |
{0.45, 0.40}, |
| 348 |
{0.40, 0.35}, |
| 349 |
{0.35, 0.33}, |
| 350 |
{0.30, 0.25}, |
| 351 |
{0.25, 0.20}, |
| 352 |
{0.20, 0.20}, |
| 353 |
{0.17, 0.18}, |
| 354 |
{0.15, 0.15}, |
| 355 |
{-1, -1}, |
| 356 |
}; |
| 357 |
|
| 358 |
static const struct balltoland BALLTOLAND_NONCOLLAPS[] = { |
| 359 |
{0.75, 0.90}, |
| 360 |
{0.60, 0.75}, |
| 361 |
{0.55, 0.70}, |
| 362 |
{0.50, 0.60}, |
| 363 |
{0.45, 0.55}, |
| 364 |
{0.40, 0.50}, |
| 365 |
{0.30, 0.38}, |
| 366 |
{0.25, 0.33}, |
| 367 |
{0.20, 0.24}, |
| 368 |
{0.17, 0.21}, |
| 369 |
{0.15, 0.19}, |
| 370 |
{-1, -1}, |
| 371 |
}; |
| 372 |
|
| 373 |
static double findbgaland(double lead, const struct balltoland *btol) |
| 374 |
{ |
| 375 |
double land = 100000.0; |
| 376 |
double mindiff = 100000.0; |
| 377 |
|
| 378 |
while (0 < btol->ball) { |
| 379 |
double diff = fabs(lead - btol->ball) / lead; |
| 380 |
if (diff < mindiff) { |
| 381 |
land = btol->land; |
| 382 |
mindiff = diff; |
| 383 |
} |
| 384 |
btol++; |
| 385 |
} |
| 386 |
|
| 387 |
return land; |
| 388 |
} |
| 389 |
|
| 390 |
int ipcb_get_bga(struct ipcb_bgaspec *spec, double diam, int collapsing) |
| 391 |
{ |
| 392 |
if (collapsing) { |
| 393 |
spec->ref.where = "14-5"; |
| 394 |
spec->ref.what = |
| 395 |
"Land Approximation (mm) for " |
| 396 |
"Collapsible Solder Balls"; |
| 397 |
spec->diam = findbgaland(diam, &BALLTOLAND_COLLAPS[0]); |
| 398 |
} else { |
| 399 |
spec->ref.where = "14-6"; |
| 400 |
spec->ref.what = |
| 401 |
"Land Approximation (mm) for " |
| 402 |
"Non-Collapsible Solder Balls"; |
| 403 |
spec->diam = findbgaland(diam, &BALLTOLAND_NONCOLLAPS[0]); |
| 404 |
} |
| 405 |
if (100 < spec->diam) { |
| 406 |
return 1; |
| 407 |
} |
| 408 |
|
| 409 |
return 0; |
| 410 |
} |
| 411 |
|