# HG changeset patch # User Paul Boddie # Date 1541716826 -3600 # Node ID ac6df9915caed1b5745cea6b2b2866e5a9d5692b # Parent 26d5c155e246aec65d92f57e8157d0330c867390 Moved various common functions to a utilities module. diff -r 26d5c155e246 -r ac6df9915cae examples/demo/main.c --- a/examples/demo/main.c Thu Nov 08 23:07:09 2018 +0100 +++ b/examples/demo/main.c Thu Nov 08 23:40:26 2018 +0100 @@ -18,9 +18,10 @@ */ -#include "pic32_c.h" +#include "debug.h" #include "init.h" -#include "debug.h" +#include "pic32_c.h" +#include "utils.h" /* Specific functionality. */ @@ -47,30 +48,6 @@ -/* Blink an attached LED with delays implemented using a loop. */ - -static void blink(uint32_t delay, uint32_t port, uint32_t pins) -{ - uint32_t counter; - - /* Clear outputs (LED). */ - - CLR_REG(port, pins); - - while (1) - { - counter = delay; - - while (counter--) __asm__(""); /* retain loop */ - - /* Invert outputs (LED). */ - - INV_REG(port, pins); - } -} - - - /* Main program. */ void main(void) diff -r 26d5c155e246 -r ac6df9915cae examples/vga/main.c --- a/examples/vga/main.c Thu Nov 08 23:07:09 2018 +0100 +++ b/examples/vga/main.c Thu Nov 08 23:40:26 2018 +0100 @@ -18,19 +18,19 @@ */ -#include "pic32_c.h" +#include "debug.h" +#include "display.h" +#include "font.h" #include "init.h" -#include "debug.h" +#include "pic32_c.h" +#include "utils.h" +#include "vga_display.h" /* Specific functionality. */ #include "devconfig.h" -#include "display.h" #include "display_config.h" -#include "font.h" #include "main.h" -#include "vga.h" -#include "vga_display.h" @@ -106,34 +106,6 @@ -/* Busy wait. */ - -static void wait(uint32_t delay) -{ - uint32_t counter = delay; - - if (!delay) return; - while (counter--) __asm__(""); /* retain loop */ -} - -/* Blink an attached LED with delays implemented using a loop. */ - -static void blink(uint32_t delay, uint32_t port, uint32_t pins) -{ - /* Clear outputs (LED). */ - - CLR_REG(port, pins); - - while (1) - { - wait(delay); - - /* Invert outputs (LED). */ - - INV_REG(port, pins); - } -} - /* Copy to the store from the display, then blit the image. */ static void plot_sprite(uint8_t *background, int x, int y) @@ -155,18 +127,6 @@ x, y, -1, 1); } -/* Wrap a value within the bounds [0, limit). */ - -static int wrap_value(int value, int limit) -{ - if (value < 0) - return limit - (-value % limit); - else if (value >= limit) - return (value - limit) % limit; - else - return value; -} - /* Plot the revealed region at the edge of the screen after scrolling. */ static void plot_screen_edge(int xorigin, int yorigin, int xstep) diff -r 26d5c155e246 -r ac6df9915cae include/debug.h --- a/include/debug.h Thu Nov 08 23:07:09 2018 +0100 +++ b/include/debug.h Thu Nov 08 23:40:26 2018 +0100 @@ -20,6 +20,8 @@ #ifndef __DEBUG_H__ #define __DEBUG_H__ +#include + /* Register output functions using UART1. */ void rbits(uint32_t reg); @@ -43,4 +45,8 @@ void uart_write_nl(void); void uart_write_string(const char *s); +/* Output signal functions. */ + +void blink(uint32_t delay, uint32_t port, uint32_t pins); + #endif /* __DEBUG_H__ */ diff -r 26d5c155e246 -r ac6df9915cae lib/debug.c --- a/lib/debug.c Thu Nov 08 23:07:09 2018 +0100 +++ b/lib/debug.c Thu Nov 08 23:40:26 2018 +0100 @@ -19,6 +19,9 @@ #include "pic32_c.h" #include "debug.h" +#include "utils.h" + + /* Register output functions using UART1. */ @@ -106,3 +109,23 @@ while (*s) uart_write(*s++); } + + + +/* Blink an attached LED with delays implemented using a loop. */ + +void blink(uint32_t delay, uint32_t port, uint32_t pins) +{ + /* Clear outputs (LED). */ + + CLR_REG(port, pins); + + while (1) + { + wait(delay); + + /* Invert outputs (LED). */ + + INV_REG(port, pins); + } +} diff -r 26d5c155e246 -r ac6df9915cae mk/common.mk --- a/mk/common.mk Thu Nov 08 23:07:09 2018 +0100 +++ b/mk/common.mk Thu Nov 08 23:40:26 2018 +0100 @@ -49,8 +49,8 @@ # Application-specific files appear after the above but before those below in # the application Makefiles. -COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/cpu.S -COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/cpu.o +COMMON_SRC = $(LIBDIR)/payload.c $(LIBDIR)/init.c $(LIBDIR)/debug.c $(LIBDIR)/utils.c $(LIBDIR)/cpu.S +COMMON_OBJ = $(LIBDIR)/payload.o $(LIBDIR)/init.o $(LIBDIR)/debug.o $(LIBDIR)/utils.o $(LIBDIR)/cpu.o DISPLAY_COMMON_SRC = $(LIBDIR)/display.c $(LIBDIR)/font.c DISPLAY_COMMON_OBJ = $(LIBDIR)/display.o $(LIBDIR)/font.o