sadc.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * This file is part of FH8620 BSP for RT-Thread distribution.
  3. *
  4. * Copyright (c) 2016 Shanghai Fullhan Microelectronics Co., Ltd.
  5. * All rights reserved
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 2 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License along
  18. * with this program; if not, write to the Free Software Foundation, Inc.,
  19. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Visit http://www.fullhan.com to get contact with Fullhan.
  22. *
  23. * Change Logs:
  24. * Date Author Notes
  25. */
  26. #ifndef SADC_H_
  27. #define SADC_H_
  28. #include <rtdef.h>
  29. #ifdef RT_USING_SADC
  30. /****************************************************************************
  31. * #define section
  32. * add constant #define here if any
  33. ***************************************************************************/
  34. //#define FH_SADC_PROC_FILE "driver/sadc"
  35. #define MAX_CHANNEL_NO (8)
  36. #define SADC_REF (3300)
  37. #define SADC_MAX_AD_VALUE (0x3ff)
  38. #define LOOP_MODE (0x55)
  39. #define ISR_MODE (0xAA)
  40. #define SADC_INIT_ALREADY (0x33)
  41. #define SADC_INIT_NOT_YET (0)
  42. #define SADC_CMD_READ_RAW_DATA (0x22)
  43. #define SADC_CMD_READ_VOLT (0x33)
  44. #define SADC_CMD_DISABLE (0x44)
  45. /****************************************************************************
  46. * ADT section
  47. * add Abstract Data Type definition here
  48. ***************************************************************************/
  49. struct wrap_sadc_reg {
  50. rt_uint32_t sadc_cmd;
  51. rt_uint32_t sadc_control;
  52. rt_uint32_t sadc_ier;
  53. rt_uint32_t sadc_int_status;
  54. rt_uint32_t sadc_dout0;
  55. rt_uint32_t sadc_dout1;
  56. rt_uint32_t sadc_dout2;
  57. rt_uint32_t sadc_dout3;
  58. rt_uint32_t sadc_debuge0;
  59. rt_uint32_t sadc_status;
  60. rt_uint32_t sadc_cnt;
  61. rt_uint32_t sadc_timeout;
  62. };
  63. struct wrap_sadc_obj {
  64. rt_uint32_t id;
  65. void *regs;
  66. rt_uint32_t irq_no;
  67. rt_uint32_t init_flag;
  68. rt_uint32_t active_channel_no;
  69. rt_uint32_t active_channel_status;
  70. rt_uint16_t channel_data[MAX_CHANNEL_NO];
  71. rt_uint32_t error_rec;
  72. rt_uint32_t en_isr;
  73. rt_uint32_t sample_mode;
  74. struct rt_mutex lock;
  75. struct rt_semaphore completion;
  76. //bind to the rtdev..
  77. rt_device_t rt_dev;
  78. };
  79. typedef struct{
  80. rt_uint32_t channel;
  81. rt_uint32_t sadc_data;
  82. }SADC_INFO;
  83. /****************************************************************************
  84. * extern variable declaration section
  85. ***************************************************************************/
  86. /****************************************************************************
  87. * section
  88. * add function prototype here if any
  89. ***************************************************************************/
  90. void rt_hw_sadc_init(void);
  91. #endif
  92. #endif /* SADC_H_ */