HostSlaveHandle.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*--------------------------------------------------------------------------------------
  2. * @file HostSlaveHandle.c
  3. * @author ZhangJing
  4. * @version base on stm32f0x
  5. * @date 2015.09.11
  6. * @brief 主从芯片数据处理
  7. ---------------------------------------------------------------------------------------*/
  8. #include "stm32f10x_rcc.h"
  9. #include "stm32f10x_gpio.h"
  10. #include "TypeDefine.h"
  11. #include "USARTSetup.h"
  12. #include "SystemAlarm.h"
  13. #include "HostSlaveHandle.h"
  14. /***************************************************************************************
  15. * Function: HostToSlaveHandle
  16. * Object: 主芯片向从芯片发送数据处理
  17. * 输入: 无
  18. * 输出: 无
  19. * 备注: 1、在非待机状态下每100ms发送一次数据给从机
  20. * 2、进入待机状态时不给从机发命令,保持休眠,节省功耗
  21. ****************************************************************************************/
  22. /*void HostToSlaveHandle( void )
  23. {
  24. uint8_t tempIndex = 0;
  25. usart3XmitBuffer[tempIndex++] = 0xaa; //AA 55 为数据同步字头
  26. usart3XmitBuffer[tempIndex++] = 0x55;
  27. usart3XmitBuffer[tempIndex++] = 1;
  28. if( realTimeData.ctlSlaveRun == StandBy )
  29. {
  30. usart3XmitBuffer[tempIndex++] = 4; //泵头断电进入休眠状态
  31. USART3Send( usart3XmitBuffer, tempIndex );
  32. realTimeData.ctlSlaveRun = WaitState;
  33. }
  34. else if( realTimeData.ctlSlaveRun != WaitState )
  35. {
  36. if( ( realTimeData.ctlSlaveRun == Poweroff ) && ( realTimeData.stateRun == Poweroff ) )
  37. {
  38. usart3XmitBuffer[tempIndex++] = 3; //关机命令
  39. }
  40. else if( ( sysAlarmFlag.MechanicalFault == ALARM_ON ) || ( sysAlarmFlag.MechanicalFault == ALARM_CONTINUE ) )
  41. {
  42. usart3XmitBuffer[tempIndex++] = 2; //机械报警,关闭电机电源
  43. }
  44. else
  45. {
  46. usart3XmitBuffer[tempIndex++] = 1; //电机开始工作
  47. }
  48. if( TaskSchedulerFlag.hostXmitFlag == TASK_FLAG_SET )
  49. {
  50. USART3Send( usart3XmitBuffer, tempIndex );
  51. TaskSchedulerFlag.hostXmitFlag = TASK_FLAG_CLEAR;
  52. }
  53. }
  54. }
  55. */
  56. void Power_off(void)
  57. {
  58. GPIO_InitTypeDef GPIO_InitStructure;
  59. RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
  60. /* Configure the GPIO_MainPOWER pin */
  61. GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;
  62. GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  63. GPIO_Init(GPIOD, &GPIO_InitStructure);
  64. /* 打开总电源(MCU 电源) */
  65. GPIO_ResetBits(GPIOD,GPIO_Pin_5);
  66. }
  67. void HostToSlaveHandle( void )
  68. {
  69. // uint8_t tempIndex = 0;
  70. /* if( realTimeData.ctlSlaveRun == StandBy )
  71. {
  72. realTimeData.ctlSlaveRun = WaitState;
  73. }
  74. else if( realTimeData.ctlSlaveRun != WaitState )*/
  75. {
  76. if( ( realTimeData.ctlSlaveRun == Poweroff ) && ( realTimeData.stateRun == Poweroff ) )
  77. {
  78. //GPIO_SetBits(GPIOD,GPIO_Pin_5); //关机命令
  79. Power_off();
  80. }
  81. else if( ( sysAlarmFlag.MechanicalFault == ALARM_ON ) || ( sysAlarmFlag.MechanicalFault == ALARM_CONTINUE ) )
  82. {
  83. GPIO_ResetBits(GPIOA,GPIO_Pin_8); //机械报警,关闭电机电源
  84. }
  85. else
  86. {
  87. GPIO_SetBits(GPIOA,GPIO_Pin_8); //电机开始工作
  88. }
  89. }
  90. }