feat: KT mBMS 펌웨어 3종(HW1/2/3) 및 통합 빌드 환경 초기 커밋 (V4.0.0.1)
This commit is contained in:
135
APP_R3221/App/Hardware/relay.c
Normal file
135
APP_R3221/App/Hardware/relay.c
Normal file
@@ -0,0 +1,135 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* @file relay.h
|
||||
* @author AMG Energy Solution Team
|
||||
* @version V1.0.0
|
||||
* @date 07-Feb-2022
|
||||
* @brief This file provides all the codes of relay control functions.
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
|
||||
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE
|
||||
* TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING
|
||||
* FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE
|
||||
* CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
|
||||
*
|
||||
* <h2><center>© COPYRIGHT 2022 AMG</center></h2>
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/** @addtogroup mBMS2
|
||||
* @{
|
||||
*/
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include "relay.h"
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
//Relay port definitions
|
||||
/* Charge Relay Port/Pin definition */
|
||||
#define CHG_RLY_PORT (PortC)
|
||||
#define CHG_RLY_PIN (Pin09)
|
||||
|
||||
/* Discharge Relay Port/Pin definition */
|
||||
#define DSG_RLY_PORT (PortD)
|
||||
#define DSG_RLY_PIN (Pin15)
|
||||
|
||||
/* Pre-Charge Relay Port/Pin definition */
|
||||
#define PCHG_RLY_PORT (PortD)
|
||||
#define PCHG_RLY_PIN (Pin13)
|
||||
|
||||
/* Charge Relay Status Port/Pin definition */
|
||||
#define CHG_RLY_STS_PORT (PortC)
|
||||
#define CHG_RLY_STS_PIN (Pin08)
|
||||
|
||||
/* Discharge Relay Status Port/Pin definition */
|
||||
#define DSG_RLY_STS_PORT (PortD)
|
||||
#define DSG_RLY_STS_PIN (Pin14)
|
||||
|
||||
/* Discharge Relay Status Port/Pin definition */
|
||||
#define PCHG_RLY_STS_PORT (PortD)
|
||||
#define PCHG_RLY_STS_PIN (Pin12)
|
||||
|
||||
// Relay port definitions
|
||||
#define CHG_RLY_OFF PORT_ResetBits(CHG_RLY_PORT , CHG_RLY_PIN );
|
||||
#define CHG_RLY_ON PORT_SetBits (CHG_RLY_PORT , CHG_RLY_PIN );
|
||||
|
||||
#define DSG_RLY_OFF PORT_ResetBits(DSG_RLY_PORT , DSG_RLY_PIN );
|
||||
#define DSG_RLY_ON PORT_SetBits (DSG_RLY_PORT , DSG_RLY_PIN );
|
||||
|
||||
#define PRE_CHG_RLY_ON PORT_ResetBits(PCHG_RLY_PORT, PCHG_RLY_PIN);
|
||||
#define PRE_CHG_RLY_OFF PORT_SetBits (PCHG_RLY_PORT, PCHG_RLY_PIN);
|
||||
|
||||
/* Private macro -------------------------------------------------------------*/
|
||||
/* Private variables ---------------------------------------------------------*/
|
||||
/* Private functions ---------------------------------------------------------*/
|
||||
|
||||
// Relay IO Initialize
|
||||
void Relay_Init(void)
|
||||
{
|
||||
stc_port_init_t stcPortInit;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
stcPortInit.enPinMode = Pin_Mode_Out;
|
||||
stcPortInit.enPinOType = Pin_OType_Od;
|
||||
stcPortInit.enExInt = Disable;
|
||||
stcPortInit.enPullUp = Disable;
|
||||
|
||||
/* Relay Control Port/Pin initialization */
|
||||
PORT_Init(CHG_RLY_PORT , CHG_RLY_PIN , &stcPortInit);
|
||||
PORT_Init(DSG_RLY_PORT , DSG_RLY_PIN , &stcPortInit);
|
||||
PORT_Init(PCHG_RLY_PORT, PCHG_RLY_PIN, &stcPortInit);
|
||||
|
||||
CHG_RLY_OFF;
|
||||
DSG_RLY_OFF;
|
||||
PRE_CHG_RLY_OFF;
|
||||
|
||||
/* configuration structure initialization */
|
||||
MEM_ZERO_STRUCT(stcPortInit);
|
||||
|
||||
stcPortInit.enPinMode = Pin_Mode_In;
|
||||
stcPortInit.enExInt = Disable;
|
||||
stcPortInit.enPullUp = Disable;
|
||||
|
||||
/* Relay Status Port/Pin initialization */
|
||||
PORT_Init(CHG_RLY_STS_PORT , CHG_RLY_STS_PIN , &stcPortInit);
|
||||
PORT_Init(DSG_RLY_STS_PORT , DSG_RLY_STS_PIN , &stcPortInit);
|
||||
PORT_Init(PCHG_RLY_STS_PORT, PCHG_RLY_STS_PIN, &stcPortInit);
|
||||
}
|
||||
|
||||
void Relay_On(uint8_t id)
|
||||
{
|
||||
switch (id) {
|
||||
case '0': DSG_RLY_ON; break;
|
||||
case '1': CHG_RLY_ON; break;
|
||||
case '2': PRE_CHG_RLY_ON; break;
|
||||
}
|
||||
}
|
||||
|
||||
void Relay_Off(uint8_t id)
|
||||
{
|
||||
switch (id) {
|
||||
case '0': DSG_RLY_OFF; break;
|
||||
case '1': CHG_RLY_OFF; break;
|
||||
case '2': PRE_CHG_RLY_OFF; break;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t Relay_Status(uint8_t id)
|
||||
{
|
||||
uint8_t result = 0;
|
||||
|
||||
switch (id) {
|
||||
case 0: result = PORT_GetBit(DSG_RLY_STS_PORT , DSG_RLY_STS_PIN ); break;
|
||||
case 1: result = PORT_GetBit(CHG_RLY_STS_PORT , CHG_RLY_STS_PIN ); break;
|
||||
case 2: result = PORT_GetBit(PCHG_RLY_STS_PORT, PCHG_RLY_STS_PIN); break;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/*******************(C)COPYRIGHT 2022 AMG ********************END OF FILE******/
|
||||
Reference in New Issue
Block a user