📄 rotary_test.c
字号:
/*******************************************************************
Analog Devices, Inc. All Rights Reserved.
This software is proprietary and confidential. By using this software
you agree to the terms of the associated Analog Devices License Agreement.
Project Name: Power_On_Self_Test
Hardware: ADSP-BF518F EZ-Board
Description: This examples performs a rotary test on the EZ-Board.
*******************************************************************/
#include <cdefBF518.h>
#include <ccblkfn.h>
#include <sys\exception.h>
#include <stdio.h>
#include <signal.h>
#include "Timer_ISR.h"
#include "PBLED_test.h"
int upcount = 0;
int downcount = 0;
/*******************************************************************
* function prototypes
*******************************************************************/
void Init_Rotary(void);
void Init_Rotary_Interrupts(void);
EX_INTERRUPT_HANDLER(CNT_ISR);
/*******************************************************************
* global variables
*******************************************************************/
int g_BlinkSpeed = BLINK_SLOW;
bool bLedsAllOff = 0;
bool bLedsAllOn = 0;
bool bMinHit = 0;
bool bMaxHit = 0;
bool bZeroHit = 0;
/*******************************************************************
* Function: Init_Keypad
* Description: This function configures the Rotary counters and
* initializes the PORT pins that are used
*******************************************************************/
void Init_Rotary(void)
{
/* initialize PORTH for alternate function - CNT CZM, CNT CUD, & CNT CDG */
*pPORTH_FER = 0x0070;
*pPORTH_MUX = 0x03C;
*pCNT_IMASK = 0x11E; /* ctr zeroed by zero marker, downcount and upcount int enable */
*pCNT_COMMAND = 0x1000; /* enable single zero-marker clear */
*pCNT_DEBOUNCE = 0x2; /* 4x filter time */
*pCNT_CONFIG = 0x001; /* enable zero counter, enable counter */
}
/*******************************************************************
* Function: Init_Rotary_Interrupts
* Description: Initializes Rotary Counter interrupts
*******************************************************************/
void Init_Rotary_Interrupts(void)
{
register_handler(ik_ivg11, CNT_ISR); /* assign ISRs to interrupt vectors */
*pILAT |= EVT_IVG11; /* clear pending IVG11 interrupts */
ssync();
*pSIC_IMASK0 |= 0x8000000; /* enable Counter (CNT) Interrupt */
}
/*******************************************************************
* Function: TEST_ROTARY
* Description: This tests the rotary counter by slowing down and
* speeding up a simple blink pattern. When the rotary
* counter is pressed the blink speed resets to the default
*******************************************************************/
int TEST_ROTARY(void)
{
int bSuccess = 1; /* returning 1 indicates a pass, anything else is a fail */
/* init globals, do this each time because we may be called more than once */
g_BlinkSpeed = BLINK_SLOW;
bLedsAllOff = 0;
bLedsAllOn = 0;
bMinHit = 0;
bMaxHit = 0;
bZeroHit = 0;
/* initialize timers */
Init_Timers();
Init_Timer_Interrupts();
/* intialize rotary register and interrupts */
Init_Rotary();
Init_Rotary_Interrupts();
ClearSet_LED_Bank( (-1), 0x0000);
/* loop until min, max, and zero have all been hit */
while ( !bMinHit || !bMaxHit || !bZeroHit )
{
if( bLedsAllOff )
{
ClearSet_LED( (LED1), 0x0 ); /* turn off */
}
else if( bLedsAllOn )
{
ClearSet_LED( (LED1), 0x1 ); /* turn on */
}
else
{
LED_Bar_Reverse(g_BlinkSpeed); /* blink LEDs with new speed */
}
}
interrupt(ik_ivg12, SIG_IGN); /* disable this signal */
/* enable counter (CNT) interrupt */
*pSIC_IMASK0 &= (~(0x8000000));
/* initialize LEDs */
Init_LEDs();
return bSuccess;
}
/*******************************************************************
* Function: CNT_ISR
* Description: ISR for up, down, or button press for the rotary
*******************************************************************/
EX_INTERRUPT_HANDLER(CNT_ISR)
{
int Status = 0;
int Counter = 0;
signed int temp = 0;
Status = *pCNT_STATUS;
Counter = *pCNT_COUNTER;
/* upcount */
if (Status & 0x2)
{
/* check to see if maximum was reached */
if( (Counter > 50) )
{
bMaxHit = 1;
bLedsAllOn = 0;
bLedsAllOff = 1;
}
else if( (Counter < 50) && (Counter >= 0) )
{
bLedsAllOn = 0;
bLedsAllOff = 0;
g_BlinkSpeed -= 10;
}
}
/* downcount */
else if (Status & 0x4)
{
/* check to see if minimum reached */
if (Counter < -50)
{
bMinHit = 1;
bLedsAllOff = 0;
bLedsAllOn = 1;
}
else if( (Counter > -50) && (Counter < 0) )
{
bLedsAllOff = 0;
bLedsAllOn = 0;
g_BlinkSpeed += 10;
}
}
else if (Status & 0x100)
{
*pCNT_COMMAND = 0x1000; /* enable single zero-marker clear */
}
/* check to see if the wheel has been pushed */
if (Status & 0x400)
{
bLedsAllOff = 0;
bLedsAllOn = 0;
bZeroHit = 1;
g_BlinkSpeed = BLINK_SLOW;
}
*pCNT_STATUS = Status; /* clear the bit */
/* make sure we never go less than 0 or else the blink routine
will take forever */
if( g_BlinkSpeed < 0 )
g_BlinkSpeed = BLINK_SLOW;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -