Subversion Repositories svnkaklik

Compare Revisions

Ignore whitespace Rev 5 → Rev 6

/programy/CodeWarrior/test/Demo_S08QG8_Test/Sources/Start08.c
0,0 → 1,284
/******************************************************************************
FILE : start08.c
PURPOSE : 68HC08 standard startup code
LANGUAGE : ANSI-C / INLINE ASSEMBLER
----------------------------------------------------------------------------
HISTORY
22 oct 93 Created.
04/17/97 Also C++ constructors called in Init().
******************************************************************************/
 
/**********************************************************************/
/* NOTE: */
/* This version of the startup code does assumes that main */
/* does never return (saving the 2 byte return address of _Startup on */
/* the stack). */
/**********************************************************************/
 
#define __NO_FLAGS_OFFSET /* we do not need the flags field in the startup data descriptor */
#define __NO_MAIN_OFFSET /* we do not need the main field in the startup data descriptor */
 
#include <start08.h>
 
#ifdef __cplusplus
#define __EXTERN_C extern "C"
#else
#define __EXTERN_C
#endif
 
 
/**********************************************************************/
/* __ONLY_INIT_SP define: */
/* This define selects an shorter version of the startup code */
/* which only loads the stack pointer and directly afterwards calls */
/* main. This version does however NOT initialized global variables */
/* (So this version is not ANSI compliant!) */
/**********************************************************************/
 
#ifndef __ONLY_INIT_SP
 
#pragma DATA_SEG FAR _STARTUP
struct _tagStartup _startupData; /* read-only:
_startupData is allocated in ROM and
initialized by the linker */
 
#pragma MESSAGE DISABLE C20001 /* Warning C20001: Different value of stackpointer depending on control-flow */
/* the function _COPY_L releases some bytes from the stack internally */
 
#ifdef __OPTIMIZE_FOR_SIZE__
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_FRAME
/*lint -esym(528, loadByte) inhibit warning about not referenced loadByte function */
static void near loadByte(void) {
asm {
PSHH
PSHX
#ifdef __HCS08__
LDHX 5,SP
LDA 0,X
AIX #1
STHX 5,SP
#else
LDA 5,SP
PSHA
LDX 7,SP
PULH
LDA 0,X
AIX #1
STX 6,SP
PSHH
PULX
STX 5,SP
#endif
PULX
PULH
RTS
}
}
#endif /* __OPTIMIZE_FOR_SIZE__ */
 
 
/*lint -esym(752,_COPY_L) inhibit message on dunction declared, but not used (it is used in HLI) */
__EXTERN_C extern void _COPY_L(void);
/* DESC: copy very large structures (>= 256 bytes) in 16 bit address space (stack incl.)
IN: TOS count, TOS(2) @dest, H:X @src
OUT:
WRITTEN: X,H */
#ifdef __ELF_OBJECT_FILE_FORMAT__
#define toCopyDownBegOffs 0
#else
#define toCopyDownBegOffs 2 /* for the hiware format, the toCopyDownBeg field is a long. Because the HC08 is big endian, we have to use an offset of 2 */
#endif
static void Init(void) {
/* purpose: 1) zero out RAM-areas where data is allocated
2) init run-time data
3) copy initialization data from ROM to RAM
*/
/*lint -esym(529,p,i) inhibit warning about symbols not used: it is used in HLI below */
int i;
int *far p;
 
asm {
ZeroOut: ;
LDA _startupData.nofZeroOuts:1 ; nofZeroOuts
INCA
STA i:1 ; i is counter for number of zero outs
LDA _startupData.nofZeroOuts:0 ; nofZeroOuts
INCA
STA i:0
LDHX _startupData.pZeroOut ; *pZeroOut
BRA Zero_5
Zero_3: ;
; CLR i:1 is already 0
Zero_4: ;
; { HX == _pZeroOut }
PSHX
PSHH
; { nof bytes in (int)2,X }
; { address in (int)0,X }
LDA 0,X
PSHA
LDA 2,X
INCA
STA p ; p:0 is used for high byte of byte counter
LDA 3,X
LDX 1,X
PULH
INCA
BRA Zero_0
Zero_1: ;
; CLRA A is already 0, so we do not have to clear it
Zero_2: ;
CLR 0,X
AIX #1
Zero_0: ;
DBNZA Zero_2
Zero_6:
DBNZ p, Zero_1
PULH
PULX ; restore *pZeroOut
AIX #4 ; advance *pZeroOut
Zero_5: ;
DBNZ i:1, Zero_4
DBNZ i:0, Zero_3
;
CopyDown: ;
 
}
 
/* copy down */
/* _startupData.toCopyDownBeg ---> {nof(16) dstAddr(16) {bytes(8)}^nof} Zero(16) */
#if defined(__OPTIMIZE_FOR_SIZE__)
asm {
#ifdef __HCS08__
LDHX _startupData.toCopyDownBeg:toCopyDownBegOffs
PSHX
PSHH
#else
LDA _startupData.toCopyDownBeg:(1+toCopyDownBegOffs)
PSHA
LDA _startupData.toCopyDownBeg:(0+toCopyDownBegOffs)
PSHA
#endif
Loop0:
JSR loadByte ; load high byte counter
TAX ; save for compare
INCA
STA i
JSR loadByte ; load low byte counter
INCA
STA i:1
DECA
BNE notfinished
CBEQX #0, finished
notfinished:
 
JSR loadByte ; load high byte ptr
PSHA
PULH
JSR loadByte ; load low byte ptr
TAX ; HX is now destination pointer
BRA Loop1
Loop3:
Loop2:
JSR loadByte ; load data byte
STA 0,X
AIX #1
Loop1:
DBNZ i:1, Loop2
DBNZ i:0, Loop3
BRA Loop0
 
finished:
AIS #2
};
#else /* defined(__OPTIMIZE_FOR_SIZE__) time optimized asm version. */
asm {
#ifdef __HCS08__
LDHX _startupData.toCopyDownBeg:toCopyDownBegOffs
#else
LDX _startupData.toCopyDownBeg:(0+toCopyDownBegOffs)
PSHX
PULH
LDX _startupData.toCopyDownBeg:(1+toCopyDownBegOffs)
#endif
next:
LDA 0,X ; list is terminated by 2 zero bytes
ORA 1,X
BEQ copydone
PSHX ; store current position
PSHH
LDA 3,X ; psh dest low
PSHA
LDA 2,X ; psh dest high
PSHA
LDA 1,X ; psh cnt low
PSHA
LDA 0,X ; psh cnt high
PSHA
AIX #4
JSR _COPY_L ; copy one block
PULH
PULX
TXA
ADD 1,X ; add low
PSHA
PSHH
PULA
ADC 0,X ; add high
PSHA
PULH
PULX
AIX #4
BRA next
copydone:
};
#endif /* defined(__OPTIMIZE_FOR_SIZE__) */
 
/* FuncInits: for C++, this are the global constructors */
#ifdef __cplusplus
#ifdef __ELF_OBJECT_FILE_FORMAT__
i = (int)(_startupData.nofInitBodies - 1);
while (i >= 0) {
(&_startupData.initBodies->initFunc)[i](); /* call C++ constructors */
i--;
}
#else /* __ELF_OBJECT_FILE_FORMAT__ */
/* HIWARE object file format */
if (_startupData.mInits != NULL) {
_PFunc *fktPtr;
fktPtr = _startupData.mInits;
while(*fktPtr != NULL) {
(**fktPtr)(); /* call constructor */
fktPtr++;
}
}
#endif /* __ELF_OBJECT_FILE_FORMAT__ */
#endif /* __cplusplus */
 
/* implement ROM libraries initialization here (see startup.c) */
}
#endif /* __ONLY_INIT_SP */
 
__EXTERN_C extern void main(void); /* prototype of main function */
 
#pragma NO_EXIT
__EXTERN_C void _Startup(void) {
/* set the reset vector to _Startup in the linker parameter file (*.prm):
'VECTOR 0 _Startup'
 
purpose: 1) initialize the stack
2) initialize run-time, ...
initialize the RAM, copy down init dat etc (Init)
3) call main;
called from: _PRESTART-code generated by the Linker
*/
 
INIT_SP_FROM_STARTUP_DESC();
#ifndef __ONLY_INIT_SP
Init();
#endif
__asm JMP main; /* with a C style main(); we would push the return address on the stack wasting 2 RAM bytes */
}
/programy/CodeWarrior/test/Demo_S08QG8_Test/Sources/demo9S08QG8.h
0,0 → 1,48
/******************************************************************************
*Copyright (C) 2003 Freescale Semiconductor, Inc.
*All Rights Reserved
*
* Filename: DEMO9S08QG8.h
* Author: r1aald
* Revision: 1.0a
*
* Description: 9S08QG8 Demo Board Header File
* Notes: Used in Projects QG8_Test.mcp, DEMO9S08QG8_APP.mcp
*******************************************************************************/
 
/* include peripheral declarations */
#include <MC9S08QG8.h> /* include peripheral declarations */
 
/* define value for LED's when on and off */
#define ON 0
#define OFF 1
/* define value for switches when up (not pressed) and down (pressed) */
#define UP 1
#define DOWN 0
 
/* define LED's */
#define LED1 PTBD_PTBD6
#define LED1_DDR PTBDD_PTBDD6
#define LED1_MASK PTBD_PTBD6_MASK
#define LED2 PTBD_PTBD7
#define LED2_DDR PTBDD_PTBDD7
#define LED2_MASK PTBD_PTBD7_MASK
 
/* define SW's */
#define SW1 PTAD_PTAD2
#define SW1_DDR PTADD_PTADD2
#define SW1_MASK PTAD_PTAD2_MASK
#define SW2 PTAD_PTAD3
#define SW2_DDR PTADD_PTADD3
#define SW2_MASK PTAD_PTAD3_MASK
 
/* define ATD Inputs */
#define POT APCTL1_ADPC0
#define POT_MASK APCTL1_ADPC0_MASK
#define PHOTO APCTL1_ADPC1
#define PHOTO_MASK APCTL1_ADPC1_MASK
 
/* define COM_EN */
#define COM_EN PTAD_PTAD4
#define COM_EN_DDR PTADD_PTADD4
#define COM_EN_MASK PTADD_PTADD4_MASK
/programy/CodeWarrior/test/Demo_S08QG8_Test/Sources/demo9S08QG8_test.c
0,0 → 1,69
 
/******************************************************************************
* Copyright (C) 2005 Freescale Semiconductor, Inc.
* All Rights Reserved
*
* Filename: DEMO9S08QG8_Test.c
* Author: r1aald
* Revision: 1.0
*
* Description: This is the test code that will reside in the QG8 demo
* to provide an out of the box experience. This simple code
* blinks LED2 and toggles LED1 when SW1 is pressed.
*
* Notes: Also serves as an example for the 9S08QG8 demo board.
* Created using CodeWarrior 3.1 for HC(S)08.
******************************************************************************/
 
 
#include <hidef.h> /* for EnableInterrupts macro */
#include <MC9S08QG8.h> /* include peripheral declarations */
#include "demo9S08QG8.h" /*include demo board declarations */
 
void main(void) {
EnableInterrupts; /* enable interrupts */
/* include your code here */
ICSC2_BDIV = 3;
LED1 =0;
LED2 =0; //Port B7 is connected to LED 2
PTBDD_PTBDD7 = 1; //Set PTB7 as an output
PTBDD_PTBDD6 = 1;
//mtim_setup
MTIMCLK_PS = 8;
MTIMCLK_CLKS = 0;
MTIMMOD = 112;
MTIMMOD = 0; //modulo = 50
MTIMSC = 0x60; //reset and start MTIM, enable ints
//KBI Set Up foe SW1
KBIPE_KBIPE2 =1; //Enable Keyboard Pin
KBISC_KBIE = 1; //Enable Keyboard Interrupts
KBISC_KBACK = 1; //Clear Pending Keyboard Interrupts
PTAPE_PTAPE2 = 1; //Enable Pullup for Keyboard pin
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave this function */
}
//KBI ISR
interrupt 18 void KBI_ISR(void) {
KBISC_KBACK = 1; //Clear Pending Keyboard Interrupts
LED1 = ~LED1; // toggle Port
}
 
 
/* MTIM_ISR - ISR that accompanies the MTIM PWM routine. */
interrupt 12 void MTIM_ISR(void) {
MTIMSC_TOF=0; // clear TOF
LED2 = ~LED2; // toggle Port
}