1 /*
2  * Copyright (c) 2022, Synopsys.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief ARC specific dsp register macros
10  */
11 
12 #ifndef _DSP_REGS_ARC_H
13 #define _DSP_REGS_ARC_H
14 
15 #include <zephyr/toolchain.h>
16 #include "dsp_context.h"
17 
18 /**
19  *
20  * @brief Load all dsp registers
21  *
22  * This function loads all DSP and AGU registers pointed to by @a regs.
23  * It is expected that a subsequent call to _store_all_dsp_registers()
24  * will be issued to dump the dsp registers to memory.
25  *
26  * The format/organization of 'struct dsp_register_set'; the generic C test
27  * code (main.c) merely treat the register set as an array of bytes.
28  *
29  * The only requirement is that the arch specific implementations of
30  * _load_all_dsp_registers() and _store_all_dsp_registers() agree
31  * on the format.
32  *
33  */
_load_all_dsp_registers(struct dsp_register_set * regs)34 void _load_all_dsp_registers(struct dsp_register_set *regs)
35 {
36 	uint32_t *temp = (uint32_t *)regs;
37 
38 	z_arc_v2_aux_reg_write(_ARC_V2_DSP_BFLY0, *temp++);
39 	z_arc_v2_aux_reg_write(_ARC_V2_AGU_AP0, *temp++);
40 	z_arc_v2_aux_reg_write(_ARC_V2_AGU_OS0, *temp++);
41 }
42 
43 /**
44  *
45  * @brief Dump all dsp registers to memory
46  *
47  * This function stores all DSP and AGU registers to the memory buffer
48  * specified by @a regs. It is expected that a previous invocation of
49  * _load_all_dsp_registers() occurred to load all the dsp
50  * registers from a memory buffer.
51  *
52  */
53 
_store_all_dsp_registers(struct dsp_register_set * regs)54 void _store_all_dsp_registers(struct dsp_register_set *regs)
55 {
56 	uint32_t *temp = (uint32_t *)regs;
57 
58 	*temp++ = z_arc_v2_aux_reg_read(_ARC_V2_DSP_BFLY0);
59 	*temp++ = z_arc_v2_aux_reg_read(_ARC_V2_AGU_AP0);
60 	*temp++ = z_arc_v2_aux_reg_read(_ARC_V2_AGU_OS0);
61 }
62 
63 /**
64  *
65  * @brief Load then dump all dsp registers to memory
66  *
67  * This function loads all DSP and AGU registers from the memory buffer
68  * specified by @a regs, and then stores them back to that buffer.
69  *
70  * This routine is called by a high priority thread prior to calling a primitive
71  * that pends and triggers a co-operative context switch to a low priority
72  * thread.
73  *
74  */
75 
_load_then_store_all_dsp_registers(struct dsp_register_set * regs)76 void _load_then_store_all_dsp_registers(struct dsp_register_set *regs)
77 {
78 	_load_all_dsp_registers(regs);
79 	_store_all_dsp_registers(regs);
80 }
81 #endif /* _DSP_REGS_ARC_H */
82