Mercurial > ~darius > hgwebdir.cgi > stm32temp
comparison libs/STM32F10x_StdPeriph_Lib_V3.5.0/Project/STM32F10x_StdPeriph_Examples/CEC/DataExchangeInterrupt/stm32f10x_it.c @ 0:c59513fd84fb
Initial commit of STM32 test code.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Mon, 03 Oct 2011 21:19:15 +1030 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c59513fd84fb |
---|---|
1 /** | |
2 ****************************************************************************** | |
3 * @file CEC/DataExchangeInterrupt/stm32f10x_it.c | |
4 * @author MCD Application Team | |
5 * @version V3.5.0 | |
6 * @date 08-April-2011 | |
7 * @brief Main Interrupt Service Routines. | |
8 * This file provides template for all exceptions handler and | |
9 * peripherals interrupt service routine. | |
10 ****************************************************************************** | |
11 * @attention | |
12 * | |
13 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS | |
14 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE | |
15 * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY | |
16 * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING | |
17 * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE | |
18 * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. | |
19 * | |
20 * <h2><center>© COPYRIGHT 2011 STMicroelectronics</center></h2> | |
21 ****************************************************************************** | |
22 */ | |
23 | |
24 /* Includes ------------------------------------------------------------------*/ | |
25 #include "stm32f10x_it.h" | |
26 #include "stm32_eval.h" | |
27 | |
28 /** @addtogroup STM32F10x_StdPeriph_Examples | |
29 * @{ | |
30 */ | |
31 | |
32 /** @addtogroup CEC_DataExchangeInterrupt | |
33 * @{ | |
34 */ | |
35 | |
36 /* Private typedef -----------------------------------------------------------*/ | |
37 /* Private define ------------------------------------------------------------*/ | |
38 /* Private macro -------------------------------------------------------------*/ | |
39 /* Private variables ---------------------------------------------------------*/ | |
40 /* Receive buffer */ | |
41 uint8_t ReceiveBuffer[10]; | |
42 /* Transmit buffer */ | |
43 uint8_t TransmitBuffer[10] = {0xDF, 0x12, 0xD3, 0x56, 0x97, | |
44 0xA1, 0xEC, 0x7B, 0x4F, 0x22}; | |
45 __IO uint8_t ReceivedFrame = 0; | |
46 uint8_t send_inc = 0, rcv_inc = 0; | |
47 uint8_t HeaderBlockValueToSend = 0; | |
48 uint8_t InitiatorAddress = 0; | |
49 uint8_t TransErrorCode = 0; | |
50 uint8_t RecepErrorCode = 0; | |
51 extern uint8_t ByteNumber; | |
52 | |
53 /* Private function prototypes -----------------------------------------------*/ | |
54 /* Private functions ---------------------------------------------------------*/ | |
55 | |
56 /******************************************************************************/ | |
57 /* Cortex-M3 Processor Exceptions Handlers */ | |
58 /******************************************************************************/ | |
59 | |
60 /** | |
61 * @brief This function handles NMI exception. | |
62 * @param None | |
63 * @retval None | |
64 */ | |
65 void NMI_Handler(void) | |
66 { | |
67 } | |
68 | |
69 /** | |
70 * @brief This function handles Hard Fault exception. | |
71 * @param None | |
72 * @retval None | |
73 */ | |
74 void HardFault_Handler(void) | |
75 { | |
76 /* Go to infinite loop when Hard Fault exception occurs */ | |
77 while (1) | |
78 { | |
79 } | |
80 } | |
81 | |
82 /** | |
83 * @brief This function handles Memory Manage exception. | |
84 * @param None | |
85 * @retval None | |
86 */ | |
87 void MemManage_Handler(void) | |
88 { | |
89 /* Go to infinite loop when Memory Manage exception occurs */ | |
90 while (1) | |
91 { | |
92 } | |
93 } | |
94 | |
95 /** | |
96 * @brief This function handles Bus Fault exception. | |
97 * @param None | |
98 * @retval None | |
99 */ | |
100 void BusFault_Handler(void) | |
101 { | |
102 /* Go to infinite loop when Bus Fault exception occurs */ | |
103 while (1) | |
104 { | |
105 } | |
106 } | |
107 | |
108 /** | |
109 * @brief This function handles Usage Fault exception. | |
110 * @param None | |
111 * @retval None | |
112 */ | |
113 void UsageFault_Handler(void) | |
114 { | |
115 /* Go to infinite loop when Usage Fault exception occurs */ | |
116 while (1) | |
117 { | |
118 } | |
119 } | |
120 | |
121 /** | |
122 * @brief This function handles SVCall exception. | |
123 * @param None | |
124 * @retval None | |
125 */ | |
126 void SVC_Handler(void) | |
127 { | |
128 } | |
129 | |
130 /** | |
131 * @brief This function handles Debug Monitor exception. | |
132 * @param None | |
133 * @retval None | |
134 */ | |
135 void DebugMon_Handler(void) | |
136 { | |
137 } | |
138 | |
139 /** | |
140 * @brief This function handles PendSVC exception. | |
141 * @param None | |
142 * @retval None | |
143 */ | |
144 void PendSV_Handler(void) | |
145 { | |
146 } | |
147 | |
148 /** | |
149 * @brief This function handles SysTick Handler. | |
150 * @param None | |
151 * @retval None | |
152 */ | |
153 void SysTick_Handler(void) | |
154 { | |
155 } | |
156 | |
157 /** | |
158 * @brief This function handles EXTI Lines 9 to 5 interrupts requests. | |
159 * @param None | |
160 * @retval None | |
161 */ | |
162 void EXTI9_5_IRQHandler(void) | |
163 { | |
164 /* Generate rising edge on Key button to detect when we push key button to initiate | |
165 transmission */ | |
166 if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET) | |
167 { | |
168 /* Turn on LED3 */ | |
169 STM_EVAL_LEDOn(LED3); | |
170 | |
171 /* Build the Header block to send */ | |
172 HeaderBlockValueToSend = (((MY_DEVICE_ADDRESS & 0xF) << 4) | (FOLLOWER & 0xF)); | |
173 | |
174 /* Write single Data in the TX Buffer to Transmit through the CEC peripheral */ | |
175 CEC_SendDataByte(HeaderBlockValueToSend); | |
176 | |
177 /* Initiate Message Transmission */ | |
178 CEC_StartOfMessage(); | |
179 | |
180 /* Clear Key Button EXTI line pending bit */ | |
181 EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE); | |
182 } | |
183 } | |
184 | |
185 /** | |
186 * @brief This function handles CEC global interrupt request. | |
187 * @param None | |
188 * @retval None | |
189 */ | |
190 void CEC_IRQHandler(void) | |
191 { | |
192 /* Turn on LED4 */ | |
193 STM_EVAL_LEDOn(LED4); | |
194 /********************** Reception *********************************************/ | |
195 /* Check if a reception error occurred */ | |
196 if (CEC_GetFlagStatus(CEC_FLAG_RERR)) | |
197 { | |
198 /* Set receive status bit (Error) */ | |
199 RecepErrorCode = CEC->ESR; | |
200 CEC_ClearFlag(CEC_FLAG_RERR | CEC_FLAG_RSOM | CEC_FLAG_REOM | CEC_FLAG_RBTF); | |
201 } | |
202 else if (CEC_GetFlagStatus(CEC_FLAG_RBTF)) | |
203 { | |
204 /* Check if the byte received is the last one of the message */ | |
205 if (CEC_GetFlagStatus(CEC_FLAG_REOM)) | |
206 { | |
207 ReceiveBuffer[rcv_inc] = CEC_ReceiveDataByte(); | |
208 rcv_inc++; | |
209 ReceivedFrame = 1; | |
210 } | |
211 /* Check if the byte received is a Header */ | |
212 else if (CEC_GetFlagStatus(CEC_FLAG_RSOM)) | |
213 { | |
214 | |
215 InitiatorAddress = ((CEC_ReceiveDataByte() >> 4) & 0x0F); | |
216 rcv_inc = 0; | |
217 } | |
218 /* Receive each byte except header in the reception buffer */ | |
219 else | |
220 { | |
221 ReceiveBuffer[rcv_inc] = CEC_ReceiveDataByte(); | |
222 rcv_inc++; | |
223 } | |
224 /* Clear all reception flags */ | |
225 CEC_ClearFlag(CEC_FLAG_RSOM | CEC_FLAG_REOM | CEC_FLAG_RBTF); | |
226 } | |
227 | |
228 /********************** Transmission ******************************************/ | |
229 /* Check if a transmission error occurred */ | |
230 if (CEC_GetFlagStatus(CEC_FLAG_TERR)) | |
231 { | |
232 TransErrorCode = CEC->ESR; | |
233 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_TERR); | |
234 | |
235 } | |
236 /* Check if end of message bit is set in the data to be transmitted */ | |
237 else if (CEC_GetFlagStatus(CEC_FLAG_TEOM)) | |
238 { | |
239 CEC_ClearFlag(CEC_FLAG_TBTRF | CEC_FLAG_RBTF); | |
240 CEC_EndOfMessageCmd(DISABLE); | |
241 } | |
242 /* Check if data byte has been sent */ | |
243 else if (CEC_GetFlagStatus(CEC_FLAG_TBTRF)) | |
244 { | |
245 /* Set EOM bit if the byte to be transmitted is the last one of the Transmit Buffer */ | |
246 if (send_inc == (ByteNumber - 1)) | |
247 { | |
248 CEC_SendDataByte(TransmitBuffer[send_inc]); | |
249 send_inc++; | |
250 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
251 CEC_EndOfMessageCmd(ENABLE); | |
252 } | |
253 else | |
254 { | |
255 /* Put the byte in the TX Buffer */ | |
256 CEC_SendDataByte(TransmitBuffer[send_inc]); | |
257 send_inc++; | |
258 CEC_ClearFlag(CEC_FLAG_TBTRF); | |
259 } | |
260 } | |
261 } | |
262 | |
263 /******************************************************************************/ | |
264 /* STM32F10x Peripherals Interrupt Handlers */ | |
265 /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ | |
266 /* available peripheral interrupt handler's name please refer to the startup */ | |
267 /* file (startup_stm32f10x_xx.s). */ | |
268 /******************************************************************************/ | |
269 | |
270 /** | |
271 * @brief This function handles PPP interrupt request. | |
272 * @param None | |
273 * @retval None | |
274 */ | |
275 /*void PPP_IRQHandler(void) | |
276 { | |
277 }*/ | |
278 | |
279 /** | |
280 * @} | |
281 */ | |
282 | |
283 /** | |
284 * @} | |
285 */ | |
286 | |
287 /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/ |