main.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <stdbool.h>
  6. #include <gfambrtumst.h>
  7. #include "mbmstapp.h"
  8. #include "driverlib/sysctl.h"
  9. /////////////////////////////////////////////////////////////////////////////
  10. /////////////////////////////////////////////////////////////////////////////
  11. /////////////////////////////////////////////////////////////////////////////
  12. /////////////////////////////////////////////////////////////////////////////
  13. // fake implementation for demo purposes
  14. // usually the date and time will be retrieved from a realtime clock
  15. static int32_t _GetRTCTDateTimeTZ(struct tm *ptm)
  16. {
  17. if(!ptm)
  18. return -1;
  19. memset(ptm, 0, sizeof(struct tm));
  20. ptm->tm_year = 119;
  21. ptm->tm_mon = 8;
  22. ptm->tm_mday = 17;
  23. ptm->tm_hour = 17;
  24. ptm->tm_min = 40;
  25. return 2; // return timezone
  26. }
  27. /////////////////////////////////////////////////////////////////////////////
  28. int main(void)
  29. {
  30. struct tm utc;
  31. int32_t nTzIndex;
  32. /////////////////////////////////////////////////////////////////////////
  33. // System initialization
  34. SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
  35. GfaUtilsInit();
  36. /////////////////////////////////////////////////////////////////////////
  37. // set date, time and timezone
  38. if((nTzIndex = _GetRTCTDateTimeTZ(&utc)) < 0)
  39. return 1;
  40. if(!GfaTimeSetUTCDateTimeTimezone(&utc, nTzIndex))
  41. return 1;
  42. /////////////////////////////////////////////////////////////////////////
  43. // start the modbus slave
  44. if(!GfaInitModbusMasterApp())
  45. return 1;
  46. while(true)
  47. {
  48. GfaDoModbusMasterApp();
  49. }
  50. }