hsk-libs-dev
270
High Speed Karlsruhe XC878 library collection
|
HSK Boot implementation. More...
#include <Infineon/XC878.h>
#include "hsk_boot.h"
#include "../hsk_isr/hsk_isr.h"
#include "../hsk_io/hsk_io.h"
Macros | |
#define | BIT_MXB 0 |
MEX3 XRAM Bank Number bits. More... | |
#define | CNT_MXB 3 |
MEX3 XRAM Bank Number bit count. More... | |
#define | BIT_MXB19 4 |
MEX3 XRAM Bank Number highest bit. More... | |
#define | XRAM_BANK 0xF |
The selected XRAM bank number. More... | |
#define | BIT_MXM 3 |
MEX3 XRAM Bank Selector bit. More... | |
#define | XRAM_SELECTOR 1 |
Set BIT_MXM to access the data memroy bank with MOVX instructions. More... | |
#define | PDATA_PAGE 0xF0 |
The page to locate pdata at. More... | |
#define | BIT_EXTOSCR 0 |
OSC_CON bit. More... | |
#define | BIT_EORDRES 1 |
OSC_CON bit. More... | |
#define | BIT_OSCSS 2 |
OSC_CON bit. More... | |
#define | BIT_XPD 3 |
OSC_CON bit. More... | |
#define | BIT_PLLPD 5 |
OSC_CON bit. More... | |
#define | BIT_PLLBYP 6 |
OSC_CON bit. More... | |
#define | BIT_PLLRDRES 7 |
OSC_CON bit. More... | |
#define | BIT_PLL_LOCK 0 |
PLL_CON bit. More... | |
#define | BIT_PLLR 1 |
PLL_CON bit. More... | |
#define | BIT_PDIV 0 |
PLL_CON1 bit. More... | |
#define | CNT_PDIV 5 |
PDIV bit count. More... | |
#define | BIT_NDIVL 2 |
PLL_CON low PLL NF-Divider bits. More... | |
#define | CNT_NDIVL 6 |
NDIVL bit count. More... | |
#define | BIT_NDIVH 5 |
PLL_CON1 high PLL NF-Divider bits. More... | |
#define | CNT_NDIVH 3 |
NDIVH bit count. More... | |
#define | BIT_NMIPLL 1 |
NMICON PLL Loss of Clock NMI Enable bit. More... | |
Functions | |
void | hsk_boot_io (void) |
Initialises all IO ports as input ports without pull. More... | |
void | hsk_boot_mem (void) |
Sets up xdata and pdata memory access. More... | |
ubyte | _sdcc_external_startup (void) |
Turns off pullup/-down for all ports prior to global/static initialisation. More... | |
void | hsk_boot_isr_nmipll (void) |
Loss of clock recovery ISR. More... | |
void | hsk_boot_extClock (const ulong clk) |
Switches to an external oscilator. More... | |
Variables | |
struct { | |
ubyte pdiv | |
The PDIV value for the configured clock speed. More... | |
uword ndiv | |
The NDIV value for the configured clock speed. More... | |
} | boot |
Boot parameter storage for the loss of clock ISR callback. More... | |
HSK Boot implementation.
The High Speed Karlsruhe XC878 boot up code implementation.
This obsoletes 3rd party provided assembler boot code.
#define BIT_EORDRES 1 |
OSC_CON bit.
External Oscillator Watchdog Reset, used when switching to an external clock.
#define BIT_EXTOSCR 0 |
OSC_CON bit.
External Oscillator Run Status Bit, used to determine whether the external oscilator is available.
#define BIT_MXB 0 |
MEX3 XRAM Bank Number bits.
Used to select the memory bank where the XRAM is located. This 4 bit field is divided, the highest bit goes into the BIT_MXB19 bit.
#define BIT_MXB19 4 |
MEX3 XRAM Bank Number highest bit.
The final MXB bit.
#define BIT_MXM 3 |
MEX3 XRAM Bank Selector bit.
#define BIT_NDIVH 5 |
PLL_CON1 high PLL NF-Divider bits.
#define BIT_NDIVL 2 |
PLL_CON low PLL NF-Divider bits.
#define BIT_NMIPLL 1 |
NMICON PLL Loss of Clock NMI Enable bit.
#define BIT_OSCSS 2 |
OSC_CON bit.
Oscillator Source Select, used to turn the external oscillator on(1)/off(0).
#define BIT_PDIV 0 |
PLL_CON1 bit.
Something to do with the CPU clock.
#define BIT_PLL_LOCK 0 |
PLL_CON bit.
PLL Lock Status Flag, used when switching to an external clock.
#define BIT_PLLBYP 6 |
OSC_CON bit.
PLL Output Bypass Control, used when switching to an external clock.
#define BIT_PLLPD 5 |
OSC_CON bit.
PLL Power Down Control, used when switching to an external clock.
#define BIT_PLLR 1 |
PLL_CON bit.
PLL Run Status Flag, used when switching to an external clock.
#define BIT_PLLRDRES 7 |
OSC_CON bit.
PLL Watchdog Reset, used when switching to an external clock.
#define BIT_XPD 3 |
OSC_CON bit.
XTAL Power Down Control, used when switching to an external clock.
#define CNT_MXB 3 |
MEX3 XRAM Bank Number bit count.
#define CNT_NDIVH 3 |
NDIVH bit count.
#define CNT_NDIVL 6 |
NDIVL bit count.
#define CNT_PDIV 5 |
PDIV bit count.
#define PDATA_PAGE 0xF0 |
The page to locate pdata at.
Use the first XRAM page, because that is where the compilers expect it.
#define XRAM_BANK 0xF |
The selected XRAM bank number.
#define XRAM_SELECTOR 1 |
Set BIT_MXM to access the data memroy bank with MOVX instructions.
Otherwise the current bank (whichever that is) would be addressed. MOVX is used to access external memory. The data memory bank is selected with the MXB bits.
|
private |
Turns off pullup/-down for all ports prior to global/static initialisation.
This function is automatically linked by SDCC and called from startup.a51 by Keil C51.
void hsk_boot_extClock | ( | const ulong | clk | ) |
Switches to an external oscilator.
This function requires xdata access.
The implemented process is named: "Select the External Oscillator as PLL input source"
The following is described in more detail in chapter 7.3 of the XC878 User Manual.
The XC878 can either use an internal 4MHz oscilator (default) or an external oscilator from 2 to 20MHz, normally referred to as FOSC. A phase-locked loop (PLL) converts it to a faster internal speed FSYS, 144MHz by default.
This implementation is currently limited to oscilators from 2MHz to 20MHz in 1MHz intervals.
The oscilator frequency is vital for external communication (e.g. CAN) and timer/counter speeds.
This implementation switches to an external clock ensuring that the PLL generates a 144MHz FSYS clock. The CLKREL divisor set to 6 generates the fast clock (FCLK) that runs at 48MHz. The remaining clocks, i.e. peripheral (PCLK), CPU (SCLK, CCLK), have a fixed divisor by 2, so they run at 24MHz.
After setting up the PLL, this function will register an ISR, that will attempt to reactivate the external oscillator in a PLL loss-of-clock event.
clk | The frequency of the external oscilator in Hz. |
WARNING - Here be dragons ...
Before messing with this stuff you should be aware that this is tricky business. Mistakes can result in hardware damage. Or at least all your timers and external interfaces will act weird.
Basically this bypasses/turns off the PLL, sets up the external oscilator and than reconfigures the PLL and brings it back into play.
Many of the OSC_CON, which is on page 1, bits are write protected. The MAIN_vUnlockProtecReg() turns the protection off for 32 cycles. So it has to be turned off each time protected bits are accessed.
|
private |
Initialises all IO ports as input ports without pull.
|
private |
Loss of clock recovery ISR.
This takes very long.
|
private |
Sets up xdata and pdata memory access.
Refer to the Processor Architecture and Memory Organization chapters of the XC878 User Manual.
|
static |
Boot parameter storage for the loss of clock ISR callback.
uword ndiv |
The NDIV value for the configured clock speed.
See table 7-5 in the data sheet for desired NDIV values. See the NDIV description for value encoding.
ubyte pdiv |
The PDIV value for the configured clock speed.
See table 7-5 in the data sheet for desired PDIV values. See the PDIV description for value encoding.