Commit e0ed3c6b authored by Martin Hofmann's avatar Martin Hofmann

rebase of recent changes

parent 5fc83df3
#
# Makefile for Micrim ucOS-III for eco32
# Makefile for Micrim uCOS-III for eco32
#
LCC = /home/wiggum/git/eco32/build/bin/lcc
BUILD = /home/wiggum/git/eco32/build/bin/
C_SRC = $(shell find ./ -type f -name *.c)
S_SRC = $(shell find ./ -type f -name *.s)
H_SRC = $(shell find ./ -type f -name *.h)
LCC = $(BUILD)/lcc
LD = $(BUILD)/ld
LOAD = $(BUILD)/load
OBJS = $(addsuffix .o,$(basename $(C_SRC))) $(addsuffix .o,$(basename $(S_SRC)))
SIM = $(BUILD)/sim
UCOS_SRCS = Micrium/Software/uC-CPU/cpu_core.c \
Micrium/Software/uCOS-III/Source/os_q.c \
Micrium/Software/uCOS-III/Source/os_stat.c \
Micrium/Software/uCOS-III/Source/os_mutex.c \
Micrium/Software/uCOS-III/Source/os_prio.c \
Micrium/Software/uCOS-III/Source/os_sem.c \
Micrium/Software/uCOS-III/Source/os_var.c \
Micrium/Software/uCOS-III/Source/os_core.c \
Micrium/Software/uCOS-III/Source/os_pend_multi.c \
Micrium/Software/uCOS-III/Source/os_dbg.c \
Micrium/Software/uCOS-III/Source/os_tick.c \
Micrium/Software/uCOS-III/Source/os_mem.c \
Micrium/Software/uCOS-III/Source/os_tmr.c \
Micrium/Software/uCOS-III/Source/os_flag.c \
Micrium/Software/uCOS-III/Source/os_msg.c \
Micrium/Software/uCOS-III/Source/os_task.c \
Micrium/Software/uCOS-III/Source/os_time.c \
Micrium/Software/uCOS-III/Source/os_int.c \
Micrium/Software/uCOS-III/Source/os_cfg_app.c \
Micrium/Software/uC-LIB/lib_mem.c \
Micrium/Software/uC-LIB/lib_math.c \
Micrium/Software/uC-LIB/lib_ascii.c \
Micrium/Software/uC-LIB/lib_str.c
ENTR_SRCS = Micrium/Software/Boards/THM/Generic/LCC/entry.s
BSP_SRCS = Micrium/Software/Boards/THM/Generic/BSP/bsp.c \
Micrium/Software/Boards/THM/Generic/BSP/bsp_timer.c
PORT_SRCS = Micrium/Software/uC-CPU/ECO32/LCC/cpu_a.s \
Micrium/Software/uCOS-III/Ports/ECO32/os_cpu_c.c \
Micrium/Software/uCOS-III/Ports/ECO32/LCC/os_cpu_a.s
APP_SRCS = app/app.c
OBJS = $(addsuffix .o,$(basename $(ENTR_SRCS))) \
$(addsuffix .o,$(basename $(BSP_SRCS))) \
$(addsuffix .o,$(basename $(PORT_SRCS))) \
$(addsuffix .o,$(basename $(UCOS_SRCS))) \
$(addsuffix .o,$(basename $(APP_SRCS)))
INC_DIRS = Micrium/Software/uC-CPU \
Micrium/Software/uC-CPU/ECO32/LCC \
Micrium/Software/uCOS-III/Source \
Micrium/Software/uCOS-III/Ports/ECO32/LCC \
Micrium/Software/uC-LIB \
Micrium/Software/Boards/THM/Generic/BSP \
Template \
app
INCS = $(addprefix -I,$(INC_DIRS))
EXE = uCOSApp
BIN = uCOSApp.bin
MAP = uCOSApp.map
EXE = kernel
BIN = kernel.bin
MAP = kernel.map
all: $(BIN)
run: $(BIN)
$(SIM) -l $(BIN) -i -a 0x00000000 -s 1 -t 0
$(BIN): $(EXE)
@echo " LOAD $@"
@$(LOAD) -p $(EXE) $(BIN)
$(EXE): $(OBJS) $(H_SRC)
$(EXE): $(OBJS)
@echo " LD $@"
@$(LD) $(OBJS) -s app/standalone.lnk -m $(MAP) -o $(EXE)
%.o: %.c
$(LCC) -A -Wo-nostdinc -Wo-nostdlib -c -o $@ $^
@echo " CC $@"
@$(LCC) -Wo-nostdinc -Wo-nostdlib $(INCS) -c -o $@ $^
%.o: %.s
@echo " AS $@"
@$(LCC) -Wo-nostdinc -Wo-nostdlib -c -o $@ $^
clean:
rm -f $(OBJS) $(EXE) $(BIN) $(MAP)
\ No newline at end of file
@echo "cleaning up.."
@rm -f $(OBJS) $(EXE) $(BIN) $(MAP)
/*
*********************************************************************************************************
*
* GENERIC BSP FILE
*
* ECO32
* GENERIC C COMPILER
*
* Filename : bsp.c
* Version : V1.00.0
* Programmer(s) : MH
*
*********************************************************************************************************
*/
#define BSP_MODULE
#include <bsp.h>
#include <bsp_timer.h>
#include <cpu.h>
/*
*********************************************************************************************************
* BSP_Init()
*
* Description : Initialize the Board Support Package
*
* Return(s) : none
*********************************************************************************************************
*/
void BSP_Init (void)
{
CPU_SR_ALLOC();
CPU_INT_DIS();
BSP_SysTickInit();
CPU_INT_EN();
}
/*
*********************************************************************************************************
* RESET()
*
* Description : RESET the application
*
* Note(s) : (1) Can be used as a hardfault recover function that will reboot the application
*
* Return(s) : none
*********************************************************************************************************
*/
void reset (void); /* in entry.s */
void RESET (void)
{
CPU_SR_ALLOC();
CPU_INT_DIS();
reset();
}
/*
*********************************************************************************************************
*
* GENERIC BSP FILE
*
* ECO32
* GENERIC C COMPILER
*
* Filename : bsp.h
* Version : V1.00.0
* Programmer(s) : MH
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This CPU header file is protected from multiple pre-processor inclusion through use of
* the CPU module present pre-processor macro definition.
*********************************************************************************************************
*/
#ifndef BSP_PRESENT /* See Note #1. */
#define BSP_PRESENT
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void RESET (void);
void BSP_Init (void);
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'bsp_def.h MODULE'.
*********************************************************************************************************
*/
#endif /* End of BSP module include. */
/*
*********************************************************************************************************
*
* GENERIC TIMER BSP FILE
*
* ECO32
* GENERIC C COMPILER
*
* Filename : bsp_timer.c
* Version : V1.00.0
* Programmer(s) : MH
*
*********************************************************************************************************
*/
#define BSP_TIMER_MODULE
#include <bsp_timer.h>
#include <cpu_core.h>
#include <os_cfg_app.h>
/*
*********************************************************************************************************
* BSP_SysTickInit()
*
* Description : Initialize the Timer that drives the systick
*
* Return(s) : none.
*
* Note(s) : (1) Timer 1 is used to drive the systick
*
* Return(s) : none
*********************************************************************************************************
*/
void BSP_SysTickInit (void)
{
TIMER1_CTL = TIMER_IE;
TIMER1_DIV = TIMERHZ / OS_CFG_TICK_RATE_HZ;
CPU_IntSrc_En(TIMER1_INTNR);
}
/*
*********************************************************************************************************
* SYS TICK HANDLER
*
* Description : Handle the system tick (SysTick) interrupt, which is used to generate the uC/OS-III tick
* interrupt.
*
* Note(s) : (1) This function must be placed in the isrtable for the timer that is used to generate the
* tick interrupt
*
* (2) Time tick handling is not implemented in the uCOS port files since uCOS does not provide
* a hook to implement a timer initialization for the sys tick timer.
*
* Return(s) : none
*********************************************************************************************************
*/
void BSP_CPU_SysTickHandler (void)
{
volatile CPU_INT32U read = 0;
read = TIMER1_CTL;
OSTimeTick();
OSIntExit();
}
/*
*********************************************************************************************************
* CPU_TS_TmrInit()
*
* Description : Initialize & start CPU timestamp timer.
*
* Argument(s) : none.
*
* Return(s) : none.
*
* Caller(s) : CPU_TS_Init().
*
* This function is an INTERNAL CPU module function & MUST be implemented by application/
* BSP function(s) [see Note #1] but MUST NOT be called by application function(s).
*
* Note(s) : (1) CPU_TS_TmrInit() is an application/BSP function that MUST be defined by the developer
* if either of the following CPU features is enabled :
*
* (a) CPU timestamps
* (b) CPU interrupts disabled time measurements
*
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
*
* (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
* data type.
*
* (1) If timer has more bits, truncate timer values' higher-order bits greater
* than the configured 'CPU_TS_TMR' timestamp timer data type word size.
*
* (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
* timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
* configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
*
* In other words, if timer size is not a binary-multiple of 8-bit octets
* (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
* octet word size SHOULD be configured (e.g. to 16-bits). However, the
* minimum supported word size for CPU timestamp timers is 8-bits.
*
* See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
* & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
*
* (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
*
* (c) When applicable, timer period SHOULD be less than the typical measured time
* but MUST be less than the maximum measured time; otherwise, timer resolution
* inadequate to measure desired times.
*
* See also 'CPU_TS_TmrRd() Note #2'.
*
* (3) Timer 0 is used for timestamps.
*********************************************************************************************************
*/
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
void CPU_TS_TmrInit (void)
{
TIMER0_CTL = 0;
TIMER0_DIV = 0xFFFFFFFF;
}
#endif
/*
*********************************************************************************************************
* CPU_TS_TmrRd()
*
* Description : Get current CPU timestamp timer count value.
*
* Argument(s) : none.
*
* Return(s) : Timestamp timer count (see Notes #2a & #2b).
*
* Caller(s) : CPU_TS_Init(),
* CPU_TS_Get32(),
* CPU_TS_Get64(),
* CPU_IntDisMeasStart(),
* CPU_IntDisMeasStop().
*
* This function is an INTERNAL CPU module function & MUST be implemented by application/
* BSP function(s) [see Note #1] but SHOULD NOT be called by application function(s).
*
* Note(s) : (1) CPU_TS_TmrRd() is an application/BSP function that MUST be defined by the developer
* if either of the following CPU features is enabled :
*
* (a) CPU timestamps
* (b) CPU interrupts disabled time measurements
*
* See 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #1'
* & 'cpu_cfg.h CPU INTERRUPTS DISABLED TIME MEASUREMENT CONFIGURATION Note #1a'.
*
* (2) (a) Timer count values MUST be returned via word-size-configurable 'CPU_TS_TMR'
* data type.
*
* (1) If timer has more bits, truncate timer values' higher-order bits greater
* than the configured 'CPU_TS_TMR' timestamp timer data type word size.
*
* (2) Since the timer MUST NOT have less bits than the configured 'CPU_TS_TMR'
* timestamp timer data type word size; 'CPU_CFG_TS_TMR_SIZE' MUST be
* configured so that ALL bits in 'CPU_TS_TMR' data type are significant.
*
* In other words, if timer size is not a binary-multiple of 8-bit octets
* (e.g. 20-bits or even 24-bits), then the next lower, binary-multiple
* octet word size SHOULD be configured (e.g. to 16-bits). However, the
* minimum supported word size for CPU timestamp timers is 8-bits.
*
* See also 'cpu_cfg.h CPU TIMESTAMP CONFIGURATION Note #2'
* & 'cpu_core.h CPU TIMESTAMP DATA TYPES Note #1'.
*
* (b) Timer SHOULD be an 'up' counter whose values increase with each time count.
*
* (1) If timer is a 'down' counter whose values decrease with each time count,
* then the returned timer value MUST be ones-complemented.
*
* (c) (1) When applicable, the amount of time measured by CPU timestamps is
* calculated by either of the following equations :
*
* (A) Time measured = Number timer counts * Timer period
*
* where
*
* Number timer counts Number of timer counts measured
* Timer period Timer's period in some units of
* (fractional) seconds
* Time measured Amount of time measured, in same
* units of (fractional) seconds
* as the Timer period
*
* Number timer counts
* (B) Time measured = ---------------------
* Timer frequency
*
* where
*
* Number timer counts Number of timer counts measured
* Timer frequency Timer's frequency in some units
* of counts per second
* Time measured Amount of time measured, in seconds
*
* (2) Timer period SHOULD be less than the typical measured time but MUST be less
* than the maximum measured time; otherwise, timer resolution inadequate to
* measure desired times.
*
* (3) Timer 0 is used for timestamps
*********************************************************************************************************
*/
#if (CPU_CFG_TS_TMR_EN == DEF_ENABLED)
CPU_TS_TMR CPU_TS_TmrRd (void)
{
return ~(CPU_TS_TMR)TIMER0_CNT;
}
#endif
/*
*********************************************************************************************************
*
* GENERIC TIMER BSP FILE
*
* ECO32
* GENERIC C COMPILER
*
* Filename : bsp_timer.h
* Version : V1.00.0
* Programmer(s) : MH
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This CPU header file is protected from multiple pre-processor inclusion through use of
* the CPU module present pre-processor macro definition.
*********************************************************************************************************
*/
#ifndef BSP_TIMER_PRESENT /* See Note #1. */
#define BSP_TIMER_PRESENT
/*
*********************************************************************************************************
* IOMEM DEFINES
*********************************************************************************************************
*/
#define TIMER0_BASE 0xF0000000
#define TIMER0_CTL (*(CPU_INT32U*)(TIMER0_BASE + 0))
#define TIMER0_DIV (*(CPU_INT32U*)(TIMER0_BASE + 4))
#define TIMER0_CNT (*(CPU_INT32U*)(TIMER0_BASE + 8))
#define TIMER0_INTNR 14
#define TIMER1_BASE 0xF0001000
#define TIMER1_CTL (*(CPU_INT32U*)(TIMER1_BASE + 0))
#define TIMER1_DIV (*(CPU_INT32U*)(TIMER1_BASE + 4))
#define TIMER1_CNT (*(CPU_INT32U*)(TIMER1_BASE + 8))
#define TIMER1_INTNR 15
#define TIMERHZ 50000000
#define TIMER_IE 0x2
#define TIMER_WR 0x1
/*
*********************************************************************************************************
* FUNCTION PROTOTYPES
*********************************************************************************************************
*/
void BSP_SysTickInit (void);
void BSP_CPU_SysTickHandler (void);
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'bsp_time.h MODULE'.
*********************************************************************************************************
*/
#endif
/*
*********************************************************************************************************
*
* GENERIC UART BSP FILE
*
* ECO32
* GENERIC C COMPILER
*
* Filename : bsp_uart.h
* Version : V1.00.0
* Programmer(s) : MH
*
*********************************************************************************************************
*/
/*
*********************************************************************************************************
* MODULE
*
* Note(s) : (1) This UART header file is protected from multiple pre-processor inclusion through use of
* the UART module present pre-processor macro definition.
*********************************************************************************************************
*/
#ifndef BSP_UART_PRESENT /* See Note #1. */
#define BSP_UART_PRESENT
#include <os.h>
/*
*********************************************************************************************************
* IOMEM DEFINES
*********************************************************************************************************
*/
#define UART0_BASE 0xF0300000
#define UART0_CTL_IN (*(CPU_INT32U*)(UART0_BASE + 0))
#define UART0_DTA_IN (*(CPU_INT32U*)(UART0_BASE + 4))
#define UART0_INTNR_IN 1
#define UART0_CTL_OUT (*(CPU_INT32U*)(UART0_BASE + 8))
#define UART0_DTA_OUT (*(CPU_INT32U*)(UART0_BASE + 12))
#define UART0_INTNR_OUT 0
#define UART1_BASE 0xF0301000
#define UART1_CTL_IN (*(CPU_INT32U*)(UART1_BASE + 0))
#define UART1_DTA_IN (*(CPU_INT32U*)(UART1_BASE + 4))
#define UART1_INTNR_IN 3
#define UART1_CTL_OUT (*(CPU_INT32U*)(UART1_BASE + 8))
#define UART1_DTA_OUT (*(CPU_INT32U*)(UART1_BASE + 12))
#define UART1_INTNR_OUT 2
#define UART_IE 0x2
#define UART_RDY 0x1
/*
*********************************************************************************************************
* MODULE END
*
* Note(s) : (1) See 'bsp_uart.h MODULE'.
*********************************************************************************************************
*/
#endif
;********************************************************************************************************
;
; ECO32 SIM BSP FILE
;
; ECO32
; LCC ANSI-C COMPILER
;
; Filename : entry.s
; Version : V1.00.0
; Programmer(s) : MH
;********************************************************************************************************
;********************************************************************************************************
; EXTERNAL FUNCTIONS
;********************************************************************************************************
.import _bbss
.import _ebss
.import _initstacktop
.import main
.import OSCfg_ISRStkBasePtr
.import OSCfg_ISRStkSizeRAM
.import OSTCBCurPtr
.import BSP_CPU_SysTickHandler
.import BSP_Uart0_RcvHandler
.import BSP_Uart1_RcvHandler
.import OSIntEnter
.import OSIntExit
.import psw
.import isrtbl
;********************************************************************************************************
; EXPORTED FUNCTIONS
;********************************************************************************************************
.export reset
;********************************************************************************************************
; CODE GENERATION DIRECTIVES
;********************************************************************************************************
.code
.align 4
;********************************************************************************************************
; EXCEPTION VECTOR
;
; Description : This is the CPUs exception vector. The CPU jumps here in case of:
;
; (1) reset
;
; (2) interrupts/exceptions
;
; (3) user tlb miss
;
; Note(s) : (1) This file needs to be linked first since it is the entry of the application.
; If not linked first the exception vector will not contain valid jump instrcutions.
;********************************************************************************************************
reset:
j startup
exception:
j isr
umiss:
j isr
;********************************************************************************************************
; STARTUP
;
; Description : This is the startup of the application. reset jumps here when the CPU starts execution or
; when to application is loaded to ram and starte.
;
; Note(s) : (1) The startup invalidades the TLB even uCOS does not use it.
;
; Returns : Must not return
;********************************************************************************************************
startup:
; protection first!
mvts $0,0
; invalidate TLB
; fill with direct-mapped virtual addresses
mvts $0,3
ldhi $8,0xC0000000
mvts $8,2
add $8,$0,0
add $9,$0,32
tlb_inv_loop:
mvts $8,1
tbwi
add $8,$8,1
bne $8,$9,tlb_inv_loop
; clear BSS
add $8,$0,_bbss
add $9,$0,_ebss
j bss_clr_test
bss_clr_loop:
stw $0,$8,0
add $8,$8,4
bss_clr_test:
bltu $8,$9,bss_clr_loop
; setup stack pointer
add $29,$0,_initstacktop
sub $29,$29,4
; update psw
add $8,$0,psw
ldhi $9,0x08000000
stw $9,$8,0
; load initial psw
mvts $9,0
; jump to main
jal main
j reset
;********************************************************************************************************
; COMMON ISR
;
; Description : This is the common ISR that is executed on all interrupts and exceptions. It needs to
; perform the following operations:
;
; (1) Save all register
;
; (2) Save SP to OSTCBCurPtr->StkPtr
;
; (3) Switch to ISR stack
;
; (4) Load and call the ISR
;
; (5) Switch to tasks stack
;
; (5) Load all register
;
; (6) Return to interrupted context
;
; Note(s) : (1) The register need to be saved and restored in the same way as OSTaskStkInit does save
; them or they will not contain valid values after they are restored.
;
; Returns : None
;********************************************************************************************************
isr:
.nosyn
; save register
sub $29,$29,4*32
stw $1,$29,4*1
stw $2,$29,4*2
stw $3,$29,4*3