bFlashWriteBlock() under HiTech

HiTech had a great compiler for PSoC's M8C processor, but, then they were bought by Microchip. Subsequently the HiTech forums were taken off line. At the request of PSoCDeveloper members PSoCDeveloper has created this forum to allow HiTech users to support each other.

Moderator: ericb

bFlashWriteBlock() under HiTech

Postby baxsie » Tue Jun 09, 2009 12:41 pm

I had some trouble with the Cypress supplied bFlashWriteBlock() routine working under HiTech.

Even though they do not say it, I think it basically does not compile right under HiTech. HiTech supplies their own version flash_writeBlock(), which they would only supply if there is reason to use it, right?

Here is my current "working under HiTech" code:
Code: Select all
#include <psoc.h>
. . .
    asm("AND F,0xFE");  //CLI
    SET_CPU_CLOCK_SPEED(OSC_CR0_CPU_12MHz);
    flash_writeBlock(input,block);
    SET_CPU_CLOCK_SPEED(OSC_CR0_CPU_24MHz);
    asm("OR  F,0x01");  //STI

I combine this with my memdifF to have this routine:
Code: Select all
in H file:

//============================================================================
//Macro to force the compiler to treat a pointer as flash.
//This variable is not used, it just has to be somewhere
//that the compiler thinks is flash. The compiler seems
//to be happy with it pointing off into space.
extern const unsigned char
  make_me_flash @ 0x8000;
#define flash(x) ((&make_me_flash - &make_me_flash) + (x))
//Usage:
// (memdifF(input,flash(block*64),count))
//block*64 will be treated as a 16-bit flash pointer
//============================================================================
// http://www.psocdeveloper.com/forums/viewtopic.php?f=3&t=4445&p=21359&hilit=cpu+speed+macro#p21359
#define SET_CPU_CLOCK_SPEED(speed) OSC_CR0&=~OSC_CR0_CPU;OSC_CR0|=(speed);
//============================================================================

in C file:

unsigned char memdifF(unsigned char *a,const unsigned char *b,unsigned char count)
  {
  while(count--)
    if((*a++)!=(*b++))
      return(1);
  return(0);
  }

void Write_To_Flash(unsigned char block,unsigned char count,unsigned char *input)
  {
  //Do not erase+write if the same data already exists
  if(memdifF(input,flash(block*64),count))
    {
    asm("AND F,0xFE");  //CLI
    SET_CPU_CLOCK_SPEED(OSC_CR0_CPU_12MHz);
    flash_writeBlock(input,block);
    SET_CPU_CLOCK_SPEED(OSC_CR0_CPU_24MHz);
    asm("OR  F,0x01");  //STI
    }
  }

Hopefully this source code will help you get bFlashWriteBlock working on the PSoC under Hi Tech C.
I'm not getting older. I'm getting bitter.
baxsie
The Big Cheese
The Big Cheese
 
Posts: 420
Joined: Mon Dec 22, 2003 10:08 pm

Return to “%s” HiTech C User-to-User Support

Who is online

Users browsing this forum: No registered users and 1 guest

cron