yc_drv_common.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /*************************************************************************
  2. *
  3. * Yichip
  4. *
  5. *************************************************************************/
  6. #include <stdint.h>
  7. #include "yc_drv_common.h"
  8. /*************************COMMON FUNC***************************/
  9. #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
  10. void HW_REG_16BIT(uint32_t reg, uint16_t word)
  11. {
  12. HW_REG_8BIT(reg, word & 0x00FF);
  13. hw_delay();
  14. HW_REG_8BIT(reg + 1,(word >> 8));
  15. }
  16. uint16_t HR_REG_16BIT(uint32_t reg)
  17. {
  18. uint16_t return_data = 0;
  19. uint16_t H_data = 0;
  20. hw_delay();
  21. return_data = HR_REG_8BIT(reg);
  22. hw_delay();
  23. H_data = HR_REG_8BIT(reg + 1);
  24. return_data = (return_data | ((H_data << 8) & 0xFF00));
  25. return return_data;
  26. }
  27. uint32_t HR_REG_24BIT(uint32_t reg)
  28. {
  29. uint32_t return_data = 0;
  30. hw_delay();
  31. return_data = HR_REG_8BIT(reg);
  32. hw_delay();
  33. return_data = return_data |(HR_REG_8BIT(reg + 1)<<8);
  34. hw_delay();
  35. return_data = return_data | (HR_REG_8BIT(reg + 2)<<16);
  36. return return_data;
  37. }
  38. void xmemcpy(uint8_t* dest,const uint8_t* src, uint16_t len)
  39. {
  40. while(len--)
  41. *dest++ = *src++;
  42. return;
  43. }
  44. uint16_t xstrlen(const char *s)
  45. {
  46. int n;
  47. for(n=0;*s!='\0';s++) {
  48. n++;
  49. }
  50. return n;
  51. }
  52. void error_handle()
  53. {
  54. while(1);
  55. }
  56. void whileDelay(int delayValue)
  57. {
  58. int delayMS;
  59. for (int k=0; k < delayValue; k++){
  60. delayMS = 20000;
  61. while(delayMS--);
  62. }
  63. }
  64. void whileDelayshort(int delayValue)
  65. {
  66. int delayMS;
  67. for (int k=0; k < delayValue; k++){
  68. delayMS = 2000;
  69. while(delayMS--);
  70. }
  71. }