/********************************************************
*
* 北京四维卓信电子有限公司
*
* 【OpenADSP开源社区】
*
********************************************************/
#include <cdef21489.h>
#include <def21489.h>
#include <sru.h>
#include <signal.h>
#include <sysreg.h>
#include "PBLED_test.h"
int main(void)
{
InitPLL();
Config_SRU_LEDS();
Setup_Ints();
while(1);
}
void InitPLL(void)
{
int n;
*pPMCTL = (PLLM16|PLLD4|DIVEN);
*pPMCTL |= PLLBP;
*pPMCTL ^= DIVEN;
for(n = 0; n < 10000; n++ )
{
asm("nop;");
}
*pPMCTL ^= PLLBP;
}
void Config_SRU_LEDS(void)
{
SRU(FLAG4_O,DPI_PB06_I); //DPI => We can use flags.
SRU(FLAG5_O,DPI_PB07_I); //DPI => We can use flags.
SRU(FLAG6_O,DPI_PB08_I); //DPI => We can use flags.
SRU(FLAG7_O,DPI_PB13_I); //DPI => We can use flags.
}
void LED0_ON(void)
{
SRU(HIGH,DPI_PBEN06_I);
}
void LED1_ON(void)
{
SRU(HIGH,DPI_PBEN07_I);
}
void LED2_ON(void)
{
SRU(HIGH,DPI_PBEN08_I);
}
void LED3_ON(void)
{
SRU(HIGH,DPI_PBEN13_I);
}
void LED0_OFF(void)
{
SRU(LOW,DPI_PBEN06_I);
}
void LED1_OFF(void)
{
SRU(LOW,DPI_PBEN07_I);
}
void LED2_OFF(void)
{
SRU(LOW,DPI_PBEN08_I);
}
void LED3_OFF(void)
{
SRU(LOW,DPI_PBEN13_I);
}
void Config_SRU_INTS(void)
{
SRU(LOW,DAI_PB15_I); //assign pin buffer 15 low so it is an input
SRU(LOW,DAI_PB16_I); //assign pin buffer 16 low so it is an input
SRU(LOW,DAI_PB19_I); //assign pin buffer 19 low so it is an input
SRU(LOW,DAI_PB20_I); //assign pin buffer 20 low so it is an input
SRU(DAI_PB15_O,MISCA0_I); //route so that DAI pin buffer 15 connects to MISCA1
SRU(DAI_PB16_O,MISCA1_I); //route so that DAI pin buffer 16 connects to MISCA2
SRU(DAI_PB19_O,MISCA2_I); //route so that DAI pin buffer 19 connects to MISCA1
SRU(DAI_PB20_O,MISCA3_I); //route so that DAI pin buffer 20 connects to MISCA2
SRU(LOW,PBEN15_I); //assign pin 15 low so it is an input
SRU(LOW,PBEN16_I); //assign pin 16 low so it is an input
SRU(LOW,PBEN19_I); //assign pin 19 low so it is an input
SRU(LOW,PBEN20_I); //assign pin 20 low so it is an input
}
//////////////////////////////////////////////////////////////////////////////
// void Setup_Ints(void)
//
// PURPOSE: Configure the system to accept the push buttons as inputs
//
//////////////////////////////////////////////////////////////////////////////
void Setup_Ints(void)
{
Config_SRU_INTS();
(*pDAI_IRPTL_PRI) = (SRU_EXTMISCA0_INT | SRU_EXTMISCA1_INT | SRU_EXTMISCA2_INT | SRU_EXTMISCA3_INT ); //unmask individual interrupts
(*pDAI_IRPTL_RE) = (SRU_EXTMISCA0_INT | SRU_EXTMISCA1_INT | SRU_EXTMISCA2_INT | SRU_EXTMISCA3_INT ); //make sure interrupts latch on the rising edge
//Set up interrupt priorities
sysreg_bit_set(sysreg_IMASK, DAIHI); //DAIHI//make DAI interrupts high priority
interrupt(SIG_DAIH,DAIroutine);
}
//////////////////////////////////////////////////////////////////////////////
// void DAIroutine(int sig_int)
//
// PURPOSE: ISR for pushbutton 1,2,3,4
//
//////////////////////////////////////////////////////////////////////////////
void DAIroutine(int sig_int)
{
int iTest;
iTest = (*pDAI_IRPTL_H); // reading pDAI_IRPTL_H clears the latched interrupt.
if( SRU_EXTMISCA0_INT == iTest )
{
LED0_ON();
LED1_ON();
LED2_ON();
LED3_ON();
}
else if( SRU_EXTMISCA1_INT == iTest )
{
LED0_OFF();
LED1_ON();
LED2_OFF();
LED3_ON();
}
else if( SRU_EXTMISCA2_INT == iTest )
{
LED0_ON();
LED1_OFF();
LED2_ON();
LED3_OFF();
}
else if( SRU_EXTMISCA3_INT == iTest )
{
LED0_OFF();
LED1_OFF();
LED2_OFF();
LED3_OFF();
}
}