📄 hall.c
字号:
/*
* Hall.c
*
* Target : ARM
*
* Copyright (c) Texas Instruments 1995
*
*/
#include "sys_types.h"
#include "nucleus.h"
#include <assert.h>
#include "iq.h"
//#include "hall.h"
#include "mem.h"
#include "inth.h"
#include "armio.h"
#include "sim.h"
//#include "pwr.h"
//#include "../melody/madebug.h"
unsigned char gHallStatus; // 0--gHallStatus the flip is opened
// 1--gHallStatus the flip is closed
unsigned short initial_state;
unsigned short pre_state=-1;
extern int g_switchon;
extern int MMIStart_completed;
extern void MI_dbgPrintf(const char* const format, ...);
//extern driver_Parameter drvpara;
#define HALL_SIM_CMD (MEM_SIM + 0x00)
#define HALL_SIM_MASK (MEM_SIM + 0x0E)
#define HALL_SIM_CONF2 (MEM_SIM + 0x06)
#define HALL_SIM_IT_CD (MEM_SIM + 0x10)
void Hall_OC_hisr_entry( void );
typedef struct {
NU_HISR hisr;
char hisr_stack[512];
} T_HISR_INFOS;
T_HISR_INFOS Hall_OC_hisr = {0};
/*
* Hall_Init
*
*
* if receive buffer full, read char
* if transmitter empty, change direction, transmit a dummy char
*
*/
void Hall_Init(void)
{
unsigned short tmp;
// unmask interrupt register
* (volatile unsigned short *) INTH_MASK_REG2 &= ~0x01; //unmask Hall interrupt;
* (volatile unsigned short *) HALL_SIM_MASK &= ~(1<<5); //unmask MASK_SIM_CD
// time delay for filtering of SIM_CD time-unit 1024*Tck13M ( card extraction )
// or 8192 *Tck13M ( card insertion )
*(volatile unsigned short*) HALL_SIM_CONF2 |= 0x000e;
initial_state= *( (volatile unsigned short *)MEM_ARMIO ) & 0x04;
if( initial_state != 0 )
gHallStatus = 1;
else
gHallStatus = 0;
NU_Create_HISR( &Hall_OC_hisr.hisr,
"HALL_OC_HISR",
Hall_OC_hisr_entry,
2,
Hall_OC_hisr.hisr_stack,
sizeof(Hall_OC_hisr.hisr_stack) );
}
void Hall_OC_IntHandler( void )
{
unsigned short stat, cur_state;
// mask interrupt register
* (volatile unsigned short *) INTH_MASK_REG2 |= 0x01; //mask Hall interrupt;
*(volatile unsigned short*) HALL_SIM_CONF2 |= 0x000e;
stat = *( volatile unsigned short*) HALL_SIM_IT_CD;
if( stat )
NU_Activate_HISR(&Hall_OC_hisr.hisr);
else
* (volatile unsigned short *) INTH_MASK_REG2 &= ~0x01; //unmask Hall interrupt;
}
void Hall_OC_hisr_entry( void )
{
unsigned short stat;
stat = *( (volatile unsigned short *)MEM_ARMIO ) & 0x04;
MI_dbgPrintf("HALL !!!!! -- stat=%d, initial_state=0x%x", stat, initial_state );
if( MMIStart_completed == 0 ){
if( stat != 0 )
gHallStatus = 1;
else
gHallStatus = 0;
* (volatile unsigned short *) INTH_MASK_REG2 &= ~0x01; //unmask Hall interrupt;
pre_state = stat;
return;
}
if( pre_state == stat ){
* (volatile unsigned short *) INTH_MASK_REG2 &= ~0x01; //unmask Hall interrupt;
return;
}
else
pre_state = stat;
SendVirtualKeyToMMI(0,100);
}
int GetHallStatus(void){
unsigned short stat;
#ifndef _INNOVATION_EMULATOR_
// if ((*( (volatile unsigned short *)MEM_ARMIO ) & 0x04)!=0)
// {
// return 1; //the flip is opened
// } else
// {
// return 0; //the flip is closed
// }
return gHallStatus;
#else
return 1;
#endif
}
/*
return: <0 , abnormal status
=0 , the flip is closed
=1 , the flip is opened
*/
int HallStatus(void){
#ifndef _INNOVATION_EMULATOR_
//*((volatile UINT16 *) 0xfffef006) &= 0XFFBF;
//*((volatile UINT16 *) 0xfffe4804) |= 0X04;
#if 0
if( MMIStart_completed == 0 )
{
if ((*( (volatile unsigned short *)MEM_ARMIO ) & 0x04)!=0)
return 1; //the flip is opened
else
return 0; //the flip is closed
}
else
#endif
return gHallStatus;
#else
return 1;
#endif
}
int HallInterruptHandler (void){
int i;
i = HallOnOffDigitalFilter();
if( i == 3 )
return 1; //noise signal
else{
if( i == gHallStatus)
return 1; //noise signal
else
{
gHallStatus= i;
return 0; //normal
}
}
}
int HallOnOffDigitalFilter(void){
int i = 0;
if ((*((volatile unsigned short *)MEM_ARMIO ) & 0x04)!=0)
{ //the flip is opened
for (i = 0; i < 10; i++)
{
rvf_delay(3);
if (((*((volatile unsigned short *)MEM_ARMIO ) & 0x04)==0))
return 3; ///this is hall noise
}
//open Normal
return 1;
}
else
{//the flip is closed
for (i = 0; i < 10; i++)
{
rvf_delay(3);
if (((*((volatile unsigned short *)MEM_ARMIO ) & 0x04)!=0))
return 3; ///close: this is hall noise
}
//close: Normal
return 0;
}
}
/* added trace_pctm command*/
#ifdef DRVPCTMTRACE
void TraceHallOnOff(void) {
RivieraTrace_Chunhui("_HallOnOff=", GetHallStatus() );
return;
}
#endif
void AI_UnmaskHall_IT( void )
{
* (volatile unsigned short *) INTH_MASK_REG2 &= ~0x01; //unmask Hall interrupt;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -