cpu_ebi.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 Gerson Fernando Budke
3  *
4  * This file is subject to the terms and conditions of the GNU Lesser
5  * General Public License v2.1. See the file LICENSE in the top level
6  * directory for more details.
7  */
8 
19 #include "periph_cpu.h"
20 
21 #ifndef CPU_EBI_H
22 #define CPU_EBI_H
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 typedef uint32_t hugemem_ptr_t;
29 
30 #define HUGEMEM_NULL 0
31 
32 void ebi_init(void);
33 
40 static inline uint8_t hugemem_read8(const hugemem_ptr_t from)
41 {
42  uint8_t value;
43 
44  __asm__ volatile (
45  /* place 24 bit address into r30, r31, RAMPZ
46  * r31:r30 <- %B[from]:%A[from]
47  * RAMPZ <- %C[from]
48  */
49  "movw r30, %A[from] \n\t"
50  "out %[rampz], %C[from] \n\t"
51  /* read byte from 24 bit address
52  * register <- *(RAMPZ + Z)
53  */
54  "ld %[dest], Z \n\t"
55  /* clear ramp */
56  "out %[rampz], __zero_reg__ \n\t"
57  : [dest] "=r"(value)
58  : [from] "r"(from),
59  [rampz] "i"(&RAMPZ)
60  : "r30", "r31"
61  );
62 
63  return value;
64 }
65 
72 static inline void hugemem_write8(hugemem_ptr_t to, uint8_t val)
73 {
74  __asm__ volatile (
75  /* place 24 bit address into r30, r31, RAMPZ
76  * r31:r30 <- %B[from]:%A[from]
77  * RAMPZ <- %C[from]
78  */
79  "movw r30, %A[to] \n\t"
80  "out %[rampz], %C[to] \n\t"
81  /* write byte to 24 bit address
82  * (RAMPZ + Z) <- register
83  */
84  "st Z, %[val] \n\t"
85  /* clear ramp */
86  "out %[rampz], __zero_reg__ \n\t"
87  :
88  : [to] "r"(to),
89  [val] "r"(val),
90  [rampz] "i"(&RAMPZ)
91  : "r30", "r31"
92  );
93 }
94 
101 uint16_t hugemem_read16(const hugemem_ptr_t from);
102 
109 void hugemem_write16(hugemem_ptr_t to, uint16_t val);
110 
117 uint32_t hugemem_read32(const hugemem_ptr_t from);
118 
125 void hugemem_write32(hugemem_ptr_t to, uint32_t val);
126 
136 void hugemem_read_block(void *to, const hugemem_ptr_t from, size_t size);
137 
147 void hugemem_write_block(hugemem_ptr_t to, const void *from, size_t size);
148 
149 #ifdef __cplusplus
150 }
151 #endif
152 
153 #endif /* CPU_EBI_H */
void hugemem_write32(hugemem_ptr_t to, uint32_t val)
Store two register pair to external memory pointer.
uint32_t hugemem_read32(const hugemem_ptr_t from)
Load two register pair from external memory pointer.
void hugemem_write_block(hugemem_ptr_t to, const void *from, size_t size)
Write byte stream from internal memory to external memory.
static void hugemem_write8(hugemem_ptr_t to, uint8_t val)
Store byte register to external memory pointer.
Definition: cpu_ebi.h:72
static uint8_t hugemem_read8(const hugemem_ptr_t from)
Load byte register from external memory pointer.
Definition: cpu_ebi.h:40
uint16_t hugemem_read16(const hugemem_ptr_t from)
Load register pair from external memory pointer.
void hugemem_read_block(void *to, const hugemem_ptr_t from, size_t size)
Read byte stream from external memory to internal memory.
void hugemem_write16(hugemem_ptr_t to, uint16_t val)
Store register pair to external memory pointer.
Shared CPU specific definitions for the STM32 family.