// Author: Jan-Derk Bakker, Daniel Giritzer
// Date: 2017-06-02
// Description: Simple module to read/write from/to any location in memory.
-// Remarks: -
-// Revision: 1
+// Remarks: assumes a 4k page size and that sizeof(unsigned long) == 4
+// Revision: 1.2
// Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
// Copyright (C) 2017, Daniel Giritzer (giri@nwrk.biz)
///////////////////////////////////////////////////////////////////////////
#define MAP_SIZE 4096UL
#define MAP_MASK (MAP_SIZE - 1)
+
+/////////////////////////////////////////////////
+/// \brief This function is called by the module
+/// if an error occurs.
+///
+/// \param char* Custom error Message.
+/////////////////////////////////////////////////
static void ERROR(char* custom)
{
+ //print custom error message
fprintf(stderr, "Error: %s \n", custom);
+
+ //print further information
fprintf(stderr, "Info: %d, %s\n",
errno, strerror(errno));
}
+/////////////////////////////////////////////////
+/// \brief This function allows writing to memory
+/// on the specified address.
+///
+/// \param char* Address to write to
+/// \param char* 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 fd;
return EXIT_SUCCESS;
}
+/////////////////////////////////////////////////
+/// \brief This function allows reading the memory
+/// on the specified address.
+///
+/// \param char* 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 fd;
///////////////////////////////////////////////////////////////////////////
-// Workfile: devmem2.h (Implementation)
+// Workfile: devmem2.h (Header)
// Author: Jan-Derk Bakker, Daniel Giritzer
// Date: 2017-06-02
// Description: Simple module to read/write from/to any location in memory.
-// Remarks: -
-// Revision: 1
+// Remarks: assumes a 4k page size and that sizeof(unsigned long) == 4
+// Revision: 1.2
// Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
// Copyright (C) 2017, Daniel Giritzer (giri@nwrk.biz)
///////////////////////////////////////////////////////////////////////////
#ifndef DEVMEM2_H_INCLUDED
#define DEVMEM2_H_INCLUDED
-
+/////////////////////////////////////////////////
+/// \brief This function allows writing to memory
+/// on the specified address.
+///
+/// \param char* Address to write to
+/// \param char* Value to write
+/// \param int Access type, should be 'w' (word),
+/// 'h' (halfword), 'b'(byte)
+/////////////////////////////////////////////////
int writemem(char* address, char* value, int access_type);
+/////////////////////////////////////////////////
+/// \brief This function allows reading the memory
+/// on the specified address.
+///
+/// \param char* 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);
-
#endif // DEVMEM2_H_INCLUDED
+///////////////////////////////////////////////////////////////////////////
+// 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"
{
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;
}