hole.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. * hole.c - Classify holes and connect them with pads
  3. *
  4. * Written 2010, 2012 by Werner Almesberger
  5. * Copyright 2010, 2012 by Werner Almesberger
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. */
  12. #include "error.h"
  13. #include "inst.h"
  14. #include "overlap.h"
  15. #include "hole.h"
  16. static int check_through_hole(struct inst *pad, struct inst *hole)
  17. {
  18. if (!overlap(pad, hole, ao_none))
  19. return 1;
  20. if (!inside(hole, pad)) {
  21. fail("hole (line %d) not completely inside "
  22. "pad \"%s\" (line %d)", hole->obj->lineno,
  23. pad->u.pad.name, pad->obj->lineno);
  24. instantiation_error = pad->obj;
  25. return 0;
  26. }
  27. if (hole->u.hole.pad) {
  28. /*
  29. * A hole can only be on several pads if the pads themselves
  30. * overlap. We'll catch this error in refine_copper.
  31. */
  32. return 1;
  33. }
  34. if (pad->u.pad.hole) {
  35. fail("pad \"%s\" (line %d) has multiple holes (lines %d, %d)",
  36. pad->u.pad.name, pad->obj->lineno,
  37. hole->obj->lineno, pad->u.pad.hole->obj->lineno);
  38. instantiation_error = pad->obj;
  39. return 0;
  40. }
  41. pad->u.pad.hole = hole;
  42. hole->u.hole.pad = pad;
  43. return 1;
  44. }
  45. static int connect_holes(const struct pkg *pkg)
  46. {
  47. struct inst *pad, *hole;
  48. for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
  49. for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
  50. if (!check_through_hole(pad, hole))
  51. return 0;
  52. return 1;
  53. }
  54. static void clear_links(const struct pkg *pkg)
  55. {
  56. struct inst *pad, *hole;
  57. for (pad = pkg->insts[ip_pad_copper]; pad; pad = pad->next)
  58. pad->u.pad.hole = NULL;
  59. for (pad = pkg->insts[ip_pad_special]; pad; pad = pad->next)
  60. pad->u.pad.hole = NULL;
  61. for (hole = pkg->insts[ip_hole]; hole; hole = hole->next)
  62. hole->u.hole.pad = NULL;
  63. }
  64. int link_holes(int linked)
  65. {
  66. const struct pkg *pkg;
  67. for (pkg = pkgs; pkg; pkg = pkg->next) {
  68. clear_links(pkg);
  69. if (linked)
  70. if (!connect_holes(pkg))
  71. return 0;
  72. }
  73. return 1;
  74. }