Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renesas M32C port. Compiler: M3T-NC308WA #10

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions ports/m32c/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
---------------------------------------------------------------------------

Library: Atomthreads M32C/80 Port
Author: Juan Angel Hernandez Hernandez <[email protected]>
License: BSD Revised

---------------------------------------------------------------------------

M32C/80 PORT

This folder contains a port of the Atomthreads real time kernel for the
M32C/80 processor architecture.

All of the cross-platform kernel code is contained in the top-level
'kernel' folder, while ports to specific CPU architectures are contained in
the 'ports' folder tree.

Atomthreads includes a suite of automated tests which prove the key OS
functionality, and can be used with any architecture ports.


---------------------------------------------------------------------------

FILES IN THE m32c port folder

* atomport.c: Contains the main C code that forms the portion of the core
M32C/80 architecture port that can be implemented in C.
* atomport-asm.A30: Contains the main assembler code that forms the portion
of the core M32C/80 architecture port that must be implemented in assembler.
* tests-main.c: Contains a sample Atomthreads application starting at
main() that initialises the operating system and runs the automated test
suite applications. You will normally make your own main() function
suitable for your application, possibly using this as a basis.
* atomport.h: Port-specific header required by the kernel for each port.
* atomport-private.h: Port-specific header required by atomport.c


---------------------------------------------------------------------------

PREREQUISITES

The port works with the Renesas HEW tools.
Tools:
*High-performance Embedded Workshop (HEW) V 4.09.00.007
*M3T-NC308WA compiler.

Since Renesas HEW only works with absolute paths, if you cloned this repository
to c: the code will compile and load without doing any extra steps.
If you cloned to another different path do the following:
-Click on Build->Renesas M32C standard toolchain, a window shall show up.
-On the C tab, select:
Category: Source,
Show entries For: Include file directories
Click add, and add the following paths:
-\your clone path\atomthreads\kernel
-\your clone path\atomthreads\tests
-\your clone path\atomthreads\ports\m32c

---------------------------------------------------------------------------

BUILDING AND PROGRAMMING TO THE TARGET DEVICE

In this port the target is a simulator. But you can also change the target and
download the code to a development kit.
Open the file:
\atomthreads\ports\m32c\hew_tests\hew_tst_sem1\hew_tst_sem1.hws

Click Ok on the Init window
Click Build->Build All
And the code will automatically be loaded into the simulator target.

---------------------------------------------------------------------------

HEW SIMULATOR SPECIFICS

The virtual timer interrupt and the virtual UART, are already setup when you
load the project. For the virtual led, you need to open the LED.pnl file so
the led can show up.

*Virtual Timer Interrupt:
The virtual interrupt is set in View->CPU->I/O Timing Setting.
Defaults for this port:
-Interval: 10 msec
-Vector 23 (timer B2)
-Priority: 1 (Possible values are 0-7)

*Virtual UART:
The virtual UART is set in View->CPU->OutputPort Then click on the "Set"
icon.
Defaults for this port:
-Printf - UART1
-Output Format:
*Window TEXT
*File TEXT

*Virtual LED:
The virtual LED is set in View->Graphic->GUI I/O
Click on the folder icon that says "Load" when you do a mouseover. Open the
file called led.pnl
The path of the led.pnl file is:
\atomthreads\ports\m32c\hew_tests\led.pnl

---------------------------------------------------------------------------

RUNNING THE AUTOMATED TESTS WITH THE HEW SIMULATOR

Atomthreads contains a set of generic kernel tests which can be run on any
port to prove that all core functionality is working on your target. In
order to accommodate a full testing regime, a large number of test threads
are spawned which on ATmega platforms requires at least 1KB and possibly
more RAM. Bear this in mind if you wish to run all of the automated tests
on your target platform.

The full set of tests can be found in the top-level 'tests' folder. Each of
these tests has to be built as an independent HEW project. In this port a
HEW project using sem1.c is provided. To run the rest of the tests remove
sem1.c and then add any other test file to the project.


Example 1. Test results with a breakpoint:
-Open: \atomthreads\ports\m32c\hew_tests\hew_tst_sem1\hew_tst_sem1.hws
-Click Ok on the Init window
-Click Build->Build All
-The code will automatically be loaded into the simulator target.
-Put a breakpoint at the end of the test in tests-main.c
-Click on Debug->Reset Go. When the test finishes you shall see the virtual
UART, test result output.

Example 2. Test results with a virtual led flashing:
-Open: \atomthreads\ports\m32c\hew_tests\hew_tst_sem1\hew_tst_sem1.hws
-Click Ok on the Init window
-Click Build->Build All
-The code will automatically be loaded into the simulator target.
-On the View->Graphic->GUI I/O window click on the folder icon called "Load"
and open the led.pnl file. The path of the led.pnl file is:
\atomthreads\ports\m32c\hew_tests\led.pnl
-Click on Debug->Reset Go. When the test finishes you shall see the led flash.
-When the led is flashing click "Stop" in the simulator and the virtual UART
output will print the result of the test.


---------------------------------------------------------------------------

WRITING APPLICATIONS

The easiest way to start a new application which utilises the Atomthreads
scheduler is to base your main application startup on tests-main.c. This
initialises the OS, sets up a UART and calls out to the test module entry
functions. You can generally simply replace the call to the test modules by
a call to your own application startup code.


---------------------------------------------------------------------------

PORTING TO NEW PLATFORMS

Follow the very useful porting guide that you can find in atomthreads.com/

---------------------------------------------------------------------------
73 changes: 73 additions & 0 deletions ports/m32c/atomport-asm.A30
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
;/*
; * Copyright (c) 2014, Juan Angel Hernandez Hdez. for Atomthreads Project.
; * All rights reserved.
; *
; * Redistribution and use in source and binary forms, with or without
; * modification, are permitted provided that the following conditions
; * are met:
; *
; * 1. Redistributions of source code must retain the above copyright
; * notice, this list of conditions and the following disclaimer.
; * 2. Redistributions in binary form must reproduce the above copyright
; * notice, this list of conditions and the following disclaimer in the
; * documentation and/or other materials provided with the distribution.
; * 3. No personal names or organizations' names associated with the
; * Atomthreads project may be used to endorse or promote products
; * derived from this software without specific prior written permission.
; *
; * THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
; * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
; * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
; * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
; * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
; * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
; * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
; * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
; * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
; * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
; * POSSIBILITY OF SUCH DAMAGE.
; */


;/**
; * \b _timer_b2
; *
; * Timer B2 interrupt service routine.
; * On interrupt, the U flag is cleared meaning that the interrupt stack (IStack)
; * is selected. FLG and PC are saved on IStack, this routine then cuts and pastes
; * FLG and PC from IStack to UStack (User stack) so that all data relevant to a
; * thread is kept on the same stack area. This also makes the IStack available to
; * use for interrupt nesting.
; *
; * @return None
; */

.GLB _atomIntEnter
.GLB _atomTimerTick
.GLB $atomIntExit
.GLB __timer_b2
.FB 0

.SECTION program,CODE,ALIGN
.align
.GLB __timer_b2
.rvector 23, __timer_b2
__timer_b2:
PUSHC FB ;Save FB temporary on I stack.
FSET U ;Select user stack
PUSHC ISP ;Save ISP in U stack
POPC FB ;POP ISP to FB
PUSH.W 8H[FB] ;Copy FLG from Istack to Ustack
PUSH.L 4H[FB] ;Copy TskX ReturnAddress from Istack to Ustack
FCLR U ;Select Istack
POPC FB ;restore original value of FB
ADD.L #6,SP ;Clean Istack, so it is free for interrupts.
FSET U ;Carry on, on Ustack

JSR.A _atomIntEnter
JSR.A _atomTimerTick

MOV.B:Q #1H,R0L ;Pass the TRUE parameter
JSR.A $atomIntExit
REIT
.END
79 changes: 79 additions & 0 deletions ports/m32c/atomport-private.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2014, Juan Angel Hernandez Hdez. for Atomthreads Project.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. No personal names or organizations' names associated with the
* Atomthreads project may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __ATOM_PORT_PRIVATE_H
#define __ATOM_PORT_PRIVATE_H

/* Enumeration for interrupt level */
typedef enum
{
INTERRUPT_LVL_0 = 0x00,
INTERRUPT_LVL_1 = 0x01,
INTERRUPT_LVL_2 = 0x02,
INTERRUPT_LVL_3 = 0x03,
INTERRUPT_LVL_4 = 0x04,
INTERRUPT_LVL_5 = 0x05,
INTERRUPT_LVL_6 = 0x06,
INTERRUPT_LVL_7 = 0x07
} teINTERRUPT_PRIORITY_LEVEL;

/* CPU Frequency */
#define M32C_OSC_FREQUENCY 20000000L
#define PRESCALE_VALUE 8

/* 1MS tick defines */
#define COUNT_10MS (M32C_OSC_FREQUENCY/PRESCALE_VALUE)/100

/* Using simulator */
#define HEW_SIMULATOR

/* Function prototypes */
void init_timerb2(void);
void init_pin_P0_0(void);
void toggle_pin_P0_0(void);

/* Timer B2 registers */
#pragma ADDRESS TB2MR 035Dh
#pragma ADDRESS TB2 0354h
#pragma ADDRESS TB2IC 0096h
uint8_t TB2MR;
uint16_t TB2;
uint8_t TB2IC;

/* TIMER B2 (software int 23) */
#pragma interrupt _timer_b2(vect=23)

/* LED pin */
#pragma ADDRESS PD0 03E2h //Input or output 0:Input 1:Output
#pragma ADDRESS P0 03E0h //R/W
uint8_t PD0;
uint8_t P0;

#endif /* __ATOM_PORT_PRIVATE_H */
58 changes: 58 additions & 0 deletions ports/m32c/atomport-tests.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (c) 2010, Kelvin Lawson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. No personal names or organizations' names associated with the
* Atomthreads project may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE ATOMTHREADS PROJECT AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef __ATOM_PORT_TESTS_H
#define __ATOM_PORT_TESTS_H

/* Include Atomthreads kernel API */
#include "atom.h"

/* Prerequisite include for ATOMLOG() macro (via printf) */
#include <stdio.h>

/* Logger macro for viewing test results */
#define ATOMLOG printf

/*
* String location macro: for platforms which need to place strings in
* alternative locations, e.g. on avr-gcc strings can be placed in
* program space, saving SRAM. On most platforms this can expand to
* empty.
*/
#define _STR(x) x

/* Default thread stack size (in bytes) */
#define TEST_THREAD_STACK_SIZE 264

/* Uncomment to enable logging of stack usage to UART */
/* #define TESTS_LOG_STACK_USAGE */


#endif /* __ATOM_PORT_TESTS_H */

Loading