# --------------------------------------------------------------------------
#  --  This file is a part of COBHAM RESEARCH source code.
#  --  Copyright (C) 2015, Cobham Gaisler AB - all rights reserved.
#  --
#  -- ANY USE OR REDISTRIBUTION IN PART OR IN WHOLE MUST BE HANDLED IN
#  -- ACCORDANCE WITH THE GAISLER LICENSE AGREEMENT AND MUST BE APPROVED
#  -- IN ADVANCE IN WRITING.
#  --
#  -- BY DEFAULT, DISTRIBUTION OR DISCLOSURE IS NOT PERMITTED.
#  -------------------------------------------------------------------------- 
#
#include ../../config.mk

CC=sparc-rtems-gcc
CFLAGS=-Wall -g -O2 -mcpu=v8 -qngmp

PROGS= rtems-gr740-amp1 rtems-gr740-amp2 rtems-gr740-amp3 rtems-gr740-amp4 rtems-gr740-amp.grmon2

# Shared Message Passing Communication Area
GR740_AMP_SHM_START=0x00000000
GR740_AMP_SHM_SIZE=0x1000
# Memory resource split up between CPU nodes
GR740_AMP_TEXT1=0x00001000
GR740_AMP_TEXT2=0x01000000
GR740_AMP_TEXT3=0x02000000
GR740_AMP_TEXT4=0x03000000
GR740_AMP_STACK1=0x00fffff0
GR740_AMP_STACK2=0x01fffff0
GR740_AMP_STACK3=0x02fffff0
GR740_AMP_STACK4=0x03fffff0
all: $(PROGS)

rtems-gr740-amp1: rtems-gr740-amp.c config_amp.c
	$(CC) $(CFLAGS) \
		-DSHM_START=$(GR740_AMP_SHM_START) \
		-DSHM_SIZE=$(GR740_AMP_SHM_SIZE) \
		-DNODE_NUMBER=1 \
		-Wl,-Ttext,$(GR740_AMP_TEXT1) $< -o $@

rtems-gr740-amp2: rtems-gr740-amp.c config_amp.c
	$(CC) $(CFLAGS) \
		-DSHM_START=$(GR740_AMP_SHM_START) \
		-DSHM_SIZE=$(GR740_AMP_SHM_SIZE) \
		-DNODE_NUMBER=2 \
		-Wl,-Ttext,$(GR740_AMP_TEXT2) $< -o $@

rtems-gr740-amp3: rtems-gr740-amp.c config_amp.c
	$(CC) $(CFLAGS) \
		-DSHM_START=$(GR740_AMP_SHM_START) \
		-DSHM_SIZE=$(GR740_AMP_SHM_SIZE) \
		-DNODE_NUMBER=3 \
		-Wl,-Ttext,$(GR740_AMP_TEXT3) $< -o $@

rtems-gr740-amp4: rtems-gr740-amp.c config_amp.c
	$(CC) $(CFLAGS) \
		-DSHM_START=$(GR740_AMP_SHM_START) \
		-DSHM_SIZE=$(GR740_AMP_SHM_SIZE) \
		-DNODE_NUMBER=4 \
		-Wl,-Ttext,$(GR740_AMP_TEXT4) $< -o $@

# AMP Targets 
.PHONY:rtems-gr740-amp.grmon2
rtems-gr740-amp.grmon2:
	@echo "# GRMON 2.0 script: Load and run RTEMS GR740 AMP example" > $@
	@echo "reset" 				>> $@
	@echo "bp del" 				>> $@
	@echo "irq route 0 0" 			>> $@
	@echo "irq route 1 1" 			>> $@
	@echo "irq route 2 2" 			>> $@
	@echo "irq route 3 3" 			>> $@
	@echo "irq ctrl 0" 			>> $@
	@echo "load rtems-gr740-amp1 cpu0"	>> $@
	@echo "ep $(GR740_AMP_TEXT1) cpu0"	>> $@
	@echo "stack $(GR740_AMP_STACK1) cpu0"	>> $@

	@echo "load rtems-gr740-amp2 cpu1"	>> $@
	@echo "ep $(GR740_AMP_TEXT2) cpu1"	>> $@
	@echo "stack $(GR740_AMP_STACK2) cpu1"	>> $@

	@echo "load rtems-gr740-amp3 cpu2"	>> $@
	@echo "ep $(GR740_AMP_TEXT3) cpu2"	>> $@
	@echo "stack $(GR740_AMP_STACK3) cpu2"	>> $@

	@echo "load rtems-gr740-amp4 cpu3"	>> $@
	@echo "ep $(GR740_AMP_TEXT4) cpu3"	>> $@
	@echo "stack $(GR740_AMP_STACK4) cpu3"	>> $@

	@echo "cpu act 0"			>> $@
	@echo "go" 				>> $@
	
clean:
	-rm -f *.o $(PROGS) > /dev/null
