1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
|
/*
* Copyright : (C) 2022 Phytium Information Technology, Inc.
* All Rights Reserved.
*
* This program is OPEN SOURCE software: you can redistribute it and/or modify it
* under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
* either version 1.0 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the Phytium Public License for more details.
*
*
* FilePath: fgpio_sinit.c
* Date: 2022-02-10 14:53:42
* LastEditTime: 2022-02-18 08:25:29
* Description: This files is for GPIO static variables
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
* 1.0 zhugengyu 2022-3-1 init commit
*/
/***************************** Include Files *********************************/
#include "fparameters.h"
#include "fgpio_hw.h"
#include "fgpio.h"
/************************** Constant Definitions *****************************/
/**************************** Type Definitions *******************************/
/***************** Macros (Inline Functions) Definitions *********************/
/************************** Function Prototypes ******************************/
/************************** Variable Definitions *****************************/
#if defined(FGPIO_VERSION_1) /* FT2000-4, D2000 */
extern const FGpioConfig fgpio_cfg_tbl[FGPIO_NUM];
#elif defined(FGPIO_VERSION_2) /* E2000 GPIO 0 ~ 5 */
extern FGpioConfig fgpio_cfg_tbl[FGPIO_NUM];
#endif
/*****************************************************************************/
#if defined(FGPIO_VERSION_1) /* FT2000-4, D2000 */
/**
* @name: FGpioLookupConfig
* @msg: 获取GPIO控制器的默认配置
* @return {const FGpioConfig *} GPIO控制器的默认配置
* @param {u32} instance_id, GPIO控制器实例号
*/
const FGpioConfig *FGpioLookupConfig(u32 instance_id)
{
const FGpioConfig *ptr = NULL;
u32 index;
for (index = 0; index < FGPIO_NUM; index++)
{
if (fgpio_cfg_tbl[index].instance_id == instance_id)
{
ptr = &fgpio_cfg_tbl[index];
break;
}
}
return ptr;
}
#elif defined(FGPIO_VERSION_2) /* E2000 GPIO 0 ~ 5 */
/**
* @name: FGpioSetIrqNum
* @msg: 设置GPIO控制器各引脚的中断号
* @return {NONE}
* @param {u32} instance_id, GPIO控制器实例号
* @param {FGpioConfig} *ptr, GPIO控制器的默认配置
*/
static void FGpioSetIrqNum(u32 instance_id, FGpioConfig *ptr)
{
u32 pin_id;
u32 irq_num;
if (FGPIO_WITH_PIN_IRQ >= instance_id) /* GPIO 0 ~ 2 */
{
/* each pin has its own interrupt id */
for (pin_id = FGPIO_PIN_0; pin_id < FGPIO_PIN_NUM; pin_id++)
{
ptr->irq_num[pin_id] = FGPIO_PIN_IRQ_NUM_GET(instance_id, pin_id);
}
}
else
{
if (FGPIO_ID_3 == instance_id)
{
irq_num = FGPIO_3_IRQ_NUM;
}
else if (FGPIO_4_IRQ_NUM == instance_id)
{
irq_num = FGPIO_4_IRQ_NUM;
}
else if (FGPIO_5_IRQ_NUM == instance_id)
{
irq_num = FGPIO_5_IRQ_NUM;
}
/* all pins in the controller share the same interrupt id */
for (pin_id = FGPIO_PIN_0; pin_id < FGPIO_PIN_NUM; pin_id++)
{
ptr->irq_num[pin_id] = irq_num;
}
}
return;
}
/**
* @name: FGpioLookupConfig
* @msg: 获取GPIO控制器的默认配置
* @return {const FGpioConfig *} GPIO控制器的默认配置
* @param {u32} instance_id, GPIO控制器实例号
*/
const FGpioConfig *FGpioLookupConfig(u32 instance_id)
{
const FGpioConfig *ptr = NULL;
u32 index;
static boolean irq_num_set = FALSE;
if (FALSE == irq_num_set) /* set irq num in the first time */
{
for (index = 0; index < FGPIO_NUM; index++)
{
FGpioSetIrqNum(index, &fgpio_cfg_tbl[index]);
}
irq_num_set = TRUE;
}
for (index = 0; index < FGPIO_NUM; index++) /* find configs of controller */
{
if (fgpio_cfg_tbl[index].instance_id == instance_id)
{
ptr = &fgpio_cfg_tbl[index];
break;
}
}
return ptr;
}
#endif
|