/******************** (C) COPYRIGHT 2015 TRARRII ******************************
* File Name : User_sbc.c
* Author : ZhaiZhipeng
* Version : V1.0.0
* Date : 10/19/2015
* Toolversion :TASKING VX-toolset for C166 v3.1r2
* Bussystem : SPI
* Description : SBC Driver Code
* Software is licensed for : Changchun Trarrii Electronic Technology Co.,Ltd.
*******************************************************************************/
//SBC SPI 配置:小端,极性=0,发送16字节 而且管脚接反需要重新配置引脚
//1,关看门狗
//2,开2,3 -- Normal Mode VCC2_ON(bit3,bit4)为"01",VCC3_ON(bit5)为"1",MODE(bit6,bit7)为"00"
//3,配置唤醒源 --- SBC Normal Mode下配置WK_CTRL_2寄存器中 WK1_EN(bit0), WK2_EN(bit1), WK3_EN(bit2)都为"1",然后再配置
//3,进入SLEEP模式 但是VCC3不关 --- M_S_CTRL进入Sleep Mode / Stop Mode
//
//
#include ".\System\main.h"
#define delayspims 500
//1、上电后,VCC1(5V)、 VCC2(5V)、VCC3(选择3.3V输出)正常工作
u16 volatile rtc_flage=0;//控制休眠用的rct标志
u16 volatile sbc_flage=0;
uword SpiSbcSend(uword uwData)
{
U1C0_SSC_vSetSELO(0);
U1C0_SSC_vSendData(uwData);
while(0==U1C0_SSC_ubTxDataReady());
U1C0_SSC_vSetSELO(1);
return SpiSbcGet();
}
/*******************************************************************************
*Function Name:SpiSbcGet
*Description: 读取SBC寄存器值
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
uword SpiSbcGet(void)
{
while(0==U1C0_SSC_ubRxDataReady());
return(U1C0_SSC_uwGetData());
}
/*******************************************************************************
*Function Name:SbcInit
*Description: SBC初始化
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcInit(void)
{
// Delay2();
ClearWk1();
// Delay2();
ClearWk2();
// Delay2();
SbcConWkSourcCanDis();
// Delay2();
SbcConWkSourcDis();
// Delay2();
// SbcWkPullOn();
SbcVcc23on();
// Delay2();
}
void SbcSleep(void)
{
// Delay2();
// SbcWkPullOn();
Delay2();
SbcConWkSourc();//配置wk1 和wk2 为唤醒源
// Delay2();
// SbcConWkSourcCan();//配置can为唤醒源
Delay2();
SbcVcc12off();//进入sleep模式 并且关闭vcc2和vcc3
Delay2();
}
/*******************************************************************************
*Function Name:SbcWd1000ms
*Description: SBC喂狗
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcWd1000ms(void)
{
SpiSbcSend(0X0683);
}
/*******************************************************************************
*Function Name:SbcVcc23on
*Description: 打开SBC VCC2,VCC3
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcVcc23on(void)
{
SpiSbcSend(0X2881);
}
void SbcVcc2on(void)
{
SpiSbcSend(0X0881);
}
void SbcVcc3on(void)
{
SpiSbcSend(0X2081);
}
/*******************************************************************************
*Function Name:SbcWkPullOn
*Description: 配置唤醒管脚的上下拉
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcWkPullOn(void)
{
//WK1->Pull-down 10 3G high low high
//WK2->Pull-up 01 BT low high low
//WK3->Pull-down because board is Pull-down 01
SpiSbcSend(0X1688);
}
/*******************************************************************************
*Function Name:SbcConWkSourc
*Description: 使能唤醒源WK1 WK2 WK3
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcConWkSourc(void)
{
// SpiSbcSend(0X0787);
SpiSbcSend(0X0387);
}
/*******************************************************************************
*Function Name:SbcConWkSourcDis
*Description: 失能唤醒源WK1 WK2 WK3
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcConWkSourcDis(void)
{
SpiSbcSend(0X0087);
}
/*******************************************************************************
*Function Name:SbcConWkSourcCan
*Description: 使能唤醒源CAN
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcConWkSourcCan(void)
{
// SpiSbcSend(0X0184); //设置休眠唤醒的功能
SpiSbcSend(0X0084);//去掉休眠唤醒的功能
}
/*******************************************************************************
*Function Name:SbcConWkSourcCanDis
*Description: 失能唤醒源CAN
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcConWkSourcCanDis(void)
{
SpiSbcSend(0X0384);
}
/*******************************************************************************
*Function Name:SbcSleep
*Description: SBC休眠
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void SbcVcc12off(void)
{
// SpiSbcSend(0X6081);//休眠只有 只有VCC3输出
// SpiSbcSend(0X4081);//休眠只有 只有VCC3不输出
SpiSbcSend(0X4481);//休眠只有 只有VCC3不输出 并且设置vcc1过载进入复位模式和失效安全模式
}
/*******************************************************************************
*Function Name:ClearWk1
*Description: 清除WK1 WK2 WK3唤醒标志
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void ClearWk1() //清楚唤醒标志位 寄存器1
{
SpiSbcSend(0XffC6);
}
/*******************************************************************************
*Function Name:ClearWk2
*Description: 清除CAN唤醒标志
*Params: NONE
*Return: NONE
*Limitation: NONE
*Date: 2015-10-19
*Version: V1.0.0
*Record: 2015-10-19 Create
*Author: ZhaiZhipeng
*******************************************************************************/
void ClearWk2() //清楚唤醒标志位 寄存器2
{
SpiSbcSend(0XffC7);
}
评论7