feat: Integrate NFC functionality
parent
071788de56
commit
e513e0fff1
|
|
@ -400,6 +400,10 @@
|
||||||
</option>
|
</option>
|
||||||
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH.1406977247" name="Include paths (-I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH" valueType="includePath">
|
<option IS_BUILTIN_EMPTY="false" IS_VALUE_EMPTY="false" id="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH.1406977247" name="Include paths (-I)" superClass="com.ti.ccstudio.buildDefinitions.TMS470_GNU_9.0.compilerID.INCLUDE_PATH" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INCLUDE_PATH}"/>
|
<listOptionValue builtIn="false" value="${COM_TI_MSPM0_SDK_INCLUDE_PATH}"/>
|
||||||
|
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/ivec_bws_nfc/ivec_bsw_common/inc}"/>
|
||||||
|
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/ivec_ECU/ivec_ecu_nfc/inc}"/>
|
||||||
|
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/ivec_bws_nfc/ivec_bsw_common/inc}"/>
|
||||||
|
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/ivec_bws_nfc/ivec_bsw_nfc/inc}"/>
|
||||||
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_INCLUDE_PATH}"/>
|
<listOptionValue builtIn="false" value="${SYSCONFIG_TOOL_INCLUDE_PATH}"/>
|
||||||
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Generated Codes}"/>
|
<listOptionValue builtIn="false" value="${workspace_loc:/${ProjName}/Generated Codes}"/>
|
||||||
<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
|
<listOptionValue builtIn="false" value="${PROJECT_ROOT}"/>
|
||||||
|
|
|
||||||
|
|
@ -159,10 +159,16 @@ encoding//Test__GNU/ivec_ECU/ivec_ecu_can/src/subdir_rules.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_ECU/ivec_ecu_can/src/subdir_vars.mk=UTF-8
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_can/src/subdir_vars.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_ECU/ivec_ecu_common/src/subdir_rules.mk=UTF-8
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_common/src/subdir_rules.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_ECU/ivec_ecu_common/src/subdir_vars.mk=UTF-8
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_common/src/subdir_vars.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_nfc/src/subdir_rules.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_nfc/src/subdir_vars.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_ECU/ivec_ecu_uart/src/subdir_rules.mk=UTF-8
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_uart/src/subdir_rules.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_ECU/ivec_ecu_uart/src/subdir_vars.mk=UTF-8
|
encoding//Test__GNU/ivec_ECU/ivec_ecu_uart/src/subdir_vars.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_RTE/src/subdir_rules.mk=UTF-8
|
encoding//Test__GNU/ivec_RTE/src/subdir_rules.mk=UTF-8
|
||||||
encoding//Test__GNU/ivec_RTE/src/subdir_vars.mk=UTF-8
|
encoding//Test__GNU/ivec_RTE/src/subdir_vars.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_bws_nfc/ivec_bsw_common/src/subdir_rules.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_bws_nfc/ivec_bsw_common/src/subdir_vars.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_bws_nfc/ivec_bsw_nfc/src/subdir_rules.mk=UTF-8
|
||||||
|
encoding//Test__GNU/ivec_bws_nfc/ivec_bsw_nfc/src/subdir_vars.mk=UTF-8
|
||||||
encoding//Test__GNU/makefile=UTF-8
|
encoding//Test__GNU/makefile=UTF-8
|
||||||
encoding//Test__GNU/objects.mk=UTF-8
|
encoding//Test__GNU/objects.mk=UTF-8
|
||||||
encoding//Test__GNU/sources.mk=UTF-8
|
encoding//Test__GNU/sources.mk=UTF-8
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,30 @@
|
||||||
|
#ifndef IVEC_ECU_NFC_H
|
||||||
|
#define IVEC_ECU_NFC_H
|
||||||
|
|
||||||
|
|
||||||
|
#include "ivec_ecu_common.h"
|
||||||
|
|
||||||
|
#define IVEC_ECU_NFC_I2C_ADDR ( 0x24 )
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
IVEC_ECU_NFC_SERIF_I2C = 0,
|
||||||
|
IVEC_ECU_NFC_UART2 = 1,
|
||||||
|
}IVEC_EcuNfcComMode_e;
|
||||||
|
|
||||||
|
typedef struct
|
||||||
|
{
|
||||||
|
IVEC_EcuNfcComMode_e eNfcChannel;
|
||||||
|
void *pvChannelHandle;
|
||||||
|
}IVEC_EcuNfcConfig_s;
|
||||||
|
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcInit(IVEC_EcuNfcConfig_s *pxNfcConfig);
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcDeInit(IVEC_EcuNfcConfig_s *pxNfcConfig);
|
||||||
|
void vEcu_NfcReset(void);
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcWriteData(IVEC_EcuNfcConfig_s *pxNfcConfig, uint8_t *pu8Buffer, uint32_t u32Length);
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcReadData(IVEC_EcuNfcConfig_s* pxNfcConfig, uint8_t* pu8Buffer, uint32_t u32Length,uint32_t timeout);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* IVEC_ECU_NFC_H */
|
||||||
|
|
@ -0,0 +1,110 @@
|
||||||
|
#include "ivec_ecu_common.h"
|
||||||
|
|
||||||
|
#include "ivec_ecu_nfc.h"
|
||||||
|
#include "ivec_ecu_uart.h"
|
||||||
|
#define LOG_STRING "ivec-ecu-nfc"
|
||||||
|
static IVEC_McalUartHandle_s __gprv_UartNfcHandle = { 0 };
|
||||||
|
|
||||||
|
|
||||||
|
void vEcu_NfcReset(void)
|
||||||
|
{
|
||||||
|
// xMCAL_GpioWritePin(135, ivecMCAL_LVL_LOW);
|
||||||
|
// ql_rtos_task_sleep_ms(40);
|
||||||
|
// xMCAL_GpioWritePin(135, ivecMCAL_LVL_HIGH);
|
||||||
|
}
|
||||||
|
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcInit(IVEC_EcuNfcConfig_s* pxNfcConfig)
|
||||||
|
{
|
||||||
|
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||||
|
IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS;
|
||||||
|
if (pxNfcConfig == NULL)
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (pxNfcConfig->eNfcChannel == IVEC_ECU_NFC_UART2)
|
||||||
|
{
|
||||||
|
__gprv_UartNfcHandle.eUartPortNumber = IVEC_MCAL_UART_PORT_3;
|
||||||
|
xECU_UARTInit(&__gprv_UartNfcHandle, IVEC_MCAL_UART_BAUD_115200);
|
||||||
|
pxNfcConfig->pvChannelHandle = &__gprv_UartNfcHandle;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_NOT_IMPLEMENTED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
IVEC_ECU_FUNC_EXIT(LOG_STRING, l_xFuncStatus);
|
||||||
|
return l_xFuncStatus;
|
||||||
|
}
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcReadData(IVEC_EcuNfcConfig_s* pxNfcConfig, uint8_t* pu8Buffer, uint32_t u32Length,uint32_t timeout)
|
||||||
|
{
|
||||||
|
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||||
|
IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS;
|
||||||
|
if (pxNfcConfig == NULL || pu8Buffer == NULL || u32Length == 0)
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (pxNfcConfig->eNfcChannel == IVEC_ECU_NFC_UART2)
|
||||||
|
{
|
||||||
|
l_xFuncStatus = xECU_UARTGetData(pxNfcConfig->pvChannelHandle, pu8Buffer, u32Length, timeout);
|
||||||
|
// l_xFuncStatus = (IVEC_EcuCommonErr_e)xMCAL_I2cReadSlave(&__gprv_xNfcI2cHandle, pu8Buffer, u32Length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_NOT_IMPLEMENTED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
IVEC_ECU_FUNC_EXIT(LOG_STRING, l_xFuncStatus);
|
||||||
|
return l_xFuncStatus;
|
||||||
|
|
||||||
|
}
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcWriteData(IVEC_EcuNfcConfig_s* pxNfcConfig, uint8_t* pu8Buffer, uint32_t u32Length)
|
||||||
|
{
|
||||||
|
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||||
|
IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS;
|
||||||
|
if (pxNfcConfig == NULL || pu8Buffer == NULL || u32Length == 0)
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (pxNfcConfig->eNfcChannel == IVEC_ECU_NFC_UART2)
|
||||||
|
{
|
||||||
|
|
||||||
|
l_xFuncStatus = xECU_UartWrite(pxNfcConfig->pvChannelHandle, pu8Buffer, u32Length);
|
||||||
|
// l_xFuncStatus = (IVEC_EcuCommonErr_e)xMCAL_I2cWriteSlave((McalI2cHandle_s *)pxNfcConfig->pvChannelHandle, pu8Buffer, u32Length);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_NOT_IMPLEMENTED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
IVEC_ECU_FUNC_EXIT(LOG_STRING, l_xFuncStatus);
|
||||||
|
return l_xFuncStatus;
|
||||||
|
}
|
||||||
|
IVEC_EcuCommonErr_e xECU_NfcDeInit(IVEC_EcuNfcConfig_s* pxNfcConfig)
|
||||||
|
{
|
||||||
|
IVEC_ECU_FUNC_ENTRY(LOG_STRING);
|
||||||
|
IVEC_McalCommonErr_e l_xFuncStatus = commonMCAL_SUCCESS;
|
||||||
|
if (pxNfcConfig == NULL)
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_INVALID_PARAM;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
if (pxNfcConfig->eNfcChannel == IVEC_ECU_NFC_UART2)
|
||||||
|
{
|
||||||
|
|
||||||
|
// l_xFuncStatus = (IVEC_EcuCommonErr_e)xMCAL_I2cDeInit(&__gprv_xNfcI2cHandle);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
l_xFuncStatus = commonECU_NOT_IMPLEMENTED;
|
||||||
|
goto exit;
|
||||||
|
}
|
||||||
|
exit:
|
||||||
|
IVEC_ECU_FUNC_EXIT(LOG_STRING, l_xFuncStatus);
|
||||||
|
return l_xFuncStatus;
|
||||||
|
}
|
||||||
|
|
@ -18,7 +18,6 @@
|
||||||
|
|
||||||
// UART Handles
|
// UART Handles
|
||||||
IVEC_EcuUartHandle_s g_xUartHandle;
|
IVEC_EcuUartHandle_s g_xUartHandle;
|
||||||
IVEC_EcuUartHandle_s g_xUart2Handle;
|
|
||||||
IVEC_EcuCANHandle_s g_xCanHandle;
|
IVEC_EcuCANHandle_s g_xCanHandle;
|
||||||
|
|
||||||
// Configuration Macros
|
// Configuration Macros
|
||||||
|
|
@ -221,6 +220,7 @@ void vRTE_AppInit(void)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
vRTE_InitUartCanEcho();
|
vRTE_InitUartCanEcho();
|
||||||
|
vRTE_NfcInit();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Callback function for timer interrupt.
|
* @brief Callback function for timer interrupt.
|
||||||
|
|
@ -238,14 +238,8 @@ void vRTE_InitUartCanEcho(void)
|
||||||
{
|
{
|
||||||
g_xUartHandle.u8Qbuffer = g_prvU8CanUartDataBuffer;
|
g_xUartHandle.u8Qbuffer = g_prvU8CanUartDataBuffer;
|
||||||
g_xUartHandle.u16QbufSize = eteCAN_UART_BUFFER_MAX_SIZE_u32;
|
g_xUartHandle.u16QbufSize = eteCAN_UART_BUFFER_MAX_SIZE_u32;
|
||||||
|
|
||||||
#if (rteUART_PIN_SELECTION_u8 == 1)
|
|
||||||
g_xUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT3;
|
|
||||||
g_xUartHandle.u32BaudRate = IVEC_ECU_UART_BAUD_115200;
|
|
||||||
#elif (rteUART_PIN_SELECTION_u8 == 2)
|
|
||||||
g_xUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT2;
|
g_xUartHandle.eUartPortNumber = IVEC_ECU_UART_PORT2;
|
||||||
g_xUartHandle.u32BaudRate = IVEC_ECU_UART_BAUD_115200;
|
g_xUartHandle.u32BaudRate = IVEC_ECU_UART_BAUD_115200;
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
xECU_UartInit(&g_xUartHandle);
|
xECU_UartInit(&g_xUartHandle);
|
||||||
|
|
@ -261,6 +255,11 @@ void vRTE_InitUartCanEcho(void)
|
||||||
}
|
}
|
||||||
xECU_CANInit(&g_xCanHandle);
|
xECU_CANInit(&g_xCanHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vRTE_NfcInit(void)
|
||||||
|
{
|
||||||
|
bBSW_NfcInit();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Initializes the application run processes.
|
* @brief Initializes the application run processes.
|
||||||
*
|
*
|
||||||
|
|
@ -274,6 +273,7 @@ void vRTE_AppRunInit(void)
|
||||||
{
|
{
|
||||||
vRTE_ProcessUartData();
|
vRTE_ProcessUartData();
|
||||||
vRTE_ProcessCanData();
|
vRTE_ProcessCanData();
|
||||||
|
vRTE_UartNfcProcess();
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* @brief Callback function for timer interrupt.
|
* @brief Callback function for timer interrupt.
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
#ifndef IVEC_BSW_COMMON_H
|
||||||
|
#define IVEC_BSW_COMMON_H
|
||||||
|
#include "ivec_ecu_common.h"
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
//common
|
||||||
|
commonBSW_SUCCESS = 0,
|
||||||
|
commonBSW_WAIT,
|
||||||
|
commonBSW_INVALID_PARAM=-7,
|
||||||
|
commonBSW_FAIL = -6,
|
||||||
|
commonBSW_INIT_FAIL = -5,
|
||||||
|
commonBSW_DEINIT_FAIL,
|
||||||
|
commonBSW_CONFIG_FAIL,
|
||||||
|
commonBSW_READ_FAIL,
|
||||||
|
commonBSW_WRITE_FAIL,
|
||||||
|
commonBSW_ALREADY_INIT=-20,
|
||||||
|
commonBSW_ALREADY_DEINIT,
|
||||||
|
commonBSW_NOT_IMPLEMENTED
|
||||||
|
|
||||||
|
|
||||||
|
}IVEC_BswCommonErr_e;
|
||||||
|
|
||||||
|
typedef IVEC_EcuCommonCanFrame_s IVEC_BswCommonCanFrame_s;
|
||||||
|
|
||||||
|
#define IVEC_DELAY_MS(x)
|
||||||
|
|
||||||
|
#define BSW_LOG_ENABLE 0
|
||||||
|
#if BSW_LOG_ENABLE==1
|
||||||
|
#define IVEC_BSW_LOG(LOG_STRING, msg ,...) QL_LOG(QL_LOG_LEVEL_INFO, LOG_STRING, msg, ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define IVEC_BSW_LOG(LOG_STRING,msg, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
#define IVEC_BSW_FUNC_ENTRY(LOG_STRING,...) QL_LOG(QL_LOG_LEVEL_INFO, LOG_STRING, "BSW Entry", ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define IVEC_BSW_FUNC_ENTRY(LOG_STRING, ...)
|
||||||
|
#endif
|
||||||
|
#if 0
|
||||||
|
#define IVEC_BSW_FUNC_EXIT(LOG_STRING,...) QL_LOG(QL_LOG_LEVEL_INFO, LOG_STRING, "BSW Exit:%d", ##__VA_ARGS__)
|
||||||
|
#else
|
||||||
|
#define IVEC_BSW_FUNC_EXIT(LOG_STRING, ...)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* IVEC_BSW_COMMON_H */
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
#ifndef IVEC_BSW_NFC_H
|
||||||
|
#define IVEC_BSW_NFC_H
|
||||||
|
|
||||||
|
#include "ivec_bsw_common.h"
|
||||||
|
#define IVEC_BSW_NFC_MIFRAE_AUTH_A 0x60//imported from pn532 lib
|
||||||
|
#define IVEC_BSW_NFC_MIFRAE_AUTH_B 0x61//imported from pn532 lib
|
||||||
|
|
||||||
|
|
||||||
|
bool bBSW_NfcTest();
|
||||||
|
bool bBSW_NfcInit();
|
||||||
|
bool bBSW_NfcMifareClassicDataRead(uint8_t *pu8Uid,uint8_t u8UidLen,uint32_t u32BlockAddr,uint8_t *pu8Key, uint8_t u8keyType,uint8_t *pu8Data );
|
||||||
|
bool bBSW_NfcConfigure();
|
||||||
|
int i328BSW_NfcScanMIFARE(uint8_t *pu8Uid);
|
||||||
|
int i328BSW_NfcAutoPollMIFARE();
|
||||||
|
#endif /* IVEC_BSW_NFC_H */
|
||||||
|
|
@ -0,0 +1,128 @@
|
||||||
|
#include "ivec_bsw_nfc.h"
|
||||||
|
#include "ivec_ecu_nfc.h"
|
||||||
|
#include "ivec_cmplx_gptimer.h"
|
||||||
|
#include "pn532.h"
|
||||||
|
#define LOG_STRING "ivec-bsw-nfc"
|
||||||
|
IVEC_EcuNfcConfig_s xNfcConfig = { 0 };
|
||||||
|
static PN532 __gprv_pn532 = { 0 };
|
||||||
|
|
||||||
|
|
||||||
|
int i32Bsw_Pn532Reset(void)
|
||||||
|
{
|
||||||
|
//add gpio
|
||||||
|
vEcu_NfcReset();
|
||||||
|
return PN532_STATUS_OK;
|
||||||
|
}
|
||||||
|
int i32Bsw_Pn532ReadData(uint8_t* data, uint16_t count)
|
||||||
|
{
|
||||||
|
int i32Ret = xECU_NfcReadData(&xNfcConfig, data, count, 200) == commonECU_SUCCESS ? PN532_STATUS_OK : PN532_ERROR_I2CBUSY;
|
||||||
|
// if(i32Ret==PN532_STATUS_OK)
|
||||||
|
// {
|
||||||
|
// memmove(data,data+1,count);
|
||||||
|
// }
|
||||||
|
return i32Ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i32Bsw_Pn532WriteData(uint8_t* data, uint16_t count)
|
||||||
|
{
|
||||||
|
return xECU_NfcWriteData(&xNfcConfig, data, count) == commonECU_SUCCESS ? PN532_STATUS_OK : PN532_ERROR_I2CBUSY;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bBsw_Pn532WaitReady(uint32_t timeout)
|
||||||
|
{
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
int i32Bsw_Pn532Wakeup(void) {
|
||||||
|
|
||||||
|
//add gpio
|
||||||
|
uint8_t wakeup[] = { 0x55, 0x55, 0x00, 0x00, 0x00, 0x00 };
|
||||||
|
xECU_UartWrite(xNfcConfig.pvChannelHandle, &wakeup[0], sizeof(wakeup));
|
||||||
|
vEcu_NfcReset();
|
||||||
|
return PN532_STATUS_OK;
|
||||||
|
}
|
||||||
|
void vBsw_Pn532Log(const char* log) {
|
||||||
|
IVEC_BSW_LOG(LOG_STRING, "%s", log);
|
||||||
|
}
|
||||||
|
void vBsw_Pn532Init(PN532* pxPn532) {
|
||||||
|
// init the pn532 functions
|
||||||
|
pxPn532->reset = i32Bsw_Pn532Reset;
|
||||||
|
pxPn532->read_data = i32Bsw_Pn532ReadData;
|
||||||
|
pxPn532->write_data = i32Bsw_Pn532WriteData;
|
||||||
|
pxPn532->wait_ready = bBsw_Pn532WaitReady;
|
||||||
|
pxPn532->wakeup = i32Bsw_Pn532Wakeup;
|
||||||
|
pxPn532->log = vBsw_Pn532Log;
|
||||||
|
|
||||||
|
// hardware wakeup
|
||||||
|
pxPn532->wakeup();
|
||||||
|
}
|
||||||
|
bool bBSW_NfcInit()
|
||||||
|
{
|
||||||
|
xNfcConfig.eNfcChannel = IVEC_ECU_NFC_UART2;
|
||||||
|
if (xECU_NfcInit(&xNfcConfig) != commonECU_SUCCESS)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
vBsw_Pn532Init(&__gprv_pn532);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bBSW_NfcTest()
|
||||||
|
{
|
||||||
|
uint8_t pu8Buff[56] = { 0 };
|
||||||
|
send_wakeup(&__gprv_pn532);
|
||||||
|
return get_firmware(&__gprv_pn532, pu8Buff, 4) == 4;
|
||||||
|
}
|
||||||
|
|
||||||
|
int i328BSW_NfcScanMIFARE(uint8_t* pu8Uid)
|
||||||
|
{
|
||||||
|
uint8_t l_u8Buff[32] = { 0 };
|
||||||
|
if (xECU_NfcReadData(&xNfcConfig, l_u8Buff, 21, 5) == commonECU_SUCCESS)
|
||||||
|
{
|
||||||
|
if (l_u8Buff[0] != PN532_PREAMBLE && l_u8Buff[1] != PN532_STARTCODE1 && l_u8Buff[2] != PN532_STARTCODE2)
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
// Check length & length checksum match.
|
||||||
|
uint8_t frame_len = l_u8Buff[3];
|
||||||
|
if (((frame_len + l_u8Buff[4]) & 0xFF) != 0) {
|
||||||
|
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
if (frame_len < 14)
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
// Check frame checksum value matches bytes.
|
||||||
|
uint8_t checksum = 0;
|
||||||
|
for (uint8_t i = 0; i < frame_len + 1; i++) {
|
||||||
|
checksum += l_u8Buff[5 + i];
|
||||||
|
}
|
||||||
|
checksum &= 0xFF;
|
||||||
|
if (checksum != 0) {
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
if (l_u8Buff[5] != 0xd5 && l_u8Buff[6] != 0x61 && l_u8Buff[8]!=0x10)//verify auto poll cmd resp
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
uint8_t l_u8NfcIdLen=l_u8Buff[14];
|
||||||
|
if(l_u8NfcIdLen>10)
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
|
||||||
|
// Return frame data.
|
||||||
|
for (uint8_t i = 0; i < l_u8NfcIdLen; i++) {
|
||||||
|
pu8Uid[i] = l_u8Buff[15+ i];
|
||||||
|
}
|
||||||
|
return l_u8NfcIdLen;
|
||||||
|
}
|
||||||
|
return PN532_STATUS_ERROR;
|
||||||
|
}
|
||||||
|
int i328BSW_NfcAutoPollMIFARE()
|
||||||
|
{
|
||||||
|
return auto_poll_command(&__gprv_pn532) == PN532_STATUS_OK;
|
||||||
|
}
|
||||||
|
bool bBSW_NfcConfigure()//call it after test success
|
||||||
|
{
|
||||||
|
return configure_sam(&__gprv_pn532) == PN532_STATUS_OK;
|
||||||
|
}
|
||||||
|
bool bBSW_NfcMifareClassicDataRead(uint8_t* pu8Uid, uint8_t u8UidLen, uint32_t u32BlockAddr, uint8_t* pu8Key, uint8_t u8keyType, uint8_t* pu8Data)
|
||||||
|
{
|
||||||
|
if (UART_MifareClassicAuthenticateBlock(&__gprv_pn532, pu8Uid, u8UidLen, (u32BlockAddr / 4) * 4, u8keyType, pu8Key) == PN532_STATUS_OK)
|
||||||
|
return UART_MifareClassicReadBlock(&__gprv_pn532, pu8Data, u32BlockAddr) == PN532_STATUS_OK;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
Loading…
Reference in New Issue