Skip to content
This repository has been archived by the owner on Jun 11, 2023. It is now read-only.

Commit

Permalink
The big ETL switch!
Browse files Browse the repository at this point in the history
  • Loading branch information
cbiffle committed Apr 13, 2014
1 parent bf5e1d2 commit 513ea24
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 63 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ vga[S_files] := \
vga[cc_flags] := -std=gnu++0x -O2

vga[libs] := \
etl/common:common \
lib/stm32f4xx:stm32f4xx

include $(depth)/build/Makefile.rules
6 changes: 3 additions & 3 deletions bitmap.cc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#include "vga/bitmap.h"

#include "lib/common/algorithm.h"
#include "etl/common/algorithm.h"

using common::min;
using etl::common::min;

#define INVARIANT(c) while (!(c)) {}
#define PRE(c) while (!(c)) {}
Expand Down Expand Up @@ -40,7 +40,7 @@ static void bitrow_almost_aligned(unsigned const *source,
unsigned start_bit,
unsigned bit_count) {
PRE(start_bit < 32);
unsigned bits = common::min(32u - start_bit, bit_count);
unsigned bits = min(32u - start_bit, bit_count);
unsigned mask = maskbits(bits) << start_bit;
*dest = (*dest & ~mask) | (*source & mask);

Expand Down
4 changes: 2 additions & 2 deletions copy_words.S
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
@ r2 number of words to transfer.
.section .ramcode,"ax",%progbits
.balign 4
.global _Z10copy_wordsPKmPmm
.global _Z10copy_wordsPKjPjj
.thumb_func
_Z10copy_wordsPKmPmm:
_Z10copy_wordsPKjPjj:
@ Name our registers.
src .req r0
dst .req r1
Expand Down
8 changes: 4 additions & 4 deletions copy_words.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
#ifndef COPY_WORDS_H
#define COPY_WORDS_H

#include "lib/armv7m/types.h"
#include "etl/armv7m/types.h"

/*
* Moves some number of aligned words using the fastest method I could think up.
*/
void copy_words(armv7m::Word const *source,
armv7m::Word *dest,
armv7m::Word count);
void copy_words(etl::armv7m::Word const *source,
etl::armv7m::Word *dest,
etl::armv7m::Word count);

#endif // COPY_WORDS_H
8 changes: 4 additions & 4 deletions measurement.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "vga/measurement.h"

using armv7m::SysTick;
using armv7m::sys_tick;
using etl::armv7m::SysTick;
using etl::armv7m::sys_tick;

using stm32f4xx::Gpio;
using stm32f4xx::gpioc;
using etl::stm32f4xx::Gpio;
using etl::stm32f4xx::gpioc;

namespace vga {

Expand Down
12 changes: 6 additions & 6 deletions measurement.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@
#define VGA_MEASUREMENT_H

#include "lib/common/attribute_macros.h"
#include "lib/armv7m/sys_tick.h"
#include "lib/stm32f4xx/gpio.h"
#include "etl/armv7m/sys_tick.h"
#include "etl/stm32f4xx/gpio.h"

namespace vga {

void msigs_init();

INLINE void msig_a_set() {
stm32f4xx::gpioc.set(stm32f4xx::Gpio::p9);
etl::stm32f4xx::gpioc.set(etl::stm32f4xx::Gpio::p9);
}

INLINE void msig_a_clear() {
stm32f4xx::gpioc.clear(stm32f4xx::Gpio::p9);
etl::stm32f4xx::gpioc.clear(etl::stm32f4xx::Gpio::p9);
}

INLINE void msig_a_toggle() {
stm32f4xx::gpioc.toggle(stm32f4xx::Gpio::p9);
etl::stm32f4xx::gpioc.toggle(etl::stm32f4xx::Gpio::p9);
}

void mtim_init();

INLINE unsigned mtim_get() {
return armv7m::sys_tick.read_cvr().get_current();
return etl::armv7m::sys_tick.read_cvr().get_current();
}

} // namespace vga
Expand Down
6 changes: 4 additions & 2 deletions rast/bitmap_1.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "vga/vga.h"
#include "vga/unpack_1bpp.h"

using etl::armv7m::Word;

namespace vga {
namespace rast {

Expand Down Expand Up @@ -75,8 +77,8 @@ bool Bitmap_1::can_bg_use_bitband() const {
}

void Bitmap_1::copy_bg_to_fg() const {
copy_words(reinterpret_cast<armv7m::Word *>((void *) _fb[!_page1]),
reinterpret_cast<armv7m::Word *>((void *) _fb[_page1]),
copy_words(reinterpret_cast<Word *>((void *) _fb[!_page1]),
reinterpret_cast<Word *>((void *) _fb[_page1]),
_bytes_per_line * _lines / 4);
}

Expand Down
4 changes: 2 additions & 2 deletions timing.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef VGA_TIMING_H
#define VGA_TIMING_H

#include "lib/stm32f4xx/rcc.h"
#include "etl/stm32f4xx/rcc.h"

namespace vga {

Expand All @@ -22,7 +22,7 @@ struct Timing {
* AHB) frequency. The clock_config specifies how to achieve the desired
* CPU clock, and thus implicitly defines the CPU clock.
*/
stm32f4xx::ClockConfig clock_config;
etl::stm32f4xx::ClockConfig clock_config;

/*
* Horizontal timing.
Expand Down
85 changes: 45 additions & 40 deletions vga.cc
Original file line number Diff line number Diff line change
@@ -1,45 +1,50 @@
#include "vga/vga.h"

#include "lib/common/attribute_macros.h"
#include "lib/armv7m/exceptions.h"
#include "lib/armv7m/exception_table.h"
#include "lib/armv7m/instructions.h"
#include "lib/armv7m/scb.h"

#include "lib/stm32f4xx/adv_timer.h"
#include "lib/stm32f4xx/ahb.h"
#include "lib/stm32f4xx/apb.h"
#include "lib/stm32f4xx/dbg.h"
#include "lib/stm32f4xx/dma.h"
#include "lib/stm32f4xx/flash.h"
#include "lib/stm32f4xx/gpio.h"
#include "lib/stm32f4xx/interrupts.h"
#include "lib/stm32f4xx/rcc.h"
#include "lib/stm32f4xx/syscfg.h"
#include "etl/armv7m/exceptions.h"
#include "etl/armv7m/exception_table.h"
#include "etl/armv7m/instructions.h"
#include "etl/armv7m/scb.h"

#include "etl/stm32f4xx/rcc.h"

#include "etl/stm32f4xx/adv_timer.h"
#include "etl/stm32f4xx/ahb.h"
#include "etl/stm32f4xx/apb.h"
#include "etl/stm32f4xx/dbg.h"
#include "etl/stm32f4xx/dma.h"
#include "etl/stm32f4xx/flash.h"
#include "etl/stm32f4xx/gpio.h"
#include "etl/stm32f4xx/interrupt_table.h"
#include "etl/stm32f4xx/interrupts.h"
#include "etl/stm32f4xx/syscfg.h"

#include "vga/arena.h"
#include "vga/copy_words.h"
#include "vga/timing.h"
#include "vga/measurement.h"
#include "vga/rasterizer.h"

using stm32f4xx::AdvTimer;
using stm32f4xx::AhbPeripheral;
using stm32f4xx::ApbPeripheral;
using stm32f4xx::Dbg;
using stm32f4xx::dbg;
using stm32f4xx::Dma;
using stm32f4xx::dma2;
using stm32f4xx::flash;
using stm32f4xx::Gpio;
using stm32f4xx::gpioc;
using stm32f4xx::gpioe;
using stm32f4xx::Interrupt;
using stm32f4xx::rcc;
using stm32f4xx::syscfg;
using stm32f4xx::tim1;
using stm32f4xx::tim8;
using stm32f4xx::Word;
using etl::armv7m::Scb;
using etl::armv7m::scb;

using etl::stm32f4xx::AdvTimer;
using etl::stm32f4xx::AhbPeripheral;
using etl::stm32f4xx::ApbPeripheral;
using etl::stm32f4xx::Dbg;
using etl::stm32f4xx::dbg;
using etl::stm32f4xx::Dma;
using etl::stm32f4xx::dma2;
using etl::stm32f4xx::flash;
using etl::stm32f4xx::Gpio;
using etl::stm32f4xx::gpioc;
using etl::stm32f4xx::gpioe;
using etl::stm32f4xx::Interrupt;
using etl::stm32f4xx::rcc;
using etl::stm32f4xx::syscfg;
using etl::stm32f4xx::tim1;
using etl::stm32f4xx::tim8;
using etl::stm32f4xx::Word;

#define IN_SCAN_RAM SECTION(".vga_scan_ram")
#define IN_LOCAL_RAM SECTION(".vga_local_ram")
Expand Down Expand Up @@ -128,7 +133,7 @@ void init() {
// set using narrower SoC priorities (0-15). This is a bit ugly.
set_irq_priority(Interrupt::tim8_cc, 0);
set_irq_priority(Interrupt::tim1_cc, 1);
set_exception_priority(armv7m::Exception::pend_sv, 0xFF);
scb.set_exception_priority(etl::armv7m::Exception::pend_sv, 0xFF);

// Enable Flash cache and prefetching to try and reduce jitter.
// This only affects best-effort-level code, not anything realtime.
Expand Down Expand Up @@ -305,15 +310,15 @@ void configure_band_list(Band const *head) {
}

void wait_for_vblank() {
while (!in_vblank()) armv7m::wait_for_interrupt();
while (!in_vblank()) etl::armv7m::wait_for_interrupt();
}

bool in_vblank() {
return current_line < current_timing.video_start_line;
}

void sync_to_vblank() {
while (in_vblank()) armv7m::wait_for_interrupt();
while (in_vblank()) etl::armv7m::wait_for_interrupt();
wait_for_vblank();
}

Expand Down Expand Up @@ -460,10 +465,10 @@ static void end_of_active_video() {
vga::current_line = line + 1;

// Pend a PendSV to process hblank tasks.
armv7m::scb.write_icsr(armv7m::Scb::icsr_value_t().with_pendsvset(true));
scb.write_icsr(Scb::icsr_value_t().with_pendsvset(true));
}

RAM_CODE void stm32f4xx_tim1_cc_handler() {
RAM_CODE void etl_stm32f4xx_tim1_cc_handler() {
// We access this APB2 timer through the bridge on AHB1. This implies
// both wait states and resource conflicts with scanout. Get done fast.
tim1.write_sr(tim1.read_sr().with_cc2if(false));
Expand All @@ -472,10 +477,10 @@ RAM_CODE void stm32f4xx_tim1_cc_handler() {
// This ensures that the M4's D-code bus is available for exception entry.
// NOTE: this behaves correctly on the M4, but WFI is not guaranteed to
// actually do anything.
armv7m::wait_for_interrupt();
etl::armv7m::wait_for_interrupt();
}

RAM_CODE void stm32f4xx_tim8_cc_handler() {
RAM_CODE void etl_stm32f4xx_tim8_cc_handler() {
// We have to clear our interrupt flags, or this will recur.
auto sr = tim8.read_sr();

Expand Down Expand Up @@ -508,7 +513,7 @@ static vga::Rasterizer *get_next_rasterizer() {
}

RAM_CODE
void v7m_pend_sv_handler() {
void etl_armv7m_pend_sv_handler() {
vga::hblank_interrupt();

if (is_rendered_state(vga::state)) {
Expand Down

0 comments on commit 513ea24

Please sign in to comment.