📄 blink.c
字号:
//*********************************************************
//
// tsblink.c : Simple example of flag toggling on the
// TigerSharc to blink LEDs
//
// PROVIDED BY:
// ------------
// Bittware, Inc.
// 33 North Main Street
// Concord, NH 03301
// Ph: 603-226-0404
// Fax: 603-226-6667
// WWW: www.bittware.com
// E-mail: support@bittware.com
//
// Copyright (c) 2001
//
// Ver. Dates Author Changes
// ---- -------- ------ -----------------------------
// 1.0 11/29/01 rpc Creation
//*********************************************************
#include <defts101.h>
#include <sysreg.h>
#include <signal.h>
#include <stdio.h>
/**********************************************************/
#define USE_INTERRUPT 1 // Set to 1 to use the timer interrupt
/**********************************************************/
#define FLG0O 0x00100000 // Make FLG0 output
#define FLG1O 0x00200000 // Make FLG1 output
#define FLG2O 0x00400000 // Make FLG2 output
#define FLG3O 0x00800000 // Make FLG3 output
#define FLG0 0x01000000 // Bit for FLG0
#define FLG1 0x02000000 // Bit for FLG1
#define FLG2 0x04000000 // Bit for FLG2
#define FLG3 0x08000000 // Bit for FLG3
#define TMR0RN 0x00001000 // Bit to enable timer 0
#define TMR1RN 0x00002000 // Bit to enable timer 1
/**********************************************************/
int count, cnt;
volatile int intr_count = 0;
/**********************************************************/
/* */
/* */
/* */
/**********************************************************/
void timer0_handler(int sig)
{
if(intr_count % 2)
__builtin_sysreg_write(__SQCTLST, (FLG2|FLG3)); // set the flag bits
else
__builtin_sysreg_write(__SQCTLCL, ~(FLG2|FLG3)); //clear the flag bits
intr_count++;
printf("1111122321\n");
}
/**********************************************************/
/* */
/* */
/* */
/**********************************************************/
void main ( void )
{
int tmr_val;
//__builtin_sysreg_write(IVSW, 0xFFFB);
// Set up SYSCON and SDRAM
//__builtin_sysreg_write(__SYSCON,0x003a3041); // or 0x3a3027
//__builtin_sysreg_write(__SDRCON,0x00003003); // SDRAM enabled, CAS LATENCY = two, Pipe Depth = 0, Page Boundry = 256,
// Initialize flags and get Processor ID
__builtin_sysreg_write(__SQCTLST, (FLG2O | FLG3O)); // make flags 2 and 3 outputs
#if USE_INTERRUPT
// Set up timer interrupts
interrupt(SIGTIMER0LP, timer0_handler); // attach handler for timer0 interrupt
tmr_val = 0x1000000*3; // timer value based on proc ID
__builtin_sysreg_write(__TMRIN0L, tmr_val); // set timer0 low count
__builtin_sysreg_write(__TMRIN0H, 0); // set timer0 high count
__builtin_sysreg_write(__SQCTLST, TMR0RN); // start timer0
#endif
// Toggle flags to blink LEDs
while(1)
{
count++;
#if !USE_INTERRUPT
for (cnt = 0 ; cnt < 2500000 ; cnt++); // delay
if(count % 2)
__builtin_sysreg_write(__SQCTLST, (FLG2|FLG3)); // set the flag bits
else
__builtin_sysreg_write(__SQCTLCL, ~(FLG2|FLG3)); //clear the flag bits
#endif
}
}
/**********************************************************/
/* End of file tsblink.c */
/**********************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -