Added Project Structure
authorDaniel Giritzer <daniel@giritzer.eu>
Fri, 2 Jun 2017 15:34:21 +0000 (17:34 +0200)
committerDaniel Giritzer <daniel@giritzer.eu>
Fri, 2 Jun 2017 15:34:21 +0000 (17:34 +0200)
src/Makefile [new file with mode: 0644]
src/devmem2.c [new file with mode: 0644]
src/devmem2.h [new file with mode: 0644]
src/main.c [new file with mode: 0644]
src/tvout.cbp [new file with mode: 0644]

diff --git a/src/Makefile b/src/Makefile
new file mode 100644 (file)
index 0000000..32c6b01
--- /dev/null
@@ -0,0 +1,125 @@
+############################################################################
+# Workfile: Makefile
+# Author: Daniel Giritzer, S1510306010
+#        giri@nwrk.biz
+# Date: 06.04.2016
+# Description: Universal Makefile for Unix based Operating Systems
+#
+# Remarks:     Compatible with CodeBlocks (C::B)
+#                      PROJNAME variable should match your project name!
+# Revision: 5.4
+# Usage: make debug            - builds debug version
+#               make release   - builds release version
+#               make all       - builds debug and release version
+#               make clean     - cleans project
+#               make rebuild   - builds everything from scratch
+############################################################################
+
+####################
+#GENERAL | EDIT 1/3
+####################
+WORKDIR = $(shell pwd)
+SOURCES := $(shell ls *.c)
+PROJNAME = tvout
+
+CC = gcc
+CXX = g++
+AR = ar
+LD = g++
+WINDRES = windres
+
+INC =
+CFLAGS = -Wall -fexceptions -std=c++11
+RESINC =
+LIBDIR =
+LIB =
+LDFLAGS =
+
+############################
+#DEBUG SETTINGS | EDIT: 2/3
+############################
+INC_DEBUG = $(INC)
+CFLAGS_DEBUG = $(CFLAGS) -g
+RESINC_DEBUG = $(RESINC)
+RCFLAGS_DEBUG = $(RCFLAGS)
+LIBDIR_DEBUG = $(LIBDIR)
+LIB_DEBUG = $(LIB)
+LDFLAGS_DEBUG = $(LDFLAGS)
+OBJDIR_DEBUG = obj/Debug
+DEP_DEBUG =
+OUT_DEBUG = bin/Debug/$(PROJNAME)
+
+
+##############################
+#RELEASE SETTINGS | EDIT: 3/3
+##############################
+INC_RELEASE = $(INC)
+CFLAGS_RELEASE = $(CFLAGS) -O2
+RESINC_RELEASE = $(RESINC)
+RCFLAGS_RELEASE = $(RCFLAGS)
+LIBDIR_RELEASE = $(LIBDIR)
+LIB_RELEASE = $(LIB)
+LDFLAGS_RELEASE = $(LDFLAGS) -s
+OBJDIR_RELEASE = obj/Release
+DEP_RELEASE =
+OUT_RELEASE = bin/Release/$(PROJNAME)
+
+############################
+#OBJECT LISTS | DO NOT EDIT!
+############################
+OBJ_DEBUG = $(addprefix $(OBJDIR_DEBUG)/,$(SOURCES:%.c=%.o))
+OBJ_RELEASE = $(addprefix $(OBJDIR_RELEASE)/,$(SOURCES:%.c=%.o))
+
+
+##########################
+#FUNCTIONS | DO NOT EDIT!
+##########################
+
+######## General
+all All: debug release
+clean Clean: cleanDebug cleanRelease
+rebuild Rebuild: clean debug release
+
+######## DEBUG
+before_debug:
+       test -d bin/Debug || mkdir -p bin/Debug
+       test -d $(OBJDIR_DEBUG) || mkdir -p $(OBJDIR_DEBUG)
+
+after_debug:
+
+debug Debug: before_debug out_debug after_debug
+
+out_debug: before_debug $(OBJ_DEBUG) $(DEP_DEBUG)
+       $(LD) $(LDFLAGS_DEBUG) $(LIBDIR_DEBUG) $(OBJ_DEBUG) $(LIB_DEBUG) -o $(OUT_DEBUG)
+
+$(OBJDIR_DEBUG)/%.o: %.c
+       $(CXX) $(CFLAGS_DEBUG) $(INC_DEBUG) -c $< -D_DEBUG -o $@
+
+clean_debug cleanDebug:
+       rm -f $(OBJ_DEBUG) $(OUT_DEBUG)
+       rm -rf bin/Debug
+       rm -rf $(OBJDIR_DEBUG)
+
+
+######## RELEASE
+before_release:
+       test -d bin/Release || mkdir -p bin/Release
+       test -d $(OBJDIR_RELEASE) || mkdir -p $(OBJDIR_RELEASE)
+
+after_release:
+
+release Release: before_release out_release after_release
+
+out_release: before_release $(OBJ_RELEASE) $(DEP_RELEASE)
+       $(LD) $(LDFLAGS_RELEASE) $(LIBDIR_RELEASE) $(OBJ_RELEASE) $(LIB_RELEASE) -o $(OUT_RELEASE)
+
+$(OBJDIR_RELEASE)/%.o: %.c
+       $(CXX) $(CFLAGS_RELEASE) $(INC_RELEASE) -c $< -o $@
+
+clean_release cleanRelease:
+       rm -f $(OBJ_RELEASE) $(OUT_RELEASE)
+       rm -rf bin/Release
+       rm -rf $(OBJDIR_RELEASE)
+
+.PHONY: before_debug after_debug clean_debug cleanDebug before_release after_release clean_release cleanRelease
+
diff --git a/src/devmem2.c b/src/devmem2.c
new file mode 100644 (file)
index 0000000..7793703
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ * devmem2.c: Simple program to read/write from/to any location in memory.
+ *
+ *  Copyright (C) 2000, Jan-Derk Bakker (J.D.Bakker@its.tudelft.nl)
+ *
+ *
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <signal.h>
+#include <fcntl.h>
+#include <ctype.h>
+#include <termios.h>
+#include <sys/types.h>
+#include <sys/mman.h>
+
+#define FATAL do { fprintf(stderr, "Error at line %d, file %s (%d) [%s]\n", \
+  __LINE__, __FILE__, errno, strerror(errno)); exit(1); } while(0)
+
+#define MAP_SIZE 4096UL
+#define MAP_MASK (MAP_SIZE - 1)
+
+void writemem(address, value, int accesstype) {
+    int fd;
+    void *map_base, *virt_addr;
+       unsigned long read_result, writeval;
+       off_t target;
+       int access_type = 'w';
+
+       if(argc < 2) {
+               fprintf(stderr, "\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]);
+               exit(1);
+       }
+       target = strtoul(argv[1], 0, 0);
+
+       if(argc > 2)
+               access_type = tolower(argv[2][0]);
+
+
+    if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
+    printf("/dev/mem opened.\n");
+    fflush(stdout);
+
+    /* Map one page */
+    map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
+    if(map_base == (void *) -1) FATAL;
+    printf("Memory mapped at address %p.\n", map_base);
+    fflush(stdout);
+
+    virt_addr = map_base + (target & MAP_MASK);
+    switch(access_type) {
+               case 'b':
+                       read_result = *((unsigned char *) virt_addr);
+                       break;
+               case 'h':
+                       read_result = *((unsigned short *) virt_addr);
+                       break;
+               case 'w':
+                       read_result = *((unsigned long *) virt_addr);
+                       break;
+               default:
+                       fprintf(stderr, "Illegal data type '%c'.\n", access_type);
+                       exit(2);
+       }
+
+       if(argc > 3) {
+               writeval = strtoul(argv[3], 0, 0);
+               switch(access_type) {
+                       case 'b':
+                               *((unsigned char *) virt_addr) = writeval;
+                               read_result = *((unsigned char *) virt_addr);
+                               break;
+                       case 'h':
+                               *((unsigned short *) virt_addr) = writeval;
+                               read_result = *((unsigned short *) virt_addr);
+                               break;
+                       case 'w':
+                               *((unsigned long *) virt_addr) = writeval;
+                               read_result = *((unsigned long *) virt_addr);
+                               break;
+               }
+               printf("Written 0x%X; readback 0x%X\n", writeval, read_result);
+               fflush(stdout);
+       }
+
+       if(munmap(map_base, MAP_SIZE) == -1) FATAL;
+    close(fd);
+    return 0;
+}
+
+void readmem(address, int accesstype)
+{
+    int fd;
+    void *map_base, *virt_addr;
+       unsigned long read_result, writeval;
+       off_t target;
+       int access_type = accesstype;
+
+       target = strtoul(argv[1], 0, 0);
+
+
+    if((fd = open("/dev/mem", O_RDWR | O_SYNC)) == -1) FATAL;
+    printf("/dev/mem opened.\n");
+    fflush(stdout);
+
+    /* Map one page */
+    map_base = mmap(0, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, target & ~MAP_MASK);
+    if(map_base == (void *) -1) FATAL;
+    printf("Memory mapped at address %p.\n", map_base);
+    fflush(stdout);
+
+    virt_addr = map_base + (target & MAP_MASK);
+    switch(access_type) {
+               case 'b':
+                       read_result = *((unsigned char *) virt_addr);
+                       break;
+               case 'h':
+                       read_result = *((unsigned short *) virt_addr);
+                       break;
+               case 'w':
+                       read_result = *((unsigned long *) virt_addr);
+                       break;
+               default:
+                       fprintf(stderr, "Illegal data type '%c'.\n", access_type);
+                       exit(2);
+       }
+}
+
diff --git a/src/devmem2.h b/src/devmem2.h
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/src/main.c b/src/main.c
new file mode 100644 (file)
index 0000000..022b16e
--- /dev/null
@@ -0,0 +1,8 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+int main()
+{
+    printf("Hello world!\n");
+    return 0;
+}
diff --git a/src/tvout.cbp b/src/tvout.cbp
new file mode 100644 (file)
index 0000000..f1e8d89
--- /dev/null
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+       <FileVersion major="1" minor="6" />
+       <Project>
+               <Option title="tvout" />
+               <Option pch_mode="2" />
+               <Option compiler="gcc" />
+               <Build>
+                       <Target title="Debug">
+                               <Option output="bin/Debug/tvout" prefix_auto="1" extension_auto="1" />
+                               <Option object_output="obj/Debug/" />
+                               <Option type="1" />
+                               <Option compiler="gcc" />
+                               <Compiler>
+                                       <Add option="-g" />
+                               </Compiler>
+                       </Target>
+                       <Target title="Release">
+                               <Option output="bin/Release/tvout" prefix_auto="1" extension_auto="1" />
+                               <Option object_output="obj/Release/" />
+                               <Option type="1" />
+                               <Option compiler="gcc" />
+                               <Compiler>
+                                       <Add option="-O2" />
+                               </Compiler>
+                               <Linker>
+                                       <Add option="-s" />
+                               </Linker>
+                       </Target>
+               </Build>
+               <Compiler>
+                       <Add option="-Wall" />
+               </Compiler>
+               <Unit filename="main.c">
+                       <Option compilerVar="CC" />
+               </Unit>
+               <Extensions>
+                       <code_completion />
+                       <envvars />
+                       <lib_finder disable_auto="1" />
+                       <debugger />
+               </Extensions>
+       </Project>
+</CodeBlocks_project_file>