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.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

xt.h 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. Copyright 2010,2011,2012,2013 Jun WAKO <[email protected]>
  3. Copyright 2016 Ethan Apodaca <[email protected]>
  4. This software is licensed with a Modified BSD License.
  5. All of this is supposed to be Free Software, Open Source, DFSG-free,
  6. GPL-compatible, and OK to use in both free and proprietary applications.
  7. Additions and corrections to this file are welcome.
  8. Redistribution and use in source and binary forms, with or without
  9. modification, are permitted provided that the following conditions are met:
  10. * Redistributions of source code must retain the above copyright
  11. notice, this list of conditions and the following disclaimer.
  12. * Redistributions in binary form must reproduce the above copyright
  13. notice, this list of conditions and the following disclaimer in
  14. the documentation and/or other materials provided with the
  15. distribution.
  16. * Neither the name of the copyright holders nor the names of
  17. contributors may be used to endorse or promote products derived
  18. from this software without specific prior written permission.
  19. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  20. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  21. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  22. ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  23. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  24. CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  25. SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  26. INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  27. CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  28. ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  29. POSSIBILITY OF SUCH DAMAGE.
  30. */
  31. #ifndef XT_H
  32. #define XT_H
  33. #include <stdbool.h>
  34. #include "wait.h"
  35. #include "xt_io.h"
  36. #include "print.h"
  37. void xt_host_init(void);
  38. uint8_t xt_host_recv(void);
  39. /*--------------------------------------------------------------------
  40. * static functions
  41. *------------------------------------------------------------------*/
  42. static inline uint16_t wait_clock_lo(uint16_t us)
  43. {
  44. while (clock_in() && us) { asm(""); wait_us(1); us--; }
  45. return us;
  46. }
  47. static inline uint16_t wait_clock_hi(uint16_t us)
  48. {
  49. while (!clock_in() && us) { asm(""); wait_us(1); us--; }
  50. return us;
  51. }
  52. static inline uint16_t wait_data_lo(uint16_t us)
  53. {
  54. while (data_in() && us) { asm(""); wait_us(1); us--; }
  55. return us;
  56. }
  57. static inline uint16_t wait_data_hi(uint16_t us)
  58. {
  59. while (!data_in() && us) { asm(""); wait_us(1); us--; }
  60. return us;
  61. }
  62. #endif