/// \brief This function allows writing to memory
/// on the specified address.
///
-/// \param char* Address to write to
-/// \param char* Value to write
+/// \param unsigned long Address to write to
+/// \param unsigned long Value to write
/// \param int Access type, should be 'w' (word),
/// 'h' (halfword), 'b'(byte)
/////////////////////////////////////////////////
-int writemem(char* address, char* value, int access_type)
+int writemem(unsigned long address, unsigned long writeval, int access_type)
{
int fd;
void *map_base = 0;
void *virt_addr = 0;
- unsigned long writeval = 0;
-
- off_t target = strtoul(address, 0, 0);
+ off_t target = address;
+ // Try to open /dev/mem
if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1)
{
ERROR("Opening /dev/mem/ failed!");
// Map one page
map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
+ // Check if mapping was successful
if(map_base == (void *) -1)
{
+ //Print error on failure
ERROR("Mapping Memory Page Failed!");
return EXIT_FAILURE;
}
-
+ //calculate virtual address
virt_addr = map_base + (target & MAP_MASK);
- writeval = strtoul(value, 0, 0);
+
+ //write value to memory
switch(access_type)
{
case 'b':
break;
}
-
+ //unmap memory
if(munmap(map_base, MAP_SIZE) == -1)
{
ERROR("Unmapping Memory Page Failed!");
/// 'h' (halfword), 'b'(byte)
/// \param unsigned long* pointer result variable
/////////////////////////////////////////////////
-int readmem(char* address, int access_type, unsigned long *result)
+int readmem(unsigned long address, int access_type, unsigned long *result)
{
int fd;
void *map_base, *virt_addr;
- off_t target;
unsigned long read_result = 0;
- target = strtoul(address, 0, 0);
+ off_t target = address;
+ //check if result variable is a nullpointer
if(result == NULL)
{
//Print error on failure
return EXIT_FAILURE;
}
+ //calculate virtual address
virt_addr = map_base + (target & MAP_MASK);
+
+ //read value
switch(access_type)
{
case 'b':
break;
}
+ // unmap memory
if(munmap(map_base, MAP_SIZE) == -1)
{
ERROR("Unmapping Memory Page Failed!");
return EXIT_FAILURE;
}
+ // return result
*result = read_result;
close(fd);
/// \brief This function allows writing to memory
/// on the specified address.
///
-/// \param char* Address to write to
-/// \param char* Value to write
+/// \param unsigned long Address to write to
+/// \param unsigned long Value to write
/// \param int Access type, should be 'w' (word),
/// 'h' (halfword), 'b'(byte)
/////////////////////////////////////////////////
-int writemem(char* address, char* value, int access_type);
+int writemem(unsigned long address, unsigned long writeval, int access_type);
/////////////////////////////////////////////////
/// \brief This function allows reading the memory
/// on the specified address.
///
-/// \param char* Address to read from
+/// \param unsigned long Address to read from
/// \param int Access type, should be 'w' (word),
/// 'h' (halfword), 'b'(byte)
/// \param unsigned long* pointer result variable
/////////////////////////////////////////////////
-int readmem(char* address, int access_type, unsigned long *result);
+int readmem(unsigned long address, int access_type, unsigned long *result);
#endif // DEVMEM2_H_INCLUDED
///////////////////////////////////////////////////////////////////////////
-// Workfile: devmem2_test.c (Implementation)
+// Workfile: tvout.c (Implementation)
// Author: Daniel Giritzer
// Date: 2017-06-02
-// Description: Simple Testdriver for the devmem2 module
+// Description: Simple Program to move the
// Remarks: -
// Revision: 1
// Copyright (C) 2017, Daniel Giritzer (giri@nwrk.biz)
#include <stdio.h>
#include <stdlib.h>
#include "devmem2.h"
+#include "tvout.h"
int main()
{
unsigned long readfrommemory = 0;
//Testing writemem
- writemem("0x01E00130", "0x10140025", 'w');
+ writemem(0x01E00130, 0x10140025, 'w');
//Testing readmem
- readmem("0x01E00130", 'w', &readfrommemory);
+ readmem(0x01E00130, 'w', &readfrommemory);
//Print read value to stdout
printf("Value: 0x%X \n", (unsigned int)readfrommemory);
--- /dev/null
+///////////////////////////////////////////////////////////////////////////
+// Workfile: devmem2_test.c (Implementation)
+// Author: Daniel Giritzer
+// Date: 2017-06-02
+// Description: Simple Testdriver for the devmem2 module
+// Remarks: -
+// Revision: 1
+// Copyright (C) 2017, Daniel Giritzer (giri@nwrk.biz)
+///////////////////////////////////////////////////////////////////////////
+#include <stdio.h>
+#include <stdlib.h>
+#include "devmem2.h"
+
+int main()
+{
+ unsigned long readfrommemory = 0;
+
+ //Testing writemem
+ writemem("0x01E00130", "0x10140025", 'w');
+
+ //Testing readmem
+ readmem("0x01E00130", 'w', &readfrommemory);
+
+ //Print read value to stdout
+ printf("Value: 0x%X \n", (unsigned int)readfrommemory);
+ return 0;
+}
--- /dev/null
+///////////////////////////////////////////////////////////////////////////
+// Workfile: tvout.h (Header)
+// Author: Daniel Giritzer
+// Date: 2017-06-02
+// Description:
+// Remarks: -
+// Revision: 1
+// Copyright (C) 2017, Daniel Giritzer (giri@nwrk.biz)
+///////////////////////////////////////////////////////////////////////////
+#ifndef TVOUT_H_INCLUDED
+#define TVOUT_H_INCLUDED
+
+#define TV_BASE 0x01E00000
+
+
+#endif // TVOUT_H_INCLUDED