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 //maybe implement this check too!
98 unsigned char FLASH_SectorBlankCheck(unsigned int secaddr, unsigned int size)
101 unsigned char empty_flag = 0;
102 unsigned int addr = secaddr;
104 /* Clear FIXE bit to see FLASH memory content instead of fixed reset vector */
107 for(count = 0; count < size; count ++)
109 /* Clear Hardware Watchdog */
111 if( *(unsigned int *)addr != 0xFFFFFFFF ) empty_flag = 1;
115 /* Set FIXE bit to see fixed reset vector */
118 if( empty_flag != 0 )
127 unsigned char FLASH_WriteHalfWord(unsigned int adr, unsigned short int data)
129 unsigned char flag = 0;
131 /* Set FLASH access mode to 16Bit Write Mode */
132 FLASH_PrepareWriteHalfWordMode();
134 /* Start Write FLASH Sequence */
138 *((volatile unsigned short int *)adr) = data;
140 /* Wait for the Auto Algorithm to finish */
143 /* Feed Hardware Watchdog */
146 if( ( *(volatile unsigned short int *)adr & DPOLL ) == (data & DPOLL) )
150 if( ( *(volatile unsigned short int *)adr & TLOVER ) == TLOVER )
152 if( ( *(volatile unsigned short int *)adr & DPOLL ) == (data & DPOLL) )
158 /* Reset FLASH (keep in mind 16Bit access to FLASH) */
159 *hseq_1 = 0x00F0; // Keep in Mind (16Bit access)
166 /* Set FLASH access mode to 32Bit Read Mode */
167 FLASH_PrepareReadMode();
172 unsigned char FLASH_ReadReset()
179 unsigned char FLASH_CheckPendingInterrupt()
181 /* Poll for Pending Interrupts which are needed here */
182 if(TMCSR0_UF) return 1; /* in this sample the only interrupt source supervised is Reload Timer 0 */
184 /* and return 1 when an Interrupt is pending */