build_base_header_file.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #! /usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. import sys, os
  4. #----------------------------------------------------------------------------------------------------------------------*
  5. separator = "//" + ("—" * 118) + "\n"
  6. #------------------------------ Arg 1 is destination file
  7. destinationFile = sys.argv [1]
  8. #------------------------------ Arg 2 is processor frequency (in MHz)
  9. CPU_MHZ = sys.argv [2]
  10. #------------------------------ Arg 2 is task count ("*" is no task)
  11. TASK_COUNT = sys.argv [3]
  12. #------------------------------ Arg 3 is teensy name
  13. TEENSY_NAME = sys.argv [4]
  14. #------------------------------ Header files
  15. s = "#pragma once\n\n"
  16. s += separator + "\n"
  17. s += "#include <stdint.h>\n"
  18. s += "#include <stdlib.h>\n"
  19. s += "#include <string.h>\n"
  20. s += "\n"
  21. s += separator
  22. s += "// TASK COUNT\n"
  23. s += separator + "\n"
  24. s += "static const uint32_t TASK_COUNT = " + TASK_COUNT + " ;\n\n"
  25. s += separator
  26. s += "// DEV BOARD\n"
  27. s += separator + "\n"
  28. s += "#define " + TEENSY_NAME + "\n"
  29. s += "\n"
  30. s += separator
  31. s += "// PROCESSOR FREQUENCY\n"
  32. s += separator + "\n"
  33. s += "#define CPU_MHZ (" + CPU_MHZ + ")\n\n"
  34. s += separator
  35. s += "// FALLTHROUGH\n"
  36. s += separator + "\n"
  37. s += "#if __GNUC__ < 7\n"
  38. s += " #define FALLTHROUGH\n"
  39. s += "#else\n"
  40. s += " #define FALLTHROUGH __attribute__ ((fallthrough))\n"
  41. s += "#endif\n\n"
  42. s += separator
  43. s += "// DIAGNOSTICS\n"
  44. s += separator + "\n"
  45. s += "#if __GNUC__ > 5\n"
  46. s += " #pragma GCC diagnostic error \"-Wduplicated-branches\"\n"
  47. s += " #pragma GCC diagnostic error \"-Wmisleading-indentation\"\n"
  48. s += "#endif\n\n"
  49. s += separator
  50. #------------------------------ Write destination file
  51. f = open (destinationFile, "wt")
  52. f.write (s)
  53. f.close()
  54. #----------------------------------------------------------------------------------------------------------------------*