dev_can_id.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /************************************************************************************************
  2. * Include *
  3. ************************************************************************************************/
  4. #include "dev_can_id.h"
  5. #include <stdint.h>
  6. /************************************************************************************************
  7. * Config *
  8. ************************************************************************************************/
  9. union
  10. {
  11. uint32_t r;
  12. struct
  13. {
  14. uint8_t sa : 8;
  15. uint8_t ps : 8;
  16. uint8_t pf : 8;
  17. uint8_t dp : 1;
  18. uint8_t r : 1;
  19. uint8_t p : 3;
  20. } b;
  21. } new_can_id;
  22. #define CAN_PGN_PF 0xFFFF00
  23. #define CAN_PGN_PS 0xFF00
  24. uint32_t g_ps = 0xF4;
  25. uint32_t g_can_id = 0x18F011F4;
  26. uint32_t g_can_ota_id = 0x18DFE1F4;
  27. uint8_t g_can_iap = 0xDF;
  28. uint32_t get_new_can_id(uint8_t pf)
  29. {
  30. new_can_id.r = g_can_id;
  31. new_can_id.b.ps = new_can_id.b.sa;
  32. new_can_id.b.sa = g_ps;
  33. new_can_id.b.pf = pf;
  34. return new_can_id.r;
  35. }
  36. uint32_t set_new_can_id(uint16_t pgn)
  37. {
  38. new_can_id.r = g_can_id;
  39. new_can_id.b.sa = g_ps;
  40. new_can_id.b.ps = pgn & 0xFF;
  41. new_can_id.b.pf = pgn >> 8;
  42. return new_can_id.r;
  43. }
  44. uint32_t get_ota_id(uint8_t pf)
  45. {
  46. new_can_id.r = g_can_ota_id;
  47. new_can_id.b.ps = new_can_id.b.sa;
  48. new_can_id.b.sa = g_ps;
  49. new_can_id.b.pf = pf;
  50. return new_can_id.r;
  51. }
  52. /************************************************************************************************
  53. * Data structs *
  54. ************************************************************************************************/
  55. /************************************************************************************************
  56. * implements *
  57. ************************************************************************************************/