/*******************************************************************************
*
* Freescale Semiconductor Inc.
* (c) Copyright 2006-2012 Freescale Semiconductor, Inc.
* ALL RIGHTS RESERVED.
*
********************************************************************************
*
* $File Name: FS65xx.c$
* @file FS65xx.c
*
* $Date: Aug-18-2015$
* @date Aug-18-2015
*
* $Version: 1.5$
* @version 1.5
*
* Description FS65xx driver source file
* @brief The function FS65xx driver source file
*
* --------------------------------------------------------------------
* $Name: $
*******************************************************************************/
/*******************************************************************************
*
* @mainpage FS65xx driver for MPC574xP
*
* @section Intro Introduction
*
* This package contains PowerSBC driver allowing to control FS65xx.
* PwSBC driver was created as a demo code to enable our customers
* to start their development quickly and to demonstrate functionality of the FS65xx
* chip. Presented driver is not AUTOSAR nor ISO26262 compliant. This driver package
* needs so-called MPC5744P Basic software drivers, which present the basic layer
* for this application.
*
* The key features of this package are the following:
* - Offer driver allowing to write and read into and from PwSBC registers
* - Switch PwSBC modes (low power, normal etc.)
* - Treat all interrupt sources (events)
* - Supervise voltages presented in the PwSBC interface
*
* For more information about the functions and configuration items see these documents:
*
*******************************************************************************
*
* @attention
*
*******************************************************************************/
/*==================================================================================================
* Project : FS65xx
* Platform : MPC574xP
* Dependencies : MPC574xP - Basic SW drivers.
* All Rights Reserved.
==================================================================================================*/
/*==================================================================================================
Revision History:
Modification This function
Author (core ID) Date D/M/Y Name Description of Changes
B35993 / BRNY001 18/08/2015 ALL Driver ported from MC33908
BRNY001 30/10/2016 FS65_ProcessSPI Added missing registers (WU_source, Diag_Vcore, Diag_vcca)
BRNY001 04/10/2017 LDT related functions Bug correction
--------------------------- ---------- ------------ ------------------------------------------
==================================================================================================*/
#include "typedefs.h"
#include "FS65xx_driver.h"
#include "FS65xx.h"
#include "sbc_65xx.h"
#include "SpiIf.h"
#include "common.h"
struct {
uint32_t writeCmd; ///last write command
uint32_t readCmd; ///last read command
uint32_t stateSPI; ///actual state of the state machine
Status_32B_tag statusPwSBC; ///actual PwSBC status
uint32_t response; ///last PwSBC response
uint32_t FSdelayDisabled; ///disables delay 3.5 us after a secure command, 1 - disabled, 0 - enabled
} SPIstruct;
struct {
uint32_t WD_answer; ///current content of the WD_answer register
register32_struct currentLFSR; ///last LFSR state
} PITstruct;
/*==================================================================================================
/ Global Variables
*==================================================================================================*/
uint8_t FS65_Error = FS65_ERROR_OK;
/*==================================================================================================*
* User-Defined Initial Values for FS65xx registers *
*==================================================================================================*
* Fill-in this table with the initialization values for the INIT registers *
* Don't bother with the secured bits, they are comuted by the initialization functions *
*==================================================================================================*/
FS65_RegVal_struct FS65_Registers_InitValues = {
0x00, // INIT_VREG;
0x43, //0x41, // INIT_WU1; io_0 up and high, io_4 any edge
0xC0, //0x40, // INIT_WU2; io_5 any edge
0x00, // INIT_INT;
0x00, // INIT_INH_INT;
0xF4, // CAN_LIN_MODE; CAN in Normal mode
0x60, // INIT_FS1B_TIMING;
0x00, // INIT_SUPERVISOR;
0x10, // INIT_FAULT;
//0x4D, // INIT_FSSM: IO_23 is fail-safe
0x00, // INIT_FSSM: IO_23 not fail-safe
0x10, // INIT_SF_IMPACT;
//(WD_WIN_4 << 4), // WD_WINDOW;0x30
// (WD_WIN_128<<4),
(WD_DISABLE<<4),//将喂狗的时间由64-128改为32-64ms
0xB2, // WD_LFSR;
0x00, // INIT_WD_CNT;
0xE0, // INIT_VCORE_OVUV_IMPACT;
0xE0, // INIT_VCCA_OVUV_IMPACT;
0xE0, // INIT_VAUX_OVUV_IMPACT;
};
static uint32 txData, rxData;
static uint32_t sbc_start = 0;
static uint32_t fs65_error_code;
uint32_t reset_source;
uint32_t fault_error_counter = 0;
/*==================================================================================================*/
/* User Callback */
/*==================================================================================================*/
/****************************************************************************!
* @par Description
* When an error is detected by the functions FS65_Init() or FS65_GetStatus(),
* this function is called. In the default implementation of this callback,
* the port PA1 is toggled every 1second.
* The users can change this behavior according to its application.
********************************************************************************/
void FS65_ErrorCallback(void) {
//Add your code below -----------
}
/****************************************************************************!
* @par Description
* When an INTb pulse is generated by the FS65 because of a SPI error, this
* user callback is called by the interrupt routine FS65_IsrSIUL
********************************************************************************/
void FS65_SPI_INT_Callback(void) {
//Add your code below
}
/****************************************************************************!
* @par Description
* When an INTb pulse is generated by the FS65 because of a CAN or LIN
* wake-up, this user callback is called by the interrupt routine FS65_IsrSIUL
********************************************************************************/
void FS65_PHYWU_INT_Callback(void) {
//Add your code below
}
/****************************************************************************!
* @par Description
* When an INTb pulse is generated by the FS65 because of automatic
* wake-up, this user callback is called by the interrupt routine FS65_IsrSIUL
********************************************************************************/
void FS65_AutoWU_INT_Callback(void) {
//Add your code below
}
/****************************************************************************!
* @par Description
* When an INTb pulse is generated by the FS65 because of the Long Duration Timer
* this user callback is called by the interrupt routine FS65_IsrSIUL
********************************************************************************/
void FS65_LDTWU_INT_Callback(void) {
//Add your cod