**************************************
MAIN.C
**************************************
#include <hidef.h>                /* for EnableInterrupts macro */
#include "derivative.h"           /* include peripheral declarations */
#include "EDS_MCinit.h"
#include "FlashRoutines.h"
void main(void) {
    MCUSetup();                     //Setup MCU (PLL, Config, IO and all other processor environment settings
    EnableInterrupts;               // enable interrupts
//    DebounceInit();                 //Initialise the debounce routines
// MAIN LOOP
for(;

{ 
//------------------------------------------------------------------------------------------------
//Main loop   
byte  RAMData[64] = {0};
byte  FlashData[64] = {0};
byte  *pRAMData = &RAMData;
byte  temp = 0x00;
char  *pFlashData;
pFlashData = (char *)Start_User_Flash_Data;
while(pRAMData != (RAMData+65)) *pRAMData++ = ++temp ;         //Fill up RAM table with 0x01 to 0x3F
pRAMData = &RAMData;                 
DisableInterrupts;
CopyInRAM();
EraseRoutine(pFlashData);
//TEST pFlashData = &FlashData;              /*Write data to a ram array for testing purposes, where FlashData is byte; FlashData[64] = {0}; */
WriteFlashRow(pRAMData, pFlashData);  //Processor resets in this function
EnableInterrupts;
for(;

 PTC ^= 1;      //Stop here and toggle PTC bit 0
    __RESET_WATCHDOG();           // feeds the dog 
    }
// END Main loop
}
******************************
PRM File
******************************
/* This is a linker parameter file for the GP32 */
NAMES END /* CodeWarrior will pass all the needed files to the linker by command line. But here you may add your own files too. */
SEGMENTS /* Here all RAM/ROM areas of the device are listed. Used in PLACEMENT below. */
    ROM             =  READ_ONLY    0xA000 TO 0xFDFF;      //Moved from 0x8000 to 0x9000 to make room for flash data storage
    F_RAM           =  READ_ONLY    0x9000 TO 0x9FFF;      //Added read write block for flash data storage
    Z_RAM           =  READ_WRITE   0x0040 TO 0x00FF;
    RAM             =  READ_WRITE   0x0100 TO 0x023F;                
    ROM_IMAGE       =  READ_ONLY    0xF000 TO 0xF2FF RELOCATE_TO 0x016F; //CDN 02/07/07 7pm
END
PLACEMENT /* Here all predefined and user segments are placed into the SEGMENTS defined above. */
    DEFAULT_RAM                         INTO  RAM;
    DEFAULT_ROM, ROM_VAR, STRINGS       INTO  ROM; /*  In case you want to use  as well, be sure the option -OnB=b is passed to the compiler. */
    _DATA_ZEROPAGE, MY_ZEROPAGE         INTO  Z_RAM;
    UserFlashData                       INTO  F_RAM;          //CDN 02/07/07 10pm
    ToCopyToRAM                         INTO  ROM_IMAGE;      //CDN 02/07/07 7pm
END
STACKSIZE 0x50
VECTOR 0 _Startup /* Reset vector: this is the default entry point for an application. */
ENTRIES
   FB01
   FB02
END
***********************************
Flash.h
***********************************
#pragma CONST_SEG UserFlashData
extern const far byte FB01;
extern const far byte FB02;
#pragma CONST_SEG DEFAULT
/*************************************************************************/
/*****                   Program-Specific Defines                           *****/
/*************************************************************************/
extern char __SEG_START_ToCopyToRAM[];    //Used for copying code to RAM
extern char __SEG_SIZE_ToCopyToRAM[];     //Used for copying code to RAM
extern byte __SEG_START_UserFlashData[];    //Used for copying code to RAM
extern byte __SEG_SIZE_UserFlashData[];     //Used for copying code to RAM
void EraseRoutine    (byte*);
void Delay (byte);
void CopyInRAM(void);        
void WriteFlashRow(byte*, byte*);
//Start_Copy_In_RAM refers to the begining of the segment
//ToCopyToRAM. This segment contains the functions after
//they have been copied to RAM.
#define Start_Copy_In_RAM __SEG_START_ToCopyToRAM
#define Size_Copy_In_RAM __SEG_SIZE_ToCopyToRAM
//Start_In_ROM refers to the begining of the segment
//ToCopyToRAM. This segment contains the functions in ROM.
//refers to thebeginining of the segment
#define Start_User_Flash_Data __SEG_START_UserFlashData
//UserFlashData start
#define User_Flash_Data __SEG_START_UserFlashData
//Size of UserFlashData as defined in PRM file
#define Size_User_Flash_Data __SEG_SIZE_UserFlashData
/*************************************************************************/
/*****                     FLASH Delay Equates                             *****/
/*************************************************************************/
// To setup these values use
// 30X + 31 cycles where X is the value u pass
// NOTE, when passing 0x00, it only takes 30 cycles, not 31.
// to take into account bus frequency
// (30X + 31) / Bus Frequency = Time
// GP32 Set at 4.9152uS
//
// .XLS formula =((30*A2)+31) / $C$2
// Where A2 is a colum from 0 > 255, and Cell C2 = bus frequency in Hertz
// Please note these results are wrong, the times are all substaintially over! (approx 25%),
// to many beers = bad code!
/*************************************************************************/
#define t5uS    0x00    // ~5uS (6.31uS)
#define t10uS   0x01    // ~10uS (12.4uS)
#define t30uS   0x03    // ~30uS (30.7uS)
#define t1mS    0xA3    // 1ms (1.00mS)
*************************************
copied out of "EDS_MCinit.h"
*************************************
void SetupConfigReg(void){
     CONFIG1 = (
     CONFIG1_STOP_MASK |
     CONFIG1_LVIRSTD_MASK |
     CONFIG1_LVIPWRD_MASK |
     CONFIG1_LVISTOP_MASK |
     CONFIG1_COPD_MASK);    
     CONFIG2 = (
     CONFIG2_OSCSTOPENB_MASK |
     CONFIG2_SCIBDSRC_MASK);
}
//------------------------------------------------------------------------------------------------
void SetupPLL(void){
  PCTL_PLLON = 0;   //Turn off PLL
//PLL to run the internal clock at 4.9152MHz
     PCTL_VPR1 = 1;
  PMSH = 0x02;
  PMSL = 0x58;
  PMRS = 0x80;    
  PCTL_PLLON = 1;     //Turn on PLL
  PCTL_BCS = 1;       //Base clock select
}
Message Edited by CarlFST60L_2nd on 
2007-08-09 09:10 AMMessage Edited by CarlFST60L_2nd on 
2007-08-09 09:12 AMMessage Edited by CarlFST60L_2nd on 
2007-08-09 09:12 AMMessage Edited by CarlFST60L_2nd on 
2007-08-09 09:15 AM