iec10x_init.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #include "dwt.h"
  2. #include "fly_param.h"
  3. #include "iec10x.h"
  4. #include "iec10x_conf.h"
  5. #include "iec10x_prio_queue.h"
  6. #include "iec10x_type.h"
  7. #include "main.h"
  8. #include "nor_flash.h"
  9. #include <string.h>
  10. #define TEST_BUF_SIZE 2048
  11. #define TEST_SECTOR_NO 127 /* 测试扇区号,值域【0,128】 */
  12. uint8_t g_TestBuf[TEST_BUF_SIZE]; /* 数据测试用缓冲区 */
  13. /*******************************************************************************
  14. * Function Name : fly_init
  15. * Description : fly_init program
  16. * Input : None
  17. * Output : None
  18. * Return : None
  19. *******************************************************************************/
  20. static int fly_init(void)
  21. {
  22. return 0;
  23. }
  24. static void *fly_malloc(unsigned char nbyte)
  25. {
  26. return malloc(nbyte);
  27. }
  28. static void fly_free(void *pblock)
  29. {
  30. free(pblock);
  31. }
  32. static iec_32u fly_set_time(PCP56Time2a_T time)
  33. {
  34. return RET_SUCESS;
  35. }
  36. static iec_32u fly_get_time(PCP56Time2a_T time)
  37. {
  38. return RET_SUCESS;
  39. }
  40. static iec_8s fly_get_station_info(iec_16u *Addr, iec_8u n, iec_8u *MaxNum)
  41. {
  42. *MaxNum = WTP_SUPPORT_END_NUMBER;
  43. *Addr = n;
  44. return RET_SUCESS;
  45. }
  46. static float fly_get_station_temp(iec_16u Addr)
  47. {
  48. return 30;
  49. }
  50. static iec_16u fly_get_link_addr(void)
  51. {
  52. return 0x0001;
  53. }
  54. static void fly_close_link(void)
  55. {
  56. // GPRSFlag = SYSTEM_FLAG_GPRS_CLOSE;
  57. // IEC104_STATE_FLAG_INIT = IEC104_FLAG_CLOSED;
  58. }
  59. void delay_ms(iec_16u ms)
  60. {
  61. us_delay(ms * 1000);
  62. }
  63. iec_8u fly_send(int socketfd, char *buf, int len)
  64. {
  65. int i;
  66. if (-1 == write(socketfd, buf, len))
  67. {
  68. LOG("-%s-,Send error \n", __FUNCTION__);
  69. return RET_ERROR;
  70. }
  71. // for (i = 0; i < len; i++)
  72. // {
  73. // NOR_WriteByte(TEST_SECTOR_NO * NOR_SECTOR_SIZE, buf[i]);
  74. if (NOR_WriteBuffer(buf, TEST_SECTOR_NO * NOR_SECTOR_SIZE + 1, len) == NOR_SUCCESS)
  75. {
  76. printf("send sram buffer ok!\r\n");
  77. }
  78. // }
  79. printf("Send Ok!\r\n");
  80. return RET_SUCESS;
  81. }
  82. void fly_lock(void)
  83. {
  84. INT8U err;
  85. OSMutexPend(net_mutex, 0, &err);
  86. // pthread_mutex_lock(&mutex);
  87. }
  88. void fly_unlock()
  89. {
  90. OSMutexPost(net_mutex);
  91. // pthread_mutex_unlock(&mutex);
  92. }
  93. static IEC10X_T fly = {
  94. "Linux",
  95. fly_init,
  96. delay_ms,
  97. fly_close_link,
  98. fly_malloc,
  99. fly_free,
  100. IEC10X_PrioEnQueue,
  101. IEC10X_PrioDeQueue,
  102. IEC10X_PrioFindQueueHead,
  103. IEC10X_HighestPrio, /* Get the highest Prio Queue*/
  104. IEC10X_PrioInitQueue,
  105. IEC10X_Prio_ClearQueue,
  106. fly_send,
  107. fly_set_time,
  108. fly_get_time,
  109. fly_get_station_info,
  110. fly_get_station_temp,
  111. fly_get_link_addr,
  112. #ifdef IEC10XLOCK
  113. fly_lock,
  114. fly_unlock
  115. #endif
  116. };
  117. iec_32u RegisterIec10x(void)
  118. {
  119. return RegisterIEC10XMoudle(&fly);
  120. }