contrib/firmware: add new adapter ANGIE's firmware/bitstream code
[openocd.git] / contrib / firmware / angie / c / src / serial.c
1 // SPDX-License-Identifier: LGPL-2.1-or-later
2
3 /*
4 * This code was taken from the fx2lib project from this link:
5 * https://github.com/djmuhlestein/fx2lib
6 *
7 * Copyright (C) 2009 Ubixum, Inc.
8 */
9
10 #include <reg_ezusb.h>
11 #include <fx2macros.h>
12 #include <serial.h>
13 #include <stdint.h>
14 /**
15 * using the comp port implies that timer 2 will be used as
16 * a baud rate generator. (Don't use timer 2)
17 **/
18 void sio0_init(uint32_t baud_rate) __critical
19 {
20 uint16_t hl; /* hl value for reload */
21 uint8_t mult; /* multiplier for clock speed */
22 uint32_t tmp; /* scratch for mult/divide */
23
24 mult = (CPUFREQ == CLK_12M) ? 1 : ((CPUFREQ == CLK_24M) ? 2 : 4);
25
26 /* set the clock rate */
27 /* use clock 2 */
28 RCLK = 1; TCLK = 1;
29 tmp = mult * 375000L * 2;
30 tmp /= baud_rate;
31 tmp += 1;
32 tmp /= 2;
33 hl = 0xFFFF - (uint16_t)tmp;
34 RCAP2H = (uint8_t)(((uint16_t)(hl) >> 8) & 0xff);
35
36 /* seems that the 24/48mhz calculations are always one less than suggested values */
37 /* trm table 14-16 */
38 RCAP2L = ((uint8_t)((uint16_t)(hl) & 0xff)) + (mult > 0 ? 1 : 0);
39
40 /* start the timer */
41 TR2 = 1;
42
43 /* set up the serial port */
44 SM0 = 0; SM1 = 1; /* serial mode 1 (asyncronous) */
45 SM2 = 0 ; /* has to do with receiving */
46 REN = 1 ; /* to enable receiving */
47 PCON |= 0x80; /* SET SMOD0, baud rate doubler */
48 TI = 1; /* we send initial byte */
49 }
50
51 int getchar(void)
52 {
53 char c;
54 while (!RI)
55 ;
56 c = SBUF0;
57 RI = 0;
58 return c;
59 }
60
61 void _transchar(char c)
62 {
63 while (!TI)
64 ; /* wait for TI=1 */
65 TI = 0;
66 SBUF0 = c;
67 }
68
69 int putchar (char c)
70 {
71 if (c == '\n')
72 _transchar('\r'); /* transmit \r\n */
73 _transchar(c);
74 if (c == '\r')
75 _transchar('\n'); /* transmit \r\n */
76 return c;
77 }

Linking to existing account procedure

If you already have an account and want to add another login method you MUST first sign in with your existing account and then change URL to read https://review.openocd.org/login/?link to get to this page again but this time it'll work for linking. Thank you.

SSH host keys fingerprints

1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=..              |
|+o..   .         |
|*.o   . .        |
|+B . . .         |
|Bo. = o S        |
|Oo.+ + =         |
|oB=.* = . o      |
| =+=.+   + E     |
|. .=o   . o      |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)