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 
9 #pragma once
10 
21 #include "periph_cpu.h"
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
27 typedef uint32_t hugemem_ptr_t;
28 
29 #define HUGEMEM_NULL 0
30 
31 void ebi_init(void);
32 
39 static inline uint8_t hugemem_read8(const hugemem_ptr_t from)
40 {
41  uint8_t value;
42 
43  __asm__ volatile (
44  /* place 24 bit address into r30, r31, RAMPZ
45  * r31:r30 <- %B[from]:%A[from]
46  * RAMPZ <- %C[from]
47  */
48  "movw r30, %A[from] \n\t"
49  "out %[rampz], %C[from] \n\t"
50  /* read byte from 24 bit address
51  * register <- *(RAMPZ + Z)
52  */
53  "ld %[dest], Z \n\t"
54  /* clear ramp */
55  "out %[rampz], __zero_reg__ \n\t"
56  : [dest] "=r"(value)
57  : [from] "r"(from),
58  [rampz] "i"(&RAMPZ)
59  : "r30", "r31"
60  );
61 
62  return value;
63 }
64 
71 static inline void hugemem_write8(hugemem_ptr_t to, uint8_t val)
72 {
73  __asm__ volatile (
74  /* place 24 bit address into r30, r31, RAMPZ
75  * r31:r30 <- %B[from]:%A[from]
76  * RAMPZ <- %C[from]
77  */
78  "movw r30, %A[to] \n\t"
79  "out %[rampz], %C[to] \n\t"
80  /* write byte to 24 bit address
81  * (RAMPZ + Z) <- register
82  */
83  "st Z, %[val] \n\t"
84  /* clear ramp */
85  "out %[rampz], __zero_reg__ \n\t"
86  :
87  : [to] "r"(to),
88  [val] "r"(val),
89  [rampz] "i"(&RAMPZ)
90  : "r30", "r31"
91  );
92 }
93 
100 uint16_t hugemem_read16(const hugemem_ptr_t from);
101 
108 void hugemem_write16(hugemem_ptr_t to, uint16_t val);
109 
116 uint32_t hugemem_read32(const hugemem_ptr_t from);
117 
124 void hugemem_write32(hugemem_ptr_t to, uint32_t val);
125 
135 void hugemem_read_block(void *to, const hugemem_ptr_t from, size_t size);
136 
146 void hugemem_write_block(hugemem_ptr_t to, const void *from, size_t size);
147 
148 #ifdef __cplusplus
149 }
150 #endif
151 
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:71
static uint8_t hugemem_read8(const hugemem_ptr_t from)
Load byte register from external memory pointer.
Definition: cpu_ebi.h:39
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.