📄 lib_at91.lst
字号:
##############################################################################
# #
# IAR ARM ANSI C/EC++ Compiler V3.10A/W32 05/Nov/2001 14:58:29 #
# Copyright 1999-2001 IAR Systems. All rights reserved. #
# #
# Cpu mode = arm #
# Code model = small #
# Endian = little #
# Source file = C:\At91\software\projects\bench\Source\lib_at91.c #
# Command line = -I C:\Compil\EW23\ARM\INC\ -I ../../..\ -lcN #
# C:\At91\software\projects\bench\IAR\ARM_INT\List\ -la #
# C:\At91\software\projects\bench\IAR\ARM_INT\List\ -o #
# C:\At91\software\projects\bench\IAR\ARM_INT\Obj\ -e #
# -s9 --debug --cpu_mode arm --code_model small --endian #
# little --cpu=arm7tdmi C:\At91\software\projects\bench\S #
# ource\lib_at91.c #
# List file = C:\At91\software\projects\bench\IAR\ARM_INT\List\lib_at #
# 91.lst #
# Object file = C:\At91\software\projects\bench\IAR\ARM_INT\Obj\lib_at9 #
# 1.r79 #
# #
# #
##############################################################################
C:\At91\software\projects\bench\Source\lib_at91.c
1 //*----------------------------------------------------------------------------
2 //* ATMEL Microcontroller Software Support - ROUSSET -
3 //*----------------------------------------------------------------------------
4 //* The software is delivered "AS IS" without warranty or condition of any
5 //* kind, either express, implied or statutory. This includes without
6 //* limitation any warranty or condition with respect to merchantability or
7 //* fitness for any particular purpose, or against the infringements of
8 //* intellectual property rights of others.
9 //*----------------------------------------------------------------------------
10 //* File Name : lib_at91.c
11 //* Object : bench for the AT91EB01, use PIO in input and
12 //* output libraries definition
13 //*
14 //* 1.0 03/09/01 JPP : Creation
15 //*----------------------------------------------------------------------------
16
17
18 #include "periph/pio/lib_pio.h"
19 #include "periph/power_saving/lib_power_save.h"
20 #include "periph/power_saving/ps40800.h"
21 #include "parts/m40800/lib_m40800.h"
22 #include "periph/usart/lib_usart.h"
23 #include "periph/power_saving/lib_power_save.h"
24 #include "periph/timer_counter/tc.h"
25 #include "periph/timer_counter/lib_tc.h"
26 #include "periph/power_saving/lib_power_save.h"
27 #include "periph/stdc/lib_err.h"
28
29
30 /*-----------------*/
31 /* PIO Controllers */
32 /*-----------------*/
33
34 /* Instantiate PIO Controllers Pointers */
35 const StructPIO *Pio = PIO_BASE ;
36
37 /* PIO Controller Descriptor */
38 const PioCtrlDesc PIO_DESC =
39 {
40 PIO_BASE,
41 PIO_ID,
42 NB_PIO
43 } ;
44
45
46 /*-------*/
47 /* USART */
48 /*-------*/
49
50 /* Usart 0 Descriptor */
51 const UsartDesc USART0_DESC =
52 {
53 USART0_BASE,
54 &PIO_DESC,
55 PIORXD0,
56 PIOTXD0,
57 PIOSCK0,
58 US0_ID ,
59 } ;
60
61 /* Usart 1 Descriptor */
62 const UsartDesc USART1_DESC =
63 {
64 USART1_BASE ,
65 &PIO_DESC,
66 PIORXD1,
67 PIOTXD1,
68 PIOSCK1,
69 US1_ID ,
70 } ;
71
72
73 /*------------------------*/
74 /* Timer Counter Channels */
75 /*------------------------*/
76
77 /* Timer Counter Channel 0 Descriptor */
78 const TCDesc TC0_DESC =
79 {
80 TC0_BASE,
81 &PIO_DESC,
82 TC0_ID,
83 PIOTIOA0,
84 PIOTIOB0,
85 PIOTCLK0
86 } ;
87
88 /* Timer Counter Channel 1 Descriptor */
89 const TCDesc TC1_DESC =
90 {
91 TC1_BASE,
92 &PIO_DESC,
93 TC1_ID,
94 PIOTIOA1,
95 PIOTIOB1,
96 PIOTCLK1
97 } ;
98
99 /* Timer Counter Channel 2 Descriptor */
100 const TCDesc TC2_DESC =
101 {
102 TC2_BASE,
103 &PIO_DESC,
104 TC2_ID,
105 PIOTIOA2,
106 PIOTIOB2,
107 PIOTCLK2
108 } ;
109
110 /* Timer Counter Block Descriptor */
111 const TCBlockDesc TCB_DESC =
112 {
113 &TC0_DESC,
114 &TC1_DESC,
115 &TC2_DESC,
116 } ;
117
118
119
120 //*----------------------------------------------------------------------------
121 //* Function Name : at91_pio_open
122 //* Object : Setup pins to be Parallel IOs, as managed by the PIO
123 //* Input Parameters : <pio_pt> = PIO Controller Descriptor
124 //* : <mask> = bit mask identifying the PIOs
125 //* : <config> = mask identifying the PIOs configuration
126 //* Output Parameters : none
127 //* Functions called : none
128 //*----------------------------------------------------------------------------
129 void at91_pio_open ( const PioCtrlDesc *pio_pt, u_int mask, u_int config )
130 //* Begin
131 {
132 u_int x ;
133 //* If PIOs required to be output
134 if ((config & PIO_SENSE_BIT) != 0 )
135 {
136 //* Defines the PIOs as output
137 pio_pt->pio_base->PIO_OER = mask ;
138 }
139 //* Else
140 else
141 {
142 //* Defines the PIOs as input
143 pio_pt->pio_base->PIO_ODR = mask ;
144 }
145
146 //* If PIOs required to be filtered
147 if ((config & PIO_FILTER_BIT) != 0 )
148 {
149 //* Enable the filter on PIOs
150 pio_pt->pio_base->PIO_IFER = mask ;
151 }
152 else
153 {
154 //* Disable the filter on PIOs
155 pio_pt->pio_base->PIO_IFDR = mask ;
156 }
157
158 //* If PIOs required to be open-drain
159 if ((config & PIO_OPENDRAIN_BIT) != 0 )
160 {
161 //* Enable the filter on PIOs
162 pio_pt->pio_base->PIO_MDER = mask ;
163 }
164 else
165 {
166 //* Disable the filter on PIOs
167 pio_pt->pio_base->PIO_MDSR = mask ;
168 }
169
170 //* If PIOs required for an input change interrupt
171 if ((config & PIO_INPUT_IRQ_BIT) != 0 )
172 {
173 //* Remove any interrupt */
174 x = pio_pt->pio_base->PIO_ISR ;
175 //* Enable the Input Change Interrupt on PIOs
176 pio_pt->pio_base->PIO_IER = mask ;
177 }
178 else
179 {
180 //* Disable the Input Change Interrupt on PIOs
181 pio_pt->pio_base->PIO_IDR = mask ;
182 }
183
184 //* Defines the pins to be controlled by PIO Controller
185 pio_pt->pio_base->PIO_PER = mask ;
186
187 //* End
188 }
189 //*----------------------------------------------------------------------------
190 //* Function Name : at91_pio_close
191 //* Object : Cancel PIO Controller handling from pins managed by
192 //* a peripheral
193 //* Input Parameters : <pio_pt> = PIO Descriptor pointer
194 //* : <mask> = defines the pins to managed by peripheral
195 //* Output Parameters : none
196 //* Functions called : none
197 //*----------------------------------------------------------------------------
198 void at91_pio_close ( const PioCtrlDesc *pio_pt, u_int mask )
199 //* Begin
200 {
201 //* Define PIOs to be controlled by peripherals
202 pio_pt->pio_base->PIO_PDR = mask ;
203
204 //* End
205 }
206
207 //*----------------------------------------------------------------------------
208 //* Function Name : at91_pio_write
209 //* Object : Write a data on required PIOs
210 //* Input Parameters : <pio_pt> = PIO Controller Descriptor Address
211 //* : <mask> = defines work pins
212 //* : <state> = defines set ( =0) or clear ( #0)
213 //* Output Parameters : none
214 //* Functions called : none
215 //*----------------------------------------------------------------------------
216 void at91_pio_write ( const PioCtrlDesc *pio_pt, u_int mask, u_int state )
217 //* Begin
218 {
219 if (state == PIO_CLEAR_OUT )
220 {
221 //* Clear PIOs with data at 0 in CODR (Clear Output Data Register)
222 pio_pt->pio_base->PIO_CODR = mask ;
223 }
224 else
225 {
226 //* Set PIOs with data at 1 in SODR (Set Output Data Register)
227 pio_pt->pio_base->PIO_SODR = mask ;
228 }
229
230 //* End
231 }
232 //*----------------------------------------------------------------------------
233 //* Function Name : at91_pio_read
234 //* Object : Read the state of the PIO pins
235 //* Input Parameters : <pio_pt> = PIO Controller Descriptor Address
236 //* Output Parameters : defines the pins value
237 //* Functions called : at91_clock_get_status, at91_clock_open,
238 //* at91_clock_close
239 //*----------------------------------------------------------------------------
240 u_int at91_pio_read ( const PioCtrlDesc *pio_pt)
241
242 //* Begin
243 {
244
245 u_int return_val ;
246 u_int save_clock ;
247
248 //* Get clock Status
249 save_clock = at91_clock_get_status ( pio_pt->periph_id ) ;
250
251 //* Enable the PIO Clock
252 at91_clock_open ( pio_pt->periph_id ) ;
253
254 //* Read the Data in input of the PIO Controller
255 return_val = pio_pt->pio_base->PIO_PDSR ;
256
257 //* If PIO controller clock was disabled
258 if (( save_clock & (1 << pio_pt->periph_id)) == 0 )
259 {
260 //* Disable the PIO Clock
261 at91_clock_close ( pio_pt->periph_id ) ;
262 }
263
264 return (return_val);
265
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -