-/* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
-/* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
-/* ELIGIBILITY FOR ANY PURPOSES. */
-/* (C) Fujitsu Microelectronics Europe GmbH */
-/*------------------------------------------------------------------------
- MAIN.C
- - description
- - See README.TXT for project description and disclaimer.
-
- 06.10.06 1.01 UMa changed includes
--------------------------------------------------------------------------*/
-
-
-/*************************@INCLUDE_START************************/
#include "mb91465k.h"
-#include "vectors.h"
-#include "rlt.h"
#include "flash.h"
-/**************************@INCLUDE_END*************************/
-/*********************@GLOBAL_VARIABLES_START*******************/
-/**********************@GLOBAL_VARIABLES_END********************/
+#define BUFSIZE 0x20
+#define cleardata() memset(data,0,BUFSIZE)
+void increaseled(void)
+{
+#define T_INIT 1100
+ static unsigned int t = T_INIT;
+ static unsigned char l = (1<<0);
+ static unsigned char s = 1;
+ if(t == 0) {
+ if(l & (1<<0)) {
+ s = 1;
+ } else if (l & (1<<7)) {
+ s = 0;
+ }
+ l = s ? l << 1 : l >> 1;
+ PDR14 = ~l;
+ t = T_INIT;
+ } else {
+ t--;
+ }
+}
+
+static unsigned char recvbyte(void)
+{
+ return Getch4();
+}
+
+static unsigned short recvword(void)
+{
+ static unsigned char b1, b2;
+ static unsigned short ret;
+ b1 = recvbyte();
+ b2 = recvbyte();
+ ret = (unsigned short)(b2 << 8) | b1;
+ return ret;
+}
-/*******************@FUNCTION_DECLARATION_START*****************/
+static unsigned int recvdword(void)
+{
+ static unsigned char b1, b2, b3, b4;
+ static unsigned int ret;
+ b1 = recvbyte();
+ b2 = recvbyte();
+ b3 = recvbyte();
+ b4 = recvbyte();
+ ret = ((unsigned int) (b4 << 24)) | ((unsigned int) (b3 << 16)) | ((unsigned int) (b2 << 8)) |(unsigned int)b1;
+ return ret;
+}
-/*********************@FUNCTION_HEADER_START*********************
-*@FUNCTION NAME: main() *
-* *
-*@DESCRIPTION: The main function controls the program flow *
-* *
-*@PARAMETER: none *
-* *
-*@RETURN: none *
-* *
-***********************@FUNCTION_HEADER_END*********************/
+static void halt(void)
+{
+ while(1) {
+ HWWD_CL = 0;
+ }
+}
+static void panic(void)
+{
+ PDR14 = 0x22;
+ halt();
+}
void main(void)
{
- unsigned char error = 0;
- unsigned char global_error = 0;
- unsigned int i;
+ unsigned int address;
+ unsigned short i, size, next;
+ unsigned char running = 1, data[BUFSIZE] = {0};
- /* Enable Clock Monitor */
- CSCFG_MONCKI = 1;
- CMCFG = 0x0D;
-
- __EI(); /* enable interrupts */
- __set_il(31); /* allow all levels */
- InitIrqLevels(); /* init interrupts */
-
- PORTEN = 0x3; /* enable I/O Ports */
- /* This feature is not supported by MB91V460A */
- /* For all other devices the I/O Ports must be enabled*/
-
- /* Enable LEDs */
+ /*Enable LEDs*/
DDR14 = 0xFF;
PDR14 = 0xff;
- /* Initialize Reload Timer Channel 0 */
- RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);
- RLT_SetReloadValue(0,0xfffe);
- RLT_TriggerTimer(0);
- RLT_EnableInterrupt(0, 1);
-
- /* Initialize UART4 */
+ /*Initialize UART4*/
InitUart4();
- /* Output Welcome Message */
- Puts4(" \n\n");
- Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
-
- /* Do BlankCheck on Sector at 0xA0000 */
- Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");
- error = FLASH_SectorBlankCheck(0xA0000, 0x4000);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- Puts4("failed.\n");
- }
-
- /* Show Current Content of 0xA0000 ... 0xA001F */
- i=0;
- Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
- while(i < 0x20)
- {
- Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4(" ");
- i++;
- if( (i % 0x10) == 0 ) Puts4("\n");
- }
- Puts4("\n");
-
- /* SectorErase of FLASH Memory 0xA0000*/
- Puts4("Sector Erase of 0xA0000 ... ");
- error = FLASH_SectorErase(0xA0000);
- error = FLASH_SectorErase(0xA0004);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- global_error = 1;
- Puts4("failed.\n");
+ while(running) {
+ cleardata();
+ increaseled();
+ switch(recvbyte()) {
+ case 0x15: //chip erase
+ Putch4(0x45);
+ PDR14 = ~(0x05);
+ if(FLASH_ChipErase() != 1) {
+ panic();
+ }
+ Putch4(0x23);
+ break;
+
+ case 0x13: //receive
+ Putch4(0x37);
+ increaseled();
+
+ address = recvdword();
+ increaseled();
+
+ size = recvword();
+ increaseled();
+
+ for(i=0; i<size; i++) { /* get data */
+ increaseled();
+ data[i] = recvbyte();
+ }
+
+ for(i=0; i<size; i+=2) { /* flash the data */
+ increaseled();
+ next = (((unsigned short)data[i])<<8) | (unsigned short)data[i+1];
+ if(FLASH_WriteHalfWord(address + i, next) != 1) {
+ panic();
+ }
+ }
+ Putch4(0x28); //Flashing done.
+ break;
+
+ case 0x97: /* exit and restart (let do this by the watchdog!) */
+ while(1) {
+ unsigned long tmp = 1800;
+ while(tmp)
+ tmp = tmp - 1;
+ increaseled();
+ }
+
+ case 0x99: /* exit */
+ running = 0;
+ break;
+ default: break;
+ }
}
- /* Do BlankCheck on Sectors at 0xA0000 */
- Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");
- error = FLASH_SectorBlankCheck(0xA0000, 0x4000);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- global_error = 1;
- Puts4("failed.\n");
- }
-
- /* Show Current Content of 0xA0000 ... 0xA001F */
- i=0;
- Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
- while(i < 0x20)
- {
- Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4(" ");
- i++;
- if( (i % 0x10) == 0 ) Puts4("\n");
- }
- Puts4("\n");
-
- /* Write 0x55AA to 0xA0002 */
- Puts4("Write 0x55AA to 0xA0002 ... ");
- error = FLASH_WriteHalfWord(0xA0002,0x55AA);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- global_error = 1;
- Puts4("failed.\n");
- }
+ PDR14 = 0x55; //signal that we finished now!
+ halt();
- /* Write 0x33CC to 0xA0004 */
- Puts4("Write 0x33CC to 0xA0004 ... ");
- error = FLASH_WriteHalfWord(0xA0004,0x33CC);
- if( error == 1 )
- {
- Puts4("done.\n");
- }
- else
- {
- global_error = 1;
- Puts4("failed.\n");
+#if 0
+ i = 0;
+ baseaddr = 0xf4000;
+ for (; i <0x10; i+=4) {
+ (void) FLASH_SectorErase(baseaddr + i);
+ increaseled();
}
-
- /* Show Current Content of 0xA0000 ... 0xA001F */
- i=0;
- Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
- while(i < 0x20)
- {
- Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4(" ");
- i++;
- if( (i % 0x10) == 0 ) Puts4("\n");
- }
- Puts4("\n");
-
- /* Output Ready Meassage */
- if( global_error != 0 )
- {
- Puts4("\n********* FLASH Programming Demo failed **********\n");
- }
- else
- {
- Puts4("\n********* FLASH Programming Demo done **********\n");
+ i = 0;
+ baseaddr = 0xf4000;
+ for(; i<9; i++) {
+ increaseled();
+ (void) FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);
}
- RLT_EnableInterrupt(0, 0);
-
- while(1) /* endless loop */
- {
-
- HWWD_CL = 0;
-
- /* feed hardware watchdog */
- /* (Only for devices with hardware (R/C based) watchdog) */
- /* The hardware (R/C based) watchdog is started */
- /* automatically after power-up and can not be stopped */
- /* If the hardware watchdog is not cleared frequently */
- /* a reset is generated. */
- }
+#endif
}
-
-/********************@FUNCTION_DECLARATION_END******************/