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_pe.h 2.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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_PE_H
  18. #define PDB_PE_H
  19. #include <stdbool.h>
  20. #include <stdint.h>
  21. #include <ch.h>
  22. #include "pdb_conf.h"
  23. /*
  24. * Events for the Policy Engine thread, sent by user code
  25. */
  26. /* Tell the PE to send a Get_Source_Cap message */
  27. #define PDB_EVT_PE_GET_SOURCE_CAP EVENT_MASK(7)
  28. /* Tell the PE that new power is required */
  29. #define PDB_EVT_PE_NEW_POWER EVENT_MASK(8)
  30. /*
  31. * Structure for Policy Engine thread and variables
  32. */
  33. struct pdb_pe {
  34. /* Policy Engine thread and working area */
  35. THD_WORKING_AREA(_wa, PDB_PE_WA_SIZE);
  36. thread_t *thread;
  37. /* PE mailbox for received PD messages */
  38. mailbox_t mailbox;
  39. /* PD message header template */
  40. uint16_t hdr_template;
  41. /* The received message we're currently working with */
  42. union pd_msg *_message;
  43. /* The most recent Request from the DPM */
  44. union pd_msg *_last_dpm_request;
  45. /* Whether or not we have an explicit contract */
  46. bool _explicit_contract;
  47. /* Whether or not we're receiving minimum power */
  48. bool _min_power;
  49. /* The number of hard resets we've sent */
  50. int8_t _hard_reset_counter;
  51. /* The result of the last Type-C Current match comparison */
  52. int8_t _old_tcc_match;
  53. /* The index of the first PPS APDO */
  54. uint8_t _pps_index;
  55. /* The index of the just-requested PPS APDO */
  56. uint8_t _last_pps;
  57. /* Virtual timer for SinkPPSPeriodicTimer */
  58. virtual_timer_t _sink_pps_periodic_timer;
  59. /* Queue for the PE mailbox */
  60. msg_t _mailbox_queue[PDB_MSG_POOL_SIZE];
  61. };
  62. #endif /* PDB_PE_H */