-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from luanxg/develop
添加代码和说明文档
- Loading branch information
Showing
3 changed files
with
140 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,54 @@ | ||
# devmem | ||
## devmem | ||
|
||
RT-Thread 上的 MCU/CPU 读写内存/寄存器的小工具,在menuconfig里选中软件包后,在msh上输入`devmem`查看使用说明。 | ||
|
||
``` | ||
msh />devmem | ||
Usage: devmem address [type [data]] | ||
address : memory address to act upon | ||
type : access operation type : [b]yte, [h]alfword, [w]ord | ||
data : data to be written | ||
``` | ||
### 写内存/寄存器 | ||
|
||
#### byte方式写入 | ||
|
||
``` | ||
devmem 0x600a4000 b 0xa | ||
``` | ||
|
||
#### halfword方式写入 | ||
|
||
``` | ||
devmem 0x600a4000 h 0xab | ||
``` | ||
|
||
#### word方式写入 | ||
|
||
``` | ||
devmem 0x600a4000 w 0xabcd | ||
``` | ||
|
||
### 读内存/寄存器 | ||
|
||
#### byte方式读取 | ||
|
||
``` | ||
msh />devmem 0x600a4000 b | ||
0x0a | ||
``` | ||
|
||
#### halfword方式读取 | ||
|
||
``` | ||
msh />devmem 0x600a4000 h | ||
0x00ab | ||
``` | ||
|
||
#### word方式读取 | ||
|
||
``` | ||
msh />devmem 0x600a4000 w | ||
0x0000abcd | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
from building import * | ||
import rtconfig | ||
|
||
cwd = GetCurrentDir() | ||
src = Glob('*.c') | ||
CPPPATH = [] | ||
|
||
group = DefineGroup('devmem', src, depend = ['PKG_USING_DEVMEM'], CPPPATH = CPPPATH) | ||
|
||
Return('group') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#include <rthw.h> | ||
#include <rtthread.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <ctype.h> | ||
|
||
static void devmem(int argc, char **argv) | ||
{ | ||
rt_uint64_t tmp; | ||
rt_uint32_t addr, value; | ||
int access_type = 'w'; | ||
|
||
/* check args */ | ||
if (argc < 2) | ||
{ | ||
rt_kprintf("\nUsage:\t%s address [type [data]]\n" | ||
"\taddress : memory address to act upon\n" | ||
"\ttype : access operation type : [b]yte, [h]alfword, [w]ord\n" | ||
"\tdata : data to be written\n\n", argv[0]); | ||
return; | ||
} | ||
|
||
/* get address */ | ||
tmp = strtoll(argv[1], RT_NULL, 16); | ||
addr = (rt_uint32_t)tmp; | ||
|
||
/* get access_type */ | ||
if (argc >= 3) | ||
{ | ||
access_type = tolower(argv[2][0]); | ||
} | ||
|
||
if (argc >= 4) | ||
{ | ||
/* write value */ | ||
tmp = strtoll(argv[3], RT_NULL, 16); | ||
value = (rt_uint32_t)tmp; | ||
|
||
switch (access_type) | ||
{ | ||
case 'b': | ||
*(volatile rt_uint8_t*)addr = (rt_uint8_t)value; | ||
break; | ||
case 'h': | ||
*(volatile rt_uint16_t*)addr = (rt_uint16_t)value; | ||
break; | ||
case 'w': | ||
*(volatile rt_uint32_t*)addr = (rt_uint32_t)value; | ||
break; | ||
default: | ||
*(volatile rt_uint32_t*)addr = (rt_uint32_t)value; | ||
break; | ||
} | ||
} | ||
else | ||
{ | ||
/* read value */ | ||
switch (access_type) | ||
{ | ||
case 'b': | ||
rt_kprintf("0x%02x\n", *(volatile rt_uint8_t*)addr); | ||
break; | ||
case 'h': | ||
rt_kprintf("0x%04x\n", *(volatile rt_uint16_t*)addr); | ||
break; | ||
case 'w': | ||
rt_kprintf("0x%08x\n", *(volatile rt_uint32_t*)addr); | ||
break; | ||
default: | ||
rt_kprintf("0x%08x\n", *(volatile rt_uint32_t*)addr); | ||
break; | ||
} | ||
} | ||
} | ||
MSH_CMD_EXPORT(devmem, devmem address [type [data]]); |