4 void FLASH_PrepareWriteHalfWordMode()
6 /* Set FLASH Access Mode via BootROM Routine */
7 /* For details refer to the Hardware Manual or Data Sheet */
12 LDI #0x01,R4 ; Set FLASH to 16Bit read/write Mode
13 LDI #0x04,R5 ; Go 4 times through delay loop (64MHz CLKB)
21 /* Set the FLASH Interface to Write Timing */
22 /* For details refer to the Hardware Manual or Data Sheet */
23 /* Setting shown here is for CLKB = 64MHz */
29 void FLASH_PrepareReadMode()
31 /* Set FLASH Access Mode via BootROM Routine */
32 /* For details refer to the Hardware Manual or Data Sheet */
37 LDI #0x00,R4 ; Set FLASH to 32Bit read/write Mode
38 LDI #0x04,R5 ; Go 4 times through delay loop (64MHz CLKB)
46 /* Set the FLASH Interface to Read Timing */
47 /* For details refer to the Hardware Manual or Data Sheet */
48 /* Setting shown here is for CLKB = 64MHz */
54 unsigned char FLASH_ChipErase(void)
56 unsigned char flag = 0;
58 /*Set FLASH access mode to 16Bit Write Mode*/
59 FLASH_PrepareWriteHalfWordMode();
61 /*Start FLASH Sector Erase Sequence*/
69 /*Wait for the Auto Algorithm to finish*/
71 /* Feed Hardware Watchdog */
77 if(*hseq_1 & TLOVER) {
82 /*Reset FLASH (keep in mind 16Bit access to FLASH)*/
83 *hseq_1 = 0x00F0; // Keep in Mind (16Bit access)
90 /*Set FLASH access mode to 32Bit Read Mode*/
91 FLASH_PrepareReadMode();
96 #if 0 //maybe implement this check too!
97 unsigned char FLASH_SectorBlankCheck(unsigned int secaddr, unsigned int size)
100 unsigned char empty_flag = 0;
101 unsigned int addr = secaddr;
103 /* Clear FIXE bit to see FLASH memory content instead of fixed reset vector */
106 for(count = 0; count < size; count ++)
108 /* Clear Hardware Watchdog */
110 if( *(unsigned int *)addr != 0xFFFFFFFF ) empty_flag = 1;
114 /* Set FIXE bit to see fixed reset vector */
117 if( empty_flag != 0 )
126 unsigned char FLASH_WriteHalfWord(unsigned int adr, unsigned short int data)
128 unsigned char flag = 0;
130 /* Set FLASH access mode to 16Bit Write Mode */
131 FLASH_PrepareWriteHalfWordMode();
133 /* Start Write FLASH Sequence */
137 *((volatile unsigned short int *)adr) = data;
139 /* Wait for the Auto Algorithm to finish */
142 /* Feed Hardware Watchdog */
145 if( ( *(volatile unsigned short int *)adr & DPOLL ) == (data & DPOLL) )
149 if( ( *(volatile unsigned short int *)adr & TLOVER ) == TLOVER )
151 if( ( *(volatile unsigned short int *)adr & DPOLL ) == (data & DPOLL) )
157 /* Reset FLASH (keep in mind 16Bit access to FLASH) */
158 *hseq_1 = 0x00F0; // Keep in Mind (16Bit access)
165 /* Set FLASH access mode to 32Bit Read Mode */
166 FLASH_PrepareReadMode();
171 unsigned char FLASH_ReadReset()
178 unsigned char FLASH_CheckPendingInterrupt()
180 /* Poll for Pending Interrupts which are needed here */
181 if(TMCSR0_UF) return 1; /* in this sample the only interrupt source supervised is Reload Timer 0 */
183 /* and return 1 when an Interrupt is pending */