sitara_depot/utils/FileToSharedMem/DevMem.cpp

42 lines
1.1 KiB
C++

#include <iostream>
#include <cstring>
#include "MemMapping.h"
int main(int argc, char **argv)
{
switch(argc)
{
case 2:
{
size_t addrPhys = std::stoull(argv[1], nullptr, 0);
int val;
MemMapping map(O_RDONLY, addrPhys, sizeof(val), PROT_READ, MAP_PRIVATE);
memcpy(&val, map.get(), sizeof(val));
std::cout << "0x" << std::hex << val << std::endl;
}
break;
case 3:
{
size_t addrPhys = std::stoull(argv[1], nullptr, 0);
int val = std::stoull(argv[2], nullptr, 0);
MemMapping map(O_RDWR | O_SYNC, addrPhys, sizeof(val), PROT_READ | PROT_WRITE, MAP_SHARED);
memcpy(map.get(), &val, sizeof(val));
}
break;
default:
{
std::cout << "Wrong argument count!" << std::endl;
std::cout << "Usage:" << std::endl;
std::cout << "Read 32 bits: devmem 0x12345678" << std::endl;
std::cout << "Write 32 bits: devmem 0x12345678 314159" << std::endl;
}
break;
}
return 0;
}