Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

170 rindas
5.0 KiB

  1. /**
  2. *
  3. * \file
  4. *
  5. * \brief NMC1500 Peripherials Application Interface.
  6. *
  7. * Copyright (c) 2015 Atmel Corporation. All rights reserved.
  8. *
  9. * \asf_license_start
  10. *
  11. * \page License
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions are met:
  15. *
  16. * 1. Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer.
  18. *
  19. * 2. Redistributions in binary form must reproduce the above copyright notice,
  20. * this list of conditions and the following disclaimer in the documentation
  21. * and/or other materials provided with the distribution.
  22. *
  23. * 3. The name of Atmel may not be used to endorse or promote products derived
  24. * from this software without specific prior written permission.
  25. *
  26. * THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
  27. * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  28. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
  29. * EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
  30. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  31. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  32. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  33. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  34. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  35. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  36. * POSSIBILITY OF SUCH DAMAGE.
  37. *
  38. * \asf_license_stop
  39. *
  40. */
  41. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  42. INCLUDES
  43. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  44. #include "driver/include/m2m_periph.h"
  45. #include "driver/source/nmasic.h"
  46. #include "m2m_hif.h"
  47. #ifdef CONF_PERIPH
  48. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  49. MACROS
  50. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  51. #define GPIO_OP_DIR 0
  52. #define GPIO_OP_SET 1
  53. #define GPIO_OP_GET 2
  54. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  55. DATA TYPES
  56. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  57. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  58. STATIC FUNCTIONS
  59. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  60. static sint8 get_gpio_idx(uint8 u8GpioNum)
  61. {
  62. if (u8GpioNum >= M2M_PERIPH_GPIO_MAX)
  63. return -1;
  64. if (u8GpioNum == M2M_PERIPH_GPIO15) {
  65. return 15;
  66. } else if (u8GpioNum == M2M_PERIPH_GPIO16) {
  67. return 16;
  68. } else if (u8GpioNum == M2M_PERIPH_GPIO18) {
  69. return 18;
  70. } else if (u8GpioNum == M2M_PERIPH_GPIO3) {
  71. return 3;
  72. } else if (u8GpioNum == M2M_PERIPH_GPIO4) {
  73. return 4;
  74. } else if (u8GpioNum == M2M_PERIPH_GPIO5) {
  75. return 5;
  76. } else if (u8GpioNum == M2M_PERIPH_GPIO6) {
  77. return 6;
  78. } else {
  79. return -2;
  80. }
  81. }
  82. /*
  83. * GPIO read/write skeleton with wakeup/sleep capability.
  84. */
  85. static sint8 gpio_ioctl(uint8 op, uint8 u8GpioNum, uint8 u8InVal, uint8 *pu8OutVal)
  86. {
  87. sint8 ret, gpio;
  88. ret = hif_chip_wake();
  89. if (ret != M2M_SUCCESS)
  90. goto _EXIT;
  91. gpio = get_gpio_idx(u8GpioNum);
  92. if (gpio < 0)
  93. goto _EXIT1;
  94. if (op == GPIO_OP_DIR) {
  95. ret = set_gpio_dir((uint8)gpio, u8InVal);
  96. } else if (op == GPIO_OP_SET) {
  97. ret = set_gpio_val((uint8)gpio, u8InVal);
  98. } else if (op == GPIO_OP_GET) {
  99. ret = get_gpio_val((uint8)gpio, pu8OutVal);
  100. }
  101. if (ret != M2M_SUCCESS)
  102. goto _EXIT1;
  103. _EXIT1:
  104. ret = hif_chip_sleep();
  105. _EXIT:
  106. return ret;
  107. }
  108. /*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
  109. FUNCTION IMPLEMENTATION
  110. *=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*/
  111. sint8 m2m_periph_init(tstrPerphInitParam *param)
  112. {
  113. return M2M_SUCCESS;
  114. }
  115. sint8 m2m_periph_gpio_set_dir(uint8 u8GpioNum, uint8 u8GpioDir)
  116. {
  117. return gpio_ioctl(GPIO_OP_DIR, u8GpioNum, u8GpioDir, NULL);
  118. }
  119. sint8 m2m_periph_gpio_set_val(uint8 u8GpioNum, uint8 u8GpioVal)
  120. {
  121. return gpio_ioctl(GPIO_OP_SET, u8GpioNum, u8GpioVal, NULL);
  122. }
  123. sint8 m2m_periph_gpio_get_val(uint8 u8GpioNum, uint8 *pu8GpioVal)
  124. {
  125. return gpio_ioctl(GPIO_OP_GET, u8GpioNum, 0, pu8GpioVal);
  126. }
  127. sint8 m2m_periph_gpio_pullup_ctrl(uint8 u8GpioNum, uint8 u8PullupEn)
  128. {
  129. /* TBD */
  130. return M2M_SUCCESS;
  131. }
  132. sint8 m2m_periph_i2c_master_init(tstrI2cMasterInitParam *param)
  133. {
  134. /* TBD */
  135. return M2M_SUCCESS;
  136. }
  137. sint8 m2m_periph_i2c_master_write(uint8 u8SlaveAddr, uint8 *pu8Buf, uint16 u16BufLen, uint8 flags)
  138. {
  139. /* TBD */
  140. return M2M_SUCCESS;
  141. }
  142. sint8 m2m_periph_i2c_master_read(uint8 u8SlaveAddr, uint8 *pu8Buf, uint16 u16BufLen, uint16 *pu16ReadLen, uint8 flags)
  143. {
  144. /* TBD */
  145. return M2M_SUCCESS;
  146. }
  147. sint8 m2m_periph_pullup_ctrl(uint32 pinmask, uint8 enable)
  148. {
  149. return pullup_ctrl(pinmask, enable);
  150. }
  151. #endif /* CONF_PERIPH */