From d337fd18ad5ee3ebd8c7a7a491877be4177f9b4e Mon Sep 17 00:00:00 2001 From: Markus Hitter Date: Fri, 24 Jul 2015 14:29:16 +0200 Subject: [PATCH] mendel.c: move CPU initialisation to cpu.c (cpu-avr.c). No functional change, but more code separated by architecture. --- cpu-arm.c | 3 ++- cpu-avr.c | 34 +++++++++++++++++++++++++++++++++- cpu.h | 2 +- mendel.c | 29 ++++------------------------- simulator/simulator.c | 6 ++++-- 5 files changed, 44 insertions(+), 30 deletions(-) diff --git a/cpu-arm.c b/cpu-arm.c index 1febeac..91c9a14 100644 --- a/cpu-arm.c +++ b/cpu-arm.c @@ -7,6 +7,7 @@ #if defined TEACUP_C_INCLUDE && defined __ARMEL__ -/* Nothing yet. */ +void cpu_init() { +} #endif /* defined TEACUP_C_INCLUDE && defined __ARMEL__ */ diff --git a/cpu-avr.c b/cpu-avr.c index 58c249e..9d4ff4c 100644 --- a/cpu-avr.c +++ b/cpu-avr.c @@ -7,6 +7,38 @@ #if defined TEACUP_C_INCLUDE && defined __AVR__ -/* Nothing yet. */ +#include +#include "pinio.h" + + +/** Initialise the CPU. + + This sets up the CPU the way we need it. It disables modules we don't use, + so they don't mess on the I/O pins they're connected to. +*/ +void cpu_init() { + #ifdef PRR + #if defined TEMP_MAX6675 || defined SD + PRR = MASK(PRTWI) | MASK(PRADC); + #else + PRR = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); + #endif + #elif defined PRR0 + #if defined TEMP_MAX6675 || defined SD + PRR0 = MASK(PRTWI) | MASK(PRADC); + #else + PRR0 = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); + #endif + #if defined(PRUSART3) + // Don't use USART2 or USART3. Leave USART1 for GEN3 and derivatives. + PRR1 |= MASK(PRUSART3) | MASK(PRUSART2); + #endif + #if defined(PRUSART2) + // Don't use USART2 or USART3. Leave USART1 for GEN3 and derivatives. + PRR1 |= MASK(PRUSART2); + #endif + #endif + ACSR = MASK(ACD); +} #endif /* defined TEACUP_C_INCLUDE && defined __AVR__ */ diff --git a/cpu.h b/cpu.h index 612d043..c61a8d2 100644 --- a/cpu.h +++ b/cpu.h @@ -2,6 +2,6 @@ #ifndef _CPU_H #define _CPU_H -/* Nothing yet. */ +void cpu_init(void); #endif /* _CPU_H */ diff --git a/mendel.c b/mendel.c index 2a7ebe3..3f3190d 100644 --- a/mendel.c +++ b/mendel.c @@ -32,6 +32,7 @@ #include "config_wrapper.h" #endif /* __ARMEL_NOTYET__ */ +#include "cpu.h" #include "serial.h" #ifndef __ARMEL_NOTYET__ #include "dda_queue.h" @@ -69,31 +70,6 @@ /// initialise all I/O - set pins as input or output, turn off unused subsystems, etc void io_init(void) { #ifndef __ARMEL_NOTYET__ - // disable modules we don't use - #ifdef PRR - #if defined TEMP_MAX6675 || defined SD - PRR = MASK(PRTWI) | MASK(PRADC); - #else - PRR = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); - #endif - #elif defined PRR0 - #if defined TEMP_MAX6675 || defined SD - PRR0 = MASK(PRTWI) | MASK(PRADC); - #else - PRR0 = MASK(PRTWI) | MASK(PRADC) | MASK(PRSPI); - #endif - #if defined(PRUSART3) - // don't use USART2 or USART3- leave USART1 for GEN3 and derivatives - PRR1 |= MASK(PRUSART3) | MASK(PRUSART2); - #endif - #if defined(PRUSART2) - // don't use USART2 or USART3- leave USART1 for GEN3 and derivatives - PRR1 |= MASK(PRUSART2); - #endif - #endif - ACSR = MASK(ACD); - - // setup I/O pins // X Stepper WRITE(X_STEP_PIN, 0); SET_OUTPUT(X_STEP_PIN); @@ -206,6 +182,9 @@ void io_init(void) { investigated). */ void init(void) { + + cpu_init(); + #ifndef __ARMEL_NOTYET__ // set up watchdog wd_init(); diff --git a/simulator/simulator.c b/simulator/simulator.c index 649589a..96ee137 100644 --- a/simulator/simulator.c +++ b/simulator/simulator.c @@ -10,7 +10,9 @@ #include "simulator.h" #include "data_recorder.h" -uint8_t ACSR; +void cpu_init(void) { +} + uint8_t TIMSK1; uint16_t TCCR0A, @@ -205,7 +207,7 @@ void sim_tick(char ch) { fflush(stdout); } -static char gcode_buffer[300]; +static char gcode_buffer[300]; static int gcode_buffer_index; void sim_gcode_ch(char ch) { // Got CR, LF or buffer full