-
Notifications
You must be signed in to change notification settings - Fork 0
/
platform-rp2040.c
98 lines (80 loc) · 1.57 KB
/
platform-rp2040.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
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
89
90
91
92
93
94
95
96
97
98
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2023 SASANO Takayoshi <[email protected]>
#include <stdio.h>
#include <string.h>
#include "pico/stdio_usb.h"
#include "pico/time.h"
#include "pico/rand.h"
char *serdev = NULL;
#ifdef KEYSTR
char *keystr = KEYSTR;
#else
#error KEYSTR not defined
#endif
int platform_setup(int argc, char *argv[])
{
stdio_usb_init();
stdio_set_translate_crlf(&stdio_usb, false);
while (!stdio_usb_connected())
sleep_ms(100);
return 0;
}
int platform_finish(void)
{
printf("system halted\n");
stdio_flush();
sleep_ms(1000); // enough time to flush needed
asm __volatile__(
" cpsid i \n"
"0: \n"
" wfi \n"
" b 0b \n"
);
/* NOTREACHED */
return 0;
}
void random_engine_initialize(void)
{
/* do nothing */
}
void random_fill_buf(void *buf, int len)
{
int i;
uint8_t *p = (uint8_t *)buf;
uint64_t v;
for (i = 0; i < len; ) {
v = get_rand_64();
if (i < len) p[i++] = v;
if (i < len) p[i++] = v >> 8;
if (i < len) p[i++] = v >> 16;
if (i < len) p[i++] = v >> 24;
if (i < len) p[i++] = v >> 32;
if (i < len) p[i++] = v >> 40;
if (i < len) p[i++] = v >> 48;
if (i < len) p[i++] = v >> 56;
}
}
char serial_read_char(void)
{
int c;
while ((c = getchar_timeout_us(1000000)) == PICO_ERROR_TIMEOUT);
return c;
}
void serial_send_buffer(const void *buf, int len)
{
int i;
for (i = 0; i < len; i++)
putchar_raw(((char *)buf)[i]);
}
void serial_send_string(const char *str)
{
serial_send_buffer(str, strlen(str));
}
int serial_open(const char *arg)
{
return 0;
}
void serial_close(void)
{
/* do nothing */
}