📄 pca.c
字号:
/*
*********************************************************************************
* Copyright (c) 2005 ASIX Electronic Corporation All rights reserved.
*
* This is unpublished proprietary source code of ASIX Electronic Corporation
*
* The copyright notice above does not evidence any actual or intended
* publication of such source code.
*********************************************************************************
*/
/*================================================================================
* Module Name : pca.c
* Purpose : This file include PCA interrupt service routine and
* PCA driver.
* Author : Robin Lee
* Date : 2006-06-23
* Notes :
* $Log$
*================================================================================
*/
/* INCLUDE FILE DECLARATIONS */
#include "reg80390.h"
#include "types.h"
#include "pca.h"
/* STATIC VARIABLE DECLARATIONS */
static U8_T pcaIntrFlag = 0;
static U8_T pcaCapHiReg[5] = {0};
static U8_T pcaCapLoReg[5] = {0};
static U8_T pcaSwTimerFlag = 0;
static U32_T pcaOverFlowCount = 0;
static U32_T pcaCapVal[5] = 0;
static U32_T pcaCexVal[5] = 0;
static void PcaDebug(void);
/* LOCAL SUBPROGRAM DECLARATIONS */
static void pca_ISR(void);
static void pca_Func(void);
/* LOCAL SUBPROGRAM BODIES */
/*
*--------------------------------------------------------------------------------
* static void PcaISR(void)
* Purpose :
* Params :
* Returns :
* Note :
*--------------------------------------------------------------------------------
*/
static void pca_ISR(void) interrupt 8 //use interrupt 3 (0x43)
{
pca_Func();
}
/*
*--------------------------------------------------------------------------------
* static void pca_Func(void)
* Purpose : PCA interrupt service routine. It will determine what mode is in each module
* Params : none.
* Returns : none.
* Note :
*--------------------------------------------------------------------------------
*/
static void pca_Func(void)
{
while(1)
{
EA = 0;
pcaIntrFlag = CCON;
EA = 1;
if (pcaIntrFlag & PCA_CCF0)
{
pcaIntrFlag &= ~PCA_CCF0;
pcaCapHiReg[PCA_MODULE0] = CCAPH0;
pcaCapLoReg[PCA_MODULE0] = CCAPL0;
pcaCapVal[0] = (U32_T)(((U16_T)pcaCapHiReg[PCA_MODULE0] << 8) | ((U16_T)pcaCapLoReg[PCA_MODULE0]));
switch (CCAPM0 & 0x7E)
{
case PCA_CAP_POS :
case PCA_CAP_NEG :
case PCA_CAP_POS_NEG :
break;
case PCA_SW_TIMER :
pcaSwTimerFlag |= PCA_CCF0;
break;
case PCA_HI_SPEED_OUT :
// PCA_ModuleTimer(PCA_MODULE0, 0);
break;
case PCA_8BIT_PWM :
// PCA_ModuleTimer(PCA_MODULE0, 0);
break;
}
}
else if (pcaIntrFlag & PCA_CCF1)
{
pcaIntrFlag &= ~PCA_CCF1;
pcaCapHiReg[PCA_MODULE1] = CCAPH1;
pcaCapLoReg[PCA_MODULE1] = CCAPL1;
pcaCapVal[1] = (U32_T)(((U16_T)pcaCapHiReg[PCA_MODULE1] << 8) | ((U16_T)pcaCapLoReg[PCA_MODULE1]));
switch (CCAPM1 & 0x7E)
{
case PCA_CAP_POS :
case PCA_CAP_NEG :
case PCA_CAP_POS_NEG :
break;
case PCA_SW_TIMER :
pcaSwTimerFlag |= PCA_CCF1;
break;
case PCA_HI_SPEED_OUT :
// PCA_ModuleTimer(PCA_MODULE1, 0);
break;
case PCA_8BIT_PWM :
// PCA_ModuleTimer(PCA_MODULE1, 0);
break;
}
}
else if (pcaIntrFlag & PCA_CCF2)
{
pcaIntrFlag &= ~PCA_CCF2;
pcaCapHiReg[PCA_MODULE2] = CCAPH2;
pcaCapLoReg[PCA_MODULE2] = CCAPL2;
pcaCapVal[2] = (U32_T)(((U16_T)pcaCapHiReg[PCA_MODULE2] << 8) | ((U16_T)pcaCapLoReg[PCA_MODULE2]));
switch (CCAPM2 & 0x7E)
{
case PCA_CAP_POS :
case PCA_CAP_NEG :
case PCA_CAP_POS_NEG :
break;
case PCA_SW_TIMER :
pcaSwTimerFlag |= PCA_CCF2;
break;
case PCA_HI_SPEED_OUT :
// PCA_ModuleTimer(PCA_MODULE2, 0);
break;
case PCA_8BIT_PWM :
// PCA_ModuleTimer(PCA_MODULE2, 0);
break;
}
}
else if (pcaIntrFlag & PCA_CCF3)
{
pcaIntrFlag &= ~PCA_CCF3;
pcaCapHiReg[PCA_MODULE3] = CCAPH3;
pcaCapLoReg[PCA_MODULE3] = CCAPL3;
pcaCapVal[3] = (U32_T)(((U16_T)pcaCapHiReg[PCA_MODULE3] << 8) | ((U16_T)pcaCapLoReg[PCA_MODULE3]));
switch (CCAPM3 & 0x7E)
{
case PCA_CAP_POS :
case PCA_CAP_NEG :
case PCA_CAP_POS_NEG :
break;
case PCA_SW_TIMER :
pcaSwTimerFlag |= PCA_CCF3;
break;
case PCA_HI_SPEED_OUT :
// PCA_ModuleTimer(PCA_MODULE3, 0);
break;
case PCA_8BIT_PWM :
// PCA_ModuleTimer(PCA_MODULE3, 0);
break;
}
}
else if (pcaIntrFlag & PCA_CCF4)
{
pcaIntrFlag &= ~PCA_CCF4;
pcaCapHiReg[PCA_MODULE4] = CCAPH4;
pcaCapLoReg[PCA_MODULE4] = CCAPL4;
pcaCapVal[4] = (U32_T)(((U16_T)pcaCapHiReg[PCA_MODULE4] << 8) | ((U16_T)pcaCapLoReg[PCA_MODULE4]));
switch (CCAPM4 & 0x7E)
{
case PCA_CAP_POS :
case PCA_CAP_NEG :
case PCA_CAP_POS_NEG :
break;
case PCA_SW_TIMER :
pcaSwTimerFlag |= PCA_CCF4;
break;
case PCA_HI_SPEED_OUT :
// PCA_ModuleTimer(PCA_MODULE4, 0);
break;
case PCA_8BIT_PWM :
// PCA_ModuleTimer(PCA_MODULE4, 0);
break;
}
}
else if (pcaIntrFlag & PCA_CF)
{
pcaOverFlowCount ++;
}
else
break;
}
}
/* EXPORTED SUBPROGRAM BODIES */
/*
*--------------------------------------------------------------------------------
* void PCA_ValueInit(void)
* Purpose : Initial all global values in PCA module.
* Params : none
* Returns : none
* Note :
*--------------------------------------------------------------------------------
*/
void PCA_ValueInit(void)
{
U8_T i;
pcaIntrFlag = 0;
pcaSwTimerFlag = 0;
pcaOverFlowCount = 0;
for (i=0 ; i<5 ; i++)
{
pcaCapHiReg[i] = 0;
pcaCapLoReg[i] = 0;
}
}
/*
*--------------------------------------------------------------------------------
* void PCA_ModeSetup(U8_T modeVal, U8_T ctrlVal)
* Purpose : AX11000 PCA mode configuration and initial global values.
* Params : modeVal - CMOD register for counter overflow interrupt and clock frequency.
* ctrlVal - control register to start counter and clear interrupt flag.
* Returns : none.
* Note :
*--------------------------------------------------------------------------------
*/
void PCA_ModeSetup(U8_T modeVal, U8_T ctrlVal)
{
CMOD = modeVal;
CCON = ctrlVal;
PCA_ValueInit();
}
/*
*--------------------------------------------------------------------------------
* void PCA_ModuleSetup(U8_T moduleNum, U8_T modeType,
* U8_T intrEnb, U16_T timerVal)
* Purpose : Configure one module type, interrupt and compare/capture registers.
* Params : moduleNum - a module number (0 ~ 4)
* modeType - the type in the module
* intrEnb - interrupt enable if need
* timerVal - compare/capture register value if need
* Returns :
* Note :
*--------------------------------------------------------------------------------
*/
void PCA_ModuleSetup(U8_T moduleNum, U8_T modeType, U8_T intrEnb, U16_T timerVal)
{
PCA_ValueInit();
switch (moduleNum)
{
case PCA_MODULE0 :
CCAPL0 = (U8_T)(timerVal & 0x00FF);
CCAPH0 = (U8_T)((timerVal & 0xFF00) >> 8);
CCAPM0 = modeType | intrEnb;
break;
case PCA_MODULE1 :
CCAPL1 = (U8_T)(timerVal & 0x00FF);
CCAPH1 = (U8_T)((timerVal & 0xFF00) >> 8);
CCAPM1 = modeType | intrEnb;
break;
case PCA_MODULE2 :
CCAPL2 = (U8_T)(timerVal & 0x00FF);
CCAPH2 = (U8_T)((timerVal & 0xFF00) >> 8);
CCAPM2 = modeType | intrEnb;
break;
case PCA_MODULE3 :
CCAPL3 = (U8_T)(timerVal & 0x00FF);
CCAPH3 = (U8_T)((timerVal & 0xFF00) >> 8);
CCAPM3 = modeType | intrEnb;
break;
case PCA_MODULE4 :
CCAPL4 = (U8_T)(timerVal & 0x00FF);
CCAPH4 = (U8_T)((timerVal & 0xFF00) >> 8);
CCAPM4 = modeType | intrEnb;
break;
}
}
/*
*--------------------------------------------------------------------------------
* void PCA_ModuleTimer(U8_T moduleNum, U16_T newtimerVal)
* Purpose : Set the timeout value into a module which is configured in compare mode
* Params : moduleNum - module number (0 ~ 4)
* newtimerVal - the new value in the compare register.
* Returns : none
* Note :
*--------------------------------------------------------------------------------
*/
void PCA_ModuleTimer(U8_T moduleNum, U16_T newtimerVal)
{
switch (moduleNum)
{
case PCA_MODULE0 :
CCAPL0 = (U8_T)(newtimerVal & 0x00FF);
CCAPH0 = (U8_T)((newtimerVal & 0xFF00) >> 8);
break;
case PCA_MODULE1 :
CCAPL1 = (U8_T)(newtimerVal & 0x00FF);
CCAPH1 = (U8_T)((newtimerVal & 0xFF00) >> 8);
break;
case PCA_MODULE2 :
CCAPL2 = (U8_T)(newtimerVal & 0x00FF);
CCAPH2 = (U8_T)((newtimerVal & 0xFF00) >> 8);
break;
case PCA_MODULE3 :
CCAPL3 = (U8_T)(newtimerVal & 0x00FF);
CCAPH3 = (U8_T)((newtimerVal & 0xFF00) >> 8);
break;
case PCA_MODULE4 :
CCAPL4 = (U8_T)(newtimerVal & 0x00FF);
CCAPH4 = (U8_T)((newtimerVal & 0xFF00) >> 8);
break;
}
}
/*
*--------------------------------------------------------------------------------
* U16_T PCA_GetModuleCaptureValue(U8_T moduleNum)
* Purpose : Get the capture value in each module.
* Params : moduleNum - a module number to get (0~4)
* Returns : valCapture - capture register value
* Note :
*--------------------------------------------------------------------------------
*/
U16_T PCA_GetModuleCaptureValue(U8_T moduleNum)
{
U16_T valCapture = 0;
valCapture = pcaCapVal[moduleNum];
return valCapture;
}
/*
*--------------------------------------------------------------------------------
* U8_T PCA_GetWhichSwTimer(void)
* Purpose : Get which module has a software timer out.
* Params : none.
* Returns : pcaSwTimerFlag - indicate which module in software timer timeout.
* Note :
*--------------------------------------------------------------------------------
*/
U8_T PCA_GetWhichSwTimer(void)
{
return pcaSwTimerFlag;
}
/* End of pca.c */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -