Skip to content

Commit c11ec50

Browse files
committed
first commit
0 parents  commit c11ec50

27 files changed

+3738
-0
lines changed

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.[oa]
2+
.*.d
3+
*~
4+
*.ld
5+
*.elf
6+
*.bin
7+
*.hex
8+
*.orig
9+
*.rej
10+
kswitch_v2*

COPYING

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
This is free and unencumbered software released into the public domain.
2+
3+
Anyone is free to copy, modify, publish, use, compile, sell, or
4+
distribute this software, either in source code form or as a compiled
5+
binary, for any purpose, commercial or non-commercial, and by any
6+
means.
7+
8+
In jurisdictions that recognize copyright laws, the author or authors
9+
of this software dedicate any and all copyright interest in the
10+
software to the public domain. We make this dedication for the benefit
11+
of the public at large and to the detriment of our heirs and
12+
successors. We intend this dedication to be an overt act of
13+
relinquishment in perpetuity of all present and future rights to this
14+
software under copyright law.
15+
16+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19+
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20+
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21+
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22+
OTHER DEALINGS IN THE SOFTWARE.
23+
24+
For more information, please refer to <http://unlicense.org/>

Makefile

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
2+
export FW_VER := 0.1a
3+
4+
PROJ = FF_OSD
5+
VER := v$(FW_VER)
6+
7+
SUBDIRS += src
8+
9+
.PHONY: all clean dist flash start serial
10+
11+
ifneq ($(RULES_MK),y)
12+
13+
export ROOT := $(CURDIR)
14+
15+
all:
16+
$(MAKE) -C src -f $(ROOT)/Rules.mk $(PROJ).elf $(PROJ).bin $(PROJ).hex
17+
clean:
18+
rm -rf $(PROJ)-$(VER)*
19+
$(MAKE) -f $(ROOT)/Rules.mk $@
20+
21+
dist: all
22+
rm -rf $(PROJ)-$(VER)*
23+
mkdir -p $(PROJ)-$(VER)
24+
cp -a src/$(PROJ).elf $(PROJ)-$(VER)
25+
cp -a src/$(PROJ).bin $(PROJ)-$(VER)
26+
cp -a src/$(PROJ).hex $(PROJ)-$(VER)
27+
zip -r $(PROJ)-$(VER) $(PROJ)-$(VER)
28+
rm -rf $(PROJ)-$(VER)
29+
30+
endif
31+
32+
BAUD=921600
33+
34+
flash: all
35+
sudo ~/stm32flash/stm32flash -b $(BAUD) \
36+
-vw src/$(PROJ).hex /dev/ttyUSB0
37+
38+
start:
39+
sudo ~/stm32flash/stm32flash -b $(BAUD) -g 0 /dev/ttyUSB0
40+
41+
serial:
42+
sudo miniterm.py /dev/ttyUSB0 115200

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# FF_OSD: On Screen Display for FlashFloppy
2+
3+
An On Screen Display (OSD) which emulates the popular LCD I2C interface.
4+
5+
Hence it can be connected to a range of hardware which targets this type
6+
of LCD display.
7+
8+
Most specifically: [FlashFloppy][FF]!
9+
10+
## Download
11+
- [**Download FF_OSD**][Downloads]
12+
13+
## Documentation
14+
- [**Read the GitHub Wiki**](https://github.com/keirf/FF_OSD/wiki)
15+
16+
## Redistribution
17+
18+
FF_OSD source code, and all binary releases, are freely redistributable
19+
in any form. Please see the [license](COPYING).
20+
21+
[FF]: https://github.com/keirf/FlashFloppy/wiki
22+
[Downloads]: https://github.com/keirf/FF_OSD/wiki/Downloads

Rules.mk

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
TOOL_PREFIX = arm-none-eabi-
2+
CC = $(TOOL_PREFIX)gcc
3+
OBJCOPY = $(TOOL_PREFIX)objcopy
4+
LD = $(TOOL_PREFIX)ld
5+
6+
ifneq ($(VERBOSE),1)
7+
TOOL_PREFIX := @$(TOOL_PREFIX)
8+
endif
9+
10+
FLAGS = -g -Os -nostdlib -std=gnu99 -iquote $(ROOT)/inc
11+
FLAGS += -Wall -Werror -Wno-format -Wdeclaration-after-statement
12+
FLAGS += -Wstrict-prototypes -Wredundant-decls -Wnested-externs
13+
FLAGS += -fno-common -fno-exceptions -fno-strict-aliasing
14+
FLAGS += -mlittle-endian -mthumb -mcpu=cortex-m3 -mfloat-abi=soft
15+
16+
FLAGS += -MMD -MF .$(@F).d
17+
DEPS = .*.d
18+
19+
CFLAGS += $(FLAGS) -include decls.h
20+
AFLAGS += $(FLAGS) -D__ASSEMBLY__
21+
LDFLAGS += $(FLAGS) -Wl,--gc-sections
22+
23+
RULES_MK := y
24+
25+
include Makefile
26+
27+
OBJS += $(patsubst %,%/build.o,$(SUBDIRS))
28+
29+
# Force execution of pattern rules (for which PHONY cannot be directly used).
30+
.PHONY: FORCE
31+
FORCE:
32+
33+
.PHONY: clean
34+
35+
.SECONDARY:
36+
37+
build.o: $(OBJS)
38+
$(LD) -r -o $@ $^
39+
40+
%/build.o: FORCE
41+
$(MAKE) -f $(ROOT)/Rules.mk -C $* build.o
42+
43+
%.o: %.c Makefile
44+
@echo CC $@
45+
$(CC) $(CFLAGS) -c $< -o $@
46+
47+
%.o: %.S Makefile
48+
@echo AS $@
49+
$(CC) $(AFLAGS) -c $< -o $@
50+
51+
%.ld: %.ld.S Makefile
52+
@echo CPP $@
53+
$(CC) -P -E $(AFLAGS) $< -o $@
54+
55+
%.elf: $(OBJS) %.ld Makefile
56+
@echo LD $@
57+
$(CC) $(LDFLAGS) -T$(*F).ld $(OBJS) -o $@
58+
59+
%.hex: %.elf
60+
@echo OBJCOPY $@
61+
$(OBJCOPY) -O ihex $< $@
62+
63+
%.bin: %.elf
64+
@echo OBJCOPY $@
65+
$(OBJCOPY) -O binary $< $@
66+
67+
clean:: $(addprefix _clean_,$(SUBDIRS))
68+
rm -f *~ *.o *.elf *.hex *.bin *.ld $(DEPS)
69+
_clean_%: FORCE
70+
$(MAKE) -f $(ROOT)/Rules.mk -C $* clean
71+
72+
-include $(DEPS)

inc/cancellation.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* cancellation.h
3+
*
4+
* Asynchronously-cancellable function calls.
5+
*
6+
* Written & released by Keir Fraser <[email protected]>
7+
*
8+
* This is free and unencumbered software released into the public domain.
9+
* See the file COPYING for more details, or visit <http://unlicense.org>.
10+
*/
11+
12+
struct cancellation {
13+
uint32_t *sp;
14+
};
15+
16+
#define cancellation_is_active(c) ((c)->sp != NULL)
17+
18+
/* Execute fn() in a wrapped cancellable environment. */
19+
int call_cancellable_fn(struct cancellation *c, int (*fn)(void *), void *arg);
20+
21+
/* From IRQ content: stop running fn() and immediately return -1. */
22+
void cancel_call(struct cancellation *c);
23+
24+
/*
25+
* Local variables:
26+
* mode: C
27+
* c-file-style: "Linux"
28+
* c-basic-offset: 4
29+
* tab-width: 4
30+
* indent-tabs-mode: nil
31+
* End:
32+
*/

inc/decls.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* decls.h
3+
*
4+
* Pull in all other header files in an orderly fashion. Source files include
5+
* only this header, and only once.
6+
*
7+
* Written & released by Keir Fraser <[email protected]>
8+
*
9+
* This is free and unencumbered software released into the public domain.
10+
* See the file COPYING for more details, or visit <http://unlicense.org>.
11+
*/
12+
13+
#include <stdint.h>
14+
#include <stdarg.h>
15+
#include <stddef.h>
16+
17+
#include "util.h"
18+
#include "stm32f10x_regs.h"
19+
#include "stm32f10x.h"
20+
#include "intrinsics.h"
21+
22+
#include "cancellation.h"
23+
#include "time.h"
24+
#include "timer.h"
25+
26+
/*
27+
* Local variables:
28+
* mode: C
29+
* c-file-style: "Linux"
30+
* c-basic-offset: 4
31+
* tab-width: 4
32+
* indent-tabs-mode: nil
33+
* End:
34+
*/

inc/intrinsics.h

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
/*
2+
* intrinsics.h
3+
*
4+
* Compiler intrinsics for ARMv7-M core.
5+
*
6+
* Written & released by Keir Fraser <[email protected]>
7+
*
8+
* This is free and unencumbered software released into the public domain.
9+
* See the file COPYING for more details, or visit <http://unlicense.org>.
10+
*/
11+
12+
struct exception_frame {
13+
uint32_t r0, r1, r2, r3, r12, lr, pc, psr;
14+
};
15+
16+
#define _STR(x) #x
17+
#define STR(x) _STR(x)
18+
19+
/* Force a compilation error if condition is true */
20+
#define BUILD_BUG_ON(cond) ({ _Static_assert(!(cond), "!(" #cond ")"); })
21+
22+
#define __aligned(x) __attribute__((aligned(x)))
23+
#define __packed __attribute((packed))
24+
#define always_inline __inline__ __attribute__((always_inline))
25+
#define noinline __attribute__((noinline))
26+
27+
#define likely(x) __builtin_expect(!!(x),1)
28+
#define unlikely(x) __builtin_expect(!!(x),0)
29+
30+
#define illegal() asm volatile (".short 0xde00");
31+
32+
#define barrier() asm volatile ("" ::: "memory")
33+
#define cpu_sync() asm volatile("dsb; isb" ::: "memory")
34+
#define cpu_relax() asm volatile ("nop" ::: "memory")
35+
#define cpu_wfi() asm volatile ("dsb; wfi" ::: "memory")
36+
37+
#define sv_call(imm) asm volatile ( "svc %0" : : "i" (imm) )
38+
39+
#define read_special(reg) ({ \
40+
uint32_t __x; \
41+
asm volatile ("mrs %0,"#reg : "=r" (__x) ::); \
42+
__x; \
43+
})
44+
45+
#define write_special(reg,val) ({ \
46+
uint32_t __x = (uint32_t)(val); \
47+
asm volatile ("msr "#reg",%0" :: "r" (__x) :); \
48+
})
49+
50+
/* CONTROL[1] == 0 => running on Master Stack (Exception Handler mode). */
51+
#define CONTROL_SPSEL 2
52+
#define in_exception() (!(read_special(control) & CONTROL_SPSEL))
53+
54+
#define global_disable_exceptions() \
55+
asm volatile ("cpsid f; cpsid i" ::: "memory")
56+
#define global_enable_exceptions() \
57+
asm volatile ("cpsie f; cpsie i" ::: "memory")
58+
59+
/* NB. IRQ disable via CPSID/MSR is self-synchronising. No barrier needed. */
60+
#define IRQ_global_disable() asm volatile ("cpsid i" ::: "memory")
61+
#define IRQ_global_enable() asm volatile ("cpsie i" ::: "memory")
62+
63+
/* Save/restore IRQ priority levels.
64+
* NB. IRQ disable via MSR is self-synchronising. I have confirmed this on
65+
* Cortex-M3: any pending IRQs are handled before they are disabled by
66+
* a BASEPRI update. Hence no barrier is needed here. */
67+
#define IRQ_save(newpri) ({ \
68+
uint8_t __newpri = (newpri)<<4; \
69+
uint8_t __oldpri = read_special(basepri); \
70+
if (!__oldpri || (__oldpri > __newpri)) \
71+
write_special(basepri, __newpri); \
72+
__oldpri; })
73+
/* NB. Same as CPSIE, any pending IRQ enabled by this BASEPRI update may
74+
* execute a couple of instructions after the MSR instruction. This has been
75+
* confirmed on Cortex-M3. */
76+
#define IRQ_restore(oldpri) write_special(basepri, (oldpri))
77+
78+
static inline uint16_t _rev16(uint16_t x)
79+
{
80+
uint16_t result;
81+
asm volatile ("rev16 %0,%1" : "=r" (result) : "r" (x));
82+
return result;
83+
}
84+
85+
static inline uint32_t _rev32(uint32_t x)
86+
{
87+
uint32_t result;
88+
asm volatile ("rev %0,%1" : "=r" (result) : "r" (x));
89+
return result;
90+
}
91+
92+
static inline uint32_t _rbit32(uint32_t x)
93+
{
94+
uint32_t result;
95+
asm volatile ("rbit %0,%1" : "=r" (result) : "r" (x));
96+
return result;
97+
}
98+
99+
/*
100+
* Local variables:
101+
* mode: C
102+
* c-file-style: "Linux"
103+
* c-basic-offset: 4
104+
* tab-width: 4
105+
* indent-tabs-mode: nil
106+
* End:
107+
*/

0 commit comments

Comments
 (0)