-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
58 lines (50 loc) · 1.45 KB
/
main.c
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
#include "hdc.h"
#include <msp430.h>
extern const unsigned char class_hypervectors[][DIMENSION / BITS_IN_BYTE];
extern const unsigned char level_hypervectors[][DIMENSION / BITS_IN_BYTE];
extern const unsigned char position_hypervectors[][DIMENSION / BITS_IN_BYTE];
extern unsigned char input_image[IMG_SIZE];
ballot_box_t *bx = 0x20000;
hv_t inferencing = {(uint8_t *)0x3400};
void init() {
WDTCTL = WDTPW | WDTHOLD;
PM5CTL0 &= ~LOCKLPM5;
bzero(bx, DIMENSION * 2);
}
void encoding() {
uint16_t iter = IMG_SIZE, feature;
unsigned char *img_iter = input_image;
while (--iter) {
feature = *img_iter++ / 25;
bind_hypervector(inferencing, (hv_t){position_hypervectors[0]},
(hv_t){level_hypervectors[feature]});
permute_by_byte((hv_t){position_hypervectors[0]});
voting(bx, inferencing);
}
open_ballot_box(inferencing, bx);
}
uint8_t classification() {
uint8_t result = 255;
uint16_t min = 0xFFFF, cur;
for (uint8_t i = 0; i < 10; i++) {
if (cur = hamming_table(inferencing, (hv_t){class_hypervectors[i]}), min > cur) {
min = cur;
result = i;
}
}
return result;
}
int main() {
init();
encoding();
volatile uint8_t result = classification();
/* The LED on the board while start blinking if the inference completed.*/
volatile int x = 30000;
P1DIR |= 0x03;
P1OUT = 0x01;
while (1) {
while (--x)
;
P1OUT ^= 0x3;
}
}