1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 #include <assert.h>
21 #include <errno.h>
22 #include <DA1469xAB.h>
23 #include <da1469x_config.h>
24 #include <da1469x_pdc.h>
25
26 int
da1469x_pdc_add(uint8_t source,uint8_t master,uint8_t en)27 da1469x_pdc_add(uint8_t source, uint8_t master, uint8_t en)
28 {
29 int idx;
30 uint8_t select;
31
32 select = source >> 5;
33 source &= 0x1f;
34
35 for (idx = 0; idx < MCU_PDC_CTRL_REGS_COUNT; idx++) {
36 if (!(MCU_PDC_CTRL_REGS(idx) & PDC_PDC_CTRL0_REG_PDC_MASTER_Msk)) {
37 MCU_PDC_CTRL_REGS(idx) = (select << PDC_PDC_CTRL0_REG_TRIG_SELECT_Pos) |
38 (source << PDC_PDC_CTRL0_REG_TRIG_ID_Pos) |
39 (master << PDC_PDC_CTRL0_REG_PDC_MASTER_Pos) |
40 (en << PDC_PDC_CTRL0_REG_EN_XTAL_Pos);
41 return idx;
42 }
43 }
44
45 assert(0);
46
47 return -ENOENT;
48 }
49
50 void
da1469x_pdc_del(int idx)51 da1469x_pdc_del(int idx)
52 {
53 assert((idx >= 0) && (idx < MCU_PDC_CTRL_REGS_COUNT));
54 assert(MCU_PDC_CTRL_REGS(idx) & PDC_PDC_CTRL0_REG_PDC_MASTER_Msk);
55
56 MCU_PDC_CTRL_REGS(idx) &= ~PDC_PDC_CTRL0_REG_PDC_MASTER_Msk;
57 }
58
59 int
da1469x_pdc_find(int trigger,int master,uint8_t en)60 da1469x_pdc_find(int trigger, int master, uint8_t en)
61 {
62 int idx;
63 uint32_t mask;
64 uint32_t value;
65
66 mask = en << PDC_PDC_CTRL0_REG_EN_XTAL_Pos;
67 value = en << PDC_PDC_CTRL0_REG_EN_XTAL_Pos;
68 if (trigger >= 0) {
69 mask |= PDC_PDC_CTRL0_REG_TRIG_SELECT_Msk | PDC_PDC_CTRL0_REG_TRIG_ID_Msk;
70 value |= ((trigger >> 5) << PDC_PDC_CTRL0_REG_TRIG_SELECT_Pos) |
71 ((trigger & 0x1f) << PDC_PDC_CTRL0_REG_TRIG_ID_Pos);
72 }
73 if (master > 0) {
74 mask |= PDC_PDC_CTRL0_REG_PDC_MASTER_Msk;
75 value |= master << PDC_PDC_CTRL0_REG_PDC_MASTER_Pos;
76 }
77 assert(mask);
78
79 for (idx = 0; idx < MCU_PDC_CTRL_REGS_COUNT; idx++) {
80 if ((MCU_PDC_CTRL_REGS(idx) & mask) == value) {
81 return idx;
82 }
83 }
84
85 return -ENOENT;
86 }
87
88 void
da1469x_pdc_reset(void)89 da1469x_pdc_reset(void)
90 {
91 int idx;
92
93 for (idx = 0; idx < MCU_PDC_CTRL_REGS_COUNT; idx++) {
94 MCU_PDC_CTRL_REGS(idx) = 0;
95 da1469x_pdc_ack(idx);
96 }
97 }
98
99 void
da1469x_pdc_ack_all_m33(void)100 da1469x_pdc_ack_all_m33(void)
101 {
102 int idx;
103
104 for (idx = 0; idx < MCU_PDC_CTRL_REGS_COUNT; idx++) {
105 if (PDC->PDC_PENDING_CM33_REG & (1 << idx)) {
106 da1469x_pdc_ack(idx);
107 }
108 }
109 }
110