tms470.c
来自「最新版IAR FOR ARM(EWARM)5.11中的代码例子」· C语言 代码 · 共 179 行
C
179 行
#ifdef R1A384
#include <TexasInstruments/iotms470r1a384.h>
#else
#include <TexasInstruments/iotms470r1a256.h>
#endif
#define SYSCLK_8MHz 0
#define SYSCLK_20MHz 1
#define SYSCLK_40MHz 2
int sysclk;
static void(*timer_function)();
//
// System initialization.
//
void TMS470SystemInit()
{
PCR_bit.CLKDIV = 0x0F; // set ICLK
PCR_bit.PENABLE = 1; // enable peripherals
}
//
// Interrupt handlers.
//
/* Timer interrupt handler */
__irq __arm void IRQ_Handler()
{
volatile int vecno;
vecno = CIMIVEC; // read and clear interrupt
RTICNTEN = 0x03; // Stop counting
RTICNTR = 0; // clear 21-bits CNTR
RTICINT = 0x20; // interrupt control, clear CMP1 and enable CMP1 interrupt
RTICNTEN = 0x00; // Start count, CNTR and MOD will count in both USER and SYSTEM mode
(*timer_function)(); // Call timer callback function.
}
//
// Interrupt functions.
//
void TMS470InitInterrupt(void(*timer_func)())
{
timer_function = timer_func;
// Setup interrupt controller.
REQMASK |= (1<<2); // Enable channel 2 (RTICMP1)
}
//
// Timer functions.
//
void TMS470InitTimer()
{
// Setup periodic interrupt using RTI with RTICMP1
RTICNTEN = 0x03; // Stop counting
RTICNTR = 0; // clear 21-bits CNTR
// Setup periodic interrupt timer
// CMP1 used to generate 1000 us interrupt.
RTIPCTL = 1; // preload 11-bits MOD
RTICMP1 = 3689; // osc is 14.7456 MHz
RTICNTL = 0; // clear and disable tap
// interrupt control, clear CMP1 and enable CMP1 interrupt
RTICINT = 0x20;
}
void TMS470StartTimer()
{
// Start count, CNTR and MOD will count in both USER and SYSTEM mode
RTICNTEN = 0x00;
}
//
// Parallel I/O functions.
//
void TMS470InitPIO()
{
#ifdef R1A384
GIODIRA = 0xF0; // set port bit 7..4 as output
GIODIRH = 0x1E; // set port bit 4..1 as output
HETDIR = 0xFF; // set port bit 7..0 as output
GIODOUTA = 0xF0; // off
GIODOUTH = 0x1E;
HETDOUT = 0xFF;
HETDOUT = 0x00; // on
GIODOUTH = 0x00;
GIODOUTA = 0x00;
HETDOUT = 0xFF; // off
GIODOUTH = 0x1E;
GIODOUTA = 0xF0;
#else
// R1A256
HETDIR = 0xFFFFFFFF; // set port bit 7..0 as output
HETDOUT = 0xFFFFFFFF;
HETDOUT = 0x00000000; // on
HETDOUT = 0xFFFFFFFF; // off
#endif
}
//
// LED output drivers.
//
void TMS470LedSet(unsigned int mask)
{
#ifdef R1A384
mask ^= 0xFFFFFFFF;
HETDOUT = (mask >> 8) & 0xFF;
GIODOUTH = (mask >> 3) & 0x1E;
GIODOUTA = (mask << 4) & 0xF0;
#else
// R1A256
unsigned long out = 0;
mask ^= 0xFFFFFFFF;
out |= ((mask & 0x01) ? 0x00000001 : 0);
out |= ((mask & 0x02) ? 0x00000004 : 0);
out |= ((mask & 0x04) ? 0x00000010 : 0);
out |= ((mask & 0x08) ? 0x00000040 : 0);
out |= ((mask & 0x10) ? 0x00000080 : 0);
out |= ((mask & 0x20) ? 0x00000100 : 0);
out |= ((mask & 0x40) ? 0x00000400 : 0);
out |= ((mask & 0x80) ? 0x00000800 : 0);
out |= ((mask & 0x100) ? 0x00001000 : 0);
out |= ((mask & 0x200) ? 0x00002000 : 0);
out |= ((mask & 0x400) ? 0x00040000 : 0);
out |= ((mask & 0x800) ? 0x00080000 : 0);
out |= ((mask & 0x1000) ? 0x00100000 : 0);
out |= ((mask & 0x2000) ? 0x00200000 : 0);
out |= ((mask & 0x4000) ? 0x01000000 : 0);
out |= ((mask & 0x8000) ? 0x80000000 : 0);
HETDOUT = out;
#endif
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?