-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflash.c
More file actions
41 lines (34 loc) · 766 Bytes
/
flash.c
File metadata and controls
41 lines (34 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include "eggs.h"
void inline flash_setup()
{
__disable_interrupt(); // Please don't interrupt me
FCTL2 = FWKEY + FSSEL1 + FN4; // MCLK at correct speed for 8MHz clock
FCTL3 = FWKEY; // CLEAR LOCK
}
void inline flash_teardown()
{
FCTL1 = FWKEY; // Clear Write or Read
FCTL3 = FWKEY + LOCK;
__enable_interrupt(); // Please interrupt
}
void flash_write_int(int *place, int data)
{
flash_setup();
FCTL1 = FWKEY + WRT; // Enable Write
*place = data;
flash_teardown();
}
void flash_write_byte(char *place, char data)
{
flash_setup();
FCTL1 = FWKEY + WRT; // Enable Write
*place = data;
flash_teardown();
}
void flash_erase(int *segment)
{
flash_setup();
FCTL1 = FWKEY + ERASE; // Enable Erase
*segment = 0; // Dummy write
flash_teardown();
}