comparison hw.c @ 41:2db4bb90cfca

Remove unused timer and (broken) I2C code.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 01 Apr 2013 20:51:11 +1030
parents a38003b97de6
children ace431a0d0f5
comparison
equal deleted inserted replaced
40:a38003b97de6 41:2db4bb90cfca
6 #include "lcd.h" 6 #include "lcd.h"
7 #include "rtc.h" 7 #include "rtc.h"
8 8
9 #define I2C_TIMEOUT 10000 9 #define I2C_TIMEOUT 10000
10 static void hw_port_cfg(void); 10 static void hw_port_cfg(void);
11
12 /* Wait for cnt microseconds */
13 void
14 _usleep16(uint16_t cnt) {
15 TIM6->ARR = cnt > 3 ? cnt - 3 : cnt;
16 TIM_SetCounter(TIM6, 0);
17 TIM_Cmd(TIM6, ENABLE);
18 while ((TIM6->CR1 & TIM_CR1_CEN) != 0)
19 ;
20 }
21 11
22 void 12 void
23 hw_init(void) { 13 hw_init(void) {
24 hw_port_cfg(); 14 hw_port_cfg();
25 lcd_init(); 15 lcd_init();
259 SPI_Init(SPI1, &SPI_InitStructure); 249 SPI_Init(SPI1, &SPI_InitStructure);
260 250
261 /* SPI1 enable */ 251 /* SPI1 enable */
262 SPI_Cmd(SPI1, ENABLE); 252 SPI_Cmd(SPI1, ENABLE);
263 253
264 /* Configure TIM6 for interval timing */
265 /* Reset TIM6 */
266 TIM_DeInit(TIM6);
267
268 /* Time Base configuration */
269 TIM_TimeBaseStructure.TIM_Period = 0;
270 TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 2 / 1000000) - 1; /* 1 MHz clock */
271 TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
272
273 TIM_Cmd(TIM6, DISABLE);
274
275 /* Setup for single pulse mode clear UDIS */
276 TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single);
277 TIM_UpdateDisableConfig(TIM6, DISABLE);
278
279 /* Setup GPIO for delay test (2) 1-wire (3) & temp ctrl (4/5) 254 /* Setup GPIO for delay test (2) 1-wire (3) & temp ctrl (4/5)
280 * PE2 -> 3 (on header) 255 * PE2 -> 3 (on header)
281 * PE3 -> 4 256 * PE3 -> 4
282 * PE4 -> 5 257 * PE4 -> 5
283 * PE5 -> 6 258 * PE5 -> 6
285 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5; 260 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5;
286 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; 261 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
287 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; 262 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
288 GPIO_Init(GPIOE, &GPIO_InitStructure); 263 GPIO_Init(GPIOE, &GPIO_InitStructure);
289 264
265 /* Setup 1-wire bus */
290 OWInit(); 266 OWInit();
291
292 #if 0
293 while (1) {
294 GPIO_SetBits(GPIOE, GPIO_Pin_2);
295 _usleep16(10);
296 GPIO_ResetBits(GPIOE, GPIO_Pin_2);
297 _usleep16(20);
298 GPIO_SetBits(GPIOE, GPIO_Pin_2);
299 _usleep16(30);
300 GPIO_ResetBits(GPIOE, GPIO_Pin_2);
301 _usleep16(100);
302 }
303 #endif
304 267
305 /* Setup I2C bus */ 268 /* Setup I2C bus */
306 269
307 /* Configure SCL/SDA pins */ 270 /* Configure SCL/SDA pins */
308 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9; 271 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9;
323 I2C_Init(I2C1, &I2C_InitStructure); 286 I2C_Init(I2C1, &I2C_InitStructure);
324 287
325 /* Start I2C controller */ 288 /* Start I2C controller */
326 I2C_Cmd(I2C1, ENABLE); 289 I2C_Cmd(I2C1, ENABLE);
327 290
328 #if 0 291 /* Enable debug block for cycle counter
329 uint32_t I2C_TimeOut = I2C_TIMEOUT; 292 * From http://forums.arm.com/index.php?/topic/13949-cycle-count-in-cortex-m3/
330 293 * via http://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3/11530829#11530829
331 /* Clear the I2C1 AF flag */ 294 */
332 I2C_ClearFlag(I2C1, I2C_FLAG_AF);
333
334 /* Enable I2C1 acknowledgement if it is already disabled by other function */
335 I2C_AcknowledgeConfig(I2C1, ENABLE);
336
337 /*---------------------------- Transmission Phase ---------------------------*/
338
339 /* Send I2C1 START condition */
340 I2C_GenerateSTART(I2C1, ENABLE);
341
342 /*!< Test on I2C1 EV5 and clear it */
343 while ((!I2C_GetFlagStatus(I2C1, I2C_FLAG_SB)) && I2C_TimeOut) {
344 I2C_TimeOut--;
345 }
346
347 if (I2C_TimeOut == 0) {
348 return ERROR;
349 }
350
351 I2C_TimeOut = I2C_TIMEOUT;
352 /* Send STLM75 slave address for write */
353 I2C_Send7bitAddress(I2C1, LM75_ADDR, I2C_Direction_Transmitter);
354
355 while ((!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut) {
356 I2C_TimeOut--;
357 }
358
359 if ((I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_AF) != 0x00) || (I2C_TimeOut == 0)) {
360 return ERROR;
361 } else {
362 return SUCCESS;
363 }
364
365 #endif
366
367 // From http://forums.arm.com/index.php?/topic/13949-cycle-count-in-cortex-m3/
368 // via http://stackoverflow.com/questions/11530593/cycle-counter-on-arm-cortex-m4-or-m3/11530829#11530829
369 volatile uint32_t *DWT_CONTROL = (uint32_t *)0xe0001000; 295 volatile uint32_t *DWT_CONTROL = (uint32_t *)0xe0001000;
370 volatile uint32_t *SCB_DEMCR = (uint32_t *)0xe000edfc; 296 volatile uint32_t *SCB_DEMCR = (uint32_t *)0xe000edfc;
371 297
372 *SCB_DEMCR = *SCB_DEMCR | 0x01000000; 298 *SCB_DEMCR = *SCB_DEMCR | 0x01000000;
373 *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter 299 *DWT_CONTROL = *DWT_CONTROL | 1 ; // enable the counter