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. 使用Selenium爬取网站表格类数据

    本文转载自一下网站:Python爬虫(5):Selenium 爬取东方财富网股票财务报表 https://www.makcyun.top/web_scraping_withpython5.html 需 ...

  2. 09.正则表达式re-1.正则表达式

    1.正则表达式概述 正则表达式(英语:Regular Expression,在代码中常简写为regex.regexp或RE),是计算机科学的一个概念. 正则表达式使用单个字符串来描述.匹配一系列匹配某 ...

  3. 39.exact value and full text

    主要知识点 1.exact value 2.full text     在es中有两种搜索方式,exact value(精确匹配),full text(全文检索) 一.exact value 比如有一 ...

  4. Atcoder AGC031B Reversi (DP计数)

    简单的计数题.(总算做出一道AGC的B题了,然而这场比赛我忘记打了233333) 题目链接: https://atcoder.jp/contests/agc031/tasks/agc031_b 题意: ...

  5. NOIP2017总结与反思

    手动博客搬家: 本文发表于20180213 00:01:05, 原地址https://blog.csdn.net/suncongbo/article/details/79319556 //由于12月生 ...

  6. SpringBoot后台如何实现文件上传下载

    1.单文件上传: @RequestMapping(value = "/upload") @ResponseBody public String upload(@RequestPar ...

  7. 【ZOJ 4062】Plants vs. Zombies

    [链接] 我是链接,点我呀:) [题意] [题解] 二分最后的最大抵御值mid. 然后对于每个蘑菇. 都能算出来它要浇水几次mid/ai 然后如果第i个蘑菇没浇水达到要求次数. 就在i和i+1之间来回 ...

  8. find结合rm删除大量文件

    版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://navarro.blogbus.com/logs/31502374.html 例:删除/home/raven下,包括子目录 ...

  9. hdu 2586 lca在线算法(朴素算法)

    #include<stdio.h> #include<string.h>//用c/c++会爆栈,用g++ac #define inf 0x3fffffff #define N ...

  10. codevs——T3111 CYD啃骨头

     http://codevs.cn/problem/3111/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 黄金 Gold 题解  查看运行结果     题目描述 Desc ...