-
Notifications
You must be signed in to change notification settings - Fork 0
/
HA_System.cpp
202 lines (164 loc) · 6.31 KB
/
HA_System.cpp
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
/**
* @file HA_System.cpp
* @author Pham Huu Dang Nhat <[email protected]>, HLib MBoard team.
* @version 1.0
* @date 21-11-2013
* @brief This file implement HA_System.
* HA_System:
*
* (HA_SPI_p) ------------------------> (HA_ZNP) ---------------------------------> (HA_ZbStack)
* (from other system) conf_SPIParams_s:
* MB1_SPI1, SPI : master mode - baudRate = 2.25 MHz
* with SM configuration: - SPI_ns::device_t = SPI_ns::cc2530_1
* - numOfSSLines (2) conf_GPIOsParams_s:
* - GPIOs for CS (CS1: PB5, CS0: PB4) - reset : PA4
* - decode table. - srdy : PB1
* ---------------------------------- - mrdy : PB0
* CS1 | CS0 | device_t | (remember to attach, and re-init SPI
* ---------------------------------- before use)
* 0 | 0 | SPI_ns::allFree |
* 0 | 1 | SPI_ns::cc2530_1 |
* 1 | 0 | SPI_ns::at25Flash_1 |
* 1 | 1 | SPI_ns::at25Flash_2 |
* ----------------------------------
*
* (HA_flash_1) (HA_flash_2)
*
*/
/**< includes */
#include "HA_System.h"
/**<------------------ global vars and objects in HA system ------------------*/
SPI *HA_SPI_p = &MB1_SPI1;
CC2530ZNP HA_ZNP;
ZbStack HA_ZbStack;
HA_flash HA_aFlash;
/**<------------------ global vars and objects in HA system ------------------*/
/**<------------------ conf (compile-time) interface ------------------*/
/**< HA_SPI */
const uint8_t HA_SPI_numOfSSLines = 2;
GPIO_TypeDef *HA_SPI_Cs0GPIO_port = GPIOB;
const uint16_t HA_SPI_Cs0GPIO_pin = GPIO_Pin_4;
const uint32_t HA_SPI_Cs0GPIO_clk = RCC_APB2Periph_GPIOB;
GPIO_TypeDef *HA_SPI_Cs1GPIO_port = GPIOB;
const uint16_t HA_SPI_Cs1GPIO_pin = GPIO_Pin_5;
const uint32_t HA_SPI_Cs1GPIO_clk = RCC_APB2Periph_GPIOB;
SPI_ns::SM_device_t HA_SPI_decodeTable [0x01 << HA_SPI_numOfSSLines] = {
SPI_ns::allFree, //CS = 0
SPI_ns::cc2530_1, //CS = 1
SPI_ns::at25Flash_1,//CS = 2
SPI_ns::at25Flash_2 //CS = 3
};
void HA_SPI_init (void);
/**< HA_SPI */
/**< HA_ZNP */
const uint16_t HA_ZNP_SPI_baudRatePrescaler = SPI_BaudRatePrescaler_32;
SPI *HA_ZNP_SPI_p = HA_SPI_p;
const SPI_ns::SM_device_t HA_ZNP_SPI_deviceType = SPI_ns::cc2530_1;
GPIO_TypeDef *HA_ZNP_resetGPIO_port = GPIOA;
const uint16_t HA_ZNP_resetGPIO_pin = GPIO_Pin_4;
const uint32_t HA_ZNP_resetGPIO_clk = RCC_APB2Periph_GPIOA;
GPIO_TypeDef *HA_ZNP_srdyGPIO_port = GPIOB;
const uint16_t HA_ZNP_srdyGPIO_pin = GPIO_Pin_1;
const uint32_t HA_ZNP_srdyGPIO_clk = RCC_APB2Periph_GPIOB;
GPIO_TypeDef *HA_ZNP_mrdyGPIO_port = GPIOB;
const uint16_t HA_ZNP_mrdyGPIO_pin = GPIO_Pin_0;
const uint32_t HA_ZNP_mrdyGPIO_clk = RCC_APB2Periph_GPIOB;
const bool HA_ZNP_mrdyGPIO_isUsed = true;
void HA_ZNP_init (void);
/**< HA_ZNP */
/**< HA_ZbStack */
CC2530ZNP *HA_ZbStack_aZNP_p = &HA_ZNP;
void HA_ZbStack_init (void);
/**< HA_ZbStack */
/**<------------------ conf (compile-time) interface ------------------*/
/**<------------------ function implement ------------------*/
/**
* @brief HA_system_init, init HA system.
* @return None
* It simply call :
* + HA_SPI_init (); to init SPI with params in conf interface.
* + HA_ZNP_init (); to init ZNP.
* + HA_ZbStack_init (); to init ZbStack.
*
*/
void HA_system_init (void){
HA_SPI_init ();
HA_ZNP_init ();
HA_ZbStack_init ();
}
/**
* @brief HA_SPI_init, init HA_SPI.
* @return None
* It uses params in conf interface to config Slave managerment for SPI:
* number of SS lines, GPIOs for SS Lines, and decode table.
* @attention This function only config SM for SPI, and SPI object must exist before.
*/
void HA_SPI_init (void){
if (HA_SPI_p == NULL)
return;
/**< HA_SPI exist, conf SM */
HA_SPI_p->SM_numOfSSLines_set (HA_SPI_numOfSSLines);
SPI_ns::SM_GPIOParams_s HA_SPI_GPIOCs_s;
HA_SPI_GPIOCs_s.GPIO_port = HA_SPI_Cs0GPIO_port;
HA_SPI_GPIOCs_s.GPIO_pin = HA_SPI_Cs0GPIO_pin;
HA_SPI_GPIOCs_s.GPIO_clk = HA_SPI_Cs0GPIO_clk;
HA_SPI_GPIOCs_s.ssLine = 0;
HA_SPI_p->SM_GPIO_set (&HA_SPI_GPIOCs_s);
HA_SPI_GPIOCs_s.GPIO_port = HA_SPI_Cs1GPIO_port;
HA_SPI_GPIOCs_s.GPIO_pin = HA_SPI_Cs1GPIO_pin;
HA_SPI_GPIOCs_s.GPIO_clk = HA_SPI_Cs1GPIO_clk;
HA_SPI_GPIOCs_s.ssLine = 1;
HA_SPI_p->SM_GPIO_set (&HA_SPI_GPIOCs_s);
uint8_t i;
for ( i = 0; i < (0x01 << HA_SPI_numOfSSLines); i++ ){
HA_SPI_p->SM_deviceToDecoder_set (HA_SPI_decodeTable[i], i);
}
return;
}
/**
* @brief HA_ZbStack_init, init HA_ZbStack.
* @return None
* It uses params in conf interface to config SPI and GPIOs for HA_ZNP:
* SPI params, GPIOs params
* @attention
* - After this function, SPI, and GPIOs is init-ed for HA_ZNP, but
* it's recommended to attach, and re init SPI b/c SPI may be changed by other device.
* - Release SPI after finish so other device can use.
* - HA_SPI_init () has been called before this function.
*/
void HA_ZNP_init (void){
/**< init SPI, GPIOs for HA_ZNP */
CC_ns::conf_SPIParams_s CC_SPIParams_s;
CC_SPIParams_s.baudRatePrescaler = HA_ZNP_SPI_baudRatePrescaler;
CC_SPIParams_s.SPI_p = HA_ZNP_SPI_p;
CC_SPIParams_s.deviceType = HA_ZNP_SPI_deviceType;
CC_ns::conf_GPIOParams_s CC_GPIOParams_s;
CC_GPIOParams_s.resetGPIO_port = HA_ZNP_resetGPIO_port;
CC_GPIOParams_s.resetGPIO_pin = HA_ZNP_resetGPIO_pin;
CC_GPIOParams_s.resetGPIO_clk = HA_ZNP_resetGPIO_clk;
CC_GPIOParams_s.srdyGPIO_port = HA_ZNP_srdyGPIO_port;
CC_GPIOParams_s.srdyGPIO_pin = HA_ZNP_srdyGPIO_pin;
CC_GPIOParams_s.srdyGPIO_clk = HA_ZNP_srdyGPIO_clk;
CC_GPIOParams_s.mrdyGPIO_port = HA_ZNP_mrdyGPIO_port;
CC_GPIOParams_s.mrdyGPIO_pin = HA_ZNP_mrdyGPIO_pin;
CC_GPIOParams_s.mrdyGPIO_clk = HA_ZNP_mrdyGPIO_clk;
CC_GPIOParams_s.mrdyGPIO_isUsed = HA_ZNP_mrdyGPIO_isUsed;
HA_ZNP.init (&CC_SPIParams_s, &CC_GPIOParams_s);
HA_ZNP.cmd_SPI_attach ();
HA_ZNP.sys_reset_hard ();
HA_ZNP.cmd_SPI_release ();
return;
}
/**
* @brief HA_ZbStack_init, init HA_ZbStack.
* @return None
* It uses params in conf interface to config HA_ZbStack.
* HA_ZbStack_aZNP_p
* @attention
* - This function map assign pointer to HA_ZNP to aZNP_p in HA_ZbStack.
*/
void HA_ZbStack_init (void){
HA_ZbStack.init (HA_ZbStack_aZNP_p);
return;
}
/**<------------------ function implement ------------------*/