BoardPeripherals.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "BMS_Master.h"
  2. #define TEST_TIMEOUT 10000
  3. extern uint32_t Global_1msCounter;
  4. static vuint32_t TimeStamp;
  5. static void init_BoardIO();
  6. static const Board_Status Board_Status_INIT = {{0},0};
  7. Board_Status Board_S; //globaler BoardStatus
  8. void BoardPeriph_init()
  9. {
  10. RelaisLEDs_init();
  11. // IMess_init();
  12. // IMess_URef_init();
  13. TempMess_init();
  14. // UartToUsb_init();
  15. //init FRAM
  16. Board_S = Board_Status_INIT;
  17. Board_S.FRAM_Flags.B.init_ok = (FRAM_init()>=0) ? 1:0;
  18. }
  19. void BoardPeriph_test_init()
  20. {
  21. TimeStamp = Global_1msCounter;
  22. FRAM_trigger_Test();
  23. }
  24. int8_t BoardPeriph_test_update_polled()
  25. {
  26. static uint8_t state = 0;
  27. static int8_t FRAM_result = 0;
  28. static uint32_t old_Global_1msCounter = 0;
  29. uint8_t tick = 0;
  30. int8_t result = 0;
  31. if (Global_1msCounter != old_Global_1msCounter) tick = 1;
  32. switch (state) {
  33. case 0:
  34. if ( RelaisLEDs_TM_update(tick) == 1 )
  35. state = 1;
  36. break;
  37. case 1:
  38. {
  39. FRAM_update(tick);
  40. if (FRAM_result == 0) {
  41. FRAM_result = FRAM_Test_update();
  42. if (FRAM_result > 0) Board_S.FRAM_Flags.B.test_ok = 1;
  43. else if (FRAM_result < 0) Board_S.FRAM_Flags.B.test_fail = 1;
  44. }
  45. result = FRAM_result;
  46. // Board_S.test_time = Global_1msCounter - TimeStamp;
  47. // if ( Board_S.test_time >= TEST_TIMEOUT ) return -100;
  48. break;
  49. }
  50. }
  51. old_Global_1msCounter = Global_1msCounter;
  52. return result;
  53. }
  54. void BoardPeriph_update_1ms()
  55. {
  56. // IMess_update();
  57. // IMess_URef_update();
  58. TempMess_update();
  59. }
  60. void BoardPeriph_update_polled()
  61. {
  62. static uint32_t old_Global_1msCounter = 0;
  63. uint8_t tick = 0;
  64. if (Global_1msCounter != old_Global_1msCounter) {
  65. tick = 1;
  66. }
  67. FRAM_update(tick);
  68. CAN0_update();
  69. old_Global_1msCounter = Global_1msCounter;
  70. }
  71. /*
  72. void do_Testroutine()
  73. {
  74. FRAM_do_Test();
  75. ADC_do_Test();
  76. IMessLEM_do_Test();
  77. TempADC_do_Test();
  78. }*/