1 /**
2 * Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 * Description: Provides gpio port template \n
16 *
17 * History: \n
18 * 2022-07-26, Create file. \n
19 */
20 #include "hal_gpio_v150.h"
21 #include "chip_io.h"
22 #include "chip_core_irq.h"
23 #include "platform_types.h"
24 #include "platform_core.h"
25 #include "gpio_porting.h"
26
27 /**
28 * @brief GPIO group info table.
29 * Developer should adapt GPIO info here.
30 * @note This is const information and does not change during code running.
31 */
32 static hal_gpio_group_info_t const g_gpio_channel_0_group_info[GPIO_CHANNEL_0_GROUP_NUM] = {
33 // GPIO_00 ~ GPIO_07
34 {
35 .start_pin_id = GPIO_00,
36 .pin_num = GPIO_CHANNEL_0_GROUP_0_PIN_NUM,
37 .start_callback_id = GPIO_CHANNEL_0_GROUP_0_CB_START_ID,
38 },
39 };
40 static hal_gpio_group_info_t const g_gpio_channel_1_group_info[GPIO_CHANNEL_1_GROUP_NUM] = {
41 // GPIO_08 ~ GPIO_15
42 {
43 .start_pin_id = GPIO_08,
44 .pin_num = GPIO_CHANNEL_1_GROUP_0_PIN_NUM,
45 .start_callback_id = GPIO_CHANNEL_1_GROUP_0_CB_START_ID,
46 },
47 };
48 static hal_gpio_group_info_t const g_gpio_channel_2_group_info[GPIO_CHANNEL_2_GROUP_NUM] = {
49 // GPIO_16 ~ GPIO_18
50 {
51 .start_pin_id = GPIO_16,
52 .pin_num = GPIO_CHANNEL_2_GROUP_0_PIN_NUM,
53 .start_callback_id = GPIO_CHANNEL_2_GROUP_0_CB_START_ID,
54 },
55 };
56
57 /**
58 * @brief GPIO channel info table.
59 * Developer should adapt GPIO info here.
60 * @note This is const information and does not change during code running.
61 */
62 static hal_gpio_channel_info_t const g_gpio_channel_info_list[GPIO_CHANNEL_MAX_NUM] = {
63 // channel0, GPIO_00 ~ GPIO_07
64 {
65 .start_pin_id = GPIO_00,
66 .pin_num = GPIO_CHANNEL_0_PIN_NUM,
67 .group_num = GPIO_CHANNEL_0_GROUP_NUM,
68 .irq_num = GPIO_0_IRQN,
69 .base_addr = (uintptr_t)GPIO_CHANNEL_0_BASE_ADDR,
70 .group_list = (hal_gpio_group_info_t *)g_gpio_channel_0_group_info,
71 },
72
73 // channel1, GPIO_08 ~ GPIO_15
74 {
75 .start_pin_id = GPIO_08,
76 .pin_num = GPIO_CHANNEL_1_PIN_NUM,
77 .group_num = GPIO_CHANNEL_1_GROUP_NUM,
78 .irq_num = GPIO_1_IRQN,
79 .base_addr = (uintptr_t)GPIO_CHANNEL_1_BASE_ADDR,
80 .group_list = (hal_gpio_group_info_t *)g_gpio_channel_1_group_info,
81 },
82
83 // channel2, GPIO_16 ~ GPIO_18
84 {
85 .start_pin_id = GPIO_16,
86 .pin_num = GPIO_CHANNEL_2_PIN_NUM,
87 .group_num = GPIO_CHANNEL_2_GROUP_NUM,
88 .irq_num = GPIO_2_IRQN,
89 .base_addr = (uintptr_t)GPIO_CHANNEL_2_BASE_ADDR,
90 .group_list = (hal_gpio_group_info_t *)g_gpio_channel_2_group_info,
91 }
92 };
93
94 /**
95 * @brief GPIO context info table.
96 * Developer should adapt channel number, and group number of each channel here.
97 */
98 static hal_gpio_group_context_t g_gpio_channel_0_group_context[GPIO_CHANNEL_0_GROUP_NUM] = {0};
99 static hal_gpio_group_context_t g_gpio_channel_1_group_context[GPIO_CHANNEL_1_GROUP_NUM] = {0};
100 static hal_gpio_group_context_t g_gpio_channel_2_group_context[GPIO_CHANNEL_2_GROUP_NUM] = {0};
101 static hal_gpio_group_context_t const *g_gpio_channel_context_list[GPIO_CHANNEL_MAX_NUM] = {
102 g_gpio_channel_0_group_context,
103 g_gpio_channel_1_group_context,
104 g_gpio_channel_2_group_context,
105 };
106
gpio_porting_channel_info_get(uint32_t channel)107 hal_gpio_channel_info_t *gpio_porting_channel_info_get(uint32_t channel)
108 {
109 return (hal_gpio_channel_info_t *)&g_gpio_channel_info_list[channel];
110 }
111
gpio_porting_group_context_get(uint32_t channel,uint32_t group)112 hal_gpio_group_context_t *gpio_porting_group_context_get(uint32_t channel, uint32_t group)
113 {
114 hal_gpio_group_context_t *channel_info = (hal_gpio_group_context_t *)g_gpio_channel_context_list[channel];
115 return &channel_info[group];
116 }
117
gpio_porting_channel_context_clean(uint32_t channel,uint32_t group_num)118 void gpio_porting_channel_context_clean(uint32_t channel, uint32_t group_num)
119 {
120 memset_s((void *)(g_gpio_channel_context_list[channel]), sizeof(hal_gpio_group_context_t) * group_num, 0,
121 sizeof(gpio_callback_t) * group_num);
122 }
123
gpio_porting_base_addr_get(uint32_t channel)124 uintptr_t gpio_porting_base_addr_get(uint32_t channel)
125 {
126 return gpio_porting_channel_info_get(channel)->base_addr;
127 }
128
gpio_ulp_int_en(bool on)129 void gpio_ulp_int_en(bool on)
130 {
131 unused(on);
132 }
133
gpio_select_core(pin_t pin,cores_t core)134 void gpio_select_core(pin_t pin, cores_t core)
135 {
136 unused(pin);
137 unused(core);
138 }