freemyipod r495 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r494‎ | r495 | r496 >
Date:14:53, 30 January 2011
Author:theseven
Status:new
Tags:
Comment:
New application: UART demo code
Modified paths:
  • /apps/uarttest (added) (history)
  • /apps/uarttest/Makefile (added) (history)
  • /apps/uarttest/SOURCES (added) (history)
  • /apps/uarttest/ls.x (added) (history)
  • /apps/uarttest/main.c (added) (history)
  • /apps/uarttest/version.h (added) (history)

Diff [purge]

Index: apps/uarttest/SOURCES
@@ -0,0 +1 @@
 2+main.c
Index: apps/uarttest/ls.x
@@ -0,0 +1,42 @@
 2+ENTRY(__emcore_entrypoint)
 3+OUTPUT_FORMAT(elf32-littlearm)
 4+OUTPUT_ARCH(arm)
 5+
 6+MEMORY
 7+{
 8+ VIRTUAL : ORIGIN = 0x00000000, LENGTH = 0x10000000
 9+}
 10+
 11+SECTIONS
 12+{
 13+ .text :
 14+ {
 15+ __emcore_app_base = .;
 16+ KEEP(.emcoreentrypoint*)
 17+ *(.emcoreentrypoint*)
 18+ *(.text*)
 19+ *(.glue_7)
 20+ *(.glue_7t)
 21+ . = ALIGN(0x10);
 22+ } > VIRTUAL
 23+
 24+ .data :
 25+ {
 26+ *(.rodata*)
 27+ . = ALIGN(0x4);
 28+ *(.data*)
 29+ . = ALIGN(0x4);
 30+ } > VIRTUAL
 31+
 32+ .bss (NOLOAD) :
 33+ {
 34+ *(.bss*)
 35+ *(COMMON)
 36+ } > VIRTUAL
 37+
 38+ /DISCARD/ :
 39+ {
 40+ *(.eh_frame)
 41+ }
 42+
 43+}
Index: apps/uarttest/main.c
@@ -0,0 +1,50 @@
 2+#include "emcoreapp.h"
 3+
 4+
 5+#define ULCON (*((uint32_t volatile*)0x3cc00000))
 6+#define UCON (*((uint32_t volatile*)0x3cc00004))
 7+#define UFCON (*((uint32_t volatile*)0x3cc00008))
 8+#define UMCON (*((uint32_t volatile*)0x3cc0000c))
 9+#define UFSTAT (*((uint32_t volatile*)0x3cc00018))
 10+#define UTXH (*((uint8_t volatile*)0x3cc00020))
 11+#define URXH (*((uint8_t volatile*)0x3cc00024))
 12+#define UBRDIV (*((uint32_t volatile*)0x3cc00028))
 13+
 14+
 15+static void uart_tx(char byte)
 16+{
 17+ while (UFSTAT & BIT(9)) sleep(100);
 18+ UTXH = byte;
 19+}
 20+
 21+static char uart_rx()
 22+{
 23+ while (!(UFSTAT & BITRANGE(0, 3))) sleep(100);
 24+ return URXH;
 25+}
 26+
 27+static void main()
 28+{
 29+ int i;
 30+ clockgate_enable(41, true);
 31+ ULCON = 3;
 32+ UCON = 0x405;
 33+ UFCON = 7;
 34+ UMCON = 0;
 35+ switch (get_platform_id())
 36+ {
 37+ case 0x47324e49: // IN2G
 38+ UBRDIV = 38;
 39+ break;
 40+ case 0x4c435049: // IPCL
 41+ UBRDIV = 18;
 42+ break;
 43+ default:
 44+ panic(PANIC_KILLTHREAD, "Unknown platform!");
 45+ }
 46+ uart_tx('~');
 47+ while (true) uart_tx(uart_rx() ^ 0x20);
 48+}
 49+
 50+
 51+EMCORE_APP_HEADER("UART test", main, 127)
Index: apps/uarttest/version.h
@@ -0,0 +1,36 @@
 2+//
 3+//
 4+// Copyright 2010 TheSeven
 5+//
 6+//
 7+// This file is part of emBIOS.
 8+//
 9+// emBIOS is free software: you can redistribute it and/or
 10+// modify it under the terms of the GNU General Public License as
 11+// published by the Free Software Foundation, either version 2 of the
 12+// License, or (at your option) any later version.
 13+//
 14+// emBIOS is distributed in the hope that it will be useful,
 15+// but WITHOUT ANY WARRANTY; without even the implied warranty of
 16+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 17+// See the GNU General Public License for more details.
 18+//
 19+// You should have received a copy of the GNU General Public License along
 20+// with emBIOS. If not, see <http://www.gnu.org/licenses/>.
 21+//
 22+//
 23+
 24+
 25+#ifndef __VERSION_H__
 26+#define __VERSION_H__
 27+
 28+
 29+#define VERSION "0.0.1pre"
 30+#define VERSION_MAJOR 0
 31+#define VERSION_MINOR 0
 32+#define VERSION_PATCH 1
 33+#define VERSION_SVN "$REVISION$"
 34+#define VERSION_SVN_INT $REVISIONINT$
 35+
 36+
 37+#endif
\ No newline at end of file
Index: apps/uarttest/Makefile
@@ -0,0 +1,121 @@
 2+NAME := uarttest
 3+STACKSIZE := 4096
 4+COMPRESS := true
 5+
 6+EMCOREDIR ?= ../../emcore/trunk/
 7+
 8+ifeq ($(shell uname),WindowsNT)
 9+CCACHE :=
 10+else
 11+CCACHE := $(shell which ccache)
 12+endif
 13+
 14+CROSS ?= arm-elf-eabi-
 15+CC := $(CCACHE) $(CROSS)gcc
 16+AS := $(CROSS)as
 17+LD := $(CROSS)ld
 18+OBJCOPY := $(CROSS)objcopy
 19+ELF2ECA := $(CROSS)elf2emcoreapp
 20+
 21+LIBINCLUDES :=
 22+
 23+CFLAGS += -Os -fno-pie -fno-stack-protector -fomit-frame-pointer -I. -I$(EMCOREDIR)/export $(LIBINCLUDES) -ffunction-sections -fdata-sections -mcpu=arm940t -DARM_ARCH=4
 24+LDFLAGS += "$(shell $(CC) -print-libgcc-file-name)" --emit-relocs --gc-sections
 25+
 26+preprocess = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#")
 27+preprocesspaths = $(shell $(CC) $(PPCFLAGS) $(2) -E -P -x c $(1) | grep -v "^\#" | sed -e "s:^..*:$(dir $(1))&:")
 28+
 29+REVISION := $(shell svnversion .)
 30+REVISIONINT := $(shell echo $(REVISION) | sed -e "s/[^0-9].*$$//")
 31+
 32+HELPERS := build/__emcore_armhelpers.o
 33+
 34+SRC := $(call preprocesspaths,SOURCES,-I. -I..)
 35+OBJ := $(SRC:%.c=build/%.o)
 36+OBJ := $(OBJ:%.S=build/%.o) $(HELPERS)
 37+
 38+all: $(NAME)
 39+
 40+-include $(OBJ:%=%.dep)
 41+
 42+$(NAME): build/$(NAME).emcoreapp
 43+
 44+build/$(NAME).emcoreapp: build/$(NAME).elf
 45+ @echo [EMCAPP] $<
 46+ifeq ($(COMPRESS),true)
 47+ @$(ELF2ECA) -z -s $(STACKSIZE) -o $@ $^
 48+else
 49+ @$(ELF2ECA) -s $(STACKSIZE) -o $@ $^
 50+endif
 51+
 52+build/$(NAME).elf: ls.x $(OBJ)
 53+ @echo [LD] $@
 54+ @$(LD) $(LDFLAGS) -o $@ -T ls.x $(OBJ)
 55+
 56+build/%.o: %.c build/version.h
 57+ @echo [CC] $<
 58+ifeq ($(shell uname),WindowsNT)
 59+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 60+else
 61+ @-mkdir -p $(dir $@)
 62+endif
 63+ @$(CC) -c $(CFLAGS) -o $@ $<
 64+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 65+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 66+ifeq ($(shell uname),WindowsNT)
 67+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 68+else
 69+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 70+endif
 71+ @rm -f $@.dep.tmp
 72+
 73+build/%.o: %.S build/version.h
 74+ @echo [CC] $<
 75+ifeq ($(shell uname),WindowsNT)
 76+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 77+else
 78+ @-mkdir -p $(dir $@)
 79+endif
 80+ @$(CC) -c $(CFLAGS) -o $@ $<
 81+ @$(CC) -MM $(CFLAGS) $< > $@.dep.tmp
 82+ @sed -e "s|.*:|$@:|" < $@.dep.tmp > $@.dep
 83+ifeq ($(shell uname),WindowsNT)
 84+ @sed -e "s/.*://" -e "s/\\$$//" < $@.dep.tmp | fmt -1 | sed -e "s/^ *//" -e "s/$$/:/" >> $@.dep
 85+else
 86+ @sed -e 's/.*://' -e 's/\\$$//' < $@.dep.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.dep
 87+endif
 88+ @rm -f $@.dep.tmp
 89+
 90+build/__emcore_%.o: $(EMCOREDIR)/export/%.c
 91+ @echo [CC] $<
 92+ifeq ($(shell uname),WindowsNT)
 93+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 94+else
 95+ @-mkdir -p $(dir $@)
 96+endif
 97+ @$(CC) -c $(CFLAGS) -o $@ $<
 98+
 99+build/__emcore_%.o: $(EMCOREDIR)/export/%.S
 100+ @echo [CC] $<
 101+ifeq ($(shell uname),WindowsNT)
 102+ @-if not exist $(subst /,\,$(dir $@)) md $(subst /,\,$(dir $@))
 103+else
 104+ @-mkdir -p $(dir $@)
 105+endif
 106+ @$(CC) -c $(CFLAGS) -o $@ $<
 107+
 108+build/version.h: version.h .svn/entries build
 109+ @echo [PP] $<
 110+ifeq ($(shell uname),WindowsNT)
 111+ @sed -e "s/\$$REVISION\$$/$(REVISION)/" -e "s/\$$REVISIONINT\$$/$(REVISIONINT)/" < $< > $@
 112+else
 113+ @sed -e 's/\$$REVISION\$$/$(REVISION)/' -e 's/\$$REVISIONINT\$$/$(REVISIONINT)/' < $< > $@
 114+endif
 115+
 116+build:
 117+ @mkdir $@
 118+
 119+clean:
 120+ rm -rf build
 121+
 122+.PHONY: all clean $(NAME)
Index: apps/uarttest
Property changes on: apps/uarttest
___________________________________________________________________
Added: svn:ignore
## -0,0 +1 ##
 123+build