PD Buddy Sink Firmware
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * PD Buddy - USB Power Delivery for everyone
  3. * Copyright (C) 2017-2018 Clayton G. Hobbs <clay@lakeserv.net>
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef PDB_MSG_H
  19. #define PDB_MSG_H
  20. #include <stdint.h>
  21. #include <ch.h>
  22. /*
  23. * PD message union
  24. *
  25. * This can be safely read from or written to in any form without any
  26. * transformations because everything in the system is little-endian.
  27. *
  28. * Two bytes of padding are required at the start to prevent problems due to
  29. * alignment. Specifically, without the padding, &obj[0] != &bytes[2], making
  30. * the statement in the previous paragraph invalid.
  31. */
  32. union pd_msg {
  33. struct {
  34. uint8_t _pad1[2];
  35. uint8_t bytes[30];
  36. } __attribute__((packed));
  37. struct {
  38. uint8_t _pad2[2];
  39. uint16_t hdr;
  40. union {
  41. uint32_t obj[7];
  42. struct {
  43. uint16_t exthdr;
  44. uint8_t data[26];
  45. };
  46. };
  47. } __attribute__((packed));
  48. };
  49. /*
  50. * The pool of messages used by the library
  51. */
  52. extern memory_pool_t pdb_msg_pool;
  53. #endif /* PDB_MSG_H */