-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdi_lo_lvl.h
88 lines (67 loc) · 1.67 KB
/
updi_lo_lvl.h
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
UPDI_cmd.h
Created: 23-11-2017 22:46:11
Author: JMR_2
*/
#ifndef UPDI_LO_LVL_H_
#define UPDI_LO_LVL_H_
#include <stdint.h>
#include "updi_io.h"
namespace UPDI {
// UPDI registers
enum reg {
Status_A, Status_B, Control_A, Control_B,
Reg_4, Reg_5, Reg_6, ASI_Key_Status,
ASI_Reset_Request, ASI_Control_A, ASI_System_Control_A, ASI_System_Status,
ASI_CRC_Status, Reg_13, Reg_14, Reg_15
};
constexpr uint8_t RESET_ON = 0x59;
constexpr uint8_t RESET_OFF = 0x00;
// Constant Expressions
constexpr uint8_t SYNCH = 0x55;
constexpr uint8_t ACK = 0x40;
// Activation Keys
extern uint8_t Chip_Erase[8];
extern uint8_t NVM_Prog[8];
extern uint8_t UserRow_Write[8];
// Function prototypes
void rep(uint8_t);
void stcs(reg, uint8_t);
uint8_t lcds(reg);
void read_sib(uint8_t (&)[16]);
uint8_t lds_b(uint16_t);
uint16_t lds_w(uint16_t);
void sts_b(uint16_t address, uint8_t data); /* Store data at address */
void sts_w(uint16_t, uint16_t);
uint8_t ldptr_b();
uint16_t ldptr_w();
uint8_t ld_b();
uint16_t ld_w();
uint8_t ldinc_b();
uint16_t ldinc_w();
void stptr_b(uint8_t);
void stptr_w(uint16_t);
void st_b(uint8_t);
void st_w(uint16_t);
void stinc_b(uint8_t);
void stinc_w(uint16_t);
template <class T>
inline void write_key(T (& k)[8]) __attribute__(( optimize("no-tree-loop-optimize") ));
// Function Templates
template <class T>
void write_key(T (& k)[8]) {
UPDI_io::put(SYNCH);
UPDI_io::put(0xE0);
T* key_ptr = k;
for (uint8_t i = 8; i != 0; i--) {
UPDI_io::put(*key_ptr);
key_ptr++;
}
}
template <uint8_t mask = 0xFF>
uint8_t CPU_mode() {
uint8_t mode = UPDI::lcds(UPDI::reg::ASI_System_Status);
return mode & mask;
}
}
#endif /* UPDI_LO_LVL_H_ */