iec104_init.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /*******************************************************************
  2. Copyright (C):
  3. File name : HXCP_STM32.C
  4. DESCRIPTION :
  5. AUTHOR :
  6. Version : 1.0
  7. Date : 2014/02/26
  8. Others :
  9. History :
  10. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  11. 1) Date: 2014/02/26 Author: ChenDajie
  12. content:
  13. *******************************************************************/
  14. #include "PRIO_QUEUE_Iec10x.h"
  15. #include "dwt.h"
  16. #include "fly_param.h"
  17. #include "iec10x.h"
  18. #include "main.h"
  19. #include "project_var.h"
  20. // #include <errno.h>
  21. // #include <signal.h>
  22. // #include <stdio.h>
  23. // #include <stdlib.h>
  24. #include <string.h>
  25. // #include <sys/socket.h>
  26. // #include <sys/types.h>
  27. // #include <sys/wait.h>
  28. // #include <unistd.h>
  29. /*******************************************************************************
  30. * Function Name : stm32f103_init
  31. * Description : stm32f103_init program
  32. * Input : None
  33. * Output : None
  34. * Return : None
  35. *******************************************************************************/
  36. static int
  37. Linux_init(void)
  38. {
  39. return 0;
  40. }
  41. static void *Linux_Malloc(unsigned char NumByte)
  42. {
  43. return malloc(NumByte);
  44. }
  45. static void Linux_Free(void *pblock)
  46. {
  47. free(pblock);
  48. }
  49. static uint32_t Linux_SetTime(PCP56Time2a_T time)
  50. {
  51. return RET_SUCESS;
  52. }
  53. static uint32_t Linux_GetTime(PCP56Time2a_T time)
  54. {
  55. return RET_SUCESS;
  56. }
  57. static int8_t Linux_GetStationInfo(uint16_t *Addr, uint8_t n, uint8_t *MaxNum)
  58. {
  59. *MaxNum = WTP_SUPPORT_END_NUMBER;
  60. *Addr = n;
  61. return RET_SUCESS;
  62. }
  63. static float Linux_GetStaTemp(uint16_t Addr)
  64. {
  65. return 30;
  66. }
  67. static uint16_t Linux_GetLinkAddr(void)
  68. {
  69. return 0x0001;
  70. }
  71. static void Linux_CloseLink(void)
  72. {
  73. // GPRSFlag = SYSTEM_FLAG_GPRS_CLOSE;
  74. // IEC104_STATE_FLAG_INIT = IEC104_FLAG_CLOSED;
  75. }
  76. void delay_ms(uint16_t ms)
  77. {
  78. us_delay(ms * 1000);
  79. }
  80. uint8_t Linuxsend(int socketfd, char *buf, int len)
  81. {
  82. if (-1 == write(socketfd, buf, len))
  83. {
  84. LOG("-%s-,Send error \n", __FUNCTION__);
  85. return RET_ERROR;
  86. }
  87. printf("Send Ok!\r\n");
  88. return RET_SUCESS;
  89. }
  90. void LinuxLock(void)
  91. {
  92. INT8U err;
  93. OSMutexPend(net_mutex, 0, &err);
  94. // pthread_mutex_lock(&mutex);
  95. }
  96. void LinuxUnlock()
  97. {
  98. OSMutexPost(net_mutex);
  99. // pthread_mutex_unlock(&mutex);
  100. }
  101. /*******************************************************************************
  102. * Function Name : stm32f103
  103. * Description : stm32f103
  104. * Input : None
  105. * Output : None
  106. * Return : None
  107. *******************************************************************************/
  108. static IEC10X_T Linux = {
  109. "Linux",
  110. Linux_init,
  111. delay_ms,
  112. Linux_CloseLink,
  113. Linux_Malloc,
  114. Linux_Free,
  115. IEC10X_PrioEnQueue,
  116. IEC10X_PrioDeQueue,
  117. IEC10X_PrioFindQueueHead,
  118. IEC10X_HighestPrio, /* Get the highest Prio Queue*/
  119. IEC10X_PrioInitQueue,
  120. IEC10X_Prio_ClearQueue,
  121. Linuxsend,
  122. Linux_SetTime,
  123. Linux_GetTime,
  124. Linux_GetStationInfo,
  125. Linux_GetStaTemp,
  126. Linux_GetLinkAddr,
  127. #ifdef IEC10XLOCK
  128. LinuxLock,
  129. LinuxUnlock
  130. #endif
  131. };
  132. /*******************************************************************************
  133. * Function Name : mstm32f103RegisterShtxxain
  134. * Description : Main program
  135. * Input : None
  136. * Output : None
  137. * Return : None
  138. *******************************************************************************/
  139. uint32_t Stm32f103RegisterIec10x(void)
  140. {
  141. return RegisterIEC10XMoudle(&Linux);
  142. }