📄 seedvmp642_esambios.c
字号:
/********************************************************************/
/* Copyright 2004 by SEED Incorporated. */
/* All rights reserved. Property of SEED Incorporated. */
/* Restricted rights to use, duplicate or disclose this code are */
/* granted through contract. */
/* */
/********************************************************************/
/*
*---------SEEDVMP642_esambios.c---------
* This example uses a timer to read and write the ESAM.
*/
#include <stdio.h>
#include <std.h>
#include <log.h>
#include <sys.h>
#include <mem.h>
#include <sio.h>
#include <csl.h>
#include <csl_cache.h>
#include <csl_timer.h>
#include <csl_irq.h>
#include <hwi.h>
#include "seeddm642.h"
#include "seeddm642_esam.h"
#include "SEEDVMP642_esambioscfg.h"
Uint8 buffer[100];
Bool NewDataFlag = FALSE;
Bool NextDataBit = FALSE;
Uint8 ReadFlag = 0;
Uint8 esambit =0;
Uint8 reciveCnt = 0;
Uint8 esamcheck;
Uint8 esamdata;
Uns oldmask;
Uint32 intcnt=0;
Uint32 Timerintcnt =0;
Uint32 cnt=0;
Bool cntfirst = FALSE;
static Int TimerEventId1;
Int i;
extern far LOG_Obj trace;
Void main()
{
LOG_printf(&trace, "Test Esam!");
}
Void ext4_isr()
{
IRQ_disable(IRQ_EVT_EXTINT4);
HWI_disable();
IRQ_globalDisable();
cntfirst = TRUE;
NewDataFlag = TRUE;
intcnt++;
TimerEventId1 = TIMER_getEventId(hTimer1);
IRQ_reset(TimerEventId1);
IRQ_enable(TimerEventId1);
TIMER_start(hTimer1);
return;
}
Void timer_isr()
{
Timerintcnt++;
if(cntfirst == TRUE)
{
cnt++;
if(cnt ==3)
{
NextDataBit = TRUE;
cntfirst = FALSE;
cnt= 0;
}
}
else
{
cnt++;
if(cnt == 2)
{
cnt = 0;
NextDataBit = TRUE;
}
}
}
Void GetEsamDataTsk()
{
/* Reset ESAM */
SEEDDM642_rset(SEEDDM642_ESAMW, 0x0);
SEEDDM642_waitusec(10000);
SEEDDM642_rset(SEEDDM642_ESAMW, 0x4);
IRQ_reset(IRQ_EVT_EXTINT4);
IRQ_enable(IRQ_EVT_EXTINT4);
do//无数据接收到,继续等待
{
ReadFlag = seeddm642_esam_read((Uint32)(&buffer),(Uint32)(&reciveCnt));
}while(ReadFlag == 1);
for(i = 0;i<reciveCnt;i++)
{
LOG_printf(&trace,"recieve data is : 0x%x\n",buffer[i]);
}
for(;;)
{
}
}
int seeddm642_esam_read(Uint32 src, Uint32 length )
{
Uint8 *pdst;
Uint8 *plength;
Uint8 esamdata = 0;
Uint8 esambit = 0;
Uint8 esamcheck = 0;
Uint8 esamcount =0;
Uint32 i;
Uint32 n= 0;
Uint32 esamCnt =0;
/* Establish ricieve pointer */
pdst = (Uint8 *)src;
plength = (Uint8 *)length;
*plength = 0;
//打开中断
IRQ_enable(IRQ_EVT_EXTINT4);
//将IO口配置成为输入模式
SEEDDM642_rset(SEEDDM642_ESAMW, 0x4);
//如果读取标志置1,读取数据的一个BIT,共读9次,拼成一个字节
//第九个BIT为偶较验位
while(1)
{
if(NewDataFlag == FALSE)
{
//超时即数据接收完成,再无新数据产生
n++;
if(n == 1000)
{
n = 0;
esamCnt++;
}
if(esamCnt == 300)
{
esamCnt = 0;
if(esamcount ==0)
{
return 1;//无数据接收到
}
else
{
*plength = esamcount;
return 2;
}
}
}
else
{
//有新数据的产生,启动计数器
NewDataFlag = FALSE;
IRQ_disable(IRQ_EVT_EXTINT4);
//记数重新开始
esamCnt = 0;
for(i = 0;i<8;i++)
{
while(NextDataBit == FALSE){}
NextDataBit = FALSE;
esambit = SEEDDM642_rget(SEEDDM642_ESAMR);
esamcheck = esamcheck + (esambit & 0x1);
esamdata = esamdata + ((esambit & 0x1)<<i);
}
/*读较验位*/
while(NextDataBit == FALSE){}
NextDataBit = FALSE;
esambit = SEEDDM642_rget(SEEDDM642_ESAMR);
esamcheck = esamcheck + (esambit & 0x1);
if((esamcheck & 0x1) == 1)
{
*plength = esamcount;
TIMER_pause(hTimer1);
return 0;
}
*pdst++ = esamdata;
esamcount++;
esamdata = 0;
esamcheck = 0;
esambit = 0;
//停止计数器
TIMER_pause(hTimer1);
//打开中断
IRQ_reset(IRQ_EVT_EXTINT4);
IRQ_enable(IRQ_EVT_EXTINT4);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -