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.

pdb_msg.h 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*
  2. * PD Buddy Firmware Library - USB Power Delivery for everyone
  3. * Copyright 2017-2018 Clayton G. Hobbs
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. #ifndef PDB_MSG_H
  18. #define PDB_MSG_H
  19. #include <stdint.h>
  20. #include <ch.h>
  21. /*
  22. * PD message union
  23. *
  24. * This can be safely read from or written to in any form without any
  25. * transformations because everything in the system is little-endian.
  26. *
  27. * Two bytes of padding are required at the start to prevent problems due to
  28. * alignment. Specifically, without the padding, &obj[0] != &bytes[2], making
  29. * the statement in the previous paragraph invalid.
  30. */
  31. union pd_msg {
  32. struct {
  33. uint8_t _pad1[2];
  34. uint8_t bytes[30];
  35. } __attribute__((packed));
  36. struct {
  37. uint8_t _pad2[2];
  38. uint16_t hdr;
  39. union {
  40. uint32_t obj[7];
  41. struct {
  42. uint16_t exthdr;
  43. uint8_t data[26];
  44. };
  45. };
  46. } __attribute__((packed));
  47. };
  48. /*
  49. * The pool of messages used by the library
  50. */
  51. extern memory_pool_t pdb_msg_pool;
  52. #endif /* PDB_MSG_H */