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
|
/*
* 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: fmio.c
* Date: 2022-07-06 15:01:30
* LastEditTime: 2022-07-06 15:01:30
* Description: This file is for
*
* Modify History:
* Ver Who Date Changes
* ----- ------ -------- --------------------------------------
*/
#include <string.h>
#include "fmio_hw.h"
#include "fmio.h"
/***************** Macros (Inline Functions) Definitions *********************/
#define FMIO_DEBUG_TAG "MIO"
#define FMIO_ERROR(format, ...) FT_DEBUG_PRINT_E(FMIO_DEBUG_TAG, format, ##__VA_ARGS__)
#define FMIO_INFO(format, ...) FT_DEBUG_PRINT_I(FMIO_DEBUG_TAG, format, ##__VA_ARGS__)
#define FMIO_DEBUG(format, ...) FT_DEBUG_PRINT_D(FMIO_DEBUG_TAG, format, ##__VA_ARGS__)
/**
* @name: FMioFuncInit
* @msg: 初始化
* @return {*}
* @param {FMioCtrl} *instance_p
* @param {u32} mio_type
*/
FError FMioFuncInit(FMioCtrl *instance_p, u32 mio_type)
{
FASSERT(instance_p);
FError ret = FMIO_SUCCESS;
/*
* If the device is started, disallow the initialize and return a Status
* indicating it is started. This allows the user to de-initialize the device
* and reinitialize, but prevents a user from inadvertently
* initializing.
*/
if (FT_COMPONENT_IS_READY == instance_p->is_ready)
{
FMIO_ERROR("device is already initialized!!!");
return FMIO_ERR_INVAL_STATE;
}
ret = FMioSelectFunc(instance_p->config.mio_base_addr, mio_type);
if (FMIO_SUCCESS == ret)
{
instance_p->is_ready = FT_COMPONENT_IS_READY;
}
return ret;
}
/**
* @name: FMioFuncDeinit
* @msg: 去初始化
* @return {*}
* @param {FMioCtrl} *instance_p
*/
FError FMioFuncDeinit(FMioCtrl *instance_p)
{
FASSERT(instance_p);
FError ret = FMIO_SUCCESS;
instance_p->is_ready = 0;
/* 重新配置成默认IIC模式 */
ret = FMioSelectFunc(instance_p->config.mio_base_addr, FMIO_FUNC_SET_I2C);
memset(instance_p, 0, sizeof(*instance_p));
return ret;
}
/**
* @name: FMioFuncGetAddress
* @msg: 获取功能设置的基地址
* @return {uintptr}
* @param {FMioCtrl} *instance_p
*/
uintptr FMioFuncGetAddress(FMioCtrl *instance_p, u32 mio_type)
{
FASSERT(instance_p);
FError ret = FMIO_SUCCESS;
if (instance_p->is_ready != FT_COMPONENT_IS_READY)
{
FMIO_ERROR("Mio instance_id: %d ,not init.", instance_p->config.instance_id);
return FMIO_ERR_NOT_READY;
}
if (FMioGetFunc(instance_p->config.mio_base_addr) != mio_type)
{
FMIO_ERROR("Mio instance_id: %d ,mio_type error,please init type first.", instance_p->config.instance_id);
return FMIO_ERR_INVAL_STATE;
}
return instance_p->config.func_base_addr;
}
/**
* @name: FMioFuncGetIrqNum
* @msg: 获取MIO的中断号
* @return {u32}中断号
* @param {FMioCtrl} *instance_p
*/
u32 FMioFuncGetIrqNum(FMioCtrl *instance_p, u32 mio_type)
{
FASSERT(instance_p);
FError ret = FMIO_SUCCESS;
if (instance_p->is_ready != FT_COMPONENT_IS_READY)
{
FMIO_ERROR("Mio instance_id: %d ,not init.", instance_p->config.instance_id);
return FMIO_ERR_NOT_READY;
}
if (FMioGetFunc(instance_p->config.mio_base_addr) != mio_type)
{
FMIO_ERROR("Mio instance_id: %d ,mio_type error,please init type first.", instance_p->config.instance_id);
return FMIO_ERR_INVAL_STATE;
}
return instance_p->config.irq_num;
}
|