新聞中心

s3c24xx中斷的操作

作者: 時(shí)間:2016-11-21 來源:網(wǎng)絡(luò) 收藏
@******************************************************************************

@ File:head.S
@ 功能:初始化,設(shè)置中斷模式、系統(tǒng)模式的棧,設(shè)置好中斷處理函數(shù)
@******************************************************************************

.extern main
.text
.global _start
_start:
@******************************************************************************
@ 中斷向量,本程序中,除Reset和HandleIRQ外,其它異常都沒有使用
@******************************************************************************
b Reset

本文引用地址:http://m.butianyuan.cn/article/201611/319117.htm

@ 0x04: 未定義指令中止模式的向量地址
HandleUndef:
b HandleUndef

@ 0x08: 管理模式的向量地址,通過SWI指令進(jìn)入此模式
HandleSWI:
b HandleSWI

@ 0x0c: 指令預(yù)取終止導(dǎo)致的異常的向量地址
HandlePrefetchAbort:
b HandlePrefetchAbort

@ 0x10: 數(shù)據(jù)訪問終止導(dǎo)致的異常的向量地址
HandleDataAbort:
b HandleDataAbort

@ 0x14: 保留
HandleNotUsed:
b HandleNotUsed

@ 0x18: 中斷模式的向量地址
b HandleIRQ

@ 0x1c: 快中斷模式的向量地址
HandleFIQ:
b HandleFIQ //一共有8個(gè)

Reset:
ldr sp, =4096 @ 設(shè)置棧指針,以下都是C函數(shù),調(diào)用前需要設(shè)好棧
bl disable_watch_dog @ 關(guān)閉WATCHDOG,否則CPU會(huì)不斷重啟

//初始化必須做的事情關(guān)閉watchdog 設(shè)置棧指針



msr cpsr_c, #0xd2 @ 進(jìn)入中斷模式
ldr sp, =3072 @ 設(shè)置中斷模式棧指針

msr cpsr_c, #0xdf @ 進(jìn)入系統(tǒng)模式
ldr sp, =4096 @ 設(shè)置系統(tǒng)模式棧指針,
@ 其實(shí)復(fù)位之后,CPU就處于系統(tǒng)模式,
@ 前面的“ldr sp, =4096”完成同樣的功能,此句可省略

/ /進(jìn)入各種模式在于設(shè)置棧指針

bl init_led @ 初始化LED的GPIO管腳


bl init_irq @ 調(diào)用中斷初始化函數(shù),在init.c中
msr cpsr_c, #0x5f @ 設(shè)置I-bit=0,開IRQ中斷

ldr lr, =halt_loop @ 設(shè)置返回地址 //調(diào)用main函數(shù)前的工作
ldr pc, =main @ 調(diào)用main函數(shù)
halt_loop:
b halt_loop

HandleIRQ:
sub lr, lr, #4 @ 計(jì)算返回地址
stmdb sp!, { r0-r12,lr } @ 保存使用到的寄存器
@ 注意,此時(shí)的sp是中斷模式的sp
@ 初始值是上面設(shè)置的3072

ldr lr, =int_return @ 設(shè)置調(diào)用ISR即EINT_Handle函數(shù)后的返回地址
ldr pc, =EINT_Handle @ 調(diào)用中斷服務(wù)函數(shù),在interrupt.c中
int_return:
ldmia sp!, { r0-r12,pc }^ @ 中斷返回

#include "s3c24xx.h"


#define GPB5_out (1<<(5*2)) // LED1
#define GPB6_out (1<<(6*2)) // LED2
#define GPB7_out (1<<(7*2)) // LED3
#define GPB8_out (1<<(8*2)) // LED4


#define GPG11_eint (2<<(11*2)) // K1,EINT19
#define GPG3_eint (2<<(3*2)) // K2,EINT11
#define GPF2_eint (2<<(2*2)) // K3,EINT2
#define GPF0_eint (2<<(0*2)) // K4,EINT0



void disable_watch_dog(void)
{
WTCON = 0; // 關(guān)閉WATCHDOG很簡單,往這個(gè)寄存器寫0即可
}

void init_led(void)
{
GPBCON = GPB5_out | GPB6_out | GPB7_out | GPB8_out ;
}


void init_irq( )
{
GPFCON = GPF0_eint | GPF2_eint;
GPGCON = GPG3_eint | GPG11_eint;

// 對于EINT11、19,需要在EINTMASK寄存器中使能它們
EINTMASK &= (~(1<<11)) & (~(1<<19));


PRIORITY = (PRIORITY & ((~0x01) | (0x3<<7))) | (0x0 << 7) ;

// EINT0、EINT2、EINT8_23使能
INTMSK &= (~(1<<0)) & (~(1<<2)) & (~(1<<5));
}

#include "s3c24xx.h"

void EINT_Handle()
{
unsigned long oft = INTOFFSET;
unsigned long val;

switch( oft )
{
// K4被按下
case 0:
{
GPBDAT |= (0x0f<<5); // 所有LED熄滅
GPBDAT &= ~(1<<8); // LED4點(diǎn)亮
break;
}

// K3被按下
case 2:
{
GPBDAT |= (0x0f<<5); // 所有LED熄滅
GPBDAT &= ~(1<<7); // LED3點(diǎn)亮
break;
}

// K1或K2被按下
case 5:
{
GPBDAT |= (0x0f<<5); // 所有LED熄滅

// 需要進(jìn)一步判斷是K1還是K2,或是K1、K2被同時(shí)按下
val = EINTPEND;
if (val & (1<<11))
GPBDAT &= ~(1<<6); // K2被按下,LED2點(diǎn)亮
if (val & (1<<19))
GPBDAT &= ~(1<<5); // K1被按下,LED1點(diǎn)亮

break;
}

default:
break;
}

//清中斷
if( oft == 5 )
EINTPEND = (1<<11) | (1<<19); // EINT8_23合用IRQ5
SRCPND = 1< INTPND = 1< //清除的順序
}

int main()
{
while(1);
return 0;
}

s3c24xx.h


#define WTCON (*(volatile unsigned long *)0x53000000)


#define MEM_CTL_BASE 0x48000000
#define SDRAM_BASE 0x30000000


#define NFCONF (*(volatile unsigned int *)0x4e000000)
#define NFCMD (*(volatile unsigned char *)0x4e000004)
#define NFADDR (*(volatile unsigned char *)0x4e000008)
#define NFDATA (*(volatile unsigned char *)0x4e00000c)
#define NFSTAT (*(volatile unsigned char *)0x4e000010)


#define GPBCON (*(volatile unsigned long *)0x56000010)
#define GPBDAT (*(volatile unsigned long *)0x56000014)

#define GPFCON (*(volatile unsigned long *)0x56000050)
#define GPFDAT (*(volatile unsigned long *)0x56000054)
#define GPFUP (*(volatile unsigned long *)0x56000058)

#define GPGCON (*(volatile unsigned long *)0x56000060)
#define GPGDAT (*(volatile unsigned long *)0x56000064)
#define GPGUP (*(volatile unsigned long *)0x56000068)

#define GPHCON (*(volatile unsigned long *)0x56000070)
#define GPHDAT (*(volatile unsigned long *)0x56000074)
#define GPHUP (*(volatile unsigned long *)0x56000078)


#define ULCON0 (*(volatile unsigned long *)0x50000000)
#define UCON0 (*(volatile unsigned long *)0x50000004)
#define UFCON0 (*(volatile unsigned long *)0x50000008)
#define UMCON0 (*(volatile unsigned long *)0x5000000c)
#define UTRSTAT0 (*(volatile unsigned long *)0x50000010)
#define UTXH0 (*(volatile unsigned char *)0x50000020)
#define URXH0 (*(volatile unsigned char *)0x50000024)
#define UBRDIV0 (*(volatile unsigned long *)0x50000028)



#define SRCPND (*(volatile unsigned long *)0x4A000000)
#define INTMOD (*(volatile unsigned long *)0x4A000004)
#define INTMSK (*(volatile unsigned long *)0x4A000008)
#define PRIORITY (*(volatile unsigned long *)0x4A00000c)
#define INTPND (*(volatile unsigned long *)0x4A000010)
#define INTOFFSET (*(volatile unsigned long *)0x4A000014)
#define SUBSRCPND (*(volatile unsigned long *)0x4A000018)
#define INTSUBMSK (*(volatile unsigned long *)0x4A00001c)


#define EINTMASK (*(volatile unsigned long *)0x560000a4)
#define EINTPEND (*(volatile unsigned long *)0x560000a8)



關(guān)鍵詞: 中斷s3c24x

評論


技術(shù)專區(qū)

關(guān)閉