openMSP430_IO interrupt

Verilog file: omsp_gpio.v

 //============================================================================
// 4) INTERRUPT GENERATION
//============================================================================ // Port 2 interrupt
//------------------ // Delay input // The p2in_dly stores former value of p2in, it will be used for edge detection
reg [:] p2in_dly;
always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2in_dly <= 'h00;
else p2in_dly <= p2in & P2_EN_MSK; // Edge detection // Now we can detect rising and falling edge easily by combining p2in and p2in_dly
wire [:] p2in_re = p2in & ~p2in_dly;
wire [:] p2in_fe = ~p2in & p2in_dly; // Set interrupt flag // p2ies register decide which edge is interrup signal; p2ifg_set is sent to p2ifg for interrupt flag
assign p2ifg_set = {p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[],
p2ies[1] ? p2in_fe[] : p2in_re[],
p2ies[] ? p2in_fe[] : p2in_re[]} & P2_EN_MSK; // Generate CPU interrupt // Interrupt is generated when interrupt is enabled and p2ifg (interrupt flag) is available
assign irq_port2 = |(p2ie & p2ifg) & P2_EN[];

  

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

 // Delay input
reg [:] p2in_dly;
always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2in_dly <= 'h00;
else p2in_dly <= p2in; // Edge detection
wire [:] p2in_re = p2in & ~p2in_dly; // Set interrupt flag
assign p2ifg_set = { p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[],
p2in_re[]  }; // Generate CPU interrupt
assign irq_port2 = | p2ifg;

  

  P2IFG register is as following:

 // P2IFG Register
//----------------
reg [:] p2ifg; wire p2ifg_wr = P2IFG[] ? reg_hi_wr[P2IFG] : reg_lo_wr[P2IFG];
wire [:] p2ifg_nxt = P2IFG[] ? per_din[:] : per_din[:];
wire [:] p2ifg_set; always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2ifg <= 'h00;
else if (p2ifg_wr) p2ifg <= (p2ifg_nxt | p2ifg_set) & P2_EN_MSK;
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}

   // P2IFG Register
//----------------
reg [:] p2ifg; wire p2ifg_wr = reg_hi_wr[]; // If decoded address is P2IFG, then write it into data
wire [:] p2ifg_nxt = per_din[:]; // receive high byte data from openMSP
wire [:] p2ifg_set; always @ (posedge mclk or posedge puc_rst)
if (puc_rst) p2ifg <= 'h00;
else if (p2ifg_wr) p2ifg <= p2ifg_nxt | p2ifg_set; // write into
else p2ifg <= p2ifg | p2ifg_set; // read out

Verilog之openMSP430(1)的更多相关文章

  1. Verilog学习笔记简单功能实现(二)...............全加器

    先以一位全加器为例:Xi.Yi代表两个加数,Cin是地位进位信号,Cout是向高位的进位信号.列表有:   Xi     Yi    Cin Sum Cout 0 0 0 0 0 0 0 1 1 0 ...

  2. Verilog HDL模型的不同抽象级别

    所谓不同的抽象类别,实际上是指同一个物理电路,可以在不同层次上用Verilog语言来描述.如果只从行为功能的角度来描述某一电路模块,就称作行为模块.如果从电路结构的角度来描述该电路模块,就称作结构模块 ...

  3. Verilog学习笔记基本语法篇(十二)········ 编译预处理

    h Verilog HDL语言和C语言一样也提供编译预处理的功能.在Verilog中为了和一般的语句相区别,这些预处理语句以符号"`"开头,注意,这个字符位于主键盘的左上角,其对应 ...

  4. Verilog学习笔记基本语法篇(十一)········ 常用系统函数

    1)系统任务:$monitor   格式: $monitor(p1,p2,p3...pn); $monitor; $monitoron; $monitoroff; 任务$monitor提供了监控输出列 ...

  5. FPGA作为从机与STM32进行SPI协议通信---Verilog实现 [转]

    一.SPI协议简要介绍 SPI,是英语Serial Peripheral Interface的缩写,顾名思义就是串行外围设备接口.SPI,是一种高速的,全双工,同步的通信总线,并且在芯片的管脚上只占用 ...

  6. 基于Verilog HDL整数乘法器设计与仿真验证

    基于Verilog HDL整数乘法器设计与仿真验证 1.预备知识 整数分为短整数,中整数,长整数,本文只涉及到短整数.短整数:占用一个字节空间,8位,其中最高位为符号位(最高位为1表示为负数,最高位为 ...

  7. system verilog中的跳转操作

    在verilog中,使用disable声明来从执行流程中的某一点跳转到另一点.特别地,disable声明使执行流程跳转到标注名字的声明组末尾,或者一个任务的末尾. verilog中的disable命令 ...

  8. system verilog中的类型转换(type casting)、位宽转换(size casting)和符号转换(sign casting)

    类型转换 verilog中,任何类型的任何数值都用来给任何类型赋值.verilog使用赋值语句自动将一种类型的数值转换为另一种类型. 例如,当一个wire类型赋值给一个reg类型的变量时,wire类型 ...

  9. 一段比较有意思的代码——介绍system verilog中的新增幅值语句

    system verilog中新加了很多幅值语句,虽然都只适用于阻塞幅值,但是在某些场合中非常实用. 下面是一段有意思的代码,覆盖了一些用法. package definitions; typedef ...

随机推荐

  1. LINUX - getopts

    getopts optionString opt; optionString :所有参数组成的-参数串: opt:从optionString 每次取的参数值: 当optionString用[:]开头, ...

  2. 15.5.2 【Task实现细节】骨架方法的结构

    尽管骨架方法中的代码非常简单,但它暗示了状态机的职责.代码清单15-11生成的骨架方 法如下所示: [DebuggerStepThrough] [AsyncStateMachine(typeof(De ...

  3. Python——Numpy基础知识(一)

    一.Numpy的引入 1.标准的Python 中用列表(list)保存一组值,可以当作数组使用.但由于列表的元素可以是任何对象,因此列表中保存的是对象的指针.对于数值运算来说,这种结构显然比较浪费内存 ...

  4. Ubuntu Server下docker实战 01: 安装docker

    本系列文章主旨在于使用docker来搭建实际可用的基础服务,具体到每一步的操作和设置. 关于docker的原理.前世今生的内容,园子里已经有太多的文章了,此处就不再赘述. 要使用docker,当然第一 ...

  5. 利用负margin实现元素居中

    原理就是对当前元素的position设置为absolute并且相对于父元素定位,先设置left:50%;top:50%使当前元素的左上角处于父元素的中心位置,之后再应用负margin特性使其中心位于父 ...

  6. python笔记之json报错

    写爬虫的过程中不免遇到处理json数据的情况,今天在爬取新华网新闻数据时发现使用json.loads函数时报错: json.decoder.JSONDecodeError: Expecting val ...

  7. 15.Hibernate一对多双向关联映射+分页

    1.创建如下数据库脚本 --创建用户信息表 --编号,用户名,密码,年龄,性别,昵称,手机,地址,管理员,图像地址 create table users ( id ) primary key, use ...

  8. Bootstrap关于表单控件(Radio,CheckBox)

    表单控件(复选框checkbox和单选择按钮radio) Bootstrap框架中checkbox和radio有点特殊,Bootstrap针对他们做了一些特殊化处理,主要是checkbox和radio ...

  9. 转载 - 跳跃的舞者,舞蹈链(Dancing Links)算法——求解精确覆盖问题

    出处:http://www.cnblogs.com/grenet/p/3145800.html 精确覆盖问题的定义:给定一个由0-1组成的矩阵,是否能找到一个行的集合,使得集合中每一列都恰好包含一个1 ...

  10. Centos6.2中配置tomcat

    这里我使用的是tomcat6, 我使用的是server版本号的Centos, 前提是安装而且配置好了JDK. 首先通过samba把我的tomcat压缩包, 复制到了共享的文件夹.然后移动到./usr文 ...