Permalink
Browse files

Update with initial support and drivers for the Microblaze MCS

  • Loading branch information...
1 parent 2e8f47e commit 3db7967c54b667d2f623ff42b33d5483e69bb5c7 @kpansky committed Mar 18, 2012
@@ -0,0 +1,108 @@
+############
+# Settings #
+############
+
+# Build all test applications:
+# make
+#
+
+# Location of build tools and atomthreads sources
+KERNEL_DIR=../../kernel
+TESTS_DIR=../../tests
+BSP_DIR = ./mcs_bsp
+CC=mb-gcc
+OBJCOPY=mb-objcopy
+SIZE=mb-size
+LITTLE_ENDIAN=true
+
+# Enable stack-checking.
+STACK_CHECK=true
+
+# Directory for built objects
+BUILD_DIR=build
+
+# Port/application object files
+APP_OBJECTS = atomport.o tests-main.o
+APP_ASM_OBJECTS = atomport-asm.o
+BSP_OBJECTS = xiomodule.o
+BSP_LDSCRIPT = linker_bram_64k.ld
+
+# Kernel object files
+KERNEL_OBJECTS = atomkernel.o atomsem.o atommutex.o atomtimer.o atomqueue.o
+
+# Collection of built objects (excluding test applications)
+ALL_OBJECTS = $(APP_OBJECTS) $(APP_ASM_OBJECTS) $(KERNEL_OBJECTS) $(BSP_OBJECTS)
+BUILT_OBJECTS = $(patsubst %,$(BUILD_DIR)/%,$(ALL_OBJECTS))
+
+# Test object files (dealt with separately as only one per application build)
+TEST_OBJECTS = $(notdir $(patsubst %.c,%.o,$(wildcard $(TESTS_DIR)/*.c)))
+
+# Target application filenames (.elf and .hex) for each test object
+TEST_ELFS = $(patsubst %.o,%.elf,$(TEST_OBJECTS))
+TEST_HEXS = $(patsubst %.o,%.hex,$(TEST_OBJECTS))
+
+# Search build/output directory for dependencies
+vpath %.o ./$(BUILD_DIR)
+vpath %.elf ./$(BUILD_DIR)
+vpath %.hex ./$(BUILD_DIR)
+
+# GCC flags
+CFLAGS=-g -Os -Wall -Werror -mlittle-endian
+
+# Enable stack-checking (disable if not required)
+ifeq ($(STACK_CHECK),true)
+CFLAGS += -DATOM_STACK_CHECKING
+endif
+
+#################
+# Build targets #
+#################
+
+# All tests
+all: $(BUILD_DIR) $(TEST_HEXS) Makefile
+
+# Make build/output directory
+$(BUILD_DIR):
+ mkdir $(BUILD_DIR)
+
+# Test HEX files (one application build for each test)
+$(TEST_HEXS): %.hex: %.elf
+ @echo Building $@
+ $(OBJCOPY) -j .text -j .data -O ihex $(BUILD_DIR)/$< $(BUILD_DIR)/$@
+
+# Test ELF files (one application build for each test)
+$(TEST_ELFS): %.elf: %.o $(KERNEL_OBJECTS) $(BSP_OBJECTS) $(APP_OBJECTS) $(APP_ASM_OBJECTS)
+ $(CC) $(CFLAGS) $(BUILD_DIR)/$(notdir $<) $(BUILT_OBJECTS) --output $(BUILD_DIR)/$@ -Wl,-Map,$(BUILD_DIR)/$(basename $@).map -T$(BSP_DIR)/$(BSP_LDSCRIPT)
+
+# Kernel objects builder
+$(KERNEL_OBJECTS): %.o: $(KERNEL_DIR)/%.c
+ $(CC) -c $(CFLAGS) -I. -I$(BSP_DIR) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# Test objects builder
+$(TEST_OBJECTS): %.o: $(TESTS_DIR)/%.c
+ $(CC) -c $(CFLAGS) -I. -I$(KERNEL_DIR) -I$(BSP_DIR) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# Application C objects builder
+$(APP_OBJECTS): %.o: ./%.c
+ $(CC) -c $(CFLAGS) -I. -I$(KERNEL_DIR) -I$(TESTS_DIR) -I$(BSP_DIR) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# Application asm objects builder
+$(APP_ASM_OBJECTS): %.o: ./%.s
+ $(CC) -c $(CFLAGS) -x assembler-with-cpp -I. -I$(KERNEL_DIR) -I$(BSP_DIR) $< -o $(BUILD_DIR)/$(notdir $@)
+
+$(BSP_OBJECTS): %.o: $(BSP_DIR)/%.c
+ $(CC) -c $(CFLAGS) -I. -I$(KERNEL_DIR) -I$(TESTS_DIR) -I$(BSP_DIR) $< -o $(BUILD_DIR)/$(notdir $@)
+
+# .lst file builder
+%.lst: %.c
+ $(CC) $(CFLAGS) -I. -I$(KERNEL_DIR) -I$(TESTS_DIR) -I$(BSP_DIR) -Wa,-al $< > $@
+
+# Clean
+clean:
+ rm -fr build
+ rm -fr doxygen-kernel
+ rm -fr doxygen-microblaze
+
+doxygen:
+ doxygen $(KERNEL_DIR)/Doxyfile
+ doxygen ./Doxyfile
@@ -47,16 +47,16 @@ minimum.
PREREQUISITES
-TBD:
+TBD MCS:
---------------------------------------------------------------------------
BUILDING THE SOURCE
-TBD:
-Code was tested by adding required files to a SDK project exported from the
-EDK. Makefile for building on the commandline is TBD.
+TBD MCS:
+Code was tested by adding required files to a Xilinx SDK project exported from the
+Xilinx EDK. Makefile for building on the commandline is TBD.
---------------------------------------------------------------------------
@@ -42,7 +42,8 @@
* it around a critical section for safety.
*/
//#define ATOMLOG printf
-#define ATOMLOG(format, ...) {CRITICAL_STORE; CRITICAL_START(); printf(format, ##__VA_ARGS__); CRITICAL_END();}
+//#define ATOMLOG(format, ...) {CRITICAL_STORE; CRITICAL_START(); printf(format, ##__VA_ARGS__); CRITICAL_END();}
+#define ATOMLOG(format, ...) {CRITICAL_STORE; CRITICAL_START(); print(format); CRITICAL_END();}
/*
* String location macro: for platforms which need to place strings in
@@ -31,11 +31,42 @@
#include "atom.h"
#include "xparameters.h"
#include "mb_interface.h"
-#include "xtmrctr.h"
-#include "xintc.h"
+#if defined(XPAR_XIOMODULE_NUM_INSTANCES)
+
+/* We are using the Microblaze MCS */
+
+#include "xiomodule.h"
+static XIOModule myIOModule;
+
+#define myIntc myIOModule
+#define myTmrCtr myIOModule
+#define XPAR_XPS_INTC_0_DEVICE_ID XPAR_IOMODULE_0_DEVICE_ID
+#define XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR 3
+#define XPAR_XPS_TIMER_0_DEVICE_ID 0
+#define XIntc_Initialize XIOModule_Initialize
+#define XIntc_SetOptions XIOModule_SetOptions
+#define XIntc_Connect XIOModule_Connect
+#define XIntc_Start(a,b) XIOModule_Start(a)
+#define XIntc_Enable XIOModule_Enable
+#define XIntc_DeviceInterruptHandler XIOModule_DeviceInterruptHandler
+#define XTmrCtr_Initialize XIOModule_Timer_Initialize
+#define XTmrCtr_InterruptHandler XIOModule_Timer_InterruptHandler
+#define XTmrCtr_SetOptions XIOModule_Timer_SetOptions
+#define XTmrCtr_SetResetValue XIOModule_SetResetValue
+#define XTmrCtr_Start XIOModule_Timer_Start
+
+#else
+
+/* We are using a Microblaze from EDK */
+#include "xintc.h"
+#include "xtmrctr.h"
static XIntc myIntc;
static XTmrCtr myTmrCtr;
+
+#endif
+
+
volatile uint32_t myTmrCtrIntOccurred;
/**
@@ -54,14 +85,14 @@ volatile uint32_t myTmrCtrIntOccurred;
*/
void microblazeInterruptWrapper(void *DataPtr)
{
- atomIntEnter();
- myTmrCtrIntOccurred = FALSE;
- XIntc_DeviceInterruptHandler(DataPtr);
- if (myTmrCtrIntOccurred == TRUE)
- {
- atomTimerTick();
- }
- atomIntExit(TRUE);
+ atomIntEnter();
+ myTmrCtrIntOccurred = FALSE;
+ XIntc_DeviceInterruptHandler(DataPtr);
+ if (myTmrCtrIntOccurred == TRUE)
+ {
+ atomTimerTick();
+ }
+ atomIntExit(TRUE);
}
/**
@@ -74,12 +105,9 @@ void microblazeInterruptWrapper(void *DataPtr)
*
* @return None
*/
-void microblazeTimerHandler(void *CallBackRef, uint8_t TmrCtrNumber)
+void microblazeTimerHandler(void *CallBackRef)
{
- if (TmrCtrNumber == 0)
- {
- myTmrCtrIntOccurred = TRUE;
- }
+ myTmrCtrIntOccurred = TRUE;
}
/**
@@ -96,15 +124,15 @@ void microblazeInitSystemTickTimer ( void )
/* Setup the interrupt controller with the timer enabled */
XIntc_Initialize(&myIntc, XPAR_XPS_INTC_0_DEVICE_ID);
+ XIntc_SetOptions(&myIntc, XIN_SVC_ALL_ISRS_OPTION);
XIntc_Connect(&myIntc, XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR,
- (XInterruptHandler)XTmrCtr_InterruptHandler, &myTmrCtr);
+ (XInterruptHandler)microblazeTimerHandler, &myTmrCtr);
XIntc_Start(&myIntc, XIN_REAL_MODE);
XIntc_Enable(&myIntc, XPAR_XPS_INTC_0_XPS_TIMER_0_INTERRUPT_INTR);
/* Set our timer to generate automatic interrupts at a SYSTEM_TICKS_PER_SEC rate */
XTmrCtr_Initialize(&myTmrCtr, XPAR_XPS_TIMER_0_DEVICE_ID);
- XTmrCtr_SetOptions(&myTmrCtr, 0, XTC_DOWN_COUNT_OPTION | XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION);
- XTmrCtr_SetHandler(&myTmrCtr, (XTmrCtr_Handler)microblazeTimerHandler, NULL);
+ XTmrCtr_SetOptions(&myTmrCtr, 0, XTC_INT_MODE_OPTION | XTC_AUTO_RELOAD_OPTION);
XTmrCtr_SetResetValue(&myTmrCtr, 0, XPAR_CPU_CORE_CLOCK_FREQ_HZ / SYSTEM_TICKS_PER_SEC);
XTmrCtr_Start(&myTmrCtr, 0);
}
@@ -31,24 +31,28 @@
#ifndef __ATOM_PORT_H
#define __ATOM_PORT_H
+#include "xparameters.h"
#include "mb_interface.h"
+/* For NULL */
+#include <string.h>
+
/* Required number of system ticks per second (normally 100 for 10ms tick) */
#define SYSTEM_TICKS_PER_SEC 100
-/* Size of each stack entry / stack alignment size (8 bits on AVR) */
+/* Size of each stack entry / stack alignment size */
#define STACK_ALIGN_SIZE sizeof(uint32_t)
/**
* Architecture-specific types.
*/
#define uint8_t unsigned char
#define uint16_t unsigned short
-#define uint32_t unsigned long
+#define uint32_t unsigned int
#define uint64_t unsigned long long
#define int8_t char
#define int16_t short
-#define int32_t long
+#define int32_t int
#define int64_t long long
#define POINTER void *
@@ -59,7 +63,7 @@
/* Uncomment to enable stack-checking */
-#define ATOM_STACK_CHECKING
+/* #define ATOM_STACK_CHECKING */
#endif /* __ATOM_PORT_H */
Oops, something went wrong.

0 comments on commit 3db7967

Please sign in to comment.