From d722c765392420230addcb21693070011bdbf43e Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Wed, 3 Oct 2012 21:37:11 +0300 Subject: [PATCH 1/6] Initial commit --- Makefile | 56 +++++++++++++++++++++++++++ main.c | 62 +++++++++++++++++++++++++++++ uart0.c | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ uart0.h | 7 ++++ 4 files changed, 241 insertions(+) create mode 100644 Makefile create mode 100644 main.c create mode 100644 uart0.c create mode 100644 uart0.h diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..4196a66fe --- /dev/null +++ b/Makefile @@ -0,0 +1,56 @@ +PROJECT_ELF=uart.elf +PROJECT_MOT=$(PROJECT_ELF:.elf=.mot) +PROJECT_MAP=$(PROJECT_ELF:.elf=.map) +PROJECT_LST=$(PROJECT_ELF:.elf=.lst) + +PREFIX=rl78-elf + +LD = $(PREFIX)-gcc +CC = $(PREFIX)-gcc +AS = $(PREFIX)-gcc +OBJCOPY = $(PREFIX)-objcopy +OBJDUMP = $(PREFIX)-objdump +SIZE = $(PREFIX)-size + +COMMON_PATH = ../common +PROJECT_PATH = . + +PROJECT_LNK = $(COMMON_PATH)/rl78-R5F100SL.ld + +CFLAGS = -Wall -Wextra -Os -ggdb -ffunction-sections -fdata-sections -I$(PROJECT_PATH) -I$(COMMON_PATH) -mmul=g13 +LDFLAGS = -Wl,--gc-sections -Wl,-Map=$(PROJECT_MAP) -T $(PROJECT_LNK) -nostartfiles + +SOURCES = \ + $(PROJECT_PATH)/main.c \ + $(PROJECT_PATH)/uart0.c \ + $(END) + +OBJS = $(SOURCES:.c=.o) $(COMMON_PATH)/crt0.o + +.PHONY: all + +all: $(PROJECT_MOT) $(PROJECT_LST) + $(SIZE) $(PROJECT_ELF) + +rom: $(PROJECT_MOT) + +$(PROJECT_MOT): $(PROJECT_ELF) + $(OBJCOPY) -O srec $^ $@ + +$(PROJECT_LST): $(PROJECT_ELF) + $(OBJDUMP) -DS $^ > $@ + +$(PROJECT_ELF): $(OBJS) + $(LD) $(LDFLAGS) -o $@ $^ + +flash: $(PROJECT_MOT) + rl78flash -m2 -b500000 -vvwri /dev/ttyUSB0 $^ + +erase: + rl78flash -m2 -b500000 -vveri /dev/ttyUSB0 + +terminal: + rl78flash -t9600 /dev/ttyUSB0 + +clean: + -rm -f $(OBJS) $(PROJECT_ELF) $(PROJECT_MOT) $(PROJECT_MAP) $(PROJECT_LST) diff --git a/main.c b/main.c new file mode 100644 index 000000000..480321676 --- /dev/null +++ b/main.c @@ -0,0 +1,62 @@ +#include "QB-R5F100SL-TB.h" +#include "uart0.h" + +volatile unsigned char ticks = 0; +volatile unsigned char flag_1hz = 0; + +__attribute__((interrupt)) +void wdti_handler(void) +{ +} + +__attribute__((interrupt)) +void it_handler(void) +{ + ++ticks; + LED1 ^= 1; + if (0 == (0x07 & ticks)) + { + flag_1hz = 1; + } +} + +int main(void) +{ + asm("di"); + /* Setup LEDs */ + LED1 = 1; + LED2 = 1; + LED1_PIN = 0; + LED2_PIN = 0; + /* Setup clocks */ + CMC.cmc = 0x11U; /* Enable XT1, disable X1 */ + CSC.csc = 0x80U; /* Start XT1 and HOCO, stop X1 */ + CKC.ckc = 0x00U; + /* Delay 1 second */ + register unsigned long int i; + for (i = 0x000FFFFFUL; i; --i) + asm("nop"); + OSMC.osmc = 0x00; /* Supply fsub to peripherals, including Interval Timer */ + uart0_init(); + /* Setup 12-bit interval timer */ + RTCEN = 1; /* Enable 12-bit interval timer and RTC */ + ITMK = 1; /* Disable IT interrupt */ + ITPR0 = 0; /* Set interrupt priority - highest */ + ITPR1 = 0; + ITMC.itmc = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ + ITIF = 0; /* Clear interrupt request flag */ + ITMK = 0; /* Enable IT interrupt */ + asm ("ei"); /* Enable interrupts */ + for(;;) + { + if (flag_1hz) + { + LED2 = 0; + flag_1hz = 0; + const char msg[] = "Hello, RL78! [:"; + uart0_puts(msg); + LED2 = 1; + } + asm("halt"); + } +} diff --git a/uart0.c b/uart0.c new file mode 100644 index 000000000..0b79e4ac0 --- /dev/null +++ b/uart0.c @@ -0,0 +1,116 @@ +#include "uart0.h" +#include +#include + +void uart0_init(void) +{ + /* Reference R01AN0459EJ0100 or hardware manual for details */ + PIOR.pior = 0U; /* Disable IO redirection */ + PM1.pm1 |= 0x06U; /* Set P11 and P12 as inputs */ + SAU0EN = 1; /* Supply clock to serial array unit 0 */ + SPS0.sps0 = 0x44U; /* Set input clock (CK00 and CK01) to fclk/16 = 2MHz */ + ST0.st0 = 0x03U; /* Stop operation of channel 0 and 1 */ + /* Setup interrupts (disable) */ + STMK0 = 1; /* Disable INTST0 interrupt */ + STIF0 = 0; /* Clear INTST0 interrupt request flag */ + STPR10 = 1; /* Set INTST0 priority: lowest */ + STPR00 = 1; + SRMK0 = 1; /* Disable INTSR0 interrupt */ + SRIF0 = 0; /* Clear INTSR0 interrupt request flag */ + SRPR10 = 1; /* Set INTSR0 priority: lowest */ + SRPR00 = 1; + SREMK0 = 1; /* Disable INTSRE0 interrupt */ + SREIF0 = 0; /* Clear INTSRE0 interrupt request flag */ + SREPR10 = 1; /* Set INTSRE0 priority: lowest */ + SREPR00 = 1; + /* Setup operation mode for transmitter (channel 0) */ + SMR00.smr00 = 0x0023U; /* Operation clock : CK00, + Transfer clock : division of CK00 + Start trigger : software + Detect falling edge as start bit + Operation mode : UART + Interrupt source : buffer empty + */ + SCR00.scr00 = 0x8097U; /* Transmission only + Reception error interrupt masked + Phase clock : type 1 + No parity + LSB first + 1 stop bit + 8-bit data length + */ + SDR00.sdr00 = 0xCE00U; /* transfer clock : operation clock divided by 208 + 2 MHz / 208 = ~9600 bps + */ + /* Setup operation mode for receiver (channel 1) */ + NFEN0.nfen0 |= 1; /* Enable noise filter on RxD0 pin */ + SIR01.sir01 = 0x0007U; /* Clear error flags */ + SMR01.smr01 = 0x0122U; /* Operation clock : CK00 + Transfer clock : division of CK00 + Start trigger : valid edge on RxD pin + Detect falling edge as start bit + Operation mode : UART + Interrupt source : transfer end + */ + SCR01.scr01 = 0x4097U; /* Reception only + Reception error interrupt masked + Phase clock : type 1 + No parity + LSB first + 1 stop bit + 8-bit data length + */ + SDR01.sdr01 = 0xCE00U; /* transfer clock : operation clock divided by 208 + 2 MHz / 208 = ~9600 bps + */ + SO0.so0 |= 1; /* Prepare for use of channel 0 */ + SOE0.soe0 |= 1; + P1.p1 |= (1 << 2); /* Set TxD0 high */ + PM1.pm1 &= ~(1 << 2); /* Set output mode for TxD0 */ + PM1.pm1 |= (1 << 1); /* Set input mode for RxD0 */ + SS0.ss0 |= 0x03U; /* Enable UART0 operation (both channels) */ + STIF0 = 1; /* Set buffer empty interrupt request flag */ +} + +int uart0_puts(const char * s) +{ + int len = 0; + SMR00.smr00 |= 0x0001U; /* Set buffer empty interrupt */ + while ('\0' != *s) + { + while (0 == STIF0); + STIF0 = 0; + SDR00.sdr00 = *s++; + ++len; + } +#if 0 + while (0 == STIF0); + STIF0 = 0; + SDR00.sdr00 = '\r'; +#endif + while (0 == STIF0); + STIF0 = 0; + SMR00.smr00 &= ~0x0001U; + SDR00.sdr00 = '\n'; + while (0 == STIF0); +#if 0 + while (0 != SSR00.BIT.bit6); /* Wait until TSF00 == 0 */ +#endif + return len; +} + +__attribute__((interrupt)) +void st0_handler(void) +{ +} + +__attribute__((interrupt)) +void sr0_handler(void) +{ +} + +/* This is actually INTSRE0 interrupt handler */ +__attribute__((interrupt)) +void tm01h_handler(void) +{ +} diff --git a/uart0.h b/uart0.h new file mode 100644 index 000000000..fd97204f5 --- /dev/null +++ b/uart0.h @@ -0,0 +1,7 @@ +#ifndef UART0_H__ +#define UART0_H__ + +void uart0_init(void); +int uart0_puts(const char * s); + +#endif // UART0_H__ From 8ced0a746b2cdafd7e00d3440aa20b55669b0ec3 Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Sun, 17 Mar 2013 22:37:57 +0300 Subject: [PATCH 2/6] Find and use latest installed GNURL78 toolchain automatically. --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4196a66fe..f81106dca 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,10 @@ PROJECT_MOT=$(PROJECT_ELF:.elf=.mot) PROJECT_MAP=$(PROJECT_ELF:.elf=.map) PROJECT_LST=$(PROJECT_ELF:.elf=.lst) -PREFIX=rl78-elf +# Find latest installed GNURL78 toolchain. If your toolchain is already in PATH, just comment next line. +TOOL_PATH:=$(shell find /usr/share -maxdepth 1 -type d -iname "gnurl78*" | sort | tail -n 1)/bin + +PREFIX:=$(TOOL_PATH)/rl78-elf LD = $(PREFIX)-gcc CC = $(PREFIX)-gcc From ec8b88252ac3639c59c21c74bed7aaa9e443cd30 Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Sun, 17 Mar 2013 22:44:04 +0300 Subject: [PATCH 3/6] Add reset action to terminal target of Makefile. If reset signal is routed to MCU and reset action is not requested, reset signal will be held low. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f81106dca..3b183d6e8 100644 --- a/Makefile +++ b/Makefile @@ -53,7 +53,7 @@ erase: rl78flash -m2 -b500000 -vveri /dev/ttyUSB0 terminal: - rl78flash -t9600 /dev/ttyUSB0 + rl78flash -rt9600 /dev/ttyUSB0 clean: -rm -f $(OBJS) $(PROJECT_ELF) $(PROJECT_MOT) $(PROJECT_MAP) $(PROJECT_LST) From f576489c6e90d29d15fc3c66277021e8abd98bd0 Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Sun, 17 Mar 2013 22:52:01 +0300 Subject: [PATCH 4/6] In GNURL78 v13.01 __far keyword is fixed. Now it is possible to use far pointers to flash area. --- main.c | 3 +-- uart0.c | 2 +- uart0.h | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/main.c b/main.c index 480321676..ca249c544 100644 --- a/main.c +++ b/main.c @@ -53,8 +53,7 @@ int main(void) { LED2 = 0; flag_1hz = 0; - const char msg[] = "Hello, RL78! [:"; - uart0_puts(msg); + uart0_puts("Hello, RL78! [:"); LED2 = 1; } asm("halt"); diff --git a/uart0.c b/uart0.c index 0b79e4ac0..d58fa787b 100644 --- a/uart0.c +++ b/uart0.c @@ -72,7 +72,7 @@ void uart0_init(void) STIF0 = 1; /* Set buffer empty interrupt request flag */ } -int uart0_puts(const char * s) +int uart0_puts(const char __far * s) { int len = 0; SMR00.smr00 |= 0x0001U; /* Set buffer empty interrupt */ diff --git a/uart0.h b/uart0.h index fd97204f5..9512eacfb 100644 --- a/uart0.h +++ b/uart0.h @@ -2,6 +2,6 @@ #define UART0_H__ void uart0_init(void); -int uart0_puts(const char * s); +int uart0_puts(const char __far * s); #endif // UART0_H__ From 096ff72bd9333741d3a23ca316d8109106ea5a7c Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Sat, 4 Jan 2014 17:27:24 -0500 Subject: [PATCH 5/6] Uncrustify. --- main.c | 91 ++++++++++++++++++------------------ uart0.c | 142 ++++++++++++++++++++++++++++---------------------------- uart0.h | 4 +- 3 files changed, 118 insertions(+), 119 deletions(-) diff --git a/main.c b/main.c index ca249c544..4d7ea8c4a 100644 --- a/main.c +++ b/main.c @@ -5,57 +5,56 @@ volatile unsigned char ticks = 0; volatile unsigned char flag_1hz = 0; __attribute__((interrupt)) -void wdti_handler(void) +void +wdti_handler(void) { } - __attribute__((interrupt)) -void it_handler(void) +void +it_handler(void) { - ++ticks; - LED1 ^= 1; - if (0 == (0x07 & ticks)) - { - flag_1hz = 1; - } + ++ticks; + LED1 ^= 1; + if(0 == (0x07 & ticks)) { + flag_1hz = 1; + } } - -int main(void) +int +main(void) { - asm("di"); - /* Setup LEDs */ - LED1 = 1; - LED2 = 1; - LED1_PIN = 0; - LED2_PIN = 0; - /* Setup clocks */ - CMC.cmc = 0x11U; /* Enable XT1, disable X1 */ - CSC.csc = 0x80U; /* Start XT1 and HOCO, stop X1 */ - CKC.ckc = 0x00U; - /* Delay 1 second */ - register unsigned long int i; - for (i = 0x000FFFFFUL; i; --i) - asm("nop"); - OSMC.osmc = 0x00; /* Supply fsub to peripherals, including Interval Timer */ - uart0_init(); - /* Setup 12-bit interval timer */ - RTCEN = 1; /* Enable 12-bit interval timer and RTC */ - ITMK = 1; /* Disable IT interrupt */ - ITPR0 = 0; /* Set interrupt priority - highest */ - ITPR1 = 0; - ITMC.itmc = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ - ITIF = 0; /* Clear interrupt request flag */ - ITMK = 0; /* Enable IT interrupt */ - asm ("ei"); /* Enable interrupts */ - for(;;) - { - if (flag_1hz) - { - LED2 = 0; - flag_1hz = 0; - uart0_puts("Hello, RL78! [:"); - LED2 = 1; - } - asm("halt"); + asm ("di"); + /* Setup LEDs */ + LED1 = 1; + LED2 = 1; + LED1_PIN = 0; + LED2_PIN = 0; + /* Setup clocks */ + CMC.cmc = 0x11U; /* Enable XT1, disable X1 */ + CSC.csc = 0x80U; /* Start XT1 and HOCO, stop X1 */ + CKC.ckc = 0x00U; + /* Delay 1 second */ + register unsigned long int i; + for(i = 0x000FFFFFUL; i; --i) { + asm ("nop"); + } + OSMC.osmc = 0x00; /* Supply fsub to peripherals, including Interval Timer */ + uart0_init(); + /* Setup 12-bit interval timer */ + RTCEN = 1; /* Enable 12-bit interval timer and RTC */ + ITMK = 1; /* Disable IT interrupt */ + ITPR0 = 0; /* Set interrupt priority - highest */ + ITPR1 = 0; + ITMC.itmc = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ + ITIF = 0; /* Clear interrupt request flag */ + ITMK = 0; /* Enable IT interrupt */ + asm ("ei"); /* Enable interrupts */ + for(;;) { + if(flag_1hz) { + LED2 = 0; + flag_1hz = 0; + uart0_puts("Hello, RL78! [:"); + LED2 = 1; } + asm ("halt"); + } } diff --git a/uart0.c b/uart0.c index d58fa787b..1521b0493 100644 --- a/uart0.c +++ b/uart0.c @@ -2,115 +2,115 @@ #include #include -void uart0_init(void) +void +uart0_init(void) { - /* Reference R01AN0459EJ0100 or hardware manual for details */ - PIOR.pior = 0U; /* Disable IO redirection */ - PM1.pm1 |= 0x06U; /* Set P11 and P12 as inputs */ - SAU0EN = 1; /* Supply clock to serial array unit 0 */ - SPS0.sps0 = 0x44U; /* Set input clock (CK00 and CK01) to fclk/16 = 2MHz */ - ST0.st0 = 0x03U; /* Stop operation of channel 0 and 1 */ - /* Setup interrupts (disable) */ - STMK0 = 1; /* Disable INTST0 interrupt */ - STIF0 = 0; /* Clear INTST0 interrupt request flag */ - STPR10 = 1; /* Set INTST0 priority: lowest */ - STPR00 = 1; - SRMK0 = 1; /* Disable INTSR0 interrupt */ - SRIF0 = 0; /* Clear INTSR0 interrupt request flag */ - SRPR10 = 1; /* Set INTSR0 priority: lowest */ - SRPR00 = 1; - SREMK0 = 1; /* Disable INTSRE0 interrupt */ - SREIF0 = 0; /* Clear INTSRE0 interrupt request flag */ - SREPR10 = 1; /* Set INTSRE0 priority: lowest */ - SREPR00 = 1; - /* Setup operation mode for transmitter (channel 0) */ - SMR00.smr00 = 0x0023U; /* Operation clock : CK00, + /* Reference R01AN0459EJ0100 or hardware manual for details */ + PIOR.pior = 0U; /* Disable IO redirection */ + PM1.pm1 |= 0x06U; /* Set P11 and P12 as inputs */ + SAU0EN = 1; /* Supply clock to serial array unit 0 */ + SPS0.sps0 = 0x44U; /* Set input clock (CK00 and CK01) to fclk/16 = 2MHz */ + ST0.st0 = 0x03U; /* Stop operation of channel 0 and 1 */ + /* Setup interrupts (disable) */ + STMK0 = 1; /* Disable INTST0 interrupt */ + STIF0 = 0; /* Clear INTST0 interrupt request flag */ + STPR10 = 1; /* Set INTST0 priority: lowest */ + STPR00 = 1; + SRMK0 = 1; /* Disable INTSR0 interrupt */ + SRIF0 = 0; /* Clear INTSR0 interrupt request flag */ + SRPR10 = 1; /* Set INTSR0 priority: lowest */ + SRPR00 = 1; + SREMK0 = 1; /* Disable INTSRE0 interrupt */ + SREIF0 = 0; /* Clear INTSRE0 interrupt request flag */ + SREPR10 = 1; /* Set INTSRE0 priority: lowest */ + SREPR00 = 1; + /* Setup operation mode for transmitter (channel 0) */ + SMR00.smr00 = 0x0023U; /* Operation clock : CK00, Transfer clock : division of CK00 Start trigger : software Detect falling edge as start bit Operation mode : UART Interrupt source : buffer empty - */ - SCR00.scr00 = 0x8097U; /* Transmission only + */ + SCR00.scr00 = 0x8097U; /* Transmission only Reception error interrupt masked Phase clock : type 1 No parity LSB first 1 stop bit 8-bit data length - */ - SDR00.sdr00 = 0xCE00U; /* transfer clock : operation clock divided by 208 + */ + SDR00.sdr00 = 0xCE00U; /* transfer clock : operation clock divided by 208 2 MHz / 208 = ~9600 bps - */ - /* Setup operation mode for receiver (channel 1) */ - NFEN0.nfen0 |= 1; /* Enable noise filter on RxD0 pin */ - SIR01.sir01 = 0x0007U; /* Clear error flags */ - SMR01.smr01 = 0x0122U; /* Operation clock : CK00 + */ + /* Setup operation mode for receiver (channel 1) */ + NFEN0.nfen0 |= 1; /* Enable noise filter on RxD0 pin */ + SIR01.sir01 = 0x0007U; /* Clear error flags */ + SMR01.smr01 = 0x0122U; /* Operation clock : CK00 Transfer clock : division of CK00 Start trigger : valid edge on RxD pin Detect falling edge as start bit Operation mode : UART Interrupt source : transfer end - */ - SCR01.scr01 = 0x4097U; /* Reception only + */ + SCR01.scr01 = 0x4097U; /* Reception only Reception error interrupt masked Phase clock : type 1 No parity LSB first 1 stop bit 8-bit data length - */ - SDR01.sdr01 = 0xCE00U; /* transfer clock : operation clock divided by 208 + */ + SDR01.sdr01 = 0xCE00U; /* transfer clock : operation clock divided by 208 2 MHz / 208 = ~9600 bps - */ - SO0.so0 |= 1; /* Prepare for use of channel 0 */ - SOE0.soe0 |= 1; - P1.p1 |= (1 << 2); /* Set TxD0 high */ - PM1.pm1 &= ~(1 << 2); /* Set output mode for TxD0 */ - PM1.pm1 |= (1 << 1); /* Set input mode for RxD0 */ - SS0.ss0 |= 0x03U; /* Enable UART0 operation (both channels) */ - STIF0 = 1; /* Set buffer empty interrupt request flag */ + */ + SO0.so0 |= 1; /* Prepare for use of channel 0 */ + SOE0.soe0 |= 1; + P1.p1 |= (1 << 2); /* Set TxD0 high */ + PM1.pm1 &= ~(1 << 2); /* Set output mode for TxD0 */ + PM1.pm1 |= (1 << 1); /* Set input mode for RxD0 */ + SS0.ss0 |= 0x03U; /* Enable UART0 operation (both channels) */ + STIF0 = 1; /* Set buffer empty interrupt request flag */ } - -int uart0_puts(const char __far * s) +int +uart0_puts(const char __far *s) { - int len = 0; - SMR00.smr00 |= 0x0001U; /* Set buffer empty interrupt */ - while ('\0' != *s) - { - while (0 == STIF0); - STIF0 = 0; - SDR00.sdr00 = *s++; - ++len; - } -#if 0 - while (0 == STIF0); + int len = 0; + SMR00.smr00 |= 0x0001U; /* Set buffer empty interrupt */ + while('\0' != *s) { + while(0 == STIF0) ; STIF0 = 0; - SDR00.sdr00 = '\r'; -#endif - while (0 == STIF0); - STIF0 = 0; - SMR00.smr00 &= ~0x0001U; - SDR00.sdr00 = '\n'; - while (0 == STIF0); + SDR00.sdr00 = *s++; + ++len; + } #if 0 - while (0 != SSR00.BIT.bit6); /* Wait until TSF00 == 0 */ + while(0 == STIF0) ; + STIF0 = 0; + SDR00.sdr00 = '\r'; #endif - return len; + while(0 == STIF0) ; + STIF0 = 0; + SMR00.smr00 &= ~0x0001U; + SDR00.sdr00 = '\n'; + while(0 == STIF0) ; +#if 0 + while(0 != SSR00.BIT.bit6) ; /* Wait until TSF00 == 0 */ +#endif + return len; } - __attribute__((interrupt)) -void st0_handler(void) +void +st0_handler(void) { } - __attribute__((interrupt)) -void sr0_handler(void) +void +sr0_handler(void) { } - /* This is actually INTSRE0 interrupt handler */ __attribute__((interrupt)) -void tm01h_handler(void) +void +tm01h_handler(void) { } diff --git a/uart0.h b/uart0.h index 9512eacfb..b1ef1237a 100644 --- a/uart0.h +++ b/uart0.h @@ -2,6 +2,6 @@ #define UART0_H__ void uart0_init(void); -int uart0_puts(const char __far * s); +int uart0_puts(const char __far *s); -#endif // UART0_H__ +#endif /* UART0_H__ */ From 2668b17f52801c66bb3a87062468a05ac27a111b Mon Sep 17 00:00:00 2001 From: Maxim Salov Date: Sat, 4 Jan 2014 17:27:24 -0500 Subject: [PATCH 6/6] Move files. --- Makefile | 59 ------------------------------------ uart0.c => cpu/rl78/uart0.c | 0 uart0.h => cpu/rl78/uart0.h | 0 main.c | 60 ------------------------------------- 4 files changed, 119 deletions(-) delete mode 100644 Makefile rename uart0.c => cpu/rl78/uart0.c (100%) rename uart0.h => cpu/rl78/uart0.h (100%) delete mode 100644 main.c diff --git a/Makefile b/Makefile deleted file mode 100644 index 3b183d6e8..000000000 --- a/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -PROJECT_ELF=uart.elf -PROJECT_MOT=$(PROJECT_ELF:.elf=.mot) -PROJECT_MAP=$(PROJECT_ELF:.elf=.map) -PROJECT_LST=$(PROJECT_ELF:.elf=.lst) - -# Find latest installed GNURL78 toolchain. If your toolchain is already in PATH, just comment next line. -TOOL_PATH:=$(shell find /usr/share -maxdepth 1 -type d -iname "gnurl78*" | sort | tail -n 1)/bin - -PREFIX:=$(TOOL_PATH)/rl78-elf - -LD = $(PREFIX)-gcc -CC = $(PREFIX)-gcc -AS = $(PREFIX)-gcc -OBJCOPY = $(PREFIX)-objcopy -OBJDUMP = $(PREFIX)-objdump -SIZE = $(PREFIX)-size - -COMMON_PATH = ../common -PROJECT_PATH = . - -PROJECT_LNK = $(COMMON_PATH)/rl78-R5F100SL.ld - -CFLAGS = -Wall -Wextra -Os -ggdb -ffunction-sections -fdata-sections -I$(PROJECT_PATH) -I$(COMMON_PATH) -mmul=g13 -LDFLAGS = -Wl,--gc-sections -Wl,-Map=$(PROJECT_MAP) -T $(PROJECT_LNK) -nostartfiles - -SOURCES = \ - $(PROJECT_PATH)/main.c \ - $(PROJECT_PATH)/uart0.c \ - $(END) - -OBJS = $(SOURCES:.c=.o) $(COMMON_PATH)/crt0.o - -.PHONY: all - -all: $(PROJECT_MOT) $(PROJECT_LST) - $(SIZE) $(PROJECT_ELF) - -rom: $(PROJECT_MOT) - -$(PROJECT_MOT): $(PROJECT_ELF) - $(OBJCOPY) -O srec $^ $@ - -$(PROJECT_LST): $(PROJECT_ELF) - $(OBJDUMP) -DS $^ > $@ - -$(PROJECT_ELF): $(OBJS) - $(LD) $(LDFLAGS) -o $@ $^ - -flash: $(PROJECT_MOT) - rl78flash -m2 -b500000 -vvwri /dev/ttyUSB0 $^ - -erase: - rl78flash -m2 -b500000 -vveri /dev/ttyUSB0 - -terminal: - rl78flash -rt9600 /dev/ttyUSB0 - -clean: - -rm -f $(OBJS) $(PROJECT_ELF) $(PROJECT_MOT) $(PROJECT_MAP) $(PROJECT_LST) diff --git a/uart0.c b/cpu/rl78/uart0.c similarity index 100% rename from uart0.c rename to cpu/rl78/uart0.c diff --git a/uart0.h b/cpu/rl78/uart0.h similarity index 100% rename from uart0.h rename to cpu/rl78/uart0.h diff --git a/main.c b/main.c deleted file mode 100644 index 4d7ea8c4a..000000000 --- a/main.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "QB-R5F100SL-TB.h" -#include "uart0.h" - -volatile unsigned char ticks = 0; -volatile unsigned char flag_1hz = 0; - -__attribute__((interrupt)) -void -wdti_handler(void) -{ -} -__attribute__((interrupt)) -void -it_handler(void) -{ - ++ticks; - LED1 ^= 1; - if(0 == (0x07 & ticks)) { - flag_1hz = 1; - } -} -int -main(void) -{ - asm ("di"); - /* Setup LEDs */ - LED1 = 1; - LED2 = 1; - LED1_PIN = 0; - LED2_PIN = 0; - /* Setup clocks */ - CMC.cmc = 0x11U; /* Enable XT1, disable X1 */ - CSC.csc = 0x80U; /* Start XT1 and HOCO, stop X1 */ - CKC.ckc = 0x00U; - /* Delay 1 second */ - register unsigned long int i; - for(i = 0x000FFFFFUL; i; --i) { - asm ("nop"); - } - OSMC.osmc = 0x00; /* Supply fsub to peripherals, including Interval Timer */ - uart0_init(); - /* Setup 12-bit interval timer */ - RTCEN = 1; /* Enable 12-bit interval timer and RTC */ - ITMK = 1; /* Disable IT interrupt */ - ITPR0 = 0; /* Set interrupt priority - highest */ - ITPR1 = 0; - ITMC.itmc = 0x8FFFU; /* Set maximum period 4096/32768Hz = 1/8 s, and start timer */ - ITIF = 0; /* Clear interrupt request flag */ - ITMK = 0; /* Enable IT interrupt */ - asm ("ei"); /* Enable interrupts */ - for(;;) { - if(flag_1hz) { - LED2 = 0; - flag_1hz = 0; - uart0_puts("Hello, RL78! [:"); - LED2 = 1; - } - asm ("halt"); - } -}