cpu.c

来自「freescale mc9rs08le4 C code with 3,5 dig」· C语言 代码 · 共 299 行

C
299
字号
/** ###################################################################
**     THIS BEAN MODULE IS GENERATED BY THE TOOL. DO NOT MODIFY IT.
**     Filename  : Cpu.C
**     Project   : le4
**     Processor : MC9RS08LE4CPC
**     Beantype  : MC9RS08LE4_28
**     Version   : Bean 01.003, Driver 01.05, CPU db: 3.00.000
**     Datasheet : MC9RS08LE4RM Rev. 0 Draft C 8/2008
**     Compiler  : CodeWarrior RS08 C Compiler
**     Date/Time : 19/2/2009, 18:21
**     Abstract  :
**         This bean "MC9RS08LE4_28" contains initialization of the
**         CPU and provides basic methods and events for CPU core
**         settings.
**     Settings  :
**
**     Contents  :
**         SetWaitMode         - void Cpu_SetWaitMode(void);
**         GetLowVoltageFlag   - bool Cpu_GetLowVoltageFlag(void);
**         ClearLowVoltageFlag - void Cpu_ClearLowVoltageFlag(void);
**         Delay100US          - void Cpu_Delay100US(word us100);
**
**     (c) Copyright UNIS, a.s. 1997-2008
**     UNIS, a.s.
**     Jundrovska 33
**     624 00 Brno
**     Czech Republic
**     http      : www.processorexpert.com
**     mail      : info@processorexpert.com
** ###################################################################*/

/* MODULE Cpu. */

#pragma MESSAGE DISABLE C4002 /* WARNING C4002: Result not used is ignored */

#include "LCD1.h"
#include "AD1.h"
#include "SENSOR.h"
#include "RTI1.h"
#include "LEDS.h"
#include "PE_Types.h"
#include "PE_Error.h"
#include "PE_Const.h"
#include "IO_Map.h"
#include "Events.h"
#include "Cpu.h"




/*
** ===================================================================
**     Method      :  Cpu_ClearLowVoltageFlag (bean MC9RS08LE4_28)
**
**     Description :
**         This method clears the low voltage detect flag. This method
**         can be enabled only if LVD module is enabled (property <LVD
**         module> is set to 'Enabled' value) and LVD reset is disabled
**         (property <LVD operation> is not set to 'Reset' value).
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_ClearLowVoltageFlag(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_GetLowVoltageFlag (bean MC9RS08LE4_28)
**
**     Description :
**         This method returns the flag of the Low Voltage Detect
**         device. The flag is set when the low-voltage error is
**         detected. This method can be enabled only if LVD module is
**         enabled (property <LVD module> is set to 'Enabled' value)
**         and LVD reset is disabled (property <LVD operation> is not
**         set to 'Reset' value).
**     Parameters  : None
**     Returns     :
**         ---             - This method returns a true when flag is
**                           set otherwise returns a false.
** ===================================================================
*/
/*
bool Cpu_GetLowVoltageFlag(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_SetWaitMode (bean MC9RS08LE4_28)
**
**     Description :
**         Sets the low power mode - Wait mode.
**         For more information about the wait mode, see the
**         documentation of this CPU.
**         Release from the Wait mode: Reset or interrupt
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/
/*
void Cpu_SetWaitMode(void)

**      This method is implemented as macro in the header module. **
*/

/*
** ===================================================================
**     Method      :  Cpu_Delay100US (bean MC9RS08LE4_28)
**
**     Description :
**         This method realizes software delay. The length of delay
**         is at least 100 microsecond multiply input parameter
**         [us100]. As the delay implementation is not based on real
**         clock, the delay time may be increased by interrupt
**         service routines processed during the delay. The method
**         is independent on selected speed mode.
**     Parameters  :
**         NAME            - DESCRIPTION
**         us100           - Number of 100 us delay repetitions.
**     Returns     : Nothing
** ===================================================================
*/
#pragma NO_ENTRY
#pragma NO_EXIT
#pragma NO_RETURN
#pragma NO_STRING_CONSTR
void Cpu_Delay100US(word us100)
{
  /* irremovable one time overhead (ignored): 23 cycles */
  /* 2x mov: 8 cycles overhead (load parameter )*/
  /* jsr:  4 cycles overhead (jump to subroutine) */
  /* rts:  3 cycles overhead (return from subroutine) */

  /* aproximate irremovable overhead for each 100us cycle (counted) : 25 cycles */
  /* clra: 1 cycles overhead (compare parameter with 0) */
  /* cmp:  3 cycles overhead */
  /* bne:  3 cycles overhead */
  /* dec:  5 cycles overhead (decrement parameter) */
  /* lda:  3 cycles overhead */
  /* ora:  3 cycles overhead */
  /* beq:  3 cycles overhead */
  /* jmp:  4 cycles overhead */

  byte LoopCounter0;                   /* Loop counter variable */
     
  asm {
loop:
    /* 100 us delay block begin */
    /*
     * Delay
     *   - requested                  : 100 us @ 1.0464MHz,
     *   - possible                   : 105 c, 100344.039999999987 ns, delta 344.04 ns
     *   - without removable overhead : 80 c, 76452.6 ns
     */
    CLRA                               /* (1 c: 955.66 ns) clear accumulator */
    MOV #$0006,LoopCounter0            /* (4 c: 3822.63 ns) number of repetitions */
label0:                                /* inner loop */
    DEC LoopCounter0                   /* (5 c: 4778.29 ns) decrement loop 3 counter */
    CMP LoopCounter0                   /* (3 c: 2866.97 ns) compare it to zero */
    BNE label0                         /* (3 c: 2866.97 ns) repeat 255x */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    NOP                                /* (1 c: 955.66 ns) wait for 1 c */
    /* 100 us delay block end */
    CLRA
    CMP us100:1
    BNE skip1
    DEC us100
skip1:
    DEC us100:1
    LDA us100:1
    ORA us100
    BEQ skip2
    JMP loop
skip2:
    RTS                                /* return from subroutine */
  }
}

/*
** ===================================================================
**     Method      :  _EntryPoint (bean MC9RS08LE4_28)
**
**     Description :
**         Initializes the whole system like timing and so on. At the end 
**         of this function, the C startup is invoked to initialize stack,
**         memory areas and so on.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
extern void _Startup(void);            /* Forward declaration of external startup function declared in file Start12.c */

#pragma NO_FRAME
#pragma NO_EXIT
void _EntryPoint(void)
{
  /* ### MC9RS08LE4_28 "Cpu" init code ... */
  /*  PE initialization code after reset */
  /* Common initialization of the write once registers */
  /* SOPT: COPE=0,COPT=1,STOPE=1,??=0,??=0,??=0,BKGDPE=1,RSTPE=0 */
  setReg8(SOPT, 0x62);                  
  /* SPMSC1: LVDF=0,LVDACK=0,LVDIE=1,LVDRE=0,LVDSE=0,LVDE=1,??=0,BGBE=0 */
  setReg8(SPMSC1, 0x24);                
  /*  System clock initialization */
  ICSTRM = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFA); /* Initialize ICSTRM register from a non volatile memory */
  ICSSC = *(unsigned char* __paged)CONVERT_TO_PAGED(0x3FFB); /* Initialize ICSSC register from a non volatile memory */
  /* ICSC1: CLKS=0,RDIV=0,IREFS=1,IRCLKEN=1,IREFSTEN=1 */
  setReg8(ICSC1, 0x07);                /* Initialization of the ICS control register 1 */ 
  /* ICSC2: BDIV=3,RANGE=0,HGO=0,LP=0,EREFS=0,ERCLKEN=0,EREFSTEN=0 */
  setReg8(ICSC2, 0xC0);                /* Initialization of the ICS control register 2 */ 
  /*** End of PE initialization code after reset ***/
  __asm   jmp _Startup ;               /* Jump to C startup code */

}

/*
** ===================================================================
**     Method      :  PE_low_level_init (bean MC9RS08LE4_28)
**
**     Description :
**         Initializes beans and provides common register initialization. 
**         The method is called automatically as a part of the 
**         application initialization code.
**         This method is internal. It is used by Processor Expert only.
** ===================================================================
*/
void PE_low_level_init(void)
{
  /* Common initialization of the CPU registers */
  /* APCTL1: ADPC5=1 */
  setReg8Bits(APCTL1, 0x20);            
  /* PTCD: PTCD1=0,PTCD0=1 */
  clrSetReg8Bits(PTCD, 0x02, 0x01);     
  /* PTCPUD: PTCPUD1=0,PTCPUD0=0 */
  clrReg8Bits(PTCPUD, 0x03);            
  /* PTCPE: PTCPE1=0,PTCPE0=0 */
  clrReg8Bits(PTCPE, 0x03);             
  /* PTCDD: PTCDD1=1,PTCDD0=1 */
  setReg8Bits(PTCDD, 0x03);             
  /* PTASE: PTASE7=0,PTASE6=0,PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */
  setReg8(PTASE, 0x00);                 
  /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0 */
  clrReg8Bits(PTBSE, 0xFE);             
  /* PTCSE: PTCSE1=0,PTCSE0=0 */
  clrReg8Bits(PTCSE, 0x03);             
  /* PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 */
  setReg8(PTDSE, 0x00);                 
  /* PTADS: PTADS7=1,PTADS6=1,PTADS5=1,PTADS4=1,PTADS3=1,PTADS2=1,PTADS1=1,PTADS0=1 */
  setReg8(PTADS, 0xFF);                 
  /* PTBDS: PTBDS7=1,PTBDS6=1,PTBDS5=1,PTBDS4=1,PTBDS3=1,PTBDS2=1,PTBDS1=1,??=0 */
  setReg8(PTBDS, 0xFE);                 
  /* PTCDS: ??=0,??=0,??=0,??=0,??=0,??=0,PTCDS1=1,PTCDS0=1 */
  setReg8(PTCDS, 0x03);                 
  /* PTDDS: PTDDS7=1,PTDDS6=1,PTDDS5=1,PTDDS4=1,PTDDS3=1,PTDDS2=1,PTDDS1=1,PTDDS0=1 */
  setReg8(PTDDS, 0xFF);                 
  /* ### Shared modules init code ... */
  /* ### Init_LCD "LCD1" init code ... */
  LCD1_Init();
  /* ###  "AD1" init code ... */
  AD1_Init();
  /* ### BitIO "SENSOR" init code ... */
  /* ### Init_RTI "RTI1" init code ... */
  RTI1_Init();
  /* ### BitIO "LEDS" init code ... */
}

/* Initialization of the CPU registers in FLASH */

/* NVOPT: ??=1,??=1,??=1,??=1,??=1,??=1,??=1,SECD=1 */
const unsigned char NVOPT_INIT @0x00003FFC = 0xFF;

/* Initialization of the reset vector */
static const unsigned char JMPOpcode @0x3FFD = 0xBC; /* Opcode of JMP extended */
void far (*const ResetVector)(void)   @0x3FFE = _EntryPoint;

/* END Cpu. */

/*
** ###################################################################
**
**     This file was created by UNIS Processor Expert 3.04 [04.19]
**     for the Freescale RS08 series of microcontrollers.
**
** ###################################################################
*/

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?