Wince下C#直接访问外部地址

yangjidi1985 2012-09-17 08:15:24
这几天查网站上的一些C#直接读写外部地址数据的帖子,用的很多的是利用Coredll.dll里面的一些函数来间接读写地址。
但是上面的一些参数有些头大。
刚才突然看到一篇帖子试了一下,好像可以直接用Marshal.ReadByte(IntPtr address),Marshal.WriteByte(IntPtr address)来直接读取address里面的数据,只是要在写入时判断下address的值是否可写,不然会有异常。
希望能指点一下下面两个问题
1、对address可写写是否有函数能判断,或是用try……catch来判断
2、用Marshal读写外设的寄存器,例如GPIO引脚状态寄存器、flash什么的是否可行
谢谢。。。
...全文
106 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangjidi1985 2012-09-19
  • 打赏
  • 举报
回复
往学习板上操作了一下,程序立马就死了。
这个Marshal操作的好像是windows的内存,只有256M,而0x7F008828是处理器对应的外部存储空间,在内存之外,不知道可不可以这样理解。
yangjidi1985 2012-09-18
  • 打赏
  • 举报
回复
我用的三星的s3c6410的开发板,开发板还没到,现在只是自己在想怎么操作GPIO。
比如说开发板上的led灯连接的GPM[0..3],对应的寄存器如下:
/*************************************************************
GPMCON 0x7F008820 Port M Configuration Register
GPMDAT 0x7F008824 Port M Data Register
GPMPUD 0x7F008828 Port M Pull-up/down Register

GPMCON Bit Description
GPM0 [3:0] 0000 = Input 0001 = Output
0010 = Host I/F CSn 0011 = Ext. Interrupt[23]
0100 = Reserved 0101 = Reserved
0110 = CE_CF[0] 0111 = Reserved
GPM1 [7:4] 0000 = Input 0001 = Output
0010 = Host I/F CSn_main 0011 = Ext. Interrupt [24]
0100 = Reserved 0101 = Reserved
0110 = CE_CF[1] 0111 = Reserved
GPM2 [11:8] 0000 = Input 0001 = Output
0010 = Host I/F CSn_sub 0011 = Ext. Interrupt [25]
0100 = Host I/F MDP_VSYNC 0101 = Reserved
0110 = IORD_CF 0111 = Reserved
GPM3 [15:12] 0000 = Input 0001 = Output
0010 = Host I/F WEn 0011 = Ext. Interrupt [26]
0100 = Reserved 0101 = Reserved
0110 = IOWR_CF 0111 = Reserved
*
GPMDAT Bit Description
GPM[5:0] [5:0] When the port is configured as input port, the corresponding bit is the pin state. When
the port is configured as output port, the pin state is the same as the corresponding bit.
When the port is configured as functional pin, the undefined value will be read.
*
GPLPUD Bit Description
GPM[n] [2n+1:2n] 00 = pull-up/down disabled
n = 0~5 01 = pull-down enabled
10 = pull-up enabled
11 = Reserved.


************************************************************/

using System;
using System.Runtime.InteropServices;

public class Class1
{
public Class1()
{
Marshal.WriteInt32((IntPtr)0x7F008824,0x1111); //设置为输出
}

public void OpenLed0()
{
byte byteLed = Marshal.ReadByte(0x7F008828); //读状态
Marshal.WriteByte(0x7F008828, byteLed&0x0D); //写状态
}
}

不知道像这样操作寄存器可不可以。请指点下。。。

woshi_ziyu 2012-09-17
  • 打赏
  • 举报
回复
这个可以看芯片的内存地址分布图

没有函数判断能否读写

19,502

社区成员

发帖
与我相关
我的任务
社区描述
硬件/嵌入开发 嵌入开发(WinCE)
社区管理员
  • 嵌入开发(WinCE)社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧