/*

* ======ICT_LCD_ADC.c ======

* LCD and ADC for the F2812 DSK

* Copyright 2008 by Jin-Yi You.

* Author : Jin-Yi You(Tony Yu)

* Date : 2008-7-7

*/

#include "DSP281x_Device.h" // DSP281x Headerfile Include File

#include "DSP281x_Examples.h" // DSP281x Examples Include File

#include "BSL_IO_F281x_V2.h" // ICT C2000 I/O Board V2.0 fonction definitions

// ADC start parameters

#define ADC_MODCLK 0x3 // HSPCLK = SYSCLKOUT/2*ADC_MODCLK2 = 150/(2*3) = 25MHz

#define ADC_CKPS 0x0 // ADC module clock = HSPCLK/1 = 25MHz/(1) = 25MHz

#define ADC_SHCLK 0x1 // S/H width in ADC module periods = 2 ADC cycle

#define BUF_SIZE 2 // Sample buffer size

// Global variable for this example

Uint16 SampleTable[BUF_SIZE];

Uint16 i,average;

void main(void)

{

// Step 1. Initialize System Control:

// PLL, WatchDog,peripheral Clocks to default state.

// This function is found in the DSP281x_SysCtrl.c file.

InitSysCtrl();

// Step 2. Clear all interrupts and Initialize PIE control registers :

// Disable CPU interrupts

DINT;

IER = 0x0000;

IFR = 0x0000;

// Step 3. Initialize PIE control and PIE vector table:

// Initialize PIE control registers to their default state.

// This function is found in the DSP281x_PieCtrl.c file.

InitPieCtrl();

// Initialize the PIE vector table with pointers to the shell Interrupt

// Service Routines (ISR).

// This function is found in DSP281x_PieVect.c.

InitPieVectTable();

// Step 4. Initialize all the ICT C2000 I/O Device Peripherals:

ICT_IO_BOARD_Initialize();

InitAdc(); // For this example, init the ADC

// Specific clock setting for this example:

EALLOW;

SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK

EDIS;

// Specific ADC setup for this example:

AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // S/H width

AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS; // ADC module clock

AdcRegs.ADCTRL3.bit.SMODE_SEL = 0; // Enable sequential sampling modes

AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode

AdcRegs.ADCMAXCONV.all =0x0; // 1 conv’s (1 total)

AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0; // Setup conv from ADCINA0

AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run

for (i=0; i<BUF_SIZE; i++)

{

SampleTable[i] = 0;

}

// Step 5. Enable Interrupt events:

AdcRegs.ADCTRL2.all = 0x2000; // Start SEQ1

EINT; // Enable Global interrupt INTM

ERTM; // Enable Global realtime interrupt DBGM

// Step 6. User specific code

// Take ADC data and log the in SampleTable array

while(1)

{

average = 0;

for (i=0; i<BUF_SIZE; i++)

{

while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt

// Software wait = (HISPCP*2) * (ADCCLKPS*2) * (CPS+1) cycles

// = (3*2) * (1*2) * (0+1) = 12 cycles

asm(" RPT #11 || NOP");

AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;

SampleTable[i] =((AdcRegs.ADCRESULT0>4) );

average = average + SampleTable[i];

}

average = (average/BUF_SIZE);

ICT_IO_LCD_Display(3,average & 0x00FF,average > 8);

}

// Step 7. IDLE loop. Just sit and loop forever (optional):

for(;;);

}

//======

// No more.

//======

/*

* ======ICT_EVTimer1.c ======

* EV Timer1/Timer2/Timer3/Timer4 for the F2812 DSK

* Copyright 2008 by Jin-Yi You.

* Author : Jin-Yi You(Tony Yu)

* Date : 2008-7-7

*/

#include "DSP281x_Device.h" // DSP281x Headerfile Include File

#include "DSP281x_Examples.h" // DSP281x Examples Include File

#include "BSL_IO_F281x_V2.h" // ICT C2000 I/O Board V2.0 fonction definitions

interrupt void eva_timer1_isr(void);

interrupt void eva_timer2_isr(void);

interrupt void evb_timer3_isr(void);

interrupt void evb_timer4_isr(void);

void init_eva_timer1(void);

void init_eva_timer2(void);

void init_evb_timer3(void);

void init_evb_timer4(void);

// Global counts used in this example

Uint32 EvaTimer1InterruptCount = 0;

Uint32 EvaTimer2InterruptCount = 100;

Uint32 EvaTimer3InterruptCount = 200;

Uint32 EvaTimer4InterruptCount = 300;

void main(void)

{

// Step 1. Initialize System Control:

// PLL, WatchDog,peripheral Clocks to default state.

// This function is found in the DSP281x_SysCtrl.c file.

InitSysCtrl();

// Step 2. Clear all interrupts and Initialize PIE control registers :

// Disable CPU interrupts

DINT;

IER = 0x0000;

IFR = 0x0000;

// Step 3. Initialize PIE control and PIE vector table:

// Initialize PIE control registers to their default state.

// This function is found in the DSP281x_PieCtrl.c file.

InitPieCtrl();

// Initialize the PIE vector table with pointers to the shell Interrupt

// Service Routines (ISR).

// This function is found in DSP281x_PieVect.c.

InitPieVectTable();

// Interrupts that are used in this example are re-mapped to

// ISR functions found within this file.

EALLOW; // This is needed to write to EALLOW protected registers

PieVectTable.T1PINT = &eva_timer1_isr;

PieVectTable.T2PINT = &eva_timer2_isr;

PieVectTable.T3PINT = &evb_timer3_isr;

PieVectTable.T4PINT = &evb_timer4_isr;

EDIS; // This is needed to disable write to EALLOW protected registers

// Step 4. Initialize ICT C2000 I/O Device Peripherals and your functions:

ICT_IO_BOARD_Initialize();

init_eva_timer1();

init_eva_timer2();

init_evb_timer3();

init_evb_timer4();

// Step 5. Enable Interrupt events:

// Enable PIE group 2 interrupt 4 for T1PINT

PieCtrlRegs.PIEIER2.bit.INTx4 = 1;

// Enable PIE group 3 interrupt 1 for T2PINT

PieCtrlRegs.PIEIER3.bit.INTx1 = 1;

// Enable PIE group 4 interrupt 4 for T3PINT

PieCtrlRegs.PIEIER4.bit.INTx4 = 1;

// Enable PIE group 5 interrupt 1 for T4PINT

PieCtrlRegs.PIEIER5.bit.INTx1 = 1;

// Enable CPU INT2 for T1PINT, INT3 for T2PINT, INT4 for T3PINT and INT5 for T4PINT:

IER |= (M_INT2 | M_INT3 | M_INT4 | M_INT5);

// Enable global Interrupts and higher priority real-time debug events:

EINT; // Enable Global interrupt INTM

ERTM; // Enable Global realtime interrupt DBGM

// Step 6. User specific code

// Step 7. IDLE loop. Just sit and loop forever (optional):

for(;;);

}

void init_eva_timer1(void)

{

// Initialize EVA Timer 1:

// Setup Timer 1 Registers (EV A)

EvaRegs.GPTCONA.all = 0;

// Set the Period for the GP timer 1 to 0x0200;

EvaRegs.T1PR = 0x0400; // Period

EvaRegs.T1CMPR = 0x0000; // Compare Reg

// Enable Period interrupt bits for GP timer 1

// Count up, x128, internal clk, enable compare, use own period

EvaRegs.EVAIMRA.bit.T1PINT = 1;

EvaRegs.EVAIFRA.bit.T1PINT = 1;

// Clear the counter for GP timer 1

EvaRegs.T1CNT = 0x0000;

EvaRegs.T1CON.all = 0x1702;

// Start Timer 1 Period interrupt

EvaRegs.T1CON.bit.TENABLE=1;

}

void init_eva_timer2(void)

{

// Initialize EVA Timer 2:

// Setup Timer 2 Registers (EV A)

EvaRegs.GPTCONA.all = 0;

// Set the Period for the GP timer 2 to 0x0200;

EvaRegs.T2PR = 0x0800; // Period

EvaRegs.T2CMPR = 0x0000; // Compare Reg

// Enable Period interrupt bits for GP timer 2

// Count up, x128, internal clk, enable compare, use own period

EvaRegs.EVAIMRB.bit.T2PINT = 1;

EvaRegs.EVAIFRB.bit.T2PINT = 1;

// Clear the counter for GP timer 2

EvaRegs.T2CNT = 0x0000;

EvaRegs.T2CON.all = 0x1702;

// Start Timer 2 Period interrupt

EvaRegs.T2CON.bit.TENABLE=1;

}

void init_evb_timer3(void)

{

// Initialize EVB Timer 3:

// Setup Timer 3 Registers (EV B)

EvbRegs.GPTCONB.all = 0;

// Set the Period for the GP timer 3 to 0x0200;

EvbRegs.T3PR = 0x1200; // Period

EvbRegs.T3CMPR = 0x0000; // Compare Reg

// Enable Period interrupt bits for GP timer 3

// Count up, x128, internal clk, enable compare, use own period

EvbRegs.EVBIMRA.bit.T3PINT = 1;

EvbRegs.EVBIFRA.bit.T3PINT = 1;

// Clear the counter for GP timer 3

EvbRegs.T3CNT = 0x0000;

EvbRegs.T3CON.all = 0x1702;

// Start Timer 3 Period interrupt

EvbRegs.T3CON.bit.TENABLE=1;

}

void init_evb_timer4(void)

{

// Initialize EVB Timer 4:

// Setup Timer 4 Registers (EV B)

EvbRegs.GPTCONB.all = 0;

// Set the Period for the GP timer 4 to 0x0200;

EvbRegs.T4PR = 0x1600; // Period

EvbRegs.T4CMPR = 0x0000; // Compare Reg

// Enable Period interrupt bits for GP timer 4

// Count up, x128, internal clk, enable compare, use own period

EvbRegs.EVBIMRB.bit.T4PINT = 1;

EvbRegs.EVBIFRB.bit.T4PINT = 1;

// Clear the counter for GP timer 4

EvbRegs.T4CNT = 0x0000;

EvbRegs.T4CON.all = 0x1702;

// Start Timer 4 Period interrupt

EvbRegs.T4CON.bit.TENABLE=1;

}

interrupt void eva_timer1_isr(void)

{

ICT_IO_7Seg1_On(EvaTimer1InterruptCount/100);

EvaTimer1InterruptCount++;

if (EvaTimer1InterruptCount >=1000 )

EvaTimer1InterruptCount=0;

// Enable more interrupts from this timer

EvaRegs.EVAIMRA.bit.T1PINT = 1;

EvaRegs.EVAIFRA.all = BIT7;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;

}

interrupt void eva_timer2_isr(void)

{

ICT_IO_7Seg2_On(EvaTimer2InterruptCount/100);

EvaTimer2InterruptCount++;

if (EvaTimer2InterruptCount >=900 )

EvaTimer2InterruptCount=100;

// Enable more interrupts from this timer

EvaRegs.EVAIMRB.bit.T2PINT = 1;

EvaRegs.EVAIFRB.all = BIT0;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP3;

}

interrupt void evb_timer3_isr(void)

{

ICT_IO_7Seg3_On(EvaTimer3InterruptCount/100);

EvaTimer3InterruptCount++;

if (EvaTimer3InterruptCount >=800 )

EvaTimer3InterruptCount=200;

EvbRegs.EVBIFRA.all = BIT7;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP4;

}

interrupt void evb_timer4_isr(void)

{

ICT_IO_7Seg4_On(EvaTimer4InterruptCount/100);

EvaTimer4InterruptCount++;

if (EvaTimer4InterruptCount >=700 )

EvaTimer4InterruptCount=300;

EvbRegs.EVBIFRB.all = BIT0;

PieCtrlRegs.PIEACK.all = PIEACK_GROUP5;

}

//======

// No more.

//======