K60 - GPIO头文件分析

更新时间:2024-01-10 02:31:01 阅读量: 教育文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

[cpp] view plaincopyprint?

1. /* ---------------------------------------------------------------------------- 2. -- PORT

3. ---------------------------------------------------------------------------- */ 4. 5. /**

6. * @addtogroup PORT_Peripheral PORT 7. * @{ 8. */ 9.

10. /** PORT - Peripheral register structure */ 11. typedef struct PORT_MemMap {

12. uint32_t PCR[32]; /**< Pin Control Register

n, array offset: 0x0, array step: 0x4 */

13. uint32_t GPCLR; /**< Global Pin Control L

ow Register, offset: 0x80 */

14. uint32_t GPCHR; /**< Global Pin Control H

igh Register, offset: 0x84 */ 15. uint8_t RESERVED_0[24];

16. uint32_t ISFR; /**< Interrupt Status Fla

g Register, offset: 0xA0 */ 17. uint8_t RESERVED_1[28];

18. uint32_t DFER; /**< Digital Filter Enabl

e Register, offset: 0xC0 */

19. uint32_t DFCR; /**< Digital Filter Clock

Register, offset: 0xC4 */

20. uint32_t DFWR; /**< Digital Filter Width

Register, offset: 0xC8 */ 21. } volatile *PORT_MemMapPtr; 22.

23. /* ----------------------------------------------------------------------------

24. -- PORT - Register accessor macros

25. ---------------------------------------------------------------------------- */ 26. 27. /**

28. * @addtogroup PORT_Register_Accessor_Macros PORT - Register accessor macros

29. * @{ 30. */ 31.

32.

33. /* PORT - Register accessors */

34. #define PORT_PCR_REG(base,index) ((base)->PCR[index]) 35. #define PORT_GPCLR_REG(base) ((base)->GPCLR) 36. #define PORT_GPCHR_REG(base) ((base)->GPCHR) 37. #define PORT_ISFR_REG(base) ((base)->ISFR) 38. #define PORT_DFER_REG(base) ((base)->DFER) 39. #define PORT_DFCR_REG(base) ((base)->DFCR) 40. #define PORT_DFWR_REG(base) ((base)->DFWR) 41. 42. /** 43. * @}

44. */ /* end of group PORT_Register_Accessor_Macros */ 45. 46.

47. /* ----------------------------------------------------------------------------

48. -- PORT Register Masks

49. ---------------------------------------------------------------------------- */ 50. 51. /**

52. * @addtogroup PORT_Register_Masks PORT Register Masks 53. * @{ 54. */ 55.

56. /* PCR Bit Fields */

57. #define PORT_PCR_PS_MASK 0x1u 58. #define PORT_PCR_PS_SHIFT 0 59. #define PORT_PCR_PE_MASK 0x2u 60. #define PORT_PCR_PE_SHIFT 1 61. #define PORT_PCR_SRE_MASK 0x4u 62. #define PORT_PCR_SRE_SHIFT 2 63. #define PORT_PCR_PFE_MASK 0x10u 64. #define PORT_PCR_PFE_SHIFT 4 65. #define PORT_PCR_ODE_MASK 0x20u 66. #define PORT_PCR_ODE_SHIFT 5 67. #define PORT_PCR_DSE_MASK 0x40u 68. #define PORT_PCR_DSE_SHIFT 6 69. #define PORT_PCR_MUX_MASK 0x700u 70. #define PORT_PCR_MUX_SHIFT 8

71. #define PORT_PCR_MUX(x) (((uint32_t)(((uint32_t)(x)

)<

72. #define PORT_PCR_LK_MASK 0x8000u

73. #define PORT_PCR_LK_SHIFT 15 74. #define PORT_PCR_IRQC_MASK 0xF0000u 75. #define PORT_PCR_IRQC_SHIFT 16

76. #define PORT_PCR_IRQC(x) (((uint32_t)(((uint32_t)(x)

)<

77. #define PORT_PCR_ISF_MASK 0x1000000u 78. #define PORT_PCR_ISF_SHIFT 24 79. /* GPCLR Bit Fields */

80. #define PORT_GPCLR_GPWD_MASK 0xFFFFu 81. #define PORT_GPCLR_GPWD_SHIFT 0

82. #define PORT_GPCLR_GPWD(x) (((uint32_t)(((uint32_t)(x)

)<

83. #define PORT_GPCLR_GPWE_MASK 0xFFFF0000u 84. #define PORT_GPCLR_GPWE_SHIFT 16

85. #define PORT_GPCLR_GPWE(x) (((uint32_t)(((uint32_t)(x)

)<

87. #define PORT_GPCHR_GPWD_MASK 0xFFFFu 88. #define PORT_GPCHR_GPWD_SHIFT 0

89. #define PORT_GPCHR_GPWD(x) (((uint32_t)(((uint32_t)(x)

)<

90. #define PORT_GPCHR_GPWE_MASK 0xFFFF0000u 91. #define PORT_GPCHR_GPWE_SHIFT 16

92. #define PORT_GPCHR_GPWE(x) (((uint32_t)(((uint32_t)(x)

)<

94. #define PORT_ISFR_ISF_MASK 0xFFFFFFFFu 95. #define PORT_ISFR_ISF_SHIFT 0

96. #define PORT_ISFR_ISF(x) (((uint32_t)(((uint32_t)(x)

)<

98. #define PORT_DFER_DFE_MASK 0xFFFFFFFFu 99. #define PORT_DFER_DFE_SHIFT 0

100. #define PORT_DFER_DFE(x) (((uint32_t)(((uint32_t)(x

))<

102. #define PORT_DFCR_CS_MASK 0x1u 103. #define PORT_DFCR_CS_SHIFT 0 104. /* DFWR Bit Fields */

105. #define PORT_DFWR_FILT_MASK 0x1Fu 106. #define PORT_DFWR_FILT_SHIFT 0

107. #define PORT_DFWR_FILT(x) (((uint32_t)(((uint32_t)(x

))<

109. /** 110. * @}

111. */ /* end of group PORT_Register_Masks */ 112. 113.

114. /* PORT - Peripheral instance base addresses */ 115. /** Peripheral PORTA base pointer */

116. #define PORTA_BASE_PTR ((PORT_MemMapPtr)0x4004900

0u)

117. /** Peripheral PORTB base pointer */

118. #define PORTB_BASE_PTR ((PORT_MemMapPtr)0x4004A00

0u)

119. /** Peripheral PORTC base pointer */

120. #define PORTC_BASE_PTR ((PORT_MemMapPtr)0x4004B00

0u)

121. /** Peripheral PORTD base pointer */

122. #define PORTD_BASE_PTR ((PORT_MemMapPtr)0x4004C00

0u)

123. /** Peripheral PORTE base pointer */

124. #define PORTE_BASE_PTR ((PORT_MemMapPtr)0x4004D00

0u) 125.

126. /* ----------------------------------------------------------------------------

127. -- PORT - Register accessor macros

128. ---------------------------------------------------------------------------- */ 129. 130. /**

131. * @addtogroup PORT_Register_Accessor_Macros PORT - Register accessor macro

s 132. * @{ 133. */ 134. 135.

136. /* PORT - Register instance definitions */ 137. /* PORTA */

138. #define PORTA_PCR0 PORT_PCR_REG(PORTA_BASE_PT

R,0)

139. #define PORTA_PCR1 PORT_PCR_REG(PORTA_BASE_PT

R,1)

140. #define PORTA_PCR2 PORT_PCR_REG(PORTA_BASE_PT

R,2)

141. #define PORTA_PCR3 PORT_PCR_REG(PORTA_BASE_PT

R,3)

142. #define PORTA_PCR4 PORT_PCR_REG(PORTA_BASE_PT

R,4)

143. #define PORTA_PCR5 PORT_PCR_REG(PORTA_BASE_PT

R,5)

144. #define PORTA_PCR6 PORT_PCR_REG(PORTA_BASE_PT

R,6)

145. #define PORTA_PCR7 PORT_PCR_REG(PORTA_BASE_PT

R,7)

146. #define PORTA_PCR8 PORT_PCR_REG(PORTA_BASE_PT

R,8)

147. #define PORTA_PCR9 PORT_PCR_REG(PORTA_BASE_PT

R,9)

148. #define PORTA_PCR10 PORT_PCR_REG(PORTA_BASE_PT

R,10)

149. #define PORTA_PCR11 PORT_PCR_REG(PORTA_BASE_PT

R,11)

150. #define PORTA_PCR12 PORT_PCR_REG(PORTA_BASE_PT

R,12)

151. #define PORTA_PCR13 PORT_PCR_REG(PORTA_BASE_PT

R,13)

152. #define PORTA_PCR14 PORT_PCR_REG(PORTA_BASE_PT

R,14)

153. #define PORTA_PCR15 PORT_PCR_REG(PORTA_BASE_PT

R,15)

154. #define PORTA_PCR16 PORT_PCR_REG(PORTA_BASE_PT

R,16)

155. #define PORTA_PCR17 PORT_PCR_REG(PORTA_BASE_PT

R,17)

156. #define PORTA_PCR18 PORT_PCR_REG(PORTA_BASE_PT

R,18)

157. #define PORTA_PCR19 PORT_PCR_REG(PORTA_BASE_PT

R,19)

158. #define PORTA_PCR20 PORT_PCR_REG(PORTA_BASE_PT

R,20)

159. #define PORTA_PCR21 PORT_PCR_REG(PORTA_BASE_PT

R,21)

160. #define PORTA_PCR22 PORT_PCR_REG(PORTA_BASE_PT

R,22)

161. #define PORTA_PCR23 PORT_PCR_REG(PORTA_BASE_PT

R,23)

162. #define PORTA_PCR24 PORT_PCR_REG(PORTA_BASE_PT

R,24)

163. #define PORTA_PCR25 PORT_PCR_REG(PORTA_BASE_PT

R,25)

164. #define PORTA_PCR26 PORT_PCR_REG(PORTA_BASE_PT

R,26)

165. #define PORTA_PCR27 PORT_PCR_REG(PORTA_BASE_PT

R,27)

166. #define PORTA_PCR28 PORT_PCR_REG(PORTA_BASE_PT

R,28)

167. #define PORTA_PCR29 PORT_PCR_REG(PORTA_BASE_PT

R,29)

168. #define PORTA_PCR30 PORT_PCR_REG(PORTA_BASE_PT

R,30)

169. #define PORTA_PCR31 PORT_PCR_REG(PORTA_BASE_PT

R,31)

170. #define PORTA_GPCLR PORT_GPCLR_REG(PORTA_BASE_

PTR)

171. #define PORTA_GPCHR PORT_GPCHR_REG(PORTA_BASE_

PTR)

172. #define PORTA_ISFR PORT_ISFR_REG(PORTA_BASE_P

TR)

173. #define PORTA_DFER PORT_DFER_REG(PORTA_BASE_P

TR)

174. #define PORTA_DFCR PORT_DFCR_REG(PORTA_BASE_P

TR)

175. #define PORTA_DFWR PORT_DFWR_REG(PORTA_BASE_P

TR)

176. /* PORTB */

177. #define PORTB_PCR0 PORT_PCR_REG(PORTB_BASE_PT

R,0)

178. #define PORTB_PCR1 PORT_PCR_REG(PORTB_BASE_PT

R,1)

179. #define PORTB_PCR2 PORT_PCR_REG(PORTB_BASE_PT

R,2)

180. #define PORTB_PCR3 PORT_PCR_REG(PORTB_BASE_PT

R,3)

181. #define PORTB_PCR4 PORT_PCR_REG(PORTB_BASE_PT

R,4)

182. #define PORTB_PCR5 PORT_PCR_REG(PORTB_BASE_PT

R,5)

183. #define PORTB_PCR6 PORT_PCR_REG(PORTB_BASE_PT

R,6)

184. #define PORTB_PCR7 PORT_PCR_REG(PORTB_BASE_PT

R,7)

185. #define PORTB_PCR8 PORT_PCR_REG(PORTB_BASE_PT

R,8)

186. #define PORTB_PCR9 PORT_PCR_REG(PORTB_BASE_PT

R,9)

187. #define PORTB_PCR10 PORT_PCR_REG(PORTB_BASE_PT

R,10)

188. #define PORTB_PCR11 PORT_PCR_REG(PORTB_BASE_PT

R,11)

189. #define PORTB_PCR12 PORT_PCR_REG(PORTB_BASE_PT

R,12)

190. #define PORTB_PCR13 PORT_PCR_REG(PORTB_BASE_PT

R,13)

191. #define PORTB_PCR14 PORT_PCR_REG(PORTB_BASE_PT

R,14)

192. #define PORTB_PCR15 PORT_PCR_REG(PORTB_BASE_PT

R,15)

193. #define PORTB_PCR16 PORT_PCR_REG(PORTB_BASE_PT

R,16)

194. #define PORTB_PCR17 PORT_PCR_REG(PORTB_BASE_PT

R,17)

195. #define PORTB_PCR18 PORT_PCR_REG(PORTB_BASE_PT

R,18)

196. #define PORTB_PCR19 PORT_PCR_REG(PORTB_BASE_PT

R,19)

197. #define PORTB_PCR20 PORT_PCR_REG(PORTB_BASE_PT

R,20)

198. #define PORTB_PCR21 PORT_PCR_REG(PORTB_BASE_PT

R,21)

199. #define PORTB_PCR22 PORT_PCR_REG(PORTB_BASE_PT

R,22)

200. #define PORTB_PCR23 PORT_PCR_REG(PORTB_BASE_PT

R,23)

201. #define PORTB_PCR24 PORT_PCR_REG(PORTB_BASE_PT

R,24)

202. #define PORTB_PCR25 PORT_PCR_REG(PORTB_BASE_PT

R,25)

203. #define PORTB_PCR26 PORT_PCR_REG(PORTB_BASE_PT

R,26)

204. #define PORTB_PCR27 PORT_PCR_REG(PORTB_BASE_PT

R,27)

205. #define PORTB_PCR28 PORT_PCR_REG(PORTB_BASE_PT

R,28)

206. #define PORTB_PCR29 PORT_PCR_REG(PORTB_BASE_PT

R,29)

207. #define PORTB_PCR30 PORT_PCR_REG(PORTB_BASE_PT

R,30)

208. #define PORTB_PCR31 PORT_PCR_REG(PORTB_BASE_PT

R,31)

209. #define PORTB_GPCLR PORT_GPCLR_REG(PORTB_BASE_

PTR)

210. #define PORTB_GPCHR PORT_GPCHR_REG(PORTB_BASE_

PTR)

211. #define PORTB_ISFR PORT_ISFR_REG(PORTB_BASE_P

TR)

212. #define PORTB_DFER PORT_DFER_REG(PORTB_BASE_P

TR)

213. #define PORTB_DFCR PORT_DFCR_REG(PORTB_BASE_P

TR)

214. #define PORTB_DFWR PORT_DFWR_REG(PORTB_BASE_P

TR)

215. /* PORTC */

216. #define PORTC_PCR0 PORT_PCR_REG(PORTC_BASE_PT

R,0)

217. #define PORTC_PCR1 PORT_PCR_REG(PORTC_BASE_PT

R,1)

218. #define PORTC_PCR2 PORT_PCR_REG(PORTC_BASE_PT

R,2)

219. #define PORTC_PCR3 PORT_PCR_REG(PORTC_BASE_PT

R,3)

220. #define PORTC_PCR4 PORT_PCR_REG(PORTC_BASE_PT

R,4)

221. #define PORTC_PCR5 PORT_PCR_REG(PORTC_BASE_PT

R,5)

222. #define PORTC_PCR6 PORT_PCR_REG(PORTC_BASE_PT

R,6)

223. #define PORTC_PCR7 PORT_PCR_REG(PORTC_BASE_PT

R,7)

224. #define PORTC_PCR8 PORT_PCR_REG(PORTC_BASE_PT

R,8)

225. #define PORTC_PCR9 PORT_PCR_REG(PORTC_BASE_PT

R,9)

226. #define PORTC_PCR10 PORT_PCR_REG(PORTC_BASE_PT

R,10)

227. #define PORTC_PCR11 PORT_PCR_REG(PORTC_BASE_PT

R,11)

228. #define PORTC_PCR12 PORT_PCR_REG(PORTC_BASE_PT

R,12)

229. #define PORTC_PCR13 PORT_PCR_REG(PORTC_BASE_PT

R,13)

230. #define PORTC_PCR14 PORT_PCR_REG(PORTC_BASE_PT

R,14)

231. #define PORTC_PCR15 PORT_PCR_REG(PORTC_BASE_PT

R,15)

232. #define PORTC_PCR16 PORT_PCR_REG(PORTC_BASE_PT

R,16)

233. #define PORTC_PCR17 PORT_PCR_REG(PORTC_BASE_PT

R,17)

234. #define PORTC_PCR18 PORT_PCR_REG(PORTC_BASE_PT

R,18)

235. #define PORTC_PCR19 PORT_PCR_REG(PORTC_BASE_PT

R,19)

236. #define PORTC_PCR20 PORT_PCR_REG(PORTC_BASE_PT

R,20)

237. #define PORTC_PCR21 PORT_PCR_REG(PORTC_BASE_PT

R,21)

238. #define PORTC_PCR22 PORT_PCR_REG(PORTC_BASE_PT

R,22)

239. #define PORTC_PCR23 PORT_PCR_REG(PORTC_BASE_PT

R,23)

240. #define PORTC_PCR24 PORT_PCR_REG(PORTC_BASE_PT

R,24)

241. #define PORTC_PCR25 PORT_PCR_REG(PORTC_BASE_PT

R,25)

242. #define PORTC_PCR26 PORT_PCR_REG(PORTC_BASE_PT

R,26)

243. #define PORTC_PCR27 PORT_PCR_REG(PORTC_BASE_PT

R,27)

244. #define PORTC_PCR28 PORT_PCR_REG(PORTC_BASE_PT

R,28)

245. #define PORTC_PCR29 PORT_PCR_REG(PORTC_BASE_PT

R,29)

246. #define PORTC_PCR30 PORT_PCR_REG(PORTC_BASE_PT

R,30)

247. #define PORTC_PCR31 PORT_PCR_REG(PORTC_BASE_PT

R,31)

248. #define PORTC_GPCLR PORT_GPCLR_REG(PORTC_BASE_

PTR)

249. #define PORTC_GPCHR PORT_GPCHR_REG(PORTC_BASE_

PTR)

250. #define PORTC_ISFR PORT_ISFR_REG(PORTC_BASE_P

TR)

251. #define PORTC_DFER PORT_DFER_REG(PORTC_BASE_P

TR)

252. #define PORTC_DFCR PORT_DFCR_REG(PORTC_BASE_P

TR)

253. #define PORTC_DFWR PORT_DFWR_REG(PORTC_BASE_P

TR)

254. /* PORTD */

255. #define PORTD_PCR0 PORT_PCR_REG(PORTD_BASE_PT

R,0)

256. #define PORTD_PCR1 PORT_PCR_REG(PORTD_BASE_PT

R,1)

257. #define PORTD_PCR2 PORT_PCR_REG(PORTD_BASE_PT

R,2)

258. #define PORTD_PCR3 PORT_PCR_REG(PORTD_BASE_PT

R,3)

259. #define PORTD_PCR4 PORT_PCR_REG(PORTD_BASE_PT

R,4)

260. #define PORTD_PCR5 PORT_PCR_REG(PORTD_BASE_PT

R,5)

261. #define PORTD_PCR6 PORT_PCR_REG(PORTD_BASE_PT

R,6)

262. #define PORTD_PCR7 PORT_PCR_REG(PORTD_BASE_PT

R,7)

263. #define PORTD_PCR8 PORT_PCR_REG(PORTD_BASE_PT

R,8)

264. #define PORTD_PCR9 PORT_PCR_REG(PORTD_BASE_PT

R,9)

265. #define PORTD_PCR10 PORT_PCR_REG(PORTD_BASE_PT

R,10)

266. #define PORTD_PCR11 PORT_PCR_REG(PORTD_BASE_PT

R,11)

267. #define PORTD_PCR12 PORT_PCR_REG(PORTD_BASE_PT

R,12)

268. #define PORTD_PCR13 PORT_PCR_REG(PORTD_BASE_PT

R,13)

269. #define PORTD_PCR14 PORT_PCR_REG(PORTD_BASE_PT

R,14)

270. #define PORTD_PCR15 PORT_PCR_REG(PORTD_BASE_PT

R,15)

271. #define PORTD_PCR16 PORT_PCR_REG(PORTD_BASE_PT

R,16)

272. #define PORTD_PCR17 PORT_PCR_REG(PORTD_BASE_PT

R,17)

273. #define PORTD_PCR18 PORT_PCR_REG(PORTD_BASE_PT

R,18)

274. #define PORTD_PCR19 PORT_PCR_REG(PORTD_BASE_PT

R,19)

275. #define PORTD_PCR20 PORT_PCR_REG(PORTD_BASE_PT

R,20)

276. #define PORTD_PCR21 PORT_PCR_REG(PORTD_BASE_PT

R,21)

277. #define PORTD_PCR22 PORT_PCR_REG(PORTD_BASE_PT

R,22)

278. #define PORTD_PCR23 PORT_PCR_REG(PORTD_BASE_PT

R,23)

279. #define PORTD_PCR24 PORT_PCR_REG(PORTD_BASE_PT

R,24)

280. #define PORTD_PCR25 PORT_PCR_REG(PORTD_BASE_PT

R,25)

281. #define PORTD_PCR26 PORT_PCR_REG(PORTD_BASE_PT

R,26)

282. #define PORTD_PCR27 PORT_PCR_REG(PORTD_BASE_PT

R,27)

283. #define PORTD_PCR28 PORT_PCR_REG(PORTD_BASE_PT

R,28)

284. #define PORTD_PCR29 PORT_PCR_REG(PORTD_BASE_PT

R,29)

285. #define PORTD_PCR30 PORT_PCR_REG(PORTD_BASE_PT

R,30)

286. #define PORTD_PCR31 PORT_PCR_REG(PORTD_BASE_PT

R,31)

287. #define PORTD_GPCLR PORT_GPCLR_REG(PORTD_BASE_

PTR)

288. #define PORTD_GPCHR PORT_GPCHR_REG(PORTD_BASE_

PTR)

289. #define PORTD_ISFR PORT_ISFR_REG(PORTD_BASE_P

TR)

290. #define PORTD_DFER PORT_DFER_REG(PORTD_BASE_P

TR)

291. #define PORTD_DFCR PORT_DFCR_REG(PORTD_BASE_P

TR)

292. #define PORTD_DFWR PORT_DFWR_REG(PORTD_BASE_P

TR)

293. /* PORTE */

294. #define PORTE_PCR0 PORT_PCR_REG(PORTE_BASE_PT

R,0)

295. #define PORTE_PCR1 PORT_PCR_REG(PORTE_BASE_PT

R,1)

296. #define PORTE_PCR2 PORT_PCR_REG(PORTE_BASE_PT

R,2)

297. #define PORTE_PCR3 PORT_PCR_REG(PORTE_BASE_PT

R,3)

298. #define PORTE_PCR4 PORT_PCR_REG(PORTE_BASE_PT

R,4)

299. #define PORTE_PCR5 PORT_PCR_REG(PORTE_BASE_PT

R,5)

300. #define PORTE_PCR6 PORT_PCR_REG(PORTE_BASE_PT

R,6)

301. #define PORTE_PCR7 PORT_PCR_REG(PORTE_BASE_PT

R,7)

302. #define PORTE_PCR8 PORT_PCR_REG(PORTE_BASE_PT

R,8)

303. #define PORTE_PCR9 PORT_PCR_REG(PORTE_BASE_PT

R,9)

304. #define PORTE_PCR10 PORT_PCR_REG(PORTE_BASE_PT

R,10)

305. #define PORTE_PCR11 PORT_PCR_REG(PORTE_BASE_PT

R,11)

306. #define PORTE_PCR12 PORT_PCR_REG(PORTE_BASE_PT

R,12)

307. #define PORTE_PCR13 PORT_PCR_REG(PORTE_BASE_PT

R,13)

308. #define PORTE_PCR14 PORT_PCR_REG(PORTE_BASE_PT

R,14)

309. #define PORTE_PCR15 PORT_PCR_REG(PORTE_BASE_PT

R,15)

310. #define PORTE_PCR16 PORT_PCR_REG(PORTE_BASE_PT

R,16)

311. #define PORTE_PCR17 PORT_PCR_REG(PORTE_BASE_PT

R,17)

312. #define PORTE_PCR18 PORT_PCR_REG(PORTE_BASE_PT

R,18)

313. #define PORTE_PCR19 PORT_PCR_REG(PORTE_BASE_PT

R,19)

314. #define PORTE_PCR20 PORT_PCR_REG(PORTE_BASE_PT

R,20)

315. #define PORTE_PCR21 PORT_PCR_REG(PORTE_BASE_PT

R,21)

316. #define PORTE_PCR22 PORT_PCR_REG(PORTE_BASE_PT

R,22)

317. #define PORTE_PCR23 PORT_PCR_REG(PORTE_BASE_PT

R,23)

318. #define PORTE_PCR24 PORT_PCR_REG(PORTE_BASE_PT

R,24)

319. #define PORTE_PCR25 PORT_PCR_REG(PORTE_BASE_PT

R,25)

320. #define PORTE_PCR26 PORT_PCR_REG(PORTE_BASE_PT

R,26)

321. #define PORTE_PCR27 PORT_PCR_REG(PORTE_BASE_PT

R,27)

322. #define PORTE_PCR28 PORT_PCR_REG(PORTE_BASE_PT

R,28)

323. #define PORTE_PCR29 PORT_PCR_REG(PORTE_BASE_PT

R,29)

324. #define PORTE_PCR30 PORT_PCR_REG(PORTE_BASE_PT

R,30)

325. #define PORTE_PCR31 PORT_PCR_REG(PORTE_BASE_PT

R,31)

326. #define PORTE_GPCLR PORT_GPCLR_REG(PORTE_BASE_

PTR)

327. #define PORTE_GPCHR PORT_GPCHR_REG(PORTE_BASE_

PTR)

328. #define PORTE_ISFR PORT_ISFR_REG(PORTE_BASE_P

TR)

329. #define PORTE_DFER PORT_DFER_REG(PORTE_BASE_P

TR)

330. #define PORTE_DFCR PORT_DFCR_REG(PORTE_BASE_P

TR)

331. #define PORTE_DFWR PORT_DFWR_REG(PORTE_BASE_P

TR) 332.

333. /* PORT - Register array accessors */

334. #define PORTA_PCR(index) PORT_PCR_REG(PORTA_BASE_PT

R,index)

335. #define PORTB_PCR(index) PORT_PCR_REG(PORTB_BASE_PT

R,index)

336. #define PORTC_PCR(index) PORT_PCR_REG(PORTC_BASE_PT

R,index)

337. #define PORTD_PCR(index) PORT_PCR_REG(PORTD_BASE_PT

R,index)

338. #define PORTE_PCR(index) PORT_PCR_REG(PORTE_BASE_PT

R,index) 339. 340. /**

341. * @}

342. */ /* end of group PORT_Register_Accessor_Macros */ 343. 344. 345. /** 346. * @}

347. */ /* end of group PORT_Peripheral */

上述代码是K60芯片的PORT模块相关头文件定义,这里结合硬件手册 K60P100M100SF2RM 对该部分代码进行简要分析。

软件结构分析:

1、“struct PORT_MemMap{ }”:端口内存映射结构体,该结构体定义了一系列“端口控制寄存器”的名称,利用结构体本身的“平坦特性”与CPU中实际的寄存器的相对地址一一对应,实现结构体变量操作对物理地址操作的映射(这里只实现了相对映射,完全映射需要有绝对地址,下面会看到)。该结构体区域中有多块保留空间,与硬件文档地址分配一致不可删除,详见K60P100M100SF2RM 文件11.4 Memory map and register definition章节。如下图所示:

2、“#define PORT_PCR_REG(base,index) ((base)->PCR[index])”:端口内存映射结构体的内部变量宏定义,主要是便于操作结构体内部变量,该宏定义接收结构体指针(首地址),返回特定变量操作符。

3、“#define PORT_PCR_PS_MASK 0x1u”:端口寄存器中的位域屏蔽码,根据硬件手册对端口中各个寄存器的各个位域进行定义,根据缩写大概能猜想出个大概,便于后期使用,详见K60P100M100SF2RM 文件11.4.1 Pin Control Register n(PORTx_PCRn),其他定义类似。如下图所示:

4、“#define PORTA_BASE_PTR ((PORT_MemMapPtr)0x40049000u)”:定义端口A寄存器组的基地址0x40049000,该CPU中对各个寄存器的配置本质上是对内存映射地址的配置。上面讲到逻辑操作对物理地址的映射问题时,指出只能实现相对映射,这里的绝对地址定义就是为实现地址绝对映射。PORT_MemMapPtr是端口寄存器组的强制类型转换,与结构体“struct PORT_MemMap{ }”共同作用,表示基地址和偏移地址,这样就能通过结构体变量来操控该寄存器组中的任意硬件寄存器,对于其他端口定义也是类似。

5、“#define PORTA_PCR0 PORT_PCR_REG(PORTA_BASE_PTR,0)”:各个端口的内部寄存器变量定义,也是为了方便后期使用,每个端口的寄存器数量可能不一致,但都与硬件寄存器配置一致。

硬件特性分析:

1、PORT模块主要是对IO端口(不仅仅限于GPIO)的功能性能进行配置,达到一些复杂的功能实现。包括:引脚中断(中断类型配置、中断打开关闭、DMA设置)、数字输入滤波(滤波开关、滤波时钟源、分辨率)、端口控制(各个引脚功能复用、上拉/下拉,电平转换斜率,驱动强度)。例如:如果引脚想实现 GPIO模块 的功能,就需要对PORT模块进行相关配置,设置引脚复用为GPIO,设置上拉\\下拉等等。

128. #define GPIOD_PCOR GPIO_PCOR_REG(PTD_BASE_PTR

)

129. #define GPIOD_PTOR GPIO_PTOR_REG(PTD_BASE_PTR

)

130. #define GPIOD_PDIR GPIO_PDIR_REG(PTD_BASE_PTR

)

131. #define GPIOD_PDDR GPIO_PDDR_REG(PTD_BASE_PTR

)

132. /* PTE */

133. #define GPIOE_PDOR GPIO_PDOR_REG(PTE_BASE_PTR

)

134. #define GPIOE_PSOR GPIO_PSOR_REG(PTE_BASE_PTR

)

135. #define GPIOE_PCOR GPIO_PCOR_REG(PTE_BASE_PTR

)

136. #define GPIOE_PTOR GPIO_PTOR_REG(PTE_BASE_PTR

)

137. #define GPIOE_PDIR GPIO_PDIR_REG(PTE_BASE_PTR

)

138. #define GPIOE_PDDR GPIO_PDDR_REG(PTE_BASE_PTR

) 139. 140. /** 141. * @}

142. */ /* end of group GPIO_Register_Accessor_Macros */ 143. 144. 145. /** 146. * @}

147. */ /* end of group GPIO_Peripheral */

上述代码是K60芯片的GPIO模块相关头文件定义,这里结合硬件手册 K60P100M100SF2RM 对该部分代码进行简要分析。

软件结构分析:

1、“struct GPIO_MemMap { }”:GPIO模块内存映射结构体,该结构体定义了一系列“GPIO端口控制寄存器”的名称,利用结构体本身的“平坦特性”与GPIO模块中实际寄存器的相对地址一一对应,实现结构体内部变量操作对物理地址操作的映射(这里只实现了相对映射,完全映射需要有绝对地址,下面会看到),各寄存器含义可结合注释以及

K60P100M100SF2RM 文件54.2 Memory map and register definition章节。可以看到,在最左一列是各个端口寄存器的物理地址,而且每个端口组的物理首地址跟随后定义的PTx_BASE_PTR宏是一致的。这样就可以利用该结构体进行强制类型转换,把一段连续的内存空间当作某一个结构体来操作,该结构体就相当于一个“模子”,只是对内存空间换了个“视角”而已。

2、“#define GPIO_PDOR_REG(base) ((base)->PDOR)”:GPIO模块内部控制寄存器变量宏定义,该宏定义接收结构体指针,返回寄存器变量

3、“#define GPIO_PDOR_PDO_MASK 0xFFFFFFFFu”:GPIO模块寄存器内部位域屏蔽码,根据硬件操作手册对端口各个寄存器的各个位域进行定义,详见

K60P100M100SF2RM 文件54.2.1 Port Data Output Register(GPIOx_PDOR)章节。在“GPIO_PDOR_PDO_MASK”中,“GPIO”表示端口类型,“PDOR”表示某个具体寄存器名称,“PDO”表示特定寄存器内部的位域名称,可以在文档中搜索“PDO”看它出现的具体位置,就能明白了,这里的位域于其他文档中定义的位域没有区别,只不过这里的位域都是以32位为一组的,只是看起来有点特殊而已。

4、“#define PTA_BASE_PTR ((GPIO_MemMapPtr)0x400FF000u)”:定义GPIO模块A端口的寄存器组基地址0x400FF000u,该CPU中对各个寄存器的配置本质上是对内存映射地址的配置。上面讲到逻辑操作对物理地址的映射问题时,只能实现相对映射,这里的绝对地址定义就是为实现地址绝对映射。GPIO_MemMapPtrr是GPIO寄存器组的强制类型转换,与结构体“structGPIO_MemMap { }”共同作用,表示基地址和偏移地址,这样就能通过结构体变量来操控该寄存器组中的任意硬件寄存器,对于其他GPIO定义也是类似。

5、“#define GPIOA_PDOR GPIO_PDOR_REG(PTA_BASE_PTR)”:各个GPIO端口的内部寄存器变量定义,便于后期使用,与硬件手册相关。

硬件特性分析:

1、关于各个寄存器的功能,可参见绿色注释和硬件手册。K60的GPIO模块与内核之间通过“零等待状态接口”来发挥引脚的最大性能,可以任意数据大小来操作GPIO寄存器。GPIOx_PDOR寄存器内容与引脚状态直接相关,如果想改变引脚状态可以给该寄存器赋值,但是K60的特殊之处在于并非直接操作该寄存器(它只是一个数据存放的场所而已),而是提供了“设置”、“清除”和“取反”三个寄存器,用来改变GPIOx_PDOR状态,这就是“零等

待”的实现关键。通常情况下,设置寄存器位就要用到“位或”指令,清除寄存器位就要用到“位与”指令,该类指令的操作执行就需要消耗cpu时间(取数,位与,赋值),为了最大程度降低“操作延时”,直接通过“入口寄存器”操作数据(赋值),提高性能。

2、GPIO端口的数据操作也是受时钟时序影响的,从微观角度讲,作为输入口时当外部引脚电平变化并不会“瞬间”影响到GPIO输入寄存器的数值,只有当GPIO模块时钟边沿到来时,该状态改变才能体现到寄存器中。虽然这个时间非常短暂,但是并不能忽视它的存在,对于输出口也是如此。

3、关于GPIO操作还有很多选项需要配置,例如“端口上拉”、“滤波使能”、“滤波时钟”、“中断设置”、“端口复用”和“输出强度”等等,就需要设置SIM模块、中断模块、PORT模块等,共同实现GPIO的复杂功能。

4、如果GPIO配置成输入,则必须要打开PORT模块和中断模块中的相关信息;如果不需要输入功能,可以关闭这两个模块中的GPIO相关设置信息,达到节能的目的。如果GPIO配置成输出,则PORT模块和中断模块中的相关信息不需要打开,就可以配置引脚状态。

本文来源:https://www.bwwdw.com/article/1mzo.html

Top