-
Notifications
You must be signed in to change notification settings - Fork 19
/
spin_interupt.c
75 lines (68 loc) · 1.89 KB
/
spin_interupt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#include"spin_interupt.h"
#include<stdlib.h>
#include<string.h>
uint* inter_vector_function[inter_num]={NULL,NULL,NULL,NULL,NULL}; //交给用户初始化
static uchar* inter_src_list[inter_num];
static uchar* inter_prority[inter_num];
//static void *callback_data;
void spin_interupt_init(){
//中断源开关地址
inter_src_list[out_int0]=0xA8;
inter_src_list[timer0]=0xA9;
inter_src_list[out_int1]=0xAA;
inter_src_list[timer1]=0xAB;
inter_src_list[serial]=0xAC;
//中断优先级设置地址
inter_prority[out_int0]=0xB8;
inter_prority[timer0]=0xB9;
inter_prority[out_int1]=0xBA;
inter_prority[timer1]=0xBB;
inter_prority[serial]=0xBC;
}
void spin_interupt_enable(){
EA=1;
}
void spin_interupt_disable(){
EA=0;
}
void spin_interupt_open(INTER_LIST num,INTER_PRORITY prority){
IE |= 0x01<<num;
//*inter_prority[num] = prority;
//*inter_src_list[num] = enable;//按位寻址,可以写入1bit
}
void spin_interupt_close(INTER_LIST num){
IE &= (~(0x01<<num));
//*inter_src_list[num] = disable;//按位寻址,可以写入1bit
}
void spin_interupt_set_params(INTER_LIST num,uchar params){
}
void intersvr0() interrupt 0{
if(inter_vector_function[0]!=NULL)
((interupt_callback)inter_vector_function[0])();
}
void intersvr1(void) interrupt 1{
if(inter_vector_function[1]!=NULL)
((interupt_callback)inter_vector_function[1])();
}
void intersvr2(void) interrupt 2{
if(inter_vector_function[2]!=NULL)
((interupt_callback)inter_vector_function[2])();
}
void intersvr3(void) interrupt 3{
if(inter_vector_function[3]!=NULL)
((interupt_callback)inter_vector_function[3])();
}
extern volatile sem_t uart_send; //发送信号量
extern volatile buff_t idata recv_buff; //接收buff
void intersvr4(void) interrupt 4{
if(RI==1){ //接收中断
critical_area_enter();
recv_buff.buff[recv_buff.len++] = SBUF;
critical_area_exit();
RI=0;
}
if(TI==1){//发送中断
TI=0;
sem_post(uart_send);
}
}