提交 4a89cb83 作者: 高增攀

初始版本,语法错误未修改2

上级
/DcPillar/Projects/settings
/DcPillar/Projects/Debug
/DcPillar/Projects/*.tmp
/DcPillar/Projects/*.dep
/DcPillar/Si
<?xml version="1.0" encoding="iso-8859-1"?>
<workspace>
<project>
<path>$WS_DIR$\DcPillar.ewp</path>
</project>
<batchBuild/>
</workspace>
/*
FreeRTOS V8.1.2 - Copyright (C) 2014 Real Time Engineers Ltd.
All rights reserved
VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.
***************************************************************************
* *
* FreeRTOS provides completely free yet professionally developed, *
* robust, strictly quality controlled, supported, and cross *
* platform software that has become a de facto standard. *
* *
* Help yourself get started quickly and support the FreeRTOS *
* project by purchasing a FreeRTOS tutorial book, reference *
* manual, or both from: http://www.FreeRTOS.org/Documentation *
* *
* Thank you! *
* *
***************************************************************************
This file is part of the FreeRTOS distribution.
FreeRTOS is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License (version 2) as published by the
Free Software Foundation >>!AND MODIFIED BY!<< the FreeRTOS exception.
>>! NOTE: The modification to the GPL is included to allow you to !<<
>>! distribute a combined work that includes FreeRTOS without being !<<
>>! obliged to provide the source code for proprietary components !<<
>>! outside of the FreeRTOS kernel. !<<
FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. Full license text is available from the following
link: http://www.freertos.org/a00114.html
1 tab == 4 spaces!
***************************************************************************
* *
* Having a problem? Start by reading the FAQ "My application does *
* not run, what could be wrong?" *
* *
* http://www.FreeRTOS.org/FAQHelp.html *
* *
***************************************************************************
http://www.FreeRTOS.org - Documentation, books, training, latest versions,
license and Real Time Engineers Ltd. contact details.
http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,
including FreeRTOS+Trace - an indispensable productivity tool, a DOS
compatible FAT file system, and our tiny thread aware UDP/IP stack.
http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High
Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS
licenses offer ticketed support, indemnification and middleware.
http://www.SafeRTOS.com - High Integrity Systems also provide a safety
engineered and independently SIL3 certified version for use in safety and
mission critical applications that require provable dependability.
1 tab == 4 spaces!
*/
#ifndef FREERTOS_CONFIG_H
#define FREERTOS_CONFIG_H
/*-----------------------------------------------------------
* Application specific definitions.
*
* These definitions should be adjusted for your particular hardware and
* application requirements.
*
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
*
* See http://www.freertos.org/a00110.html.
*----------------------------------------------------------*/
/* Ensure stdint is only used by the compiler, and not the assembler. */
#if defined(__ICCARM__) || defined(__CC_ARM) || defined(__GNUC__)
#include <stdint.h>
extern uint32_t SystemCoreClock;
#endif
#define configUSE_PREEMPTION 1
#define configUSE_IDLE_HOOK 1
#define configUSE_TICK_HOOK 0
#define configCPU_CLOCK_HZ ( SystemCoreClock )
#define configTICK_RATE_HZ ( ( TickType_t ) 1000 )
#define configMAX_PRIORITIES ( 7 )
#define configMINIMAL_STACK_SIZE ( ( uint16_t ) 128 )
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 20 * 1024 ) )
#define configMAX_TASK_NAME_LEN ( 16 )
#define configUSE_TRACE_FACILITY 1
#define configUSE_16_BIT_TICKS 0
#define configIDLE_SHOULD_YIELD 1
#define configUSE_MUTEXES 1
#define configQUEUE_REGISTRY_SIZE 8
#define configCHECK_FOR_STACK_OVERFLOW 1
#define configUSE_RECURSIVE_MUTEXES 1
#define configUSE_MALLOC_FAILED_HOOK 0
#define configUSE_APPLICATION_TASK_TAG 0
#define configUSE_COUNTING_SEMAPHORES 1
#define configGENERATE_RUN_TIME_STATS 0
/* Co-routine definitions. */
#define configUSE_CO_ROUTINES 0
#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )
/* Software timer definitions. */
#define configUSE_TIMERS 1
#define configTIMER_TASK_PRIORITY ( 5 )
#define configTIMER_QUEUE_LENGTH 10
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
/* Set the following definitions to 1 to include the API function, or zero
to exclude the API function. */
#define INCLUDE_vTaskPrioritySet 1
#define INCLUDE_uxTaskPriorityGet 1
#define INCLUDE_vTaskDelete 1
#define INCLUDE_vTaskCleanUpResources 0
#define INCLUDE_vTaskSuspend 1
#define INCLUDE_vTaskDelayUntil 0
#define INCLUDE_vTaskDelay 1
#define INCLUDE_xQueueGetMutexHolder 1
#define INCLUDE_xTaskGetSchedulerState 1
#define INCLUDE_eTaskGetState 1
/* Cortex-M specific definitions. */
#ifdef __NVIC_PRIO_BITS
/* __BVIC_PRIO_BITS will be specified when CMSIS is being used. */
#define configPRIO_BITS __NVIC_PRIO_BITS
#else
#define configPRIO_BITS 4 /* 15 priority levels */
#endif
/* The lowest interrupt priority that can be used in a call to a "set priority"
function. */
#define configLIBRARY_LOWEST_INTERRUPT_PRIORITY 0xf
/* The highest interrupt priority that can be used by any interrupt service
routine that makes calls to interrupt safe FreeRTOS API functions. DO NOT CALL
INTERRUPT SAFE FREERTOS API FUNCTIONS FROM ANY INTERRUPT THAT HAS A HIGHER
PRIORITY THAN THIS! (higher priorities are lower numeric values. */
#define configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY 5
/* Interrupt priorities used by the kernel port layer itself. These are generic
to all Cortex-M ports, and do not rely on any particular library functions. */
#define configKERNEL_INTERRUPT_PRIORITY ( configLIBRARY_LOWEST_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* !!!! configMAX_SYSCALL_INTERRUPT_PRIORITY must not be set to zero !!!!
See http://www.FreeRTOS.org/RTOS-Cortex-M3-M4.html. */
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY << (8 - configPRIO_BITS) )
/* Normal assert() semantics without relying on the provision of an assert.h
header file. */
#define configASSERT( x ) if( ( x ) == 0 ) { taskDISABLE_INTERRUPTS(); for( ;; ); }
/* Definitions that map the FreeRTOS port interrupt handlers to their CMSIS
standard names. */
#define vPortSVCHandler SVC_Handler
#define xPortPendSVHandler PendSV_Handler
/* IMPORTANT: This define MUST be commented when used with STM32Cube firmware,
to prevent overwriting SysTick_Handler defined within STM32Cube HAL */
/* #define xPortSysTickHandler SysTick_Handler */
#endif /* FREERTOS_CONFIG_H */
#ifndef __DRV_ADC_H__
#define __DRV_ADC_H__
#include "Global.h"
/**************************ADC **************************************/
#define Cc_ADC ADC1
#define Cc_ADC_CLK RCC_APB2Periph_ADC1
#define Cc_ADC_CLK_INIT RCC_APB2PeriphClockCmd
/**************************DMA for ADC********************************/
#define Cc_ADC_DMA DMA2
#define Cc_ADC_DMA_CLK RCC_AHB1Periph_DMA2
#define Cc_ADC_DMA_CLK_INIT RCC_AHB1PeriphClockCmd
#define Cc_ADC_DMA_CHANNEL DMA_Channel_0
#define Cc_ADC_DMA_STREAM DMA2_Stream0
/**************************ADC Pin ***********************************/
#define Cc00_ADC_CHANNEL ADC_Channel_14
#define Cc00_ADC_PIN GPIO_Pin_4
#define Cc00_ADC_GPIO_PORT GPIOC
#define Cc00_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Cc01_ADC_CHANNEL ADC_Channel_15
#define Cc01_ADC_PIN GPIO_Pin_5
#define Cc01_ADC_GPIO_PORT GPIOC
#define Cc01_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
/**************************ADC **************************************/
#define Temp_ADC ADC2
#define Temp_ADC_CLK RCC_APB2Periph_ADC2
#define Temp_ADC_CLK_INIT RCC_APB2PeriphClockCmd
/**************************DMA for ADC********************************/
#define Temp_ADC_DMA DMA2
#define Temp_ADC_DMA_CLK RCC_AHB1Periph_DMA2
#define Temp_ADC_DMA_CLK_INIT RCC_AHB1PeriphClockCmd
#define Temp_ADC_DMA_CHANNEL DMA_Channel_1
#define Temp_ADC_DMA_STREAM DMA2_Stream2
/**************************ADC Pin ***********************************/
#define Temp00_ADC_CHANNEL ADC_Channel_10
#define Temp00_ADC_PIN GPIO_Pin_0
#define Temp00_ADC_GPIO_PORT GPIOC
#define Temp00_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Temp01_ADC_CHANNEL ADC_Channel_11
#define Temp01_ADC_PIN GPIO_Pin_1
#define Temp01_ADC_GPIO_PORT GPIOC
#define Temp01_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Temp02_ADC_CHANNEL ADC_Channel_12
#define Temp02_ADC_PIN GPIO_Pin_2
#define Temp02_ADC_GPIO_PORT GPIOC
#define Temp02_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Temp03_ADC_CHANNEL ADC_Channel_13
#define Temp03_ADC_PIN GPIO_Pin_3
#define Temp03_ADC_GPIO_PORT GPIOC
#define Temp03_ADC_GPIO_CLK RCC_AHB1Periph_GPIOC
extern void AdcCheckInit(void);
extern void CcCheckInit(void);
extern EnumSwitchStatus CcStatusRead(void);
extern EnumSwitchStatus CcStatusRead_B(void);
extern EnumSwitchStatus CcStatusRead_AB(void);
extern u8 NtcRetToTemp(u32 Rp,u16 Bx);
#if 0
extern u8 NtcRetToTemp(u32 Rp,u16 Bx);
#else
extern u8 PT1000RetToTemp(void);
extern u8 PT1000RetToTempN(void);
extern u8 PT1000RetToTempB_P(void);
extern u8 PT1000RetToTempB_N(void);
#endif
extern s16 Adc_GetNtcTemp(void);
extern s16 Adc_Get_a_PTemp(void);
extern s16 Adc_Get_a_NTemp(void);
extern s16 Adc_Get_B_PTemp(void);
extern s16 Adc_Get_B_NTemp(void);
#endif
/******************************************************************************
文件 : Drv_Buzzer.c
描述 : 蜂鸣器驱动
作者 :
修改 : 2015-04-02 郭涛 建立
******************************************************************************/
#include "Drv_Buzzer.h"
typedef struct
{
u16 OnMs;
u16 OffMs;
u16 CtrlCount;
}StructBuzzerCtrl;
StructBuzzerCtrl BuzzerCtrl;
osTimerId BuzzerTimer;
/******************************************************************************
函数 : BuzzerInit
描述 : 蜂鸣器IO初始化
参数 : 无
返回 : 无
******************************************************************************/
void BuzzerSet(EnumSwitchStatus Set)
{
if(eSwSta_Off == Set)
Buzzer_PORT->BSRRH = Buzzer_PIN;
else
Buzzer_PORT->BSRRL = Buzzer_PIN;
}
/******************************************************************************
函数 : BuzzerDelayCtrl
描述 : 继电器延时设置低电流,该函数在定时器里调用
参数 : 无
返回 : 无
******************************************************************************/
static void BuzzerDelayCtrl(void const *Param)
{
if(BuzzerCtrl.CtrlCount)
BuzzerCtrl.CtrlCount--;
if(BuzzerCtrl.CtrlCount)
{
if(BuzzerCtrl.CtrlCount & 0x01)
{
BuzzerSet(eSwSta_On);
osTimerStart(BuzzerTimer, BuzzerCtrl.OnMs);
}
else
{
BuzzerSet(eSwSta_Off);
osTimerStart(BuzzerTimer, BuzzerCtrl.OffMs);
}
}
else
{
BuzzerSet(eSwSta_Off);
osTimerStop(BuzzerTimer);
}
}
/******************************************************************************
函数 : BuzzerInit
描述 : 蜂鸣器IO初始化
参数 : 无
返回 : 无
******************************************************************************/
void BuzzerInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
BuzzerCtrl.OnMs = 0;
BuzzerCtrl.OffMs = 0;
BuzzerCtrl.CtrlCount = 0;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = Buzzer_PIN;
RCC_AHB1PeriphClockCmd(Buzzer_RCC, ENABLE);
GPIO_Init(Buzzer_PORT, &GPIO_InitStructure);
GPIO_ResetBits(Buzzer_PORT, Buzzer_PIN);
/* Create Touch screen Timer */
osTimerDef(BuzzerTimer, BuzzerDelayCtrl);
BuzzerTimer = osTimerCreate(osTimer(BuzzerTimer), osTimerPeriodic, (void *)0);
/* Start the TS Timer */
osTimerStart(BuzzerTimer, 33);
}
/******************************************************************************
函数 : BuzzerRun
描述 : 蜂鸣器按时间响数次
参数 : Count -- 响多少次
OnMs -- 响多长时间,毫秒
OffMs -- 灭多长时间,毫秒
返回 : 无
******************************************************************************/
void BuzzerRun(u16 Count, u16 OnMs, u16 OffMs)
{
if(Count < 1)
return;
if(OnMs < 1)
return;
osTimerStop(BuzzerTimer);
BuzzerCtrl.CtrlCount = 2*Count - 1;
BuzzerCtrl.OnMs = OnMs;
BuzzerCtrl.OffMs = OffMs;
BuzzerSet(eSwSta_On);
osTimerStart(BuzzerTimer, BuzzerCtrl.OnMs);
}
#ifndef __DRV_BUZZER_H__
#define __DRV_BUZZER_H__
#include "Global.h"
#define Buzzer_PIN GPIO_Pin_1
#define Buzzer_PORT GPIOB
#define Buzzer_RCC RCC_AHB1Periph_GPIOB
extern void BuzzerInit(void);
extern void BuzzerSet(EnumSwitchStatus Set);
extern void BuzzerRun(u16 Count, u16 OnMs, u16 OffMs);
#endif
/******************************************************************************
文件 : Drv_Can.c
描述 : Can数据收发
作者 :
修改 : 2014-09-04 郭涛 建立
******************************************************************************/
#include "Drv_Can.h"
/******************************************************************************
函数 : InternetInit
描述 : 读卡器通信接口初始化。
参数 : 无
返回 : TRUE - 初始化完成
FALSE - 初始化有误
******************************************************************************/
u8 CanInit(void)
{
CAN_InitTypeDef CAN_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
CAN_FilterInitTypeDef CAN_FilterInitStructure;
/* Enable GPIO clock */
/* Configure USART Tx and Rx as alternate function push-pull */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = Can_TX_PIN;
RCC_APB2PeriphClockCmd(Can_TX_GPIO_CLK, ENABLE);
GPIO_Init(Can_TX_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Pin = Can_RX_PIN;
RCC_APB2PeriphClockCmd(Can_RX_GPIO_CLK, ENABLE);
GPIO_Init(Can_RX_GPIO_PORT, &GPIO_InitStructure);
/* CAN register init */
//CAN_DeInit(CANx);
/* Enable Can clock */
CANx_CLK_INIT(CANx_CLK, ENABLE);
CAN_StructInit(&CAN_InitStructure);
/* CAN cell init */
CAN_InitStructure.CAN_TTCM = DISABLE;//禁止时间触发通信模式
CAN_InitStructure.CAN_ABOM = DISABLE;//软件对CAN_MCR 寄存器的INRQ 位进行置1 随后清0 后,一旦硬件检测
//到128 次11 位连续的隐性位,就退出离线状态。
CAN_InitStructure.CAN_AWUM = DISABLE;//睡眠模式通过清除CAN_MCR 寄存器的SLEEP 位,由软件唤醒
CAN_InitStructure.CAN_NART = ENABLE;//DISABLE; CAN 报文只被发送1 次,不管发送的结果如何(成功、出错或仲裁丢失)
CAN_InitStructure.CAN_RFLM = DISABLE;//在接收溢出时FIFO 未被锁定,当接收FIFO 的报文未被读出,下一个收到的报文会覆盖原有的报文
CAN_InitStructure.CAN_TXFP = DISABLE;//发送FIFO 优先级由报文的标识符来决定
CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;//CAN_Mode_LoopBack;//CAN_Mode_Normal; //CAN 硬件工作在正常模式
CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;//重新同步跳跃宽度1 个时间单位
CAN_InitStructure.CAN_BS1 = CAN_BS1_8tq;//时间段1 为8 个时间单位
CAN_InitStructure.CAN_BS2 = CAN_BS2_7tq;//时间段2 为7 个时间单位
CAN_InitStructure.CAN_Prescaler = 9; //(pclk1/((1+8+7)*9)) = 36Mhz/16/9 = 250Kbits 设定了一个时间单位的长度9
CAN_Init(CANx, &CAN_InitStructure);
CAN_FilterInitStructure.CAN_FilterNumber = 0;//指定了待初始化的过滤器0
CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;//指定了过滤器将被初始化到的模式标识符屏蔽位模式
CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_16bit;//CAN_FilterScale_32bit;//给出了过滤器位宽1 个32 位过滤器
CAN_FilterInitStructure.CAN_FilterIdHigh = 0x0000;//用来设定过滤器标识符(32 位位宽时为其高段位,16 位位宽时为第一个)
CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;//用来设定过滤器标识符(32 位位宽时为其低段位,16 位位宽时为第二个
CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x0000;//用来设定过滤器屏蔽标识符或者过滤器标识符(32 位位宽时为其高段位,16 位位宽时为第一个)
CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;//用来设定过滤器屏蔽标识符或者过滤器标识符(32 位位宽时为其低段位,16 位位宽时为第二个
CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0;//设定了指向过滤器的FIFO0
CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;//使能过滤器
CAN_FilterInit(&CAN_FilterInitStructure);
NVIC_InitStructure.NVIC_IRQChannel = CANx_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1;;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// CAN_ITConfig(CAN_IT_FMP0, ENABLE);//使能指定的CAN 中断
return TRUE;
}
void CAN_TxData(char data)
{
CanTxMsg TxMessage;
u32 i = 0;
u8 TransmitMailbox = 0;
TxMessage.StdId = 0x55;// 设定标准标识符
TxMessage.ExtId = 0x1234;// 设定扩展标识符
TxMessage.IDE = CAN_ID_EXT;// 设定消息标识符的类型
TxMessage.RTR = CAN_RTR_DATA;// 设定待传输消息的帧类型
TxMessage.DLC = 8; //设定待传输消息的帧长度
TxMessage.Data[0] = data;// 包含了待传输数据
TxMessage.Data[1] = data;// 包含了待传输数据
TxMessage.Data[2] = data;// 包含了待传输数据
TxMessage.Data[3] = data;// 包含了待传输数据
TxMessage.Data[4] = data;// 包含了待传输数据
TxMessage.Data[5] = data;// 包含了待传输数据
TxMessage.Data[6] = data;// 包含了待传输数据
TxMessage.Data[7] = data;// 包含了待传输数据
TransmitMailbox = CAN_Transmit(CANx, &TxMessage);//开始一个消息的传输
i = 0;
while((CAN_TransmitStatus(CANx, TransmitMailbox) != CAN_TxStatus_Ok) && (i != 0xFF))//通过检查CANTXOK 位来确认发送是否成功
{
i++;
}
}
#ifndef __DRV_CAN_H__
#define __DRV_CAN_H__
#include "Global.h"
#define CANx CAN1
#define CANx_CLK RCC_APB1Periph_CAN1
#define CANx_CLK_INIT RCC_APB1PeriphClockCmd
#define CANx_IRQn USB_LP_CAN1_RX0_IRQn//CAN1_RX0_IRQn
#define CANx_IRQHandler USB_LP_CAN1_RX0_IRQHandler//CAN1_RX1_IRQHandler
//#define GPIO_Remapping_CAN GPIO_Remapping_CAN1
#define Can_RX_PIN GPIO_Pin_11
#define Can_RX_GPIO_PORT GPIOA
#define Can_RX_GPIO_CLK RCC_APB2Periph_GPIOA
#define Can_TX_PIN GPIO_Pin_12
#define Can_TX_GPIO_PORT GPIOA
#define Can_TX_GPIO_CLK RCC_APB2Periph_GPIOA
extern u8 CanInit(void);
extern void CAN_TxData(char data);
#endif
/******************************************************************************
文件 :
描述 :
作者 :
修改 :
******************************************************************************/
#include "Drv_CommuSPI2.h"
osMutexId CommuSPI2Mutex = NULL;
osMutexId GetCommuMutex()
{
return CommuSPI2Mutex;
}
/**
* @brief Sends a byte through the SPI interface and return the byte received
* from the SPI bus.
* @param byte: byte to send.
* @retval The value of the received byte.
*/
u8 CommuSPI2_SendByte(u8 byte)
{
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(CommuSPI2, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send byte through the SPI1 peripheral */
SPI_I2S_SendData(CommuSPI2, byte);
/*!< Wait to receive a byte */
while (SPI_I2S_GetFlagStatus(CommuSPI2, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the byte read from the SPI bus */
return SPI_I2S_ReceiveData(CommuSPI2);
}
/**
* @brief Reads a byte from the SPI Flash.
* @note This function must be used only if the Start_Read_Sequence function
* has been previously called.
* @param None
* @retval Byte Read from the SPI Flash.
*/
u8 CommuSPI2_ReadByte(u8 DUMMY_BYTE)
{
return (CommuSPI2_SendByte(DUMMY_BYTE));
}
/**
* @brief Sends a Half Word through the SPI interface and return the Half Word
* received from the SPI bus.
* @param HalfWord: Half Word to send.
* @retval The value of the received Half Word.
*/
u16 CommuSPI2_SendHalfWord(u16 HalfWord)
{
/*!< Loop while DR register in not emplty */
while (SPI_I2S_GetFlagStatus(CommuSPI2, SPI_I2S_FLAG_TXE) == RESET);
/*!< Send Half Word through the sFLASH peripheral */
SPI_I2S_SendData(CommuSPI2, HalfWord);
/*!< Wait to receive a Half Word */
while (SPI_I2S_GetFlagStatus(CommuSPI2, SPI_I2S_FLAG_RXNE) == RESET);
/*!< Return the Half Word read from the SPI bus */
return SPI_I2S_ReceiveData(CommuSPI2);
}
#if 0
/**
* @brief DeInitializes the peripherals used by the SPI FLASH driver.
* @param None
* @retval None
*/
void CommuSPI2_LowLevel_DeInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/*!< Disable the CommuSPI2 ************************************************/
SPI_Cmd(CommuSPI2, DISABLE);
/*!< DeInitializes the CommuSPI2 *******************************************/
SPI_I2S_DeInit(CommuSPI2);
/*!< CommuSPI2 Periph clock disable ****************************************/
CommuSPI2_CLK_INIT(CommuSPI2_CLK, DISABLE);
/*!< Configure all pins used by the SPI as input floating *******************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = CommuSPI2_SCK_PIN;
GPIO_Init(CommuSPI2_SCK_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CommuSPI2_MISO_PIN;
GPIO_Init(CommuSPI2_MISO_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = CommuSPI2_MOSI_PIN;
GPIO_Init(CommuSPI2_MOSI_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
}
/**
* @brief DeInitializes the peripherals used by the SPI FLASH driver.
* @param None
* @retval None
*/
void CommuSPI2_DeInit(void)
{
CommuSPI2_LowLevel_DeInit();
}
#endif
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/**
* @brief Initializes the peripherals used by the SPI FLASH driver.
* @param None
* @retval None
*/
void CommuSPI2_LowLevel_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
// GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); /*使能SWD 禁用JTAG*/
/*!< Enable the SPI clock */
CommuSPI2_CLK_INIT(CommuSPI2_CLK, ENABLE);
/*!< Enable GPIO clocks */
RCC_AHB1PeriphClockCmd(CommuSPI2_SCK_GPIO_CLK | CommuSPI2_MISO_GPIO_CLK |
CommuSPI2_MOSI_GPIO_CLK | sFLASH_CS_GPIO_CLK, ENABLE);
/*!< SPI pins configuration *************************************************/
/*!< Connect SPI pins to AF5 */
GPIO_PinAFConfig(CommuSPI2_SCK_GPIO_PORT, CommuSPI2_SCK_SOURCE, CommuSPI2_SCK_AF);
GPIO_PinAFConfig(CommuSPI2_MISO_GPIO_PORT, CommuSPI2_MISO_SOURCE, CommuSPI2_MISO_AF);
GPIO_PinAFConfig(CommuSPI2_MOSI_GPIO_PORT, CommuSPI2_MOSI_SOURCE, CommuSPI2_MOSI_AF);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
/*!< SPI SCK pin configuration */
GPIO_InitStructure.GPIO_Pin = CommuSPI2_SCK_PIN;
GPIO_Init(CommuSPI2_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< SPI MOSI pin configuration */
GPIO_InitStructure.GPIO_Pin = CommuSPI2_MOSI_PIN;
GPIO_Init(CommuSPI2_MOSI_GPIO_PORT, &GPIO_InitStructure);
/*!< SPI MISO pin configuration */
GPIO_InitStructure.GPIO_Pin = CommuSPI2_MISO_PIN;
GPIO_Init(CommuSPI2_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sFLASH Card CS pin in output pushpull mode ********************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = sFLASH_CS_PIN;
GPIO_Init(sFLASH_CS_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN);
/*!< Configure sFLASH Card rest pin in output pushpull mode ********************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_SetBits(GPIOB, GPIO_Pin_11);
/*!< Configure W5500 Card CS pin in output pushpull mode ********************/
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = W5500_CS_PIN;
GPIO_Init(W5500_CS_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN);
/*!< SPI configuration */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//SPI_CPOL_Low;//
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//SPI_CPHA_1Edge;//
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(CommuSPI2, &SPI_InitStructure);
/*!< Enable the sFLASH_SPI */
SPI_Cmd(CommuSPI2, ENABLE);
CommuSPI2Mutex = NULL;
osMutexDef(CommuSPI2Mutex);
CommuSPI2Mutex = osMutexCreate(osMutex(CommuSPI2Mutex));
}
#ifndef __DRV_COMMUSPI2_H__
#define __DRV_COMMUSPI2_H__
/* Includes ------------------------------------------------------------------*/
#include "Global.h"
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* FLASH SPI Interface pins */
#define CommuSPI2 SPI2
#define CommuSPI2_CLK RCC_APB1Periph_SPI2
#define CommuSPI2_CLK_INIT RCC_APB1PeriphClockCmd
#define CommuSPI2_SCK_PIN GPIO_Pin_10
#define CommuSPI2_SCK_GPIO_PORT GPIOB
#define CommuSPI2_SCK_GPIO_CLK RCC_AHB1Periph_GPIOB
#define CommuSPI2_SCK_SOURCE GPIO_PinSource10
#define CommuSPI2_SCK_AF GPIO_AF_SPI2
#define CommuSPI2_MISO_PIN GPIO_Pin_14
#define CommuSPI2_MISO_GPIO_PORT GPIOB
#define CommuSPI2_MISO_GPIO_CLK RCC_AHB1Periph_GPIOB
#define CommuSPI2_MISO_SOURCE GPIO_PinSource14
#define CommuSPI2_MISO_AF GPIO_AF_SPI2
#define CommuSPI2_MOSI_PIN GPIO_Pin_15
#define CommuSPI2_MOSI_GPIO_PORT GPIOB
#define CommuSPI2_MOSI_GPIO_CLK RCC_AHB1Periph_GPIOB
#define CommuSPI2_MOSI_SOURCE GPIO_PinSource15
#define CommuSPI2_MOSI_AF GPIO_AF_SPI2
#define sFLASH_CS_PIN GPIO_Pin_10
#define sFLASH_CS_GPIO_PORT GPIOD
#define sFLASH_CS_GPIO_CLK RCC_AHB1Periph_GPIOD
#define W5500_CS_PIN GPIO_Pin_11
#define W5500_CS_GPIO_PORT GPIOD
#define W5500_CS_GPIO_CLK RCC_AHB1Periph_GPIOD
/* Exported macro ------------------------------------------------------------*/
/* Select sFLASH: Chip Select pin low */
#define sFLASH_CS_LOW() GPIO_ResetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
/* Deselect sFLASH: Chip Select pin high */
#define sFLASH_CS_HIGH() GPIO_SetBits(sFLASH_CS_GPIO_PORT, sFLASH_CS_PIN)
/* Exported macro ------------------------------------------------------------*/
/* Select W5500: Chip Select pin low */
#define W5500_CS_LOW() GPIO_ResetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN)
/* Deselect W5500: Chip Select pin high */
#define W5500_CS_HIGH() GPIO_SetBits(W5500_CS_GPIO_PORT, W5500_CS_PIN)
extern osMutexId GetCommuMutex();
extern u8 CommuSPI2_SendByte(u8 byte);
extern u8 CommuSPI2_ReadByte(u8 DUMMY_BYTE);
extern u16 CommuSPI2_SendHalfWord(u16 HalfWord);
extern void CommuSPI2_LowLevel_Init(void);
#endif /* #ifndef __DRV_SPIFLASH_H__ */
/******************************************************************************
文件 : Drv_ReaderActR1.c
描述 : 深圳市驰卡技术有限公司ACT-R1读卡器驱动
作者 :
修改 : 2014-08-26 郭涛 建立
******************************************************************************/
#include "Memory.h"
#include "Drv_CommuUSART3.h"
#include "Drv_ReaderActR1.h"
#include "Drv_ReaderPcd200.h"
#include "Drv_ReaderZLG600A.h"
osMessageQId ReaderDataRecvMsg = NULL;
osMessageQId ReaderDataSendMsg = NULL;
//static EnumReaderType ReaderType = eReaderType_No;
u8 ReaderErrorCount = 0;
u8 ReaderSendByte(u8 Data);
const StructReaderDrv ReaderDrvHandle[] =
{
{
ReaderActR1_Init,
ReaderActR1_CardFind,
ReaderActR1_IdCheck,
ReaderActR1_BlockRead,
ReaderActR1_BlockWrite
},
{
ReaderActR1_Init,
ReaderActR1_CardFind,
ReaderActR1_IdCheck,
ReaderActR1_BlockRead,
ReaderActR1_BlockWrite
},
{
ReaderPcb200_Init,
ReaderPcb200_CardFind,
ReaderPcb200_IdCheck,
ReaderPcb200_BlockRead,
ReaderPcb200_BlockWrite
},
{
ReaderZLG600A_Init,
ReaderZLG600A_CardFind,
ReaderZLG600A_IdCheck,
ReaderZLG600A_BlockRead,
ReaderZLG600A_BlockWrite
}
};
StructReaderDrv *pReaderDrv = (StructReaderDrv*)&ReaderDrvHandle[0];
/******************************************************************************
函数 : ReaderInit
描述 : 读卡器通信接口初始化。
参数 : 无
返回 : TRUE - 初始化完成
FALSE - 初始化有误
******************************************************************************/
u8 ReaderInit(void)
{
//USART_InitTypeDef USART_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* Enable GPIO clock */
/* Configure USART Tx and Rx as alternate function push-pull */
RCC_AHB1PeriphClockCmd(Reader_USARTx_TX_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_InitStructure.GPIO_Pin = Reader_USARTx_TX_PIN;
GPIO_Init(Reader_USARTx_TX_GPIO_PORT, &GPIO_InitStructure);
RCC_AHB1PeriphClockCmd(Reader_USARTx_RX_GPIO_CLK, ENABLE);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Pin = Reader_USARTx_RX_PIN;
GPIO_Init(Reader_USARTx_RX_GPIO_PORT, &GPIO_InitStructure);
/* Enable USART clock */
Reader_USARTx_CLK_INIT(Reader_USARTx_CLK, ENABLE);
/* Connect USART pins to AF7 */
GPIO_PinAFConfig(Reader_USARTx_TX_GPIO_PORT, Reader_USARTx_TX_SOURCE, Reader_USARTx_TX_AF);
GPIO_PinAFConfig(Reader_USARTx_RX_GPIO_PORT, Reader_USARTx_RX_SOURCE, Reader_USARTx_RX_AF);
/* Enable the USART OverSampling by 8 */
USART_OverSampling8Cmd(Reader_USARTx, ENABLE);
/* Enable the USARTx Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = Reader_USARTx_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Create Storage Message Queue*/
ReaderDataRecvMsg = NULL;
osMessageQDef(ReaderDataRecvMsg, 32, u8);
ReaderDataRecvMsg = osMessageCreate(osMessageQ(ReaderDataRecvMsg), NULL);
ReaderDataSendMsg = NULL;
osMessageQDef(ReaderDataSendMsg, 32, u8);
ReaderDataSendMsg = osMessageCreate(osMessageQ(ReaderDataSendMsg), NULL);
ReaderDiscern();
return TRUE;
}
/******************************************************************************
函数 : ReaderDiscern
描述 : 读卡器识别
参数 : 无
返回 : 无
******************************************************************************/
void ReaderDiscern(void)
{
if(1 == UserParam.Reader.Auto_ID)
{
ReaderActR1_Init(ReaderDataRecvMsg, ReaderSendByte);
if(TRUE == ReaderActR1_Test())
{
UserParam.Reader.ReaderType = eReaderType_ActR1;
}
else// if(UserParam.Reader.ReaderType == eReaderType_No)
{
ReaderZLG600A_Init(ReaderDataRecvMsg,ReaderSendByte);
ReaderPcb200_Init(ReaderDataRecvMsg, ReaderSendByte);
if(TRUE == ReaderPcb200_Test())
{
if(TRUE == ReaderZLG600A_Test())
UserParam.Reader.ReaderType = eReaderType_ZLG600A;
else
UserParam.Reader.ReaderType = eReaderType_Pcd200;
}
else
{
UserParam.Reader.ReaderType = eReaderType_No;
}
}
}
if(eReaderType_Max < UserParam.Reader.ReaderType)
UserParam.Reader.ReaderType = eReaderType_No;
pReaderDrv = (StructReaderDrv*)&ReaderDrvHandle[UserParam.Reader.ReaderType];
pReaderDrv->pReaderInit(ReaderDataRecvMsg, ReaderSendByte);
}
/******************************************************************************
函数 : Reader_USARTx_IRQHandler
描述 : 读卡器串口接收中断
参数 : 无
返回 : 无
******************************************************************************/
void Reader_USARTx_IRQHandler(void)
{
u16 CR1,SR;
u8 Data;
osEvent SendDataMsg;
SR = Reader_USARTx->SR;
CR1 = Reader_USARTx->CR1;
if((CR1 & USART_CR1_RXNEIE) && (SR & USART_SR_RXNE))
{
Data = (u8)Reader_USARTx->DR;
osMessagePut(ReaderDataRecvMsg, Data, 0);
}
if((CR1 & USART_CR1_TXEIE) && (SR & USART_SR_TXE))
{
SendDataMsg = osMessageGet(ReaderDataSendMsg, 0);
if(osEventMessage == SendDataMsg.status)
Reader_USARTx->DR = SendDataMsg.value.v;
else
Reader_USARTx->CR1 &= ~USART_CR1_TXEIE;
}
}
/******************************************************************************
函数 : ReaderSendData
描述 : 读卡器发送字节
参数 : Data - 接收到的字节
返回 : TRUE - 成功
FALSE - 失败
******************************************************************************/
static u8 ReaderSendByte(u8 Data)
{
osStatus EvenStatus;
EvenStatus = osMessagePut(ReaderDataSendMsg, Data, portMAX_DELAY);
if(osOK == EvenStatus)
{
Reader_USARTx->CR1 |= USART_CR1_TXEIE;
return TRUE;
}
return FALSE;
}
/******************************************************************************
函数 : Cmd_CardFind
描述 : 读卡器寻卡
参数 : pUID - 寻到卡UID
返回 : TRUE - 成功
FALSE - 失败
******************************************************************************/
int Cmd_CardFind(u8 *pUID)
{
int temp;
static u32 Time = 0;
temp = pReaderDrv->Cmd_CardFind(pUID);
if(0 != temp)
{
if(0 == Time)
Time = GetSystemTick();
if((eReaderType_No == UserParam.Reader.ReaderType)
||((GetSystemTick() - Time) > 5000))
{
ReaderDiscern();
Time = GetSystemTick();
}
}
else
Time = GetSystemTick();
return temp;
}
/******************************************************************************
函数 : ReaderActR1_IdCheck
描述 : 读卡器认证密码
参数 : pID - 密码缓存指针
Section - 需要认证的扇区号 范围0-15
Key - 'A'、'a'密码A, 'B'、'b'密码B
返回 : TRUE - 成功
FALSE - 失败
******************************************************************************/
int Cmd_IdCheck(u8* pID, u8 Section, u8 Key, u8 *pUid)
{
return pReaderDrv->pCmd_IdCheck(pID, Section, Key, pUid);
}
/******************************************************************************
函数 : Cmd_BlockRead
描述 : 读卡器读块
参数 : pData - 读数据存放指针
Block - 块号 范围0-31
返回 : TRUE - 成功
FALSE - 失败
******************************************************************************/
int Cmd_BlockRead(u8 *pData, u8 Block)
{
return pReaderDrv->pCmd_BlockRead(pData, Block);
}
/******************************************************************************
函数 : Cmd_ReadBlock
描述 : 读卡器写块
参数 : pData - 写数据存放指针
Block - 块号 范围0-31
返回 : TRUE - 成功
FALSE - 失败
******************************************************************************/
int Cmd_BlockWrite(u8 *pData, u8 Block)
{
return pReaderDrv->Cmd_BlockWrite(pData, Block);
}
#ifndef __DRV_COMMUUSART3_H__
#define __DRV_COMMUUSART3_H__
#include "Global.h"
#define Reader_USARTx_BaudRate (9600)
#define Reader_USARTx USART3
#define Reader_USARTx_CLK RCC_APB1Periph_USART3
#define Reader_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define Reader_USARTx_IRQn USART3_IRQn
#define Reader_USARTx_IRQHandler USART3_IRQHandler
#define Reader_USARTx_TX_PIN GPIO_Pin_8
#define Reader_USARTx_TX_GPIO_PORT GPIOD
#define Reader_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Reader_USARTx_TX_SOURCE GPIO_PinSource8
#define Reader_USARTx_TX_AF GPIO_AF_USART3
#define Reader_USARTx_RX_PIN GPIO_Pin_9
#define Reader_USARTx_RX_GPIO_PORT GPIOD
#define Reader_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Reader_USARTx_RX_SOURCE GPIO_PinSource9
#define Reader_USARTx_RX_AF GPIO_AF_USART3
typedef u8 (*pReaderSendByte)(u8 Data);
typedef enum
{
eReaderType_No = 0x00,
eReaderType_ActR1 = 0x01,
eReaderType_Pcd200 = 0x02,
eReaderType_ZLG600A = 0x03,
eReaderType_Max = eReaderType_ZLG600A,
}EnumReaderType;
typedef struct
{
u8 (*pReaderInit)(osMessageQId RecvOsMsgQId, pReaderSendByte pSendByte);
int (*Cmd_CardFind)(u8 *pUID);
int (*pCmd_IdCheck)(u8* pID, u8 Section, u8 Key, u8 *pUid);
int (*pCmd_BlockRead)(u8 *pData, u8 Block);
int (*Cmd_BlockWrite)(u8 *pData, u8 Block);
}StructReaderDrv;
extern u8 ReaderInit(void);
extern void ReaderDiscern(void);
extern int Cmd_CardFind(u8 *pUID);
extern int Cmd_IdCheck(u8* pID, u8 Section, u8 Key, u8 *pUid);
extern int Cmd_BlockRead(u8 *pData, u8 Block);
extern int Cmd_BlockWrite(u8 *pData, u8 Block);
#endif
#include "Drv_CommuUart.h"
pCommuUartIrqHandler CommuUartIrq;
void USART3_IRQHandler(void)
{
if(NULL != CommuUartIrq)
CommuUartIrq();
else
{
u16 CR1,SR;
vu8 Data;
SR = CommuUart_USARTx->SR;
CR1 = CommuUart_USARTx->CR1;
if((CR1 & USART_CR1_RXNEIE) && (SR & USART_SR_RXNE))
{
Data = (u8)CommuUart_USARTx->DR;
}
if((CR1 & USART_CR1_TXEIE) && (SR & USART_SR_TXE))
CommuUart_USARTx->CR1 &= ~USART_CR1_TXEIE;
}
}
void CommuUartIrqSet(pCommuUartIrqHandler Irq)
{
CommuUartIrq = Irq;
}
#ifndef __DRV_COMMUUART_H__
#define __DRV_COMMUUART_H__
#include "Global.h"
#define CommuUart_USARTx USART3
#define CommuUart_USARTx_CLK RCC_APB1Periph_USART3
#define CommuUart_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define CommuUart_USARTx_IRQn USART3_IRQn
#define CommuUart_USARTx_TX_PIN GPIO_Pin_8
#define CommuUart_USARTx_TX_GPIO_PORT GPIOD
#define CommuUart_USARTx_TX_GPIO_CLK RCC_APB2Periph_GPIOD
#define CommuUart_USARTx_RX_PIN GPIO_Pin_9
#define CommuUart_USARTx_RX_GPIO_PORT GPIOD
#define CommuUart_USARTx_RX_GPIO_CLK RCC_APB2Periph_GPIOD
typedef void (*pCommuUartIrqHandler)(void);
extern void CommuUartIrqSet(pCommuUartIrqHandler Irq);
#endif
#ifndef __DRV_CONNECT_H__
#define __DRV_CONNECT_H__
#include "Global.h"
#define Dc_ADC ADC1
#define Dc_ADC_CLK RCC_APB2Periph_ADC1
#define Dc_ADC_CLK_INIT RCC_APB2PeriphClockCmd
/**************************DMA for ADC********************************/
#define Dc_ADC_DMA DMA1
#define Dc_ADC_DMA_CLK RCC_AHBPeriph_DMA1
#define Dc_ADC_DMA_CLK_INIT RCC_AHBPeriphClockCmd
#define Dc_ADC_DMA_CHANNEL DMA1_Channel1
/**************************ADC Pin ***********************************/
#define Cp_A_ADC_CHANNEL ADC_Channel_8
#define Cp_A_ADC_PIN GPIO_Pin_1
#define Cp_A_ADC_GPIO_PORT GPIOB
#define Cp_A_ADC_GPIO_CLK RCC_APB2Periph_GPIOB
#define Cp_B_ADC_CHANNEL ADC_Channel_9
#define Cp_B_ADC_PIN GPIO_Pin_0
#define Cp_B_ADC_GPIO_PORT GPIOB
#define Cp_B_ADC_GPIO_CLK RCC_APB2Periph_GPIOB
#define TempA_ADC_CHANNEL ADC_Channel_10
#define TempA_ADC_PIN GPIO_Pin_0
#define TempA_ADC_GPIO_PORT GPIOC
#define TempA_ADC_GPIO_CLK RCC_APB2Periph_GPIOC
#define TempB_ADC_CHANNEL ADC_Channel_11
#define TempB_ADC_PIN GPIO_Pin_1
#define TempB_ADC_GPIO_PORT GPIOC
#define TempB_ADC_GPIO_CLK RCC_APB2Periph_GPIOC
/**************************PWM and timer******************************/
#define CP_TIM TIM4
#define CP_TIM_CLK RCC_APB1Periph_TIM4
#define CP_TIM_CLK_INIT RCC_APB1PeriphClockCmd
/**************************ӿ A ******************************/
#define CP_A_OUT_PIN GPIO_Pin_12
#define CP_A_OUT_GPIO_PORT GPIOD
#define CP_A_OUT_GPIO_CLK RCC_APB2Periph_GPIOD
#define CP_A_OCxInit TIM_OC1Init
#define CP_A_OCxPreloadConfig TIM_OC1PreloadConfig
/**************************Cc ******************************/
#define Cc_A_Check_PIN GPIO_Pin_14
#define Cc_A_Check_GPIO_PORT GPIOE
#define Cc_A_Check_GPIO_CLK RCC_APB2Periph_GPIOE
#define GetCcStarus_A() (((Cc_A_Check_GPIO_PORT->IDR & Cc_A_Check_PIN) != Bit_RESET) ? Bit_SET : Bit_RESET)
/**************************ӿ B ******************************/
#define CP_B_OUT_PIN GPIO_Pin_13
#define CP_B_OUT_GPIO_PORT GPIOD
#define CP_B_OUT_GPIO_CLK RCC_APB2Periph_GPIOD
#define CP_B_OCxInit TIM_OC2Init
#define CP_B_OCxPreloadConfig TIM_OC2PreloadConfig
/**************************Cc ******************************/
#define Cc_B_Check_PIN GPIO_Pin_15
#define Cc_B_Check_GPIO_PORT GPIOE
#define Cc_B_Check_GPIO_CLK RCC_APB2Periph_GPIOE
#define GetCcStarus_B() (((Cc_B_Check_GPIO_PORT->IDR & Cc_B_Check_PIN) != Bit_RESET) ? Bit_SET : Bit_RESET)
/**************************Stop ******************************/
#define Stop_Check_PIN GPIO_Pin_0
#define Stop_Check_GPIO_PORT GPIOE
#define Stop_Check_GPIO_CLK RCC_APB2Periph_GPIOE
#define GetStopStarus() (((Stop_Check_GPIO_PORT->IDR & Stop_Check_PIN) != Bit_RESET) ? Bit_SET : Bit_RESET)
/**************************׮ ******************************/
#define Door_Check_PIN GPIO_Pin_3
#define Door_Check_GPIO_PORT GPIOE
#define Door_Check_GPIO_CLK RCC_APB2Periph_GPIOE
#define GetDoorStarus() (((Door_Check_GPIO_PORT->IDR & Door_Check_PIN) != Bit_RESET) ? Bit_SET : Bit_RESET)
typedef enum
{
eDcChn_Cp_A = 0,
eDcChn_Cp_B = 1,
eDcChn_TempA = 2,
eDcChn_TempB = 3,
}EnumDcChannel;
#define Dc_AverageSize (32)
extern u16 DcAdcValueAlign[Dc_AverageSize][4];
extern void DcAdcInit(void);
extern void CpPwmInit(void);
extern void CpDutySet_A(u16 Duty);
extern void CpDutySet_B(u16 Duty);
extern void CcCheckInit(void);
extern void StopCheckInit(void);
extern void DoorCheckInit(void);
#endif
#include "Drv_DcModule.h"
#define DcModuleMaxVolt (7500)//750V
#define DcModuleMinVolt (2500)//250V
#define DcModuleMaxCurrt (200) //20A
#define DcModuleMinCurrt (40) //4A
typedef struct
{
u8 Id;
u8 Temp;
u16 Volt;
u16 Currt;
u16 State;
u32 RecvTime;
}StructDcModuleStatus;
const StructDcModuleAbility DcModuleAbility =
{
.MaxVolt = DcModuleMaxVolt,
.MinVolt = DcModuleMinVolt,
.MaxCurrt = DcModuleMaxCurrt,
.MinCurrt = DcModuleMinCurrt,
};
StructDcModuleManage DcModuleManage;
StructDcModuleStatus DcModuleStatus[64];
void DcModuleRxIrqHandle(void)
{
StructDcModuleStatus Data;
UnionLittleEnd32 Temp;
Data.Id = CANRID(DcModule_Can) & 0x000000FF;
Temp.Mult32 = CANRDA(DcModule_Can);
Data.Volt = (Temp.Disp32.LL32<<8) + Temp.Disp32.ML32;
Data.Currt = (Temp.Disp32.MH32<<8) + Temp.Disp32.HH32;
Temp.Mult32 = CANRDB(DcModule_Can);
Data.Temp= (Temp.Disp32.LL32<<8) + Temp.Disp32.ML32;
Data.State = (Temp.Disp32.MH32<<8) + Temp.Disp32.HH32;
Data.RecvTime = GetSystemTick();
if(Data.Id < 64)
{
DcModuleStatus[Data.Id] = Data;
DcModuleManage.OnlineFlag |= ((long long)1<<Data.Id);
}
}
void DcModuleCanInit(void)
{
StructPinParam PinParam;
PinParam.Dir = ePinDir_Out;
PinParam.Mode = ePinMode_PullNone;
PinParam.Func = DcModuleTx_PinFunc;
PinParam.Pin = DcModuleTx_Pin;
PinInit(DcModuleTx_Port, &PinParam);
PinParam.Dir = ePinDir_In;
PinParam.Mode = ePinMode_PullNone;
PinParam.Func = DcModuleRx_PinFunc;
PinParam.Pin = DcModuleRx_Pin;
PinInit(DcModuleRx_Port, &PinParam);
SetCanRxIrq(DcModule_Can, DcModuleRxIrqHandle);
PeriphPowerSet(DcModule_CanPower, ENABLE);
PeriphClkSet(DcModule_CanClk, ePclkDiv_CclkDiv_2);
CANMOD(DcModule_Can) = 0x01;//CAN模式寄存器,有些数据只有再CANMOD.0 == 1时才可以写入
CANIER(DcModule_Can) = 0x00;//中断使能寄存器,禁止中断
CANGSR(DcModule_Can) = 0x00;//清除错误计数器 /* Clear status register */
CANCMR(DcModule_Can) = 0x00;/* Reset CAN2 CMD register*/
CANBTR(DcModule_Can) = 0x001C0008;//波特率:250K-- BitRate = Fpclk/( (BRP+1) * (1+(Tseg1+1)+(Tseg2+1)) )
CANIER(DcModule_Can) = 0x01;//CAN1中断使能寄存器,使能接收中断以及错误中断
CANEWL(DcModule_Can) = 0x7F;//出错警告界限寄存器
CANMOD(DcModule_Can) = 0x00;//正常收发模式
CAN_AFMR = 2;/* By default filter is not used */
}
/**************************************************************************************************
** 函数名: CAN1_SendMessage
** 输 入: ulCanId----发送ID, ulCanDataA----发送数据的底4字节, ulCanDataB----发送数据的高4字节
** 输 出: 参数读取状态
** 描 述: 通过CAN通道发送数据
** 日 期: 2010/08/19
**************************************************************************************************/
u8 DcModuleSendMsg(StructDcModuleSend *pMsg)
{
u32 CANStatus;
u32 CanSendFormat;
CanSendFormat = ((((uint32)pMsg->Len) << 16) & 0x000F0000) | 0x80000000; //(bit31=1为扩展帧) (bit30 RTR = 0为数据帧)
//发送29bitID,非远程帧,3位数据,优先级域为1
CANStatus = CANSR(DcModule_Can);
if(CANStatus & 0x00000004) //缓冲区1空闲
{
CANTFI(DcModule_Can, 0) = CanSendFormat; //1 0 0000000000 0011 00000000 00000001
CANTID(DcModule_Can, 0) = pMsg->Id;
CANTDA(DcModule_Can, 0) = (pMsg->Data[0]) | (pMsg->Data[1]<<8) | (pMsg->Data[2]<<16) | (pMsg->Data[3]<<24);
CANTDB(DcModule_Can, 0) = (pMsg->Data[4]) | (pMsg->Data[5]<<8) | (pMsg->Data[6]<<16) | (pMsg->Data[7]<<24);
CANCMR(DcModule_Can) = 0x21; //发送Tx缓冲区1的数据 21
return TRUE;
}
else if(CANStatus & 0x00000400)//缓冲区2空闲
{
CANTFI(DcModule_Can, 1) = CanSendFormat;
CANTID(DcModule_Can, 1) = pMsg->Id;
CANTDA(DcModule_Can, 1) = (pMsg->Data[0]) | (pMsg->Data[1]<<8) | (pMsg->Data[2]<<16) | (pMsg->Data[3]<<24);
CANTDB(DcModule_Can, 1) = (pMsg->Data[4]) | (pMsg->Data[5]<<8) | (pMsg->Data[6]<<16) | (pMsg->Data[7]<<24);
CANCMR(DcModule_Can) = 0x41; //发送Tx缓冲区2的数据 41
return TRUE;
}
else if(CANStatus & 0x00040000) //缓冲区3空闲
{
CANTFI(DcModule_Can, 2) = CanSendFormat; //1 0 0000000000 0011 00000000 00000001
CANTID(DcModule_Can, 2) = pMsg->Id;
CANTDA(DcModule_Can, 2) = (pMsg->Data[0]) | (pMsg->Data[1]<<8) | (pMsg->Data[2]<<16) | (pMsg->Data[3]<<24);
CANTDB(DcModule_Can, 2) = (pMsg->Data[4]) | (pMsg->Data[5]<<8) | (pMsg->Data[6]<<16) | (pMsg->Data[7]<<24);
CANCMR(DcModule_Can) = 0x81; //发送Tx缓冲区1的数据 21
return TRUE;
}
return FALSE; //未发送成功,返回FALSE
}
StructDcModuleCtrl DcModuleCtrl;
void DcModuleManageProcess(void)
{
static u32 CheckTick = 0;
u8 i;
long long Flag;
u8 Count;
u32 Currt;
if((GetSystemTick() - CheckTick) < 750)
return;
CheckTick = GetSystemTick();
Flag = 1;
Count = 0;
for(i=0; i<64; i++)
{
if(Flag & DcModuleManage.OnlineFlag)
{
if((GetSystemTick() - DcModuleStatus[i].RecvTime) > 2000)
{
DcModuleManage.OnlineFlag &= ~Flag;
DcModuleManage.ValidFlag &= ~Flag;
}
else
{
if(0x0000 == (DcModuleStatus[i].State & 0x0FFF))
{
DcModuleManage.ValidFlag |= Flag;
Count++;
}
}
}
Flag = Flag << 1;
}
DcModuleManage.ValidNum = Count;
Flag = 1;
Currt = 0;
for(i=0; i<64; i++)
{
if(Flag & DcModuleManage.ValidFlag)
{
Currt += DcModuleStatus[i].Currt;
DcModuleCtrl.ActualVolt = DcModuleStatus[i].Volt;
}
Flag = Flag << 1;
}
DcModuleCtrl.ActualCurrt = Currt;
if(0 == DcModuleManage.OnlineFlag)
DcModuleCanInit();
}
void DcModuleCtrlProcess(void)
{
static u32 CtrlTick = 0;
static u8 LastFlag = 0;
StructDcModuleSend DataSend;
u32 Temp;
Temp = 0;
if(LastFlag != DcModuleCtrl.CtrlFlag)
{
LastFlag = DcModuleCtrl.CtrlFlag;
Temp++;
}
if((GetSystemTick() - CtrlTick) > 100)
{
CtrlTick = GetSystemTick();
Temp++;
}
if(0 == Temp)
return;
if(DcModuleCtrl.CtrlFlag)
{
if(DcModuleCtrl.NeedVolt > DcModuleAbility.MaxVolt)
DcModuleManage.SetVolt = DcModuleAbility.MaxVolt;
else if(DcModuleCtrl.NeedVolt > DcModuleAbility.MinVolt)
DcModuleManage.SetVolt = DcModuleCtrl.NeedVolt;
else
DcModuleManage.SetVolt = DcModuleAbility.MinVolt;
if(DcModuleManage.ValidNum)
{
Temp = DcModuleCtrl.NeedCurrt/DcModuleManage.ValidNum;
if(DcModuleCtrl.NeedCurrt % DcModuleManage.ValidNum)
Temp++;
}
else
Temp = DcModuleManage.SetCurrt;
if(Temp > DcModuleAbility.MaxCurrt)
Temp = DcModuleAbility.MaxCurrt;
else if(Temp < DcModuleAbility.MinCurrt)
Temp = DcModuleAbility.MinCurrt;
if(Temp <= DcModuleManage.SetCurrt)
DcModuleManage.SetCurrt = Temp;
else
DcModuleManage.SetCurrt++;
if(DcModuleManage.SetCurrt > DcModuleAbility.MaxCurrt)
DcModuleManage.SetCurrt = DcModuleAbility.MaxCurrt;
else if(DcModuleManage.SetCurrt < DcModuleAbility.MinCurrt)
DcModuleManage.SetCurrt = DcModuleAbility.MinCurrt;
DcModuleManage.Cmd = 0xAA;//开机
}
else
{
DcModuleManage.Cmd = 0x00;//关机
DcModuleManage.SetVolt = 0;
DcModuleManage.SetCurrt = 0;
}
DataSend.Id = 0x01013FAA;
DataSend.Len = 5;
DataSend.Data[0] = (DcModuleManage.SetVolt/100) >> 8;
DataSend.Data[1] = (DcModuleManage.SetVolt/100);
DataSend.Data[2] = (DcModuleManage.SetCurrt/100) >> 8;
DataSend.Data[3] = (DcModuleManage.SetCurrt/100);
DataSend.Data[4] = DcModuleManage.Cmd;
DcModuleSendMsg(&DataSend);
}
/* the system main thread */
void DcModule(void const *parameter)
{
osDelay(2000);
while(1)
{
DcModuleManageProcess();
osDelay(20);
DcModuleCtrlProcess();
osDelay(20);
}
}
void DcModuleSet(EnumSwitchStatus Set, u16 Volt, u16 Currt)
{
if(eSwSta_Off == Set)
{
DcModuleCtrl.CtrlFlag = 0;
DcModuleCtrl.NeedVolt = 0;
DcModuleCtrl.NeedCurrt = 0;
}
else
{
DcModuleCtrl.CtrlFlag = 1;
DcModuleCtrl.NeedVolt = Volt;
DcModuleCtrl.NeedCurrt = Currt;
}
}
u16 GetDcModuleVolt(void)
{
return DcModuleCtrl.ActualVolt;
}
u16 GetDcModuleCurrt(void)
{
return DcModuleCtrl.ActualCurrt;
}
u16 GetDcModuleVoltSet(void)
{
return DcModuleCtrl.NeedVolt;
}
u8 DcModuleInit(void)
{
DcModuleCanInit();
osThreadDef(DcModule, osPriorityAboveNormal, 0, configMINIMAL_STACK_SIZE);
if(NULL == osThreadCreate(osThread(DcModule), NULL))
return FALSE;
return TRUE;
}
#ifndef __DRV_DCMODULE_H__
#define __DRV_DCMODULE_H__
#include "Global.h"
#define DcModule_BaudRate (250)
#define DcModule_Can eCan_1
#define DcModule_CanPower ePeriphPower_CAN1
#define DcModule_CanClk ePeriphClk_CAN1
#define DcModule_CanInt CAN_INT
#define DcModuleTx_Pin ePin_1
#define DcModuleTx_Port ePort_0
#define DcModuleTx_PinFunc ePinFunc_1
#define DcModuleRx_Pin ePin_0
#define DcModuleRx_Port ePort_0
#define DcModuleRx_PinFunc ePinFunc_1
typedef struct
{
u16 MaxVolt;//0.1V/Bit;
u16 MinVolt;//0.1V/Bit;
u16 MaxCurrt;//0.1A/Bit;
u16 MinCurrt;//0.1A/Bit;
u16 SingleMaxCurrt;//0.1A/Bit
}StructDcModuleAbility;
typedef union
{
u32 Mult;
struct
{
u32 SeNunLo : 9;
u32 ProduDay: 5;
u32 ModAd : 7;//module adress
u32 MonAd : 4;//monitor adress
u32 Protocol: 4;
u32 Reserve : 3;
}Disp;
}UnionYouExtId;
typedef struct
{
u8 Data[8];
u8 Len; //֡ݳ
u32 Id;//֡ID
}StructDcModuleSend;
typedef struct
{
u8 Cmd;
u8 ValidNum;
u32 SetVolt;//0.001V/Bit
u32 SetCurrt;//0.001A/Bit
long long OnlineFlag;
long long ValidFlag;
}StructDcModuleManage;
typedef struct
{
u8 CtrlFlag;
u16 NeedVolt;//0.1V/Bit;
u16 NeedCurrt;//0.1A/Bit;
u16 ActualVolt;//0.1V/Bit;
u16 ActualCurrt;//0.1A/Bit;
}StructDcModuleCtrl;
extern StructDcModuleAbility DcModuleAbility;
extern StructDcModuleManage DcModuleManage;
extern StructDcModuleManage DcModuleManage_B;
extern StructDcModuleCtrl DcModuleCtrl;
extern StructDcModuleCtrl DcModuleCtrl_B;
extern u8 DcModuleInit(void);
extern u8 DcModuleSendMsg(StructDcModuleSend *pMsg);
extern void DcModuleSet(EnumSwitchStatus Set, u16 Volt, u16 Currt);
extern u16 GetDcModuleVolt(void);
extern u16 GetDcModuleCurrt(void);
extern u16 GetDcModuleVoltSet(void);
extern u16 GetDcModuleCurrtSet(void);
extern u8 DcModuleInit_B(void);
extern u8 DcModuleSendMsg_B(StructDcModuleSend *pMsg);
extern void DcModuleSet_B(EnumSwitchStatus Set, u16 Volt, u16 Currt);
extern u16 GetDcModuleVolt_B(void);
extern u16 GetDcModuleCurrt_B(void);
extern u16 GetDcModuleVoltSet_B(void);
extern u16 GetDcModuleCurrtSet_B(void);
extern void DcModuleSet_AB(EnumSwitchStatus Set, u16 Volt, u16 Currt);
extern u16 GetDcModuleVolt_AB(void);
extern u16 GetDcModuleCurrt_AB(void);
extern u16 GetDcModuleVoltSet_AB(void);
extern u16 GetDcModuleCurrtSet_AB(void);
extern u32 TemDecreaseCurrentValue(void);
extern u32 TemDecreaseCurrentValueB(void);
extern u8 ChargeEnable_AB;
extern u32 TemDecreaseCurrentValue(void);
#endif
#ifndef __DRV_DHT12_H__
#define __DRV_DHT12_H__
#include "Global.h"
#define Dht12_SCL_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Dht12_SCL_GPIO_PORT GPIOC
#define Dht12_SCL_PIN GPIO_Pin_15
#define Dht12_SDA_GPIO_CLK RCC_AHB1Periph_GPIOC
#define Dht12_SDA_GPIO_PORT GPIOC
#define Dht12_SDA_PIN GPIO_Pin_14
#define Dht12_SlaveAddr (0xB8)
typedef enum
{
eDht12_Humity_H_Addr = 0x00,
eDht12_Humity_L_Addr = 0x01,
eDht12_Temp_H_Addr = 0x02,
eDht12_Temp_L_Addr = 0x03,
eDht12_ChkSum_Addr = 0x04,
eDht12_end = 0x05,
}EnumDht12DataAddr;
typedef enum
{
eDht12Err_Sucess = 0, //成功
eDht12Err_DataPiont, //数据指针为空
eDht12Err_BusErr, //总线错误
eDht12Err_WriteCmd, //设备从地址写命令无应答
eDht12Err_ReadCmd, //设备从地址读命令无应答
eDht12Err_RegAddr, //寄存器高地址无应答
//eDht12Err_ChkSum,
eDht12Err_Error, //其他故障
}EnumDht12Error;
typedef enum
{
eDht12_HumityNum = 0,
eDht12_TempNum = 1,
eDht12_Num,
}EnumDht12Num;
typedef struct
{
u8 ValidFlag;
u16 Dht12Humity;
s16 Dht12Temp;
//u8 ChkSum;
}StructDht12Data;
extern StructDht12Data Dht12Data;
extern u8 Dht12Error;
extern u8 Dht12Init(void);
extern EnumDht12Error Dht12ReadData(u8 *pDh12);
extern u8 Dht12_GetHumiAndTemp(void);
extern u16 Dht12_GetHumi(void);
extern s16 Dht12_GetTemp(void);
#endif
#ifndef __DRV_DTUUSR_H__
#define __DRV_DTUUSR_H__
#include "Global.h"
#include "Global.h"
#define Dtu_BaudRate (115200)
#define Dtu_Uart eUart_0
#define Dtu_UartPower ePeriphPower_UART0
#define Dtu_UartClk ePeriphClk_UART0
#define Dtu_UartInt UART0_INT
#define DtuTx_Pin ePin_2
#define DtuTx_Port ePort_0
#define DtuTx_PinFunc ePinFunc_1
#define DtuRx_Pin ePin_3
#define DtuRx_Port ePort_0
#define DtuRx_PinFunc ePinFunc_1
typedef enum
{
eDtuSelfCtrl_None = 0,
eDtuSelfCtrl_CloseSckt,
eDtuSelfCtrl_Error,
}EnumDtuSelfCtrl;
typedef union
{
u32 Mux;
struct
{
u32 NoMod : 1;
u32 NoAp : 1;
u32 NoCon : 1;
}Bit;
}StructDtuError;
typedef struct
{
osMessageQId RecvQ;
osMessageQId SendQ;
}StructDtuCommu;
typedef struct
{
u8 ErrCnt;
u8 Status;
u32 StatusTick;
}StructDtuProc;
typedef struct
{
EnumDtuSelfCtrl SelCtrl;
#if 0
u8 Csq;
char Resp[64];
#endif
u32 LastRecvTime;
StructDtuError Err;
StructDtuCommu Uart;
StructDtuProc Proc;
osMessageQId AppRecvQ;
osMutexId SendMutex;
}StructDtuSta;
typedef void(*pDtuProcHandle)(void);
extern StructDtuSta Dtu;
extern u8 DtuInit(osMessageQId AppRecvQ);
extern u8 DtuNetAvail(void);
extern int DtuTcpSend(u8 *pData, u16 Len);
extern void DtuTcpClose(void);
#endif
#ifndef __DRV_E2ROM_H__
#define __DRV_E2ROM_H__
#include "Global.h"
#define E2rom_SCL_GPIO_CLK RCC_AHB1Periph_GPIOF
#define E2rom_SCL_GPIO_PORT GPIOF
#define E2rom_SCL_PIN GPIO_Pin_1
#define E2rom_SDA_GPIO_CLK RCC_AHB1Periph_GPIOF
#define E2rom_SDA_GPIO_PORT GPIOF
#define E2rom_SDA_PIN GPIO_Pin_0
#define E2rom_SlaveAddr (0xA0)
#define E2rom_PageSize (128)
typedef enum
{
eE2romErr_Sucess = 0, //成功
eE2romErr_DataPiont, //数据指针为空
eE2romErr_WriteOver, //写数据超范围
eE2romErr_ReadOver, //读数据超范围
eE2romErr_BusErr, //总线错误
eE2romErr_WriteCmd, //设备从地址写命令无应答
eE2romErr_ReadCmd, //设备从地址读命令无应答
eE2romErr_RegAddrHi, //寄存器高地址无应答
eE2romErr_RegAddrLo, //寄存器低地址无应答
eE2romErr_WriteData, //写数据无应答
eE2romErr_Error, //其他故障
}EnumE2romError;
extern u8 E2romInit(void);
extern EnumE2romError E2romWriteData(u16 Addr, u8 *pData, u16 Len);
extern EnumE2romError E2romReadData(u16 Addr, u8 *pData, u16 Len);
#endif
/******************************************************************************
文件 : Drv_Elock.c
描述 : 电磁锁驱动
作者 :
修改 : 2014-09-26 郭涛 建立
******************************************************************************/
#include "Drv_Elock.h"
static EnumSwitchStatus ElockSet_A;
static EnumSwitchStatus ElockSet_B;
/******************************************************************************
函数 : ElockSetStatus_A
描述 : 设置接触器状态
参数 : Status - eSwSta_On合上
eSwSta_Off断开
返回 : 无
******************************************************************************/
void ElockSetStatus_A(EnumSwitchStatus Status)
{
if(eSwSta_Off == Status)
GPIO_ResetBits(Elock_A_PORT, Elock_A_PIN);
else
GPIO_SetBits(Elock_A_PORT, Elock_A_PIN);
ElockSet_A = Status;
}
/******************************************************************************
函数 : ElockSetStatus_B
描述 : 设置接触器状态
参数 : Status - eSwSta_On合上
eSwSta_Off断开
返回 : 无
******************************************************************************/
void ElockSetStatus_B(EnumSwitchStatus Status)
{
if(eSwSta_Off == Status)
GPIO_ResetBits(Elock_B_PORT, Elock_B_PIN);
else
GPIO_SetBits(Elock_B_PORT, Elock_B_PIN);
ElockSet_B = Status;
}
/******************************************************************************
函数 : ElockInit
描述 : Cc初始化
参数 : 无
返回 : 无
******************************************************************************/
void ElockInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
ElockSet_A = eSwSta_Off;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = Elock_A_PIN;
RCC_APB2PeriphClockCmd(Elock_A_RCC, ENABLE);
GPIO_Init(Elock_A_PORT, &GPIO_InitStructure);
GPIO_ResetBits(Elock_A_PORT, Elock_A_PIN);
ElockSet_B = eSwSta_Off;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_InitStructure.GPIO_Pin = Elock_B_PIN;
RCC_APB2PeriphClockCmd(Elock_B_RCC, ENABLE);
GPIO_Init(Elock_B_PORT, &GPIO_InitStructure);
GPIO_ResetBits(Elock_B_PORT, Elock_B_PIN);
}
/******************************************************************************
函数 : ElockGetStatus_A
描述 : Elock状态获取
参数 : 无
返回 : eSwSta_On合上 eSwSta_Off 断开
******************************************************************************/
EnumSwitchStatus ElockGetStatus_A(void)
{
return ElockSet_A;
}
/******************************************************************************
函数 : ElockGetStatus_B
描述 : Elock状态获取
参数 : 无
返回 : eSwSta_On合上 eSwSta_Off 断开
******************************************************************************/
EnumSwitchStatus ElockGetStatus_B(void)
{
return ElockSet_B;
}
/******************************************************************************
函数 : ElockSetStatus
描述 : 设置接触器状态
参数 : Status - eSwSta_On合上
eSwSta_Off断开
返回 : 无
******************************************************************************/
void ElockSetStatus(EnumSwitchStatus Status)
{
if(eSwSta_Off == Status)
GPIO_ResetBits(Elock_A_PORT, Elock_A_PIN);
else
GPIO_SetBits(Elock_A_PORT, Elock_A_PIN);
ElockSet_A = Status;
}
/******************************************************************************
函数 : ElockGetStatus
描述 : Elock状态获取
参数 : 无
返回 : eSwSta_On合上 eSwSta_Off 断开
******************************************************************************/
EnumSwitchStatus ElockGetStatus(void)
{
return ElockSet_A;
}
#ifndef __DRV_ELOCK_H__
#define __DRV_ELOCK_H__
#include "Global.h"
/**************************Elock pin********************************/
#define Elock_A_PIN GPIO_Pin_4
#define Elock_A_PORT GPIOE
#define Elock_A_RCC RCC_APB2Periph_GPIOE
#define Elock_B_PIN GPIO_Pin_3
#define Elock_B_PORT GPIOE
#define Elock_B_RCC RCC_APB2Periph_GPIOE
extern void ElockInit(void);
extern void ElockSetStatus_A(EnumSwitchStatus Status);
extern EnumSwitchStatus ElockGetStatus_A(void);
extern void ElockSetStatus_B(EnumSwitchStatus Status);
extern EnumSwitchStatus ElockGetStatus_B(void);
extern void ElockSetStatus(EnumSwitchStatus Status);
extern EnumSwitchStatus ElockGetStatus(void);
#endif
#ifndef __DRV_GPRSCOMMON_H__
#define __DRV_GPRSCOMMON_H__
#include "Global.h"
#include "Drv_CommuUart.h"
#define Module_USARTx_BaudRate (115200)
#define Gprs_USARTx CommuUart_USARTx
#define Gprs_USARTx_CLK CommuUart_USARTx_CLK
#define Gprs_USARTx_CLK_INIT CommuUart_USARTx_CLK_INIT
#define Gprs_USARTx_IRQn CommuUart_USARTx_IRQn
//#define Gprs_USARTx_IRQHandler USART3_IRQHandler
#define Gprs_USARTx_TX_PIN CommuUart_USARTx_TX_PIN
#define Gprs_USARTx_TX_GPIO_PORT CommuUart_USARTx_TX_GPIO_PORT
#define Gprs_USARTx_TX_GPIO_CLK CommuUart_USARTx_TX_GPIO_CLK
#define Gprs_USARTx_RX_PIN CommuUart_USARTx_RX_PIN
#define Gprs_USARTx_RX_GPIO_PORT CommuUart_USARTx_RX_GPIO_PORT
#define Gprs_USARTx_RX_GPIO_CLK CommuUart_USARTx_RX_GPIO_CLK
#define GprsPowerCtrl_PIN GPIO_Pin_1
#define GprsPowerCtrl_PORT GPIOE
#define GprsPowerCtrl_RCC RCC_APB2Periph_GPIOE
typedef enum
{
eSelfCtrl_None = 0,
eSelfCtrl_CloseSckt,
eSelfCtrl_ShutPpp,
eSelfCtrl_Error,
}EnumGprsSelfCtrl;
typedef union
{
u32 Mux;
struct
{
u32 NoMod : 1;
u32 NoDrv : 1;
u32 NoSim : 1;
u32 NoReg : 1;
u32 NoAtt : 1;
u32 NoCop : 1;
u32 NoCon : 1;
}Bit;
}StructGprsError;
typedef struct
{
osMessageQId RecvQ;
osMessageQId SendQ;
}StructUartCtrl;
#define MaxSizeRespBuf (64)
#define MaxSizeSendBuf (1280)
typedef struct
{
u8 Sta;//0未使用 1已发送 2已应答
u8 Ack;//0未应答 1应答pResp_1 1应答pResp_2
char RespExBuf[MaxSizeRespBuf];//应答内容
char *pRespExFlag;//应答内容标志
char *pResp_1;
char *pResp_2;
}StructGprsCmd;
typedef enum
{
eSendCtrl_None = 0,
eSendCtrl_SendReq,
eSendCtrl_Sending,
eSendCtrl_SendDone,
eSendCtrl_SendErr,
}EnumGprsSendCtrl;
typedef struct
{
EnumGprsSendCtrl Ctrl;
u8 ScktNum;
u8 Buf[MaxSizeSendBuf];
u16 BufLen;
osMutexId Mutex;
}StructSend;
typedef struct
{
u8 ErrCnt;
u8 Status;
u32 StatusTick;
// u32 SelCtrlTick;
}StructGprsProc;
typedef void(*pGprsSendHandle)(void);
typedef void(*pGprsRecvHandle)(void);
typedef u8(*pGprsNetAvail)(void);
typedef struct
{
char *pModName;
pGprsSendHandle SendHandle;
pGprsRecvHandle RecvHandle;
pGprsNetAvail NetAvail;
}StructGprsDrv;
typedef struct
{
u8 Csq;
u8 MainScktNum;
EnumGprsSelfCtrl SelCtrl;
u8 Ccid[20];
StructGprsError Err;
StructUartCtrl Uart;
StructGprsCmd Cmd;
StructGprsProc Proc;
StructSend Send;
osMessageQId AppRecvQ;
StructGprsDrv *pGprsDrv;
}StructGprsSta;
typedef void(*pGprsProcHandle)(void);
extern StructGprsSta Gprs;
extern u8 GprsModSendByte(u8 Data);
extern int GprsModPrintf(char *Fmt, ...);
extern int GprsModSendCmd(char *pRespEx, char *Fmt, ...);
extern u8 GprsModWaitAck(u32 Ms);
extern u8 GprsInit(osMessageQId AppRecvQ);
extern u8 GprsNetAvail(void);
extern int GprsTcpSend(u8 *pData, u16 Len);
extern void GprsTcpClose(void);
#endif
#ifndef __DRV_IMDJYC_H__
#define __DRV_IMDJYC_H__
#include "Global.h"
#define Imd_USARTx_BaudRate (9600)
#define Imd_USARTx USART2
#define Imd_USARTx_CLK RCC_APB1Periph_USART2
#define Imd_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define Imd_USARTx_IRQn USART2_IRQn
#define Imd_USARTx_IRQHandler USART2_IRQHandler
#define Imd_USARTx_TX_PIN GPIO_Pin_5
#define Imd_USARTx_TX_GPIO_PORT GPIOD
#define Imd_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Imd_USARTx_TX_SOURCE GPIO_PinSource5
#define Imd_USARTx_TX_AF GPIO_AF_USART2
#define Imd_USARTx_RX_PIN GPIO_Pin_6
#define Imd_USARTx_RX_GPIO_PORT GPIOD
#define Imd_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Imd_USARTx_RX_SOURCE GPIO_PinSource6
#define Imd_USARTx_RX_AF GPIO_AF_USART2
#define Imd_RxTxEn_PIN GPIO_Pin_7
#define Imd_RxTxEn_GPIO_PORT GPIOD
#define Imd_RxTxEn_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ImdRtuAddr (0x01)
#define ImdRtuAddr_B (0x02)
typedef struct
{
u8 Vaild;
u8 PositWarn;
u8 NegatWarn;
u16 PositVolt;
u16 NegatVolt;
u16 PnVolt;
u16 PositResist;
u16 NegatResist;
}StructImdValue;
extern StructImdValue ImdValue;
extern StructImdValue ImdValue_B;
extern u8 ImdInit(void);
extern int ImdRead(StructImdValue *pImdValue);
extern int ImdWrite(u16 Addr, u16 Value);
extern int ImdAddrSet(u8 addr, u8 changeaddr);
extern int ImdRead_B(StructImdValue *pImdValue);
extern int ImdWrite_B(u16 Addr, u16 Value);
#endif
#ifndef __DRV_INTERNET_H__
#define __DRV_INTERNET_H__
#include "Global.h"
#include "Thd_Charge.h"
#include "Memory.h"
#define __ProtocolVer__ (0x0104)
#define __PillarType__ (0x03)//((0 == UserParam.ChgFun.Value.Num_B)?0x02:0x03)//(0x03)//0.交流单枪 0x00 1.交流双枪 0x01 2. 直流单枪 0x02 3. 直流双枪 0x03
typedef enum
{
eCmd_cSendPillarSignIn = 0xA1,//主动签到
eCmd_sAckPillarSignIn = 0xA2,//主动签到应答
eCmd_cSendHeartBeat = 0x51,//远端心跳包
eCmd_sAckHeartBeat = 0x52,//远端心跳包应答
eCmd_cSendPillarStatus = 0x40,//充电桩状态信息包上报
eCmd_sAckPillarStatus = 0x41,//服务器应答充电桩状态信息包
eCmd_cSendCardSure = 0x75,//桩上传刷卡请求数据
eCmd_sAckCardSure = 0x76,//桩上传刷卡请求数据应答
eCmd_cSendChgRecord = 0x54,//充电结束数据上传
eCmd_sAckChgRecord = 0x55,//充电结束数据上传应答
eCmd_cSendAwaitChgRecd = 0x42,//充电结束数据上传
eCmd_sAckAwaitChgRecd = 0x43,//充电结束数据上传应答
eCmd_cSendStartTransaction= 0x11,//启动充电上传
eCmd_sAckStartTransaction = 0x56,//充电结束数据上传应答
eCmd_cSendStopTransaction = 0x13,//停止充电上传
eCmd_sAckStopTransaction = 0x57,//停止充电上传应答
eCmd_cSendCancelReserve = 0x17,//取消预约上传
eCmd_sAckCancelReserve = 0x58,//取消预约上传应答
eCmd_cSendPillarSignOut = 0xA3,//主动退出登录
eCmd_sAckPillarSignOut = 0xA4,//主动退出登录应答
eCmd_sReqStartTransaction = 0x10,//远程启动充电
eCmd_cAckStartTransaction = 0x20,//远程启动充电应答
eCmd_sReqStopTransaction = 0x12,//远程停止充电
eCmd_cAckStopTransaction = 0x21,//远程停止充电应答
eCmd_sReqReserveNow = 0x14,//预约请求
eCmd_cAckReserveNow = 0x15,//预约请求应答
eCmd_sReqCancelReserve = 0x16,//取消预约
eCmd_cAckCancelReserve = 0x17,//取消预约应答
eCmd_sReqTimeSyn = 0x34,//时间同步
eCmd_cAckTimeSyn = 0x35,//时间同步应答
eCmd_sReqPillarReset = 0x18,//服务器下发重启指令
eCmd_cAckPillarReset = 0x19,//服务器下发重启指令应答
eCmd_sReqGetServerIp = 0x30,//服务器下发查询硬件服务器IP
eCmd_cAckGetServerIp = 0x31,//服务器下发查询硬件服务器IP应答
eCmd_sReqSetServerIp = 0x32,//服务器下发设置硬件服务器IP
eCmd_cAckSetServerIp = 0x33,//服务器下发设置硬件服务器IP应答
eCmd_sReqGetRate = 0x36,//服务器下发查询费率
eCmd_cAckGetRate = 0x37,//服务器下发查询费率应答
eCmd_sReqSetRate = 0x38,//服务器下发设置费率
eCmd_cAckSetRate = 0x39,//服务器下发设置费率应答
eCmd_sReqSetQrcode = 0x77,//服务器下发设置运营二维码
eCmd_cAckSetQrcode = 0x78,//服务器下发设置运营二维码应答
eCmd_cReqSetMoneyKey = 0x92,//服务器下发设置密匙
eCmd_cAckSetMoneyKey = 0x93,//服务器下发设置密匙应答
eCmd_sReqReadyToUpdate = 0x80,//服务器下发擦除准备升级指令
eCmd_cAckReadyToUpdate = 0x81,//服务器下发擦除准备升级指令应答
eCmd_sReqFileInformation = 0x82,//服务器下发升级文件名及大小信息指令
eCmd_cAckFileInformation = 0x83,//服务器下发升级文件名及大小信息指令应答
eCmd_sSendPackData = 0x84,//服务器下发升级文件数据指令
eCmd_cAckPackData = 0x85,//服务器下发升级文件数据指令应答
eCmd_sSendFileEnd = 0x86,//服务器下发升级文件数据结束指令
eCmd_cAckFileEnd = 0x87,//服务器下发升级文件数据结束指令应答
eCmd_sReqUpdateFinish = 0x88,//服务器下发完成指令
eCmd_cAckUpdateFinish = 0x89,//服务器下发完成指令应答
//FTP升级
eCmd_FtpUpgrade = 0x8A,//下达中心下发升级服务器信息命令
eCmd_FtpUpgradeAck = 0x8B,//设备对中心服务器信息命令应答
eCmd_cSendBatInfor = 0x1B,//服务器下发完成指令应答
}EnumInternetCmd;
//下游设备状态定义
typedef enum
{
eEventCode_None = 0x00,//空事件
eEventCode_PowerOn = 0x01,//开机上电 0x01 外部220V 电源给控制板上电
eEventCode_ShutDown = 0x02,//关机 0x02 220V 外部电源断开
eEventCode_SelTest = 0x03,//自检 0x03 完成充电机自检
eEventCode_WipeCard = 0x04,//刷卡 0x04 有刷卡
eEventCode_ChgStart = 0x05,//充电开始 0x05 充电机输出功率从无变为有
eEventCode_ChgStop = 0x06,//充电结束 0x06 充电机输出功率从有变为无
eEventCode_Repair = 0x07,//检修 0x07 充电机从正常(故障)工作态转为检修状态
eEventCode_UpDate = 0x08,//升级 0x08 充电机完成升级操作
eEventCode_SetParam = 0x09,//参数配置 0x09 充电机工作配置参数通过外部指令进行了调整
eEventCode_OldRecdSend= 0x0A,//数据补传 0x0A 充电机将存储在本地的未来得及上传给后台的数据启动传输给后台
eEventCode_DelRecord = 0x0B,//删除历史数据 0x0B 充电机将存储在本地的数据进行了删除操作(不含覆盖操作)
eEventCode_GetRecord = 0x0C,//历史数据导出 0x0C 充电机通过外部存储器将存储在本地的数据进行了导出
}EnumEventCode;
typedef struct
{
u8 (*pNetInit)(osMessageQId AppRecvQ);
u8 (*pNetAvail)(void);
void (*pNetClose)(void);
int (*pNetSend)(u8 *pData, u16 Len);
}StructNetDrv;
extern StructNetDrv *pNetDrv;
extern u8 InternetInit(void);
extern u8 InternetFrameRecv(u8 *pFrame);
extern u8 NetAvail(void);
extern void NetClose(void);
//(0x10) 中心系统查询签到上报
extern int SendPillarSignIn(u8 ChgNum);
//(0x58) 远端心跳包信息上报
extern int SendHeartBeat(u8 ChgNum);
extern int SendPillarStatus(u8 ChgNum);
//(0x78)充电桩智能终端上报充电记录命令
extern int SendChgRecord(u8 ChgNum);
//充电记录补传
extern int SendAwaitChgRecd(StructAwaitChgRecdLog *pChgLog);
//(0x42) 充电桩智能终端时间同步
extern int AckStartTransaction(u8 *pFrame, u32 Resp);
//(0x42) 充电桩智能终端时间同步
extern int AckStopTransaction(u8 *pFrame, u32 Resp);
//(0x42) 充电桩智能终端时间同步
extern int AckReserveNow(u8 *pFrame, u32 Resp);
extern int AckCancelReserve(u8 *pFrame, u32 Resp);
//(0x42) 充电桩智能终端时间同步
extern int AckPillarTimeSet(u8 *pFrame, u32 Resp);
extern int AckSetQrcode(u8 *pFrame);
extern int AckPillarReset(u8 *pFrame);
//(0x42) 充电桩智能终端时间同步
extern int SendStartTransaction(u8 ChgNum);
extern int SendStopTransaction(u8 ChgNum);
extern int SendCancelReserve(u8 ChgNum);
extern int SendPillarSignOut(void);
extern int AckGetServerIp(u8 *pFrame);
extern int AckSetServerIp(u8 *pFrame, u32 Resp);
extern int AckGetRate(u8 *pFrame);
extern int AckSetRate(u8 *pFrame, u32 Resp);
//刷卡数据上传认证
extern int SendCardSure(u8 ChgNum);
extern int AckSetMoneyKey(u8 *pFrame, u32 Resp);
extern int SendBatInfor(u8 ChgNum);
extern void FtpUpgradeAck(u8 *pFrame, u8 state);
#endif
#ifndef __DRV_LCD_H__
#define __DRV_LCD_H__
#include "Global.h"
#define LCD_USARTx_BaudRate (9600)
#define LCD_USARTx USART6
#define LCD_USARTx_CLK RCC_APB2Periph_USART6
#define LCD_USARTx_CLK_INIT RCC_APB2PeriphClockCmd
#define LCD_USARTx_IRQn USART6_IRQn
#define LCD_USARTx_IRQHandler USART6_IRQHandler
#define LCD_USARTx_TX_PIN GPIO_Pin_6
#define LCD_USARTx_TX_GPIO_PORT GPIOC
#define LCD_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOC
#define LCD_USARTx_TX_SOURCE GPIO_PinSource6
#define LCD_USARTx_TX_AF GPIO_AF_USART6
#define LCD_USARTx_RX_PIN GPIO_Pin_7
#define LCD_USARTx_RX_GPIO_PORT GPIOC
#define LCD_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOC
#define LCD_USARTx_RX_SOURCE GPIO_PinSource7
#define LCD_USARTx_RX_AF GPIO_AF_USART6
#define LcdFrameHeadH (0xAA)
#define LcdFrameHeadL (0xCC)
typedef enum
{
eLcdCmd_WrReg = 0x80,
eLcdCmd_RdReg = 0x81,
eLcdCmd_WrVar = 0x82,
eLcdCmd_RdVar = 0x83,
eLcdCmd_WrCurve = 0x84,
}EnumLcdCmd;
typedef enum
{
eLcdRegAddr_Backlight = 0x01,
eLcdRegAddr_Buzzer = 0x02,
eLcdRegAddr_Page = 0x03,
eLcdRegAddr_Rtc = 0x20,
eLcdRegAddr_TouchCor = 0xEA,
eLcdRegAddr_Reset = 0xEE,
}EnumRegAddr;
#pragma pack(1)
typedef struct
{
u8 HeadH; //帧头高字节
u8 HeadL; //帧头低字节
u8 FrameLen; //帧长
u8 FrameCmd; //帧命令
union //控制结构
{
struct
{
u8 Addr; //地址
u8 Data[64];//数据
}WrReg;//写寄存器
struct
{
u8 Addr; //地址
u8 Len; //读数据长度
u8 Data[64];//数据
}RdReg;//读寄存器
struct
{
u8 AddrH; //地址高
u8 AddrL; //地址低
u8 Data[64];//数据
}WrVar;//读变量
struct
{
u8 AddrH; //地址高
u8 AddrL; //地址低
u8 Len; //读数据长度,单位为word
u8 Data[64];
}RdVar;//读变量
u8 FrameData[64];
}Ctrl;
}StructLcdDwinFrame;
#pragma pack()
extern u8 LcdInit(void);
/******************************************************************
*名 称: LcdFrameRecv
*功 能 获取串口接收队列(FIFO)中一个完整的帧
*入口参数: 无
*出口参数: 无
********************************************************************/
extern u8 LcdFrameRecv(StructLcdDwinFrame *pFrame);
/******************************************************************************
函数 : LcdWriteReg
描述 : Lcd写寄存器
参数 : Addr - 写启起地址
pData - 发送的数据指针
Len - 发送的数据长度
返回 : 无
******************************************************************************/
extern void LcdWriteReg(u8 Addr, u8 *pData, u8 Len);
/******************************************************************************
函数 : LcdReadReg
描述 : Lcd读寄存器,读长度不能超过64,受限于头文件定义的帧解析结构体
参数 : Addr - 读启起地址
Len - 读数据长度
返回 : 无
******************************************************************************/
extern void LcdReadReg(u8 Addr, u8 Len);
/******************************************************************************
函数 : LcdWriteReg
描述 : Lcd写寄存器
参数 : Addr - 写启起地址
pData - 发送的数据指针
Len - 发送的数据长度
返回 : 无
******************************************************************************/
extern void LcdWriteVar(u16 Addr, u8 *pData, u8 Len);
/******************************************************************************
函数 : LcdReadVar
描述 : Lcd读变量,读长度不能超过32,受限于头文件定义的帧解析结构体
参数 : Addr - 读启起地址
Len - 读数据长度(Len,是按Word计算)
返回 : 无
******************************************************************************/
extern void LcdReadVar(u16 Addr, u8 Len);
/******************************************************************************
函数 : LcdShowPage
描述 : Lcd显示某页面
参数 : Page - 页面标号
返回 : 无
******************************************************************************/
extern void LcdShowPage(u16 Page);
/******************************************************************************
函数 : LcdGetPage
描述 : Lcd显示某页面
参数 : Page - 页面标号
返回 : 无
******************************************************************************/
void LcdGetPage(void);
/******************************************************************************
函数 : LcdShowNum
描述 : Lcd显示数值
参数 : Addr - 显示位置
Page - 页面标号
返回 : 无
******************************************************************************/
extern void LcdShowNum(u16 Addr, u16 Num);
/******************************************************************************
函数 : LcdShowStr
描述 : Lcd显示数值
参数 : Addr - 显示位置
pStr - 显示字符串
Len - 字符串长度
返回 : 无
******************************************************************************/
extern void LcdShowStr(u16 Addr, u8 *pStr, u8 Len);
/******************************************************************************
函数 : LcdSetRtc
描述 : Lcd显示数值
参数 : pTime - 时间
返回 : 无
******************************************************************************/
extern void LcdSetRtc(StructTime *pTime);
/******************************************************************************
函数 : LcdGetPage
描述 : Lcd显示某页面
参数 : Page - 页面标号
返回 : 无
******************************************************************************/
void LcdGetRtc(void);
/******************************************************************************
函数 : LcdSetBackLight
描述 : Lcd显示数值
参数 : Addr - 显示位置
pStr - 显示字符串
Len - 字符串长度
返回 : 无
******************************************************************************/
extern void LcdSetBackLight(u8 Level);
/******************************************************************************
函数 : LcdBuzzer
描述 : Lcd蜂鸣器
参数 : Ms - 响时间 10*Ms
返回 : 无
******************************************************************************/
extern void LcdBuzzer(u8 Ms);
/******************************************************************************
函数 : LcdTouchCorrect
描述 : Lcd触摸校正
参数 : 无
返回 : 无
******************************************************************************/
extern void LcdTouchCorrect(void);
/******************************************************************************
函数 : LcdReset
描述 : Lcd复位重启
参数 : 无
返回 : 无
******************************************************************************/
extern void LcdReset(void);
/******************************************************************************
函数 : LcdShowData16
描述 : Lcd显示数值
参数 : Addr - 显示位置
Page - 页面标号
返回 : 无
******************************************************************************/
extern void LcdShowData16(u16 Addr, u16 Data16);
/******************************************************************************
函数 : LcdShowData32
描述 : Lcd显示数值
参数 : Addr - 显示位置
Page - 页面标号
返回 : 无
******************************************************************************/
extern void LcdShowData32(u16 Addr, u32 Data32);
#endif
/******************************************************************************
文件 : Drv_Led.c
描述 : Led显示驱动
作者 :
修改 : 2015-03-25 郭涛 建立
******************************************************************************/
#include "Drv_Led.h"
/******************************************************************************
函数 : LedInit
描述 : Led控制初始化
参数 : 无
返回 : 无
******************************************************************************/
void LedInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* GPIO clock enable */
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Ready_PIN;
RCC_APB2PeriphClockCmd(Led_Ready_GPIO_CLK, ENABLE);
GPIO_Init(Led_Ready_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Ready_GPIO_PORT, Led_Ready_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Charge_PIN;
RCC_APB2PeriphClockCmd(Led_Charge_GPIO_CLK, ENABLE);
GPIO_Init(Led_Charge_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Charge_GPIO_PORT, Led_Charge_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Fault_1_PIN;
RCC_APB2PeriphClockCmd(Led_Fault_1_GPIO_CLK, ENABLE);
GPIO_Init(Led_Fault_1_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Fault_1_GPIO_PORT, Led_Fault_1_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Fault_2_PIN;
RCC_APB2PeriphClockCmd(Led_Fault_2_GPIO_CLK, ENABLE);
GPIO_Init(Led_Fault_2_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Fault_2_GPIO_PORT, Led_Fault_2_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Fault_3_PIN;
RCC_APB2PeriphClockCmd(Led_Fault_3_GPIO_CLK, ENABLE);
GPIO_Init(Led_Fault_3_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Fault_3_GPIO_PORT, Led_Fault_3_PIN);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Pin = Led_Fault_4_PIN;
RCC_APB2PeriphClockCmd(Led_Fault_4_GPIO_CLK, ENABLE);
GPIO_Init(Led_Fault_4_GPIO_PORT, &GPIO_InitStructure);
GPIO_SetBits(Led_Fault_4_GPIO_PORT, Led_Fault_4_PIN);
}
#ifndef __DRV_LED_H__
#define __DRV_LED_H__
#include "Global.h"
//#ifdef __FourLed__
#define Led_Ready_PIN GPIO_Pin_7//E1//E0
#define Led_Ready_GPIO_PORT GPIOE
#define Led_Ready_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Charge_PIN GPIO_Pin_8//E0//B9
#define Led_Charge_GPIO_PORT GPIOE
#define Led_Charge_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Fault_1_PIN GPIO_Pin_9//B9//E1
#define Led_Fault_1_GPIO_PORT GPIOE
#define Led_Fault_1_GPIO_CLK RCC_APB2Periph_GPIOE
/*#else
#define Led_Ready_PIN GPIO_Pin_1//E1//E0
#define Led_Ready_GPIO_PORT GPIOE
#define Led_Ready_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Charge_PIN GPIO_Pin_0//E0//B9
#define Led_Charge_GPIO_PORT GPIOE
#define Led_Charge_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Fault_1_PIN GPIO_Pin_9//B9//E1
#define Led_Fault_1_GPIO_PORT GPIOB
#define Led_Fault_1_GPIO_CLK RCC_APB2Periph_GPIOB
#endif
*/
#define Led_Fault_2_PIN GPIO_Pin_10
#define Led_Fault_2_GPIO_PORT GPIOE
#define Led_Fault_2_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Fault_3_PIN GPIO_Pin_11
#define Led_Fault_3_GPIO_PORT GPIOE
#define Led_Fault_3_GPIO_CLK RCC_APB2Periph_GPIOE
#define Led_Fault_4_PIN GPIO_Pin_12
#define Led_Fault_4_GPIO_PORT GPIOE
#define Led_Fault_4_GPIO_CLK RCC_APB2Periph_GPIOE
#define LedReadyOff() GPIO_ResetBits(Led_Ready_GPIO_PORT, Led_Ready_PIN)
#define LedReadyOn() GPIO_SetBits(Led_Ready_GPIO_PORT, Led_Ready_PIN)
#define LedChargeOff() GPIO_ResetBits(Led_Charge_GPIO_PORT, Led_Charge_PIN)
#define LedChargeOn() GPIO_SetBits(Led_Charge_GPIO_PORT, Led_Charge_PIN)
#define LedFault_1_Off() GPIO_ResetBits(Led_Fault_1_GPIO_PORT, Led_Fault_1_PIN)
#define LedFault_1_On() GPIO_SetBits(Led_Fault_1_GPIO_PORT, Led_Fault_1_PIN)
#define LedFault_2_Off() GPIO_ResetBits(Led_Fault_2_GPIO_PORT, Led_Fault_2_PIN)
#define LedFault_2_On() GPIO_SetBits(Led_Fault_2_GPIO_PORT, Led_Fault_2_PIN)
#define LedFault_3_On() GPIO_ResetBits(Led_Fault_3_GPIO_PORT, Led_Fault_3_PIN)
#define LedFault_3_Off() GPIO_SetBits(Led_Fault_3_GPIO_PORT, Led_Fault_3_PIN)
#define LedFault_4_On() GPIO_ResetBits(Led_Fault_4_GPIO_PORT, Led_Fault_4_PIN)
#define LedFault_4_Off() GPIO_SetBits(Led_Fault_4_GPIO_PORT, Led_Fault_4_PIN)
#define LedErrorOn() LedFault_1_On()
#define LedErrorOff() LedFault_1_Off()
#define NetLedOn() LedFault_2_On()
#define NetLedOff() LedFault_2_Off()
extern void LedInit(void);
#endif
#ifndef __DRV_METER_H__
#define __DRV_METER_H__
#include "Global.h"
//#include "Drv_RctF1xx.h"
#define Meter_USARTx_BaudRate (2400)
#define MeterRecvTimeOut (500)
#define MeterRate (1)//(1)//(2)//(20)
#if 0
#define Meter_A_USARTx UART4
#define Meter_A_USARTx_CLK RCC_APB1Periph_UART4
#define Meter_A_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define Meter_A_USARTx_IRQn UART4_IRQn
#define Meter_A_USARTx_IRQHandler UART4_IRQHandler
#define Meter_A_USARTx_TX_PIN GPIO_Pin_10
#define Meter_A_USARTx_TX_GPIO_PORT GPIOC
#define Meter_A_USARTx_TX_GPIO_CLK RCC_APB2Periph_GPIOC
#define Meter_A_USARTx_RX_PIN GPIO_Pin_11
#define Meter_A_USARTx_RX_GPIO_PORT GPIOC
#define Meter_A_USARTx_RX_GPIO_CLK RCC_APB2Periph_GPIOC
#define Meter_A_RxTxEn_PIN GPIO_Pin_4
#define Meter_A_RxTxEn_GPIO_PORT GPIOD
#define Meter_A_RxTxEn_GPIO_CLK RCC_APB2Periph_GPIOD
#define Meter_B_USARTx UART5
#define Meter_B_USARTx_CLK RCC_APB1Periph_UART5
#define Meter_B_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define Meter_B_USARTx_IRQn UART5_IRQn
#define Meter_B_USARTx_IRQHandler UART5_IRQHandler
#define Meter_B_USARTx_TX_PIN GPIO_Pin_12
#define Meter_B_USARTx_TX_GPIO_PORT GPIOC
#define Meter_B_USARTx_TX_GPIO_CLK RCC_APB2Periph_GPIOC
#define Meter_B_USARTx_RX_PIN GPIO_Pin_2
#define Meter_B_USARTx_RX_GPIO_PORT GPIOD
#define Meter_B_USARTx_RX_GPIO_CLK RCC_APB2Periph_GPIOD
#define Meter_B_RxTxEn_PIN GPIO_Pin_3
#define Meter_B_RxTxEn_GPIO_PORT GPIOD
#define Meter_B_RxTxEn_GPIO_CLK RCC_APB2Periph_GPIOD
#else
#define Meter_A_USARTx USART1
#define Meter_A_USARTx_CLK RCC_APB2Periph_USART1
#define Meter_A_USARTx_CLK_INIT RCC_APB2PeriphClockCmd
#define Meter_A_USARTx_IRQn USART1_IRQn
#define Meter_A_USARTx_IRQHandler USART1_IRQHandler
#define Meter_A_USARTx_TX_PIN GPIO_Pin_9
#define Meter_A_USARTx_TX_GPIO_PORT GPIOA
#define Meter_A_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOA
#define Meter_A_USARTx_TX_SOURCE GPIO_PinSource9
#define Meter_A_USARTx_TX_AF GPIO_AF_USART1
#define Meter_A_USARTx_RX_PIN GPIO_Pin_10
#define Meter_A_USARTx_RX_GPIO_PORT GPIOA
#define Meter_A_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOA
#define Meter_A_USARTx_RX_SOURCE GPIO_PinSource10
#define Meter_A_USARTx_RX_AF GPIO_AF_USART1
#define Meter_A_RxTxEn_PIN GPIO_Pin_8
#define Meter_A_RxTxEn_GPIO_PORT GPIOA
#define Meter_A_RxTxEn_GPIO_CLK RCC_AHB1Periph_GPIOA
#define Meter_B_USARTx USART2
#define Meter_B_USARTx_CLK RCC_APB1Periph_USART2
#define Meter_B_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define Meter_B_USARTx_IRQn USART2_IRQn
//#define Meter_B_USARTx_IRQHandler USART2_IRQHandler
#define Meter_B_USARTx_TX_PIN GPIO_Pin_5
#define Meter_B_USARTx_TX_GPIO_PORT GPIOD
#define Meter_B_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Meter_B_USARTx_TX_SOURCE GPIO_PinSource5
#define Meter_B_USARTx_TX_AF GPIO_AF_USART2
#define Meter_B_USARTx_RX_PIN GPIO_Pin_6
#define Meter_B_USARTx_RX_GPIO_PORT GPIOD
#define Meter_B_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define Meter_B_USARTx_RX_SOURCE GPIO_PinSource6
#define Meter_B_USARTx_RX_AF GPIO_AF_USART2
#define Meter_B_RxTxEn_PIN GPIO_Pin_7
#define Meter_B_RxTxEn_GPIO_PORT GPIOD
#define Meter_B_RxTxEn_GPIO_CLK RCC_AHB1Periph_GPIOD
#endif
typedef enum
{
eMeterSta_Unavail = 0,
eMeterSta_Avail
}EnumMeterStatus;
#define MaxMeterFrameLen (64)
typedef struct
{
EnumMeterStatus Status;
EnumMeterStatus Status_B;
EnumMeterStatus Status_AC;
u8 Addr[6];
u8 Addr_B[6];
u8 Addr_AC[6];
u8 SendLen;
u8 SendPost;
u8 SendData[MaxMeterFrameLen];
osMessageQId RecvMsg;
}StructMeterComm;
typedef struct
{
u8 Head;
u8 Addr[6];
u8 ReHead;
u8 Ctrl;
u8 Len;
u8 Data[MaxMeterFrameLen];
u8 CS;
u8 End;
}StructMeterFrame;
typedef struct
{
s32 All;
s32 Sharp;
s32 Peak;
s32 Flat;
s32 Valley;
}StructEnergy;
typedef struct
{
u32 PhaseA;
u32 PhaseB;
u32 PhaseC;
}StructVoltage;
typedef struct
{
s32 PhaseA;
s32 PhaseB;
s32 PhaseC;
}StructCurrent;
typedef enum
{
eMeter_Sum_A_Energy = 0x00000000,//组合有功总电能
eMeter_Sum_R1_Energy = 0x00000100,//组合有功费率1电能
eMeter_Sum_R2_Energy = 0x00000200,//组合有功费率2电能
eMeter_Sum_R3_Energy = 0x00000300,//组合有功费率3电能
eMeter_Sum_R4_Energy = 0x00000400,//组合有功费率4电能
eMeter_Sum_Block_Energy = 0x0000FF00,//组合有功费率电能块
eMeter_P_A_Energy = 0x00010000,//正向有功总电能
eMeter_P_R1_Energy = 0x00010100,//正向有功费率1电能
eMeter_P_R2_Energy = 0x00010200,//正向有功费率2电能
eMeter_P_R3_Energy = 0x00010300,//正向有功费率3电能
eMeter_P_R4_Energy = 0x00010400,//正向有功费率4电能
eMeter_P_Block_Energy = 0x0010FF00,//正向有功费率电能块
eMeter_Voltage_A = 0x02010100,//A相电压
eMeter_Voltage_B = 0x02010200,//B相电压
eMeter_Voltage_C = 0x02010300,//C相电压
eMeter_Voltage = 0x0201FF00,//电压数据块
eMeter_Current_A = 0x02020100,//A相电流
eMeter_Current_B = 0x02020200,//B相电流
eMeter_Current_C = 0x02020300,//C相电流
eMeter_Current = 0x0202FF00,//电流数据块
eMeter_Power = 0x02030000,//瞬时总有功功率
eMeter_Power_A = 0x02030100,//瞬时A相有功功率
eMeter_NegPower_A = 0x02040100,//瞬时A相无功功率
eMeter_PowerFac = 0x02060000,//总功率因数
eMeter_PowerFac_A = 0x02060100,//A相功率因数
eMeter_PowerHz_A = 0x02800002,//A相功率因数
}EnumMeterCmd;
typedef struct
{
s32 Energy;//0.01Kwh/bit
s32 Sharp;//0.01Kwh/bit
s32 Peak;//0.01Kwh/bit
s32 Flat;//0.01Kwh/bit
s32 Valley;//0.01Kwh/bit
u32 Voltage;//0.1V/bit
s32 Current;//0.001A/bit
u32 VoltageA;// A 电压
u32 VoltageB;
u32 VoltageC;
//s32 CurrentA;// A 电流
//s32 CurrentB;
//s32 CurrentC;
s32 Power;//0.0001Kw/bit
s32 PowerFac;//0.001/bit
s32 Freq;//0.01Hz/bit
}StructMeterValue;
extern StructMeterComm MeterComm;
extern StructMeterValue MeterValue;
extern StructMeterValue MeterValue_B;
extern StructMeterValue MeterValue_AC;
extern u8 MeterInit(void);
extern u8 MeterGetAddr(void);
extern u8 MeterGetEnergy(u32 Type, s32 *pEnergy);
extern u8 MeterGetVoltage(u32 Type, u32 *pVoltage);
extern u8 MeterGetCurrent(u32 Type, s32 *pCurrent);
extern u8 MeterGetEnergyBlock(u32 Type, StructEnergy *pEnergy);
extern u8 MeterGetVoltageBlock(StructVoltage *pVoltage);
extern u8 MeterGetCurrentBlock(StructCurrent *pCurrent);
extern u8 MeterGetPower(u32 Type, s32 *pValue);
extern u8 MeterGetPowerFac(u32 Type, s32 *pValue);
extern u8 MeterGetPositiveEnergy(u32 Type, u32 *pEnergy);
extern u8 MeterGetEnergy_B(u32 Type, s32 *pEnergy);
extern u8 MeterGetVoltage_B(u32 Type, u32 *pVoltage);
extern u8 MeterGetCurrent_B(u32 Type, s32 *pCurrent);
extern u8 MeterGetEnergyBlock_B(u32 Type, StructEnergy *pEnergy);
extern u8 MeterGetVoltageBlock_B(StructVoltage *pVoltage);
extern u8 MeterGetCurrentBlock_B(StructCurrent *pCurrent);
extern u8 MeterGetPower_B(u32 Type, s32 *pValue);
extern u8 MeterGetPowerFac_B(u32 Type, s32 *pValue);
extern u8 MeterGetPositiveEnergy_B(u32 Type, u32 *pEnergy);
#if 0
extern u8 MeterInit_B(void);
extern u8 MeterGetAddr_B(void);
extern u8 MeterGetEnergy_B(u32 Type, s32 *pEnergy);
extern u8 MeterGetVoltage_B(u32 Type, u32 *pVoltage);
extern u8 MeterGetCurrent_B(u32 Type, s32 *pCurrent);
extern u8 MeterGetEnergyBlock_B(u32 Type, StructEnergy *pEnergy);
extern u8 MeterGetVoltageBlock_B(StructVoltage *pVoltage);
extern u8 MeterGetCurrentBlock_B(StructCurrent *pCurrent);
extern u8 MeterGetPower_B(u32 Type, s32 *pValue);
extern u8 MeterGetPowerFac_B(u32 Type, s32 *pValue);
#endif
#endif
#ifndef __DRV_READERACTR1_H__
#define __DRV_READERACTR1_H__
#include "Global.h"
#define ReaderActR1_USARTx_BaudRate (9600)
#define ReaderActR1_USARTx USART3
#define ReaderActR1_USARTx_CLK RCC_APB1Periph_USART3
#define ReaderActR1_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define ReaderActR1_USARTx_IRQn USART3_IRQn
#define ReaderActR1_USARTx_IRQHandler USART3_IRQHandler
#define ReaderActR1_USARTx_TX_PIN GPIO_Pin_8
#define ReaderActR1_USARTx_TX_GPIO_PORT GPIOD
#define ReaderActR1_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderActR1_USARTx_TX_SOURCE GPIO_PinSource8
#define ReaderActR1_USARTx_TX_AF GPIO_AF_USART3
#define ReaderActR1_USARTx_RX_PIN GPIO_Pin_9
#define ReaderActR1_USARTx_RX_GPIO_PORT GPIOD
#define ReaderActR1_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderActR1_USARTx_RX_SOURCE GPIO_PinSource9
#define ReaderActR1_USARTx_RX_AF GPIO_AF_USART3
typedef u8 (*pReaderActR1SendByte)(u8 Data);
extern u8 ReaderActR1_Init(osMessageQId RecvOsMsgQId, pReaderActR1SendByte pSendByte );
extern u8 ReaderActR1_Test(void);
extern int ReaderActR1_CardFind(u8 *pUID);
extern int ReaderActR1_IdCheck(u8* pID, u8 Section, u8 Key, u8 *pUid);
extern int ReaderActR1_BlockRead(u8 *pData, u8 Block);
extern int ReaderActR1_BlockWrite(u8 *pData, u8 Block);
#endif
#ifndef __DRV_READER_H__
#define __DRV_READER_H__
#include "Global.h"
#define ReaderPcb200_USARTx_BaudRate (57600)
#define ReaderPcb200_USARTx USART3
#define ReaderPcb200_USARTx_CLK RCC_APB1Periph_USART3
#define ReaderPcb200_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define ReaderPcb200_USARTx_IRQn USART3_IRQn
#define ReaderPcb200_USARTx_IRQHandler USART3_IRQHandler
#define ReaderPcb200_USARTx_TX_PIN GPIO_Pin_8
#define ReaderPcb200_USARTx_TX_GPIO_PORT GPIOD
#define ReaderPcb200_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderPcb200_USARTx_TX_SOURCE GPIO_PinSource8
#define ReaderPcb200_USARTx_TX_AF GPIO_AF_USART3
#define ReaderPcb200_USARTx_RX_PIN GPIO_Pin_9
#define ReaderPcb200_USARTx_RX_GPIO_PORT GPIOD
#define ReaderPcb200_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderPcb200_USARTx_RX_SOURCE GPIO_PinSource9
#define ReaderPcb200_USARTx_RX_AF GPIO_AF_USART3
typedef u8 (*pReaderPcb200SendByte)(u8 Data);
extern u8 ReaderPcb200_Init(osMessageQId RecvOsMsgQId, pReaderPcb200SendByte pSendByte);
extern u8 ReaderPcb200_Test(void);
extern int ReaderPcb200_CardFind(u8 *pUID);
extern int ReaderPcb200_IdCheck(u8* pID, u8 Section, u8 Key, u8 *pUid);
extern int ReaderPcb200_BlockRead(u8 *pData, u8 Block);
extern int ReaderPcb200_BlockWrite(u8 *pData, u8 Block);
#endif
#ifndef __DRV_READERZLG600A_H__
#define __DRV_READERZLG600A_H__
#include "Global.h"
#define ReaderZLG600A_USARTx_BaudRate (57600)
#define ReaderZLG600A_USARTx USART3
#define ReaderZLG600A_USARTx_CLK RCC_APB1Periph_USART3
#define ReaderZLG600A_USARTx_CLK_INIT RCC_APB1PeriphClockCmd
#define ReaderZLG600A_USARTx_IRQn USART3_IRQn
#define ReaderZLG600A_USARTx_IRQHandler USART3_IRQHandler
#define ReaderZLG600A_USARTx_TX_PIN GPIO_Pin_8
#define ReaderZLG600A_USARTx_TX_GPIO_PORT GPIOD
#define ReaderZLG600A_USARTx_TX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderZLG600A_USARTx_TX_SOURCE GPIO_PinSource8
#define ReaderZLG600A_USARTx_TX_AF GPIO_AF_USART3
#define ReaderZLG600A_USARTx_RX_PIN GPIO_Pin_9
#define ReaderZLG600A_USARTx_RX_GPIO_PORT GPIOD
#define ReaderZLG600A_USARTx_RX_GPIO_CLK RCC_AHB1Periph_GPIOD
#define ReaderZLG600A_USARTx_RX_SOURCE GPIO_PinSource9
#define ReaderZLG600A_USARTx_RX_AF GPIO_AF_USART3
typedef u8 (*pReaderZLG600ASendByte)(u8 Data);
extern u8 ReaderZLG600A_Init(osMessageQId RecvOsMsgQId, pReaderZLG600ASendByte pSendByte);
//extern u8 ReaderZLG600A_Test(void);
extern u8 ReaderZLG600A_Test(void);
extern int ReaderZLG600A_CardFind(u8 *pUID);
extern int ReaderZLG600A_IdCheck(u8* pID, u8 Section, u8 Key, u8 *pUid);
extern int ReaderZLG600A_BlockRead(u8 *pData, u8 Block);
extern int ReaderZLG600A_BlockWrite(u8 *pData, u8 Block);
#endif
/******************************************************************************
文件 : Drv_Rtc.c
描述 : STM32F4内置RTC驱动
作者 :
修改 : 2014-08-26 郭涛 建立
******************************************************************************/
#include "Drv_Rtc.h"
/******************************************************************************
函数 : RtcUpdateTime
描述 : RTC是否有更新时间
参数 : pStr - 输出时间格式,pStr长度必须大于等于16
返回 : 无
******************************************************************************/
void RtcGetTime(u8 *pStr)
{
RTC_TimeTypeDef RTC_TimeStructure ;
RTC_DateTypeDef RTC_DateStructure ;
/* Get the current Time and Date */
RTC_GetTime(RTC_Format_BCD,&RTC_TimeStructure);
RTC_GetDate(RTC_Format_BCD,&RTC_DateStructure);
/* Fill the table2 fields with the current Time*/
pStr[0]='2' ;
pStr[1]='0' ;
pStr[2]=(((u8)(RTC_DateStructure.RTC_Year&0xF0)>>0x04)+0x30);
pStr[3]=(((u8)(RTC_DateStructure.RTC_Year&0x0F))+0x30);
pStr[4]='-' ;
pStr[5]=(((u8)(RTC_DateStructure.RTC_Month&0xF0)>>0x04)+0x30);
pStr[6]=(((u8)(RTC_DateStructure.RTC_Month&0x0F))+0x30);
pStr[7]='-' ;
pStr[8]=(((u8)(RTC_DateStructure.RTC_Date&0xF0)>>0x04)+0x30);
pStr[9]=(((u8)(RTC_DateStructure.RTC_Date&0x0F))+0x30);
pStr[10]=' ' ;
pStr[11]=(((u8)(RTC_TimeStructure.RTC_Hours&0xF0)>>0x04)+0x30);
pStr[12]=(((u8)(RTC_TimeStructure.RTC_Hours&0x0F))+0x30);
pStr[13]=':' ;
pStr[14]=(((u8)(RTC_TimeStructure.RTC_Minutes&0xF0)>>0x04)+0x30);
pStr[15]=(((u8)(RTC_TimeStructure.RTC_Minutes&0x0F))+0x30);
pStr[16]='\0' ;
}
/******************************************************************************
函数 : RtcUpdateTime
描述 : RTC是否有更新时间
参数 : pStr - 输出时间格式,pStr长度必须大于等于16
返回 : TRUE - 有更新
FALSE - 无更新
******************************************************************************/
u8 RtcUpdateTime(u8 *pStr)
{
static u32 LastTime=0 ;
static u32 LastDate=0 ;
u32 CurTime=0 ;
u32 CurDate=0 ;
RTC_TimeTypeDef RTC_TimeStructure ;
RTC_DateTypeDef RTC_DateStructure ;
#if 0
/* Get the TimeStamp time and date registers values */
CurTime = (u32)(RTC->TR & 0x007F7F00);
//秒去掉
CurDate = (u32)(RTC->DR & 0x00FFFF3F);
#endif
if((LastTime == CurTime) && (LastDate == CurDate))
return FALSE ;
/* Get the current Time and Date */
RTC_GetTime(RTC_Format_BCD, &RTC_TimeStructure);
RTC_GetDate(RTC_Format_BCD, &RTC_DateStructure);
/* Fill the table2 fields with the current Time*/
pStr[0] = '2' ;
pStr[1] = '0' ;
pStr[2] = (((u8)(RTC_DateStructure.RTC_Year&0xF0)>>0x04)+0x30);
pStr[3] = (((u8)(RTC_DateStructure.RTC_Year&0x0F))+0x30);
pStr[4] = '-' ;
pStr[5] = (((u8)(RTC_DateStructure.RTC_Month&0xF0)>>0x04)+0x30);
pStr[6] = (((u8)(RTC_DateStructure.RTC_Month&0x0F))+0x30);
pStr[7] = '-' ;
pStr[8] = (((u8)(RTC_DateStructure.RTC_Date&0xF0)>>0x04)+0x30);
pStr[9] = (((u8)(RTC_DateStructure.RTC_Date&0x0F))+0x30);
pStr[10] = ' ' ;
pStr[11] = (((u8)(RTC_TimeStructure.RTC_Hours&0xF0)>>0x04)+0x30);
pStr[12] = (((u8)(RTC_TimeStructure.RTC_Hours&0x0F))+0x30);
pStr[13] = ':' ;
pStr[14] = (((u8)(RTC_TimeStructure.RTC_Minutes&0xF0)>>0x04)+0x30);
pStr[15] = (((u8)(RTC_TimeStructure.RTC_Minutes&0x0F))+0x30);
pStr[16] = '\0' ;
LastTime=CurTime ;
LastDate=CurDate ;
return TRUE ;
}
/******************************************************************************
函数 : DateTimeInit
描述 : 时间日期初始化。
参数 : 无
返回 : 无
******************************************************************************/
void DateTimeInit(void)
{
#if 0
RTC_TimeTypeDef RTC_TimeStructure;
RTC_DateTypeDef RTC_DateStructure;
u32 Temp;
Temp = RTC_ReadBackupRegister(RTC_BKP_DR1);
if(0x32F2 == Temp)
return;
/* Set Time hh:mm:ss */
RTC_TimeStructure.RTC_H12 = RTC_H12_AM;
RTC_TimeStructure.RTC_Hours = 0x08;
RTC_TimeStructure.RTC_Minutes = 0x10;
RTC_TimeStructure.RTC_Seconds = 0x00;
RTC_SetTime(RTC_Format_BCD, &RTC_TimeStructure);
/* Set Date Week/Date/Month/Year */
RTC_DateStructure.RTC_WeekDay = 03;
RTC_DateStructure.RTC_Date = 0x01;
RTC_DateStructure.RTC_Month = 0x10;
RTC_DateStructure.RTC_Year = 0x14;
RTC_SetDate(RTC_Format_BCD, &RTC_DateStructure);
RTC_WriteBackupRegister(RTC_BKP_DR1, 0x32F2);/* Write BkUp DR0 */
#endif
}
/******************************************************************************
函数 : RtcInit
描述 : RTC初始化。
参数 : 无
返回 : TRUE - 初始化完成
FALSE - 初始化有误
******************************************************************************/
u8 RtcInit(void)
{
#if 0
RTC_InitTypeDef RTC_InitStructure;
u32 uwAsynchPrediv = 0;
u32 uwSynchPrediv = 0;
u32 Temp;
u32 ErrorTime;
RCC_BackupResetCmd(DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);/* Enable the PWR clock */
PWR_BackupAccessCmd(ENABLE);/* Allow access to RTC */
Temp = RTC_ReadBackupRegister(RTC_BKP_DR0);
if(0x1111 == Temp)
{
RCC_RTCCLKCmd(ENABLE);/* Enable the RTC Clock */
RTC_WaitForSynchro();/* Wait for RTC APB registers synchronisation */
DateTimeInit();
return TRUE;
}
ErrorTime = 0x00800000;
RCC_LSEConfig(RCC_LSE_ON);
while(RESET == RCC_GetFlagStatus(RCC_FLAG_LSERDY) && ErrorTime)
{/* Wait till LSE is ready */
ErrorTime--;
}
if(ErrorTime > 0)
{
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
uwSynchPrediv = 0xFF;
uwAsynchPrediv = 0x7F;
RCC_RTCCLKCmd(ENABLE);/* 使能RTC时钟 */
RTC_WaitForSynchro();/* 等待RTC APB寄存器同步 */
/* 配置RTC数据寄存器和分频器 */
RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv ;
RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv ;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24 ;
/* Check on RTC init */
ErrorTime = 3;
while(ERROR == RTC_Init(&RTC_InitStructure) && ErrorTime)
{
}
if(ErrorTime > 0)
{
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x1111);
DateTimeInit();
return TRUE;
}
}
if(0x2222 == Temp)
{
RCC_LSICmd(ENABLE);
RCC_RTCCLKCmd(ENABLE);/* Enable the RTC Clock */
RTC_WaitForSynchro();/* Wait for RTC APB registers synchronisation */
DateTimeInit();
return TRUE;
}
RCC_LSICmd(ENABLE);
while(RESET == RCC_GetFlagStatus(RCC_FLAG_LSIRDY))
{/* Wait till LSI is ready */
}
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);/* Select the RTC Clock Source */
/* ck_spre(1Hz) = RTCCLK(LSI) /(uwAsynchPrediv + 1)*(uwSynchPrediv + 1)*/
uwSynchPrediv = 0xF9;
uwAsynchPrediv = 0x7F;
RCC_RTCCLKCmd(ENABLE);/* 使能RTC时钟 */
RTC_WaitForSynchro();/* 等待RTC APB寄存器同步 */
/* 配置RTC数据寄存器和分频器 */
RTC_InitStructure.RTC_AsynchPrediv = uwAsynchPrediv ;
RTC_InitStructure.RTC_SynchPrediv = uwSynchPrediv ;
RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24 ;
ErrorTime = 3;
while(ERROR == RTC_Init(&RTC_InitStructure) && ErrorTime)
{/* Check on RTC init */
}
if(ErrorTime > 0)
{
RTC_WriteBackupRegister(RTC_BKP_DR0, 0x2222);
DateTimeInit();
return TRUE;
}
return FALSE;
#endif
}
#ifndef __DRV_RTC_H__
#define __DRV_RTC_H__
#include "Global.h"
//#define RTC_CLOCK_SOURCE_LSI
#define RTC_CLOCK_SOURCE_LSE
extern u8 RtcInit(void);
extern void RtcGetTime(u8 *pStr);
extern u8 RtcUpdateTime(u8* pStr);
#endif
#ifndef __DRV_RTCEXT_H__
#define __DRV_RTCEXT_H__
#include "Global.h"
#define Rtc_SCL_GPIO_CLK RCC_AHB1Periph_GPIOB
#define Rtc_SCL_GPIO_PORT GPIOB
#define Rtc_SCL_PIN GPIO_Pin_6
#define Rtc_SDA_GPIO_CLK RCC_AHB1Periph_GPIOB
#define Rtc_SDA_GPIO_PORT GPIOB
#define Rtc_SDA_PIN GPIO_Pin_7
#define Rtc_SlaveAddr (0xA2)
typedef enum
{
eRtcErr_Sucess = 0, //成功
eRtcErr_DataPiont, //数据指针为空
eRtcErr_WriteOver, //写数据超范围
eRtcErr_ReadOver, //读数据超范围
eRtcErr_BusErr, //总线错误
eRtcErr_WriteCmd, //设备从地址写命令无应答
eRtcErr_ReadCmd, //设备从地址读命令无应答
eRtcErr_RegAddr, //寄存器低地址无应答
eRtcErr_WriteData, //写数据无应答
}EnumRtcExtError;
typedef enum
{
eRtcReg_CrtlSta_1 = 0x00, //CONTROL_STATUS_1
eRtcReg_CrtlSta_2 = 0x01, //CONTROL_STATUS_2
eRtcReg_Sec = 0x02, //VL_SECONDS
eRtcReg_Min = 0x03, //MINUTES
eRtcReg_Hour = 0x04, //HOURS
eRtcReg_Day = 0x05, //DAYS
eRtcReg_Week = 0x06, //WEEKDAYS
eRtcReg_Mon = 0x07, //CENTURY_MONTHS
eRtcReg_Year = 0x08, //YEARS
eRtcReg_MinAlarm = 0x09, //MINUTE_ALARM
eRtcReg_HourAlarm = 0x0A, //HOUR_ALARM
eRtcReg_DayAlarm = 0x0B, //DAY_ALARM
eRtcReg_WeekAlarm = 0x0C, //WEEKDAY_ALARM
eRtcReg_ClkOut = 0x0D, //CLKOUT_CONTROL
eRtcReg_TimerCtrl = 0x0E, //TIMER_CONTROL
eRtcReg_Timer = 0x0F, //TIMER
}EnumRtcExtReg;
extern u8 RtcExtInit(void);
extern u8 RtcExtGetTime(StructTime *pTime);
extern u8 RtcExtSetTime(StructTime *pTime);
//*名称:BcDToHex
//*功能: BCD码转16进制
//*参数: bcd_data 要转换的BCD码数据(0-100)
//*返回: 转换后的16进制数据
extern u8 BcDToHex(u8 Bcd);
//*名称: HexToBcd
//*功能: 16进制转BCD码
//*参数: hex_data 要转换的16进制数据(0-100)
//*返回: 转换后的BCD码数据
extern u8 HexToBcd(u8 Hex);
#endif
#ifndef __DRV_SIM800C_H__
#define __DRV_SIM800C_H__
#include "Global.h"
#include "Drv_GprsCommon.h"
extern StructGprsDrv Sim800cDrv;
#endif
#ifndef __DRV_SPIFLASH_H__
#define __DRV_SPIFLASH_H__
/* Includes ------------------------------------------------------------------*/
#include "Global.h"
#define sFLASH_SECTION_SIZE (0x1000)//4K
extern osMutexId SpiFlashMutex;
/* Exported functions ------------------------------------------------------- */
/* High layer functions */
extern void sFLASH_Init(void);
extern void sFLASH_EraseSector(u32 SectorAddr);
extern void sFLASH_EraseBulk(void);
//extern void sFLASH_WritePage(u8* pBuffer, u32 WriteAddr, u16 NumByteToWrite);
extern void sFLASH_WriteBuffer(u8* pBuffer, u32 WriteAddr, u32 NumByteToWrite);
extern void sFLASH_ReadBuffer(u8* pBuffer, u32 ReadAddr, u32 NumByteToRead);
extern u32 sFLASH_ReadID(void);
#endif /* #ifndef __DRV_SPIFLASH_H__ */
#ifndef __DRV_TCUCOMM_H__
#define __DRV_TCUCOMM_H__
#include "Global.h"
#include "Thd_Charge.h"
#include "Memory.h"
#include "Thd_TCU.h"
#include "Drv_MCP2515.h"
extern u8 TCUSendMsg(StructChargeSend *pMsg);
extern void TCUCanInit_B(void);
extern osMessageQId TCUMsg;
typedef struct
{
u8 ControlType;
s16 Kwh;
u8 Percentage;
}StructPowerControl;
typedef struct cp56time2a {
u16 msec;
u16 min :6;
u8 res1 :1;
u8 iv :1; // invalid, iv = 0 有效; iv = 1 无效
u8 hour :5;
u8 res2 :2;
u8 su :1; //summer time, su = 0 标准时间; su = 1 夏季时间
u8 mday :5;
u8 wday :3;
u8 month :4;
u8 res3 :4;
u8 year :7;
u8 res4 :1;
} cp56time2a;
typedef struct
{
//u8 Len;
// u8 Data[8];
// Union1939Id Id;
u8 Prio;
u8 DP;
u8 PF;
u8 DA;
u8 SA;
u8 Len;
u8 Data[8];
u32 Pgn;
}StructTCUSend;
typedef struct
{
u8 GunNum; //抢号 单枪 0 一机多冲 1-255
u8 LoadSswitch;//负荷控制开关 是否根据用户型号提供不同输出功率 01启用02关闭其他无效
u8 PlugToChgFlag;//即插即充标识 00非 01 即插即充other:invalid
}StructStartMeg;
typedef struct
{
u8 GunNum; //抢号 单枪 0 一机多冲 1-255
u8 LoadSswitch;//负荷控制开关 是否根据用户型号提供不同输出功率 01启用02关闭其他无效
u8 AckFlag;
u32 RecvTick;
}StructStartCompMeg;
typedef struct
{
u8 GunNum; //抢号 单枪 0 一机多冲 1-255
u8 StopReason;
u8 AckFlag;
}StructStopCompMeg;
typedef enum
{
stopIdle =0,
commStop =1,
TcuFultStop =2,
ChgFultStop =3,
}stopReason;
typedef struct
{
u8 GunNum; //抢号 单枪 0 一机多冲 1-255
stopReason StopReason;//
}StructStopMeg;
typedef struct
{
u8 ChargingServiceFlag;//01充电服务停止02充电服务启用
u16 version;
u8 ChargeNum[8];
u8 ManufacturerCode[4];//厂家编码
u8 DeviceModel[2];//设备型号
u8 HardwareVersion[2];//硬件版本
u8 SoftwareVersion[2];//软件版本
u8 SoftwareData[4];//软件日期
u8 BmsVersion;//BMS协议版本号01H GB/27930-2011 02HGB/27930-2011
u16 DcMaxVolt;//模块最大电压 XXX.xV
u16 DcMinVolt;//模块最小电压 XXX.xV
u16 DcMaxCurrt;//模块最大电流 XX.xA
u16 DcMinCurrt;//模块最小电流 XX.xA
StructPowerControl PowerControl_A;
StructPowerControl PowerControl_B;
}StructTCUCControl;
typedef union
{
u8 data[5];
struct
{
u8 workStau : 2;
u8 sumFalt : 1;
u8 sumWarm : 1;
u8 Emergency: 1;
u8 smoke : 1;
u8 AccContac: 1;
u8 DCOutConOff: 1;//母线接触器据动/误动故障
u8 DCFuse : 1;//熔断器
u8 EleLock : 1;
u8 Fan : 1;
u8 SPD : 1;
u8 ImdDev : 1;
u8 BattPola : 1;
u8 ContGuid : 1;
u8 tempOver : 1;
u8 ConnTemp : 1;
u8 PutBack : 1;
u8 BMSComm : 1;
u8 InVoltHi : 1;
u8 InVoltlo : 1;
u8 DcVolHi : 1;
u8 DcVolLo : 1;
u8 DCCurrHi : 1;
u8 DcModErr : 1;
u8 DCModIn : 1;
u8 DCModInHi: 1;
u8 DCModInLo: 1;
u8 DCModPhas: 1;
u8 DcOutShor: 1;
u8 DCModOutCuHi: 1;
u8 DCModOutVoHi: 1;
u8 DCModOutVoLo: 1;
u8 DCModTempHi : 1;
u8 DCModComm : 1;
u8 DCModFan : 1;
u8 CCConnect : 1;
u8 InsertGunSta: 1;
u8 DcOutContSta: 1;
u8 ElectLock : 1;
}InfRe;
}UnionInformainReport1;
typedef union
{
u16 data;
struct
{
u16 Door : 1;//熔断器
u16 DCOutConOn : 1;//母线接触器粘连故障
u16 ImdWarm : 1;
u16 DrainResist : 1;
u16 tempOver : 1;
u16 gunTemp : 1;
u16 AccContacON : 1;//交流数日接触器据动/误动故障
u16 AccContacOff: 1;//粘连故障
u16 Power : 1;//辅助电源
u16 UniContactorOff : 1;//母线接触器据动/误动故障
u16 UniContactorOn : 1;//母线接触器据动/误动故障
}InfRe;
}UnionInformainReport2;
typedef union
{
u32 Mult;
struct
{
u32 Idle : 1;//
u32 paramAck : 1;//
u32 startAck : 1;//
u32 startComp : 1;//
u32 stopAck : 1;//
u32 stopComp : 1;//
u32 timeAck : 1;//
u32 SerConAck : 1;//
u32 GunAck : 1;//
u32 powerAck : 1;//
u32 QueryAck : 1;//
u32 DCConInfor : 1;//
u32 DCConMeasu : 1;//
u32 verification : 1;//
}Value;
}UnionTCUEM;
typedef struct
{
// u8 Valid;
UnionTCUEM tcuem;//充电控制器反馈超时
}StructTCUEM;
typedef struct
{
u8 result;
u8 FailReason;
}StructVerificationInformain;
#define TCU1939Addr (0x8A)
#define ChargerCont1939Addr (0xF6)
typedef enum
{
eCmd_start = 0x000100,// 充电启动帧
eCmd_startAck = 0x000200,// 充电启动帧反馈
eCmd_stop = 0x000300,// 充电停止帧
eCmd_stopAck = 0x000400,// 充电停止帧反馈
eCmd_time = 0x000500,// 对时帧
eCmd_timeAck = 0x000600,// 对时帧反馈
eCmd_versi = 0x000700,//版本校验帧
eCmd_versiAck = 0x000800,//版本校验帧反馈
eCmd_param = 0x000900,// 下发充电参数信息帧
eCmd_paramAck = 0x000A00,// 下发充电参数信息应答帧
eCmd_SerCon = 0x000B00,// 充电服务启停控制帧
eCmd_SerConAck = 0x000C00,// 充电服务启停控制帧应答
eCmd_Gun = 0x000D00,// 电子锁可控制帧
eCmd_GunAck = 0x000E00,// 电子锁可控制应答帧
eCmd_power = 0x000F00,// 功率调节控制帧
eCmd_powerAck = 0x001000,// 功率调节控制应答帧
eCmd_Query = 0x006000,// 充电桩配置信息查询帧
eCmd_QueryAck = 0x006100,// 充电桩配置信息查询应答帧
eCmd_verification =0x002D00,// 车辆验证数据帧
eCmd_verificationAck =0x002E00,//车辆验证应答帧
////////////状态帧/////////////////
eCmd_startComp =0x001100,// 充电启动完成帧
eCmd_startCompAck =0x001200,// 充电启动完成应答帧
eCmd_stopComp =0x001300,// 充电停止完成帧
eCmd_stopCompAck =0x001400,// 充电停止完成应答帧
///////////数据帧/直流////////////
eCmd_DCConMeasu =0x002000,// 充电控制器遥测帧
eCmd_DCTCUMeasu =0x002100,// 计费单元遥测 帧
eCmd_DCConInfor1 =0x002200,// 充电控制器遥信帧
eCmd_DCConInfor2 =0x002300,// 充电控制器遥信帧
///////////数据帧/交流////////////
eCmd_ACConMeasu =0x003000,// 充电控制器遥测帧
eCmd_ACTCUMeasu =0x003100,// 计费单元遥测 帧
eCmd_ACConInfor =0x003200,// 充电控制器遥信帧
eCmd_ACTCUInfor =0x003300,// 计费单元遥信帧
///////////心跳帧///////////
eCmd_TcuHeart =0x004000, // 计费单元心跳
eCmd_ContHeart =0x004100, // 充电控制器心跳帧
eCmd_TCUErroComm =0x005100, // 计费单元错误帧
eCmd_ConErroComm =0x005200, //充电控制器错误帧
}EnumTCUCommPgn;
extern u8 TCUCommInit(void);
extern void StartMeg ( StructTCUSend* pPgnRecv );
extern void StartMegAck_A(void);
extern void StartMegAck_B(void);
extern void startCompSend_A(void);
extern void startCompSend_B(void);
extern void ACkStartCompMeg ( StructTCUSend* pPgnRecv );
extern void StopMeg( StructTCUSend* pPgnRecv );
extern void StopMegAck_A(void );
extern void StopMegAck_B(void );
extern void stopCompSend_A(void);
extern void stopCompSend_B(void);
extern void stopCompAck( StructTCUSend* pPgnRecv);
extern void TCUHeartBeat_A(void);
extern void TCUHeartBeat_B(void);
extern void TCUtimeSet(StructTCUSend* pPgnRecv);
extern void TCUtimeSetAck(void);
extern void TCUVersionCheck(StructTCUSend* pPgnRecv);
extern void TCUVersionCheckSent(void);
extern void SerConAckAnalysis(StructTCUSend* pPgnRecv);
extern void SerConAck(void);
extern void ElectControlAnalysis(StructTCUSend* pPgnRecv);
extern void ElectControlAck(void);
extern void PowerControlAnalysis(StructTCUSend* pPgnRecv);
extern void PowerControlAck(void);
extern void InformationReporting_22_A (void);
extern void InformationReporting_22_B (void);
extern void InformationReporting_23_A (void);
extern void InformationReporting_23_B(void);
extern void measuringReporting20_A(void);
extern void measuringReporting20_B(void);
extern void ChgInfornQueryAck(void);
extern void verification(void);
extern void verificationAck(StructTCUSend* pPgnRecv);
void TcuEMMsg( UnionConEM data);
void TcuEMMsg_B( UnionConEM data);
extern StructStartMeg StartMeg_A ;
extern StructStartMeg StartMeg_B;
extern StructStartCompMeg AckStartCompMeg_A ;
extern StructStartCompMeg AckStartCompMeg_B ;
extern StructStopMeg StopMeg_A ;
extern StructStopMeg StopMeg_B ;
extern StructStopCompMeg AckStopCompMeg_A ;
extern StructStopCompMeg AckStopCompMeg_B ;
extern UnionInformainReport1 InformainReport_A;
extern UnionInformainReport1 InformainReport_B;
extern UnionInformainReport2 InformainReport2_A;
extern UnionInformainReport2 InformainReport2_B;
extern StructVerificationInformain VerificaInfo ;
extern StructVerificationInformain VerificaInfo_B ;
extern StructTCUEM TCUChgContralTCUEM_A;
extern StructTCUEM TCUChgContralTCUEM_B;
#endif
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论