owibus0stm32tim.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2013 by Uwe Bonnes(bon@elektron.ikp.physik.tu-darmstadt.de)
  3. *
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  23. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. */
  34. #include <cfg/arch.h>
  35. #include <stdint.h>
  36. #include <stdlib.h>
  37. #include <stdio.h>
  38. #include <sys/atom.h>
  39. #include <sys/event.h>
  40. #include <sys/timer.h>
  41. #include <dev/owibus.h>
  42. #include <dev/gpio.h>
  43. #include <arch/cm3/stm/stm32_owitimer.h>
  44. #include <arch/cm3/stm/stm32_gpio.h>
  45. #include <dev/hwtimer_stm32.h>
  46. #include <cfg/owi.h>
  47. /*!
  48. * \file dev/owibus0stm32tim.c
  49. * \brief Configuration of owiBus0Stm32Tim with dual channel STM32
  50. * timer, configured at library compile time.
  51. *
  52. * The OWI Bus needs to be connected of CH1|2 or CH3|4 of some timer. The
  53. * base pin is set to opendrain, and CNT and CCR1|2 or CCR3|4 are used to
  54. * generate the pulse timing and capture the rising edge.
  55. *
  56. * \verbatim
  57. * $Id: owibus0stm32tim.c 5638 2014-04-07 13:58:48Z u_bonnes $
  58. * \endverbatim
  59. */
  60. /* Compile code only when needed definitions are available */
  61. #if defined(STM32TIM_OWI0_TIMER_ID) && defined(STM32TIM_OWI0_PORT) && defined(STM32TIM_OWI0_PIN)\
  62. && defined(STM32TIM_OWI0_CHANNEL)
  63. static HANDLE STM32TIM_OWI0_MUTEX;
  64. #define STM32TIM_OWI_MUTEX STM32TIM_OWI0_MUTEX
  65. #if defined(STM32TIM_OWI0_PORT)
  66. #define STM32TIM_OWI_PORT STM32TIM_OWI0_PORT
  67. #endif
  68. #if defined(STM32TIM_OWI0_PIN)
  69. #define STM32TIM_OWI_PIN STM32TIM_OWI0_PIN
  70. #endif
  71. #if defined(STM32TIM_OWI0_CHANNEL)
  72. #define STM32TIM_OWI_CHANNEL STM32TIM_OWI0_CHANNEL
  73. #endif
  74. #if defined(STM32TIM_OWI0_REMAP)
  75. #define STM32TIM_OWI_REMAP STM32TIM_OWI0_REMAP
  76. #endif
  77. #if defined (STM32TIM_OWI0_TIMER_ID)
  78. #undef STM32TIMER_ID
  79. #define STM32TIMER_ID STM32TIM_OWI0_TIMER_ID
  80. #include <arch/cm3/stm/stm32timertran.h>
  81. #define STM32_OWITIMER_BASE STM32TIMER_BASE
  82. #define STM32_OWITIMER_SIG STM32TIMER_SIG
  83. #define STM32_OWITIMER_CLK() STM32TIMER_CLK()
  84. #define STM32_OWITIMER_RST() STM32TIMER_RST()
  85. #define STM32_OWITIMER_PCLK STM32TIMER_PCLK
  86. #define STM32_OWITIMER_NCH STM32TIMER_NCH
  87. #if defined(MCU_STM32F1)
  88. #define STM32_OWITIMER_REMAP_MASK STM32TIMER_REMAP_MASK
  89. #define STM32_OWITIMER_REMAP_SHIFT STM32TIMER_REMAP_SHIFT
  90. #else
  91. #define STM32_OWITIMER_AF STM32TIMER_AF(STM32TIM_OWI_PORT, STM32TIM_OWI0_PIN)
  92. #endif
  93. #endif
  94. /* Forward declaration */
  95. static int Stm32Tim_OwiSetup(NUTOWIBUS *bus);
  96. static int Stm32Tim_OwiTouchReset(NUTOWIBUS *bus);
  97. static int Stm32Tim_OwiReadBlock(NUTOWIBUS *bus, uint8_t *data, uint_fast8_t len);
  98. static int Stm32Tim_OwiWriteBlock(NUTOWIBUS *bus, uint8_t *data, uint_fast8_t len);
  99. /*!
  100. * \brief Library compile time configured OWI bus driver for dual-channel
  101. * STM32 hardware timer.
  102. *
  103. */
  104. NUTOWIBUS owiBus0Stm32Tim = {
  105. 0, /*!< \brief OWIBUSBUS::owibus_info */
  106. OWI_MODE_NORMAL, /*!< \brief OWIBUSBUS::mode */
  107. Stm32Tim_OwiSetup, /*!< \brief OWIBUSBUS::OwiSetup */
  108. Stm32Tim_OwiTouchReset, /*!< \brief OWIBUSBUS::OwiTouchReset*/
  109. Stm32Tim_OwiReadBlock, /*!< \brief OWIBUSBUS::OwiReadBlock */
  110. Stm32Tim_OwiWriteBlock /*!< \brief OWIBUSBUS::OwiWriteBlock */
  111. };
  112. #include "owibus_stm32tim.c"
  113. }
  114. #endif
  115. /*@}*/