openMSP之IO interrupt

IO interrupt

Verilog file: omsp_gpio.v

 1 //============================================================================
 2 // 4) INTERRUPT GENERATION
 3 //============================================================================
 4
 5 // Port 2 interrupt
 6 //------------------
 7
 8 // Delay input // The p2in_dly stores former value of p2in, it will be used for edge detection
 9 reg    [7:0] p2in_dly;
10 always @ (posedge mclk or posedge puc_rst)
11   if (puc_rst)  p2in_dly <=  8‘h00;
12   else          p2in_dly <=  p2in & P2_EN_MSK;
13
14 // Edge detection // Now we can detect rising and falling edge easily by combining p2in and p2in_dly
15 wire   [7:0] p2in_re   =   p2in & ~p2in_dly;
16 wire   [7:0] p2in_fe   =  ~p2in &  p2in_dly;
17
18 // Set interrupt flag // p2ies register decide which edge is interrup signal; p2ifg_set is sent to p2ifg for interrupt flag
19 assign       p2ifg_set = {p2ies[7] ? p2in_fe[7] : p2in_re[7],
20                           p2ies[6] ? p2in_fe[6] : p2in_re[6],
21                           p2ies[5] ? p2in_fe[5] : p2in_re[5],
22                           p2ies[4] ? p2in_fe[4] : p2in_re[4],
23                           p2ies[3] ? p2in_fe[3] : p2in_re[3],
24                           p2ies[2] ? p2in_fe[2] : p2in_re[2],
25                           p2ies[1] ? p2in_fe[1] : p2in_re[1],
26                           p2ies[0] ? p2in_fe[0] : p2in_re[0]} & P2_EN_MSK;
27
28 // Generate CPU interrupt // Interrupt is generated when interrupt is enabled and p2ifg (interrupt flag) is available
29 assign       irq_port2 = |(p2ie & p2ifg) & P2_EN[0];

  

  Assume  P2_EN is 1‘b1, interrupt is enabled(P2IE=1), interrupt edge is rising(P2IES=0), so the code is as following:

 1 // Delay input
 2 reg    [7:0] p2in_dly;
 3 always @ (posedge mclk or posedge puc_rst)
 4   if (puc_rst)  p2in_dly <=  8‘h00;
 5   else          p2in_dly <=  p2in;
 6
 7 // Edge detection
 8 wire   [7:0] p2in_re   =   p2in & ~p2in_dly;
 9
11 // Set interrupt flag
12 assign       p2ifg_set = { p2in_re[7],
13                            p2in_re[6],
14                            p2in_re[5],
15                            p2in_re[4],
16                            p2in_re[3],
17                            p2in_re[2],
18                            p2in_re[1],
19                            p2in_re[0]  };
20
21 // Generate CPU interrupt
22 assign      irq_port2 = | p2ifg;

  

  P2IFG register is as following:

 1 // P2IFG Register
 2 //----------------
 3 reg  [7:0] p2ifg;
 4
 5 wire       p2ifg_wr  = P2IFG[0] ? reg_hi_wr[P2IFG] : reg_lo_wr[P2IFG];
 6 wire [7:0] p2ifg_nxt = P2IFG[0] ? per_din[15:8]    : per_din[7:0];
 7 wire [7:0] p2ifg_set;
 8
 9 always @ (posedge mclk or posedge puc_rst)
10   if (puc_rst)        p2ifg <=  8‘h00;
11   else if (p2ifg_wr)  p2ifg <=  (p2ifg_nxt | p2ifg_set) & P2_EN_MSK;
12   else                p2ifg <=  (p2ifg     | p2ifg_set) & P2_EN_MSK;

  Assume P2_EN is 1‘b1; P2IFG=‘h2B, so P2IFG[0]=1;  p2ifg_set = 8{1‘b1}

 1  1 // P2IFG Register
 2  2 //----------------
 3  3 reg  [7:0] p2ifg;
 4  4
 5  5 wire       p2ifg_wr  =  reg_hi_wr[43]; // If decoded address is P2IFG, then write it into data
 6  6 wire [7:0] p2ifg_nxt =  per_din[15:8]; // receive high byte data from openMSP
 7  7 wire [7:0] p2ifg_set;
 8  8
 9  9 always @ (posedge mclk or posedge puc_rst)
10 10   if (puc_rst)        p2ifg <=  8‘h00;
11 11   else if (p2ifg_wr)  p2ifg <=  p2ifg_nxt | p2ifg_set; // write into
12 12   else                p2ifg <=  p2ifg     | p2ifg_set; // read out
时间: 2024-10-23 16:09:35

openMSP之IO interrupt的相关文章

内核诊断(1)interrupt took too long

The linux kernel gathers samples using 'perf' performance monitor without affecting the latencies. These include getting interrupt times. If interrupts take too long, a similar message to this prints: kernel: [ 6491.061361] perf: interrupt took too l

linux下类似Bus Hound的工具

linux下类似Bus Hound的工具 http://blog.csdn.net/liuqz2009/article/details/7886461 0推荐在linux大家有时候需要调试usb接口的串口消息,但是没有类似于windows下的bus hound工具,感觉比较痛苦,其实linux内核提供了usbmon这个工具,可以收集串口信息. 1.准备: 挂接debugfs (这个可以在内核配置中使能),加载usbmon模块(如果usbmon编译成模块). 如果usbmon编译到内核中的话,第二

Android应用耗电问题排查

1 耗电定位工具与方法 1-1 系统提供的battery信息 1-1-1 在Android 4.4 KitKat 以前使用 adb shell dumpsys batteryinfo > d:/batterinfo.log 获取电量日志 1-1-2 在Android 4.4 KitKat 及以后使用 获取日志 adb shell dumpsys batterystats > d:/batterstats.log 获取电量日志可以使用命令清除记录后重新记录 adb shell dumpsys b

java随手笔记之九之IO和线程

IO:进行数据的读写操作. 输入流:源头---->应用程序,read 输出流:应用程序(源头)--->目的地,write 字节流: InputStream,OutputStream 字符流: Reader,Writer read: 1.创建输入流对象,与要读取文件相关联 2.读取文件内容 3.关闭流 write: 1.创建输出流对象,与要写入数据的文件相关联 2.将数据写入到文件 3.关闭流 字符包装流对象: BufferdReader:String readLine(),null Buffe

停止Java线程,小心interrupt()方法

程序是很简易的.然而,在编程人员面前,多线程呈现出了一组新的难题,如果没有被恰当的解决,将导致意外的行为以及细微的.难以发现的错误. 在本篇文章中,我们针对这些难题之一:如何中断一个正在运行的线程. 背景     中断(Interrupt)一个线程意味着在该线程完成任务之前停止其正在进行的一切,有效地中止其当前的操作.线程是死亡.还是等待新的任务或是继续运行至下一步,就取决于这个程序.虽然初次看来它可能显得简单,但是,你必须进行一些预警以实现期望的结果.你最好还是牢记以下的几点告诫. 首先,忘掉

Interrupt distribution scheme for a computer bus

A method of handling processor to processor interrupt requests in a multiprocessing computer bus environment is described. This method allows a multiple-tiered, increasing priority, interrupt request scheme. This method also allows processor to proce

用IO模拟串口协议发送数据

<pre name="code" class="cpp">//文件usend.h #ifndef _USEND_H_ #define _USEND_H_ //====红外接收相关定义============================= #define PuTx_High (P_uTx = 1) //数据高 #define PuTx_Low (P_uTx = 0) //数据低 #define V_SendDatNum 6//6 //发送数据字节数 /

用普通IO接收串口数据

<pre name="code" class="cpp">//文件urece.h #ifndef _URECE_H_ #define _URECE_H_ #define V_BATOU 0x80 //电池充满 #define V_BATLV 0x40 //电池低电压 #define V_BATOI 0X20 //电池放电过流 #define V_BATOTP 0x10 //电池过温 #define V_BATOTIM 0x08 //电池充电超时 #def

Nio学习4——EchoServer在Io,Nio,Nio.2中的实现

阻塞IO实现: public class PlainEchoServer { public void serve(int port) throws IOException { final ServerSocket socket = new ServerSocket(port); try { while (true) { final Socket clientSocket = socket.accept(); System.out.println("Accepted connection from