Skip to content

Commit 039ccee

Browse files
LaurentiuM1234lgirdwood
authored andcommitted
zephyr: Introduce Zephyr version of sof/lib/io.h
The purpose of this commit is to get rid of the dependency on xtos/include/sof/lib/io.h when building SOF for Zephyr. Apart from that, this commit solves or gets us closer to solving the following issues: 1) Compiling SOF for arm64 architecture results in warnings such as the following: "warning: cast to pointer from integer of different size [-Wint-to-pointer-cast]" 2) Enabling CONFIG_SOF_ZEPHYR_STRICT_HEADERS will result in a compilation error. One of the causes for this is the fact that sof/lib/io.h doesn't exist. Signed-off-by: Laurentiu Mihalcea <laurentiu.mihalcea@nxp.com>
1 parent d4c5734 commit 039ccee

File tree

2 files changed

+88
-3
lines changed
  • xtos/include/sof/lib
  • zephyr/include/sof/lib

2 files changed

+88
-3
lines changed

xtos/include/sof/lib/io.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
* Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
66
*/
77

8-
#ifndef __SOF_LIB_IO_H__
9-
#define __SOF_LIB_IO_H__
8+
#ifndef __XTOS_SOF_LIB_IO_H__
9+
#define __XTOS_SOF_LIB_IO_H__
1010

1111

1212
#include <stdint.h>
@@ -85,4 +85,4 @@ static inline void io_reg_update_bits8(uint32_t reg, uint8_t mask,
8585

8686
#endif
8787

88-
#endif /* __SOF_LIB_IO_H__ */
88+
#endif /* __XTOS_SOF_LIB_IO_H__ */

zephyr/include/sof/lib/io.h

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/* SPDX-License-Identifier: BSD-3-Clause
2+
*
3+
* Copyright 2023 NXP
4+
*/
5+
6+
#ifndef __ZEPHYR_SOF_LIB_IO_H__
7+
#define __ZEPHYR_SOF_LIB_IO_H__
8+
9+
#if CONFIG_LIBRARY
10+
11+
#define io_reg_read16(reg) 0
12+
#define io_reg_write16(reg, val)
13+
#define io_reg_update_bits16(reg, mask, value)
14+
#define io_reg_read(reg) 0
15+
#define io_reg_write(reg, val)
16+
#define io_reg_update_bits(reg, mask, value)
17+
18+
#else
19+
20+
#include <zephyr/arch/cpu.h>
21+
22+
static inline uint8_t io_reg_read8(uint32_t reg)
23+
{
24+
return sys_read8(reg);
25+
}
26+
27+
static inline void io_reg_write8(uint32_t reg, uint8_t val)
28+
{
29+
sys_write8(val, reg);
30+
}
31+
32+
static inline void io_reg_update_bits8(uint32_t reg,
33+
uint8_t mask,
34+
uint8_t value)
35+
{
36+
io_reg_write8(reg, (io_reg_read8(reg) & (~mask)) | (value & mask));
37+
}
38+
39+
static inline uint16_t io_reg_read16(uint32_t reg)
40+
{
41+
return sys_read16(reg);
42+
}
43+
44+
static inline void io_reg_write16(uint32_t reg, uint16_t val)
45+
{
46+
sys_write16(val, reg);
47+
}
48+
49+
static inline void io_reg_update_bits16(uint32_t reg,
50+
uint16_t mask,
51+
uint16_t value)
52+
{
53+
io_reg_write16(reg, (io_reg_read16(reg) & (~mask)) | (value & mask));
54+
}
55+
56+
static inline uint32_t io_reg_read(uint32_t reg)
57+
{
58+
return sys_read32(reg);
59+
}
60+
61+
static inline void io_reg_write(uint32_t reg, uint32_t val)
62+
{
63+
sys_write32(val, reg);
64+
}
65+
66+
static inline void io_reg_update_bits(uint32_t reg,
67+
uint32_t mask,
68+
uint32_t value)
69+
{
70+
io_reg_write(reg, (io_reg_read(reg) & (~mask)) | (value & mask));
71+
}
72+
73+
static inline uint64_t io_reg_read64(uint32_t reg)
74+
{
75+
#if CONFIG_64BIT
76+
return sys_read64(reg);
77+
#else
78+
return (uint64_t)io_reg_read(reg) +
79+
(((uint64_t)io_reg_read(reg + 4)) << 32);
80+
#endif /* CONFIG_64BIT */
81+
}
82+
83+
#endif /* CONFIG_LIBRARY */
84+
85+
#endif /* __ZEPHYR_SOF_LIB_IO_H__ */

0 commit comments

Comments
 (0)