| 
									
										
										
										
											2013-05-06 12:50:19 +07:00
										 |  |  | /**************************************************************************/ | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |     @file     board.c | 
					
						
							|  |  |  |     @author   hathach (tinyusb.org) | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-05-06 12:50:19 +07:00
										 |  |  |     @section LICENSE | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Software License Agreement (BSD License) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Copyright (c) 2013, hathach (tinyusb.org) | 
					
						
							|  |  |  |     All rights reserved. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     Redistribution and use in source and binary forms, with or without | 
					
						
							|  |  |  |     modification, are permitted provided that the following conditions are met: | 
					
						
							|  |  |  |     1. Redistributions of source code must retain the above copyright | 
					
						
							|  |  |  |     notice, this list of conditions and the following disclaimer. | 
					
						
							|  |  |  |     2. Redistributions in binary form must reproduce the above copyright | 
					
						
							|  |  |  |     notice, this list of conditions and the following disclaimer in the | 
					
						
							|  |  |  |     documentation and/or other materials provided with the distribution. | 
					
						
							|  |  |  |     3. Neither the name of the copyright holders nor the | 
					
						
							|  |  |  |     names of its contributors may be used to endorse or promote products | 
					
						
							|  |  |  |     derived from this software without specific prior written permission. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY | 
					
						
							|  |  |  |     EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 
					
						
							|  |  |  |     WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 
					
						
							|  |  |  |     DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY | 
					
						
							|  |  |  |     DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 
					
						
							|  |  |  |     INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 
					
						
							|  |  |  |     LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND | 
					
						
							|  |  |  |     ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 
					
						
							|  |  |  |     INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS | 
					
						
							|  |  |  |     SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     This file is part of the tinyusb stack. | 
					
						
							|  |  |  | */ | 
					
						
							|  |  |  | /**************************************************************************/ | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include "board.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-13 23:32:07 +07:00
										 |  |  | #if TUSB_CFG_OS == TUSB_OS_NONE // TODO may move to main.c
 | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | volatile uint32_t system_ticks = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void SysTick_Handler (void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |   system_ticks++; | 
					
						
							| 
									
										
										
										
											2013-03-12 12:06:40 +07:00
										 |  |  |   tusb_tick_tock(); // TODO temporarily
 | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-09-25 11:23:53 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-04-25 15:43:33 +07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 13:17:43 +07:00
										 |  |  | #if 0
 | 
					
						
							| 
									
										
										
										
											2013-09-16 16:38:46 +07:00
										 |  |  | // FIXME refractor
 | 
					
						
							|  |  |  | void boardGetMACaddr(uint8_t *macaddr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	macaddr[0] = BOARD_MAC_ADDR0; | 
					
						
							|  |  |  | 	macaddr[1] = BOARD_MAC_ADDR1; | 
					
						
							|  |  |  | 	macaddr[2] = BOARD_MAC_ADDR2; | 
					
						
							|  |  |  | 	macaddr[3] = BOARD_MAC_ADDR3; | 
					
						
							|  |  |  | 	macaddr[4] = BOARD_MAC_ADDR4; | 
					
						
							|  |  |  | 	macaddr[5] = BOARD_MAC_ADDR5; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-09-21 13:17:43 +07:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | void check_failed(uint8_t *file, uint32_t line) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2013-03-12 20:04:29 +07:00
										 |  |  |   (void) file; | 
					
						
							|  |  |  |   (void) line; | 
					
						
							| 
									
										
										
										
											2012-12-18 15:08:30 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-03-13 10:57:30 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-07-03 13:48:11 +07:00
										 |  |  | #if 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-13 10:57:30 +07:00
										 |  |  | /**
 | 
					
						
							|  |  |  |  * HardFault_HandlerAsm: | 
					
						
							|  |  |  |  * Alternative Hard Fault handler to help debug the reason for a fault. | 
					
						
							|  |  |  |  * To use, edit the vector table to reference this function in the HardFault vector | 
					
						
							|  |  |  |  * This code is suitable for Cortex-M3 and Cortex-M0 cores | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Use the 'naked' attribute so that C stacking is not used.
 | 
					
						
							|  |  |  | __attribute__((naked)) | 
					
						
							|  |  |  | void HardFault_HandlerAsm(void){ | 
					
						
							|  |  |  |   /*
 | 
					
						
							|  |  |  |    * Get the appropriate stack pointer, depending on our mode, | 
					
						
							|  |  |  |    * and use it as the parameter to the C handler. This function | 
					
						
							|  |  |  |    * will never return | 
					
						
							|  |  |  |    */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   __asm(  ".syntax unified\n" | 
					
						
							|  |  |  |       "MOVS   R0, #4  \n" | 
					
						
							|  |  |  |       "MOV    R1, LR  \n" | 
					
						
							|  |  |  |       "TST    R0, R1  \n" | 
					
						
							|  |  |  |       "BEQ    _MSP    \n" | 
					
						
							|  |  |  |       "MRS    R0, PSP \n" | 
					
						
							|  |  |  |       "B      HardFault_HandlerC      \n" | 
					
						
							|  |  |  |       "_MSP:  \n" | 
					
						
							|  |  |  |       "MRS    R0, MSP \n" | 
					
						
							|  |  |  |       "B      HardFault_HandlerC      \n" | 
					
						
							|  |  |  |       ".syntax divided\n") ; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /**
 | 
					
						
							|  |  |  |  * HardFaultHandler_C: | 
					
						
							|  |  |  |  * This is called from the HardFault_HandlerAsm with a pointer the Fault stack | 
					
						
							|  |  |  |  * as the parameter. We can then read the values from the stack and place them | 
					
						
							|  |  |  |  * into local variables for ease of reading. | 
					
						
							|  |  |  |  * We then read the various Fault Status and Address Registers to help decode | 
					
						
							|  |  |  |  * cause of the fault. | 
					
						
							|  |  |  |  * The function ends with a BKPT instruction to force control back into the debugger | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | void HardFault_HandlerC(unsigned long *hardfault_args){ | 
					
						
							| 
									
										
										
										
											2013-03-26 12:14:04 +07:00
										 |  |  |   ATTR_UNUSED volatile unsigned long stacked_r0 ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_r1 ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_r2 ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_r3 ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_r12 ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_lr ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_pc ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long stacked_psr ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _CFSR ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _HFSR ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _DFSR ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _AFSR ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _BFAR ; | 
					
						
							|  |  |  |   ATTR_UNUSED volatile unsigned long _MMAR ; | 
					
						
							| 
									
										
										
										
											2013-03-13 10:57:30 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  |   stacked_r0  = ((unsigned long)hardfault_args[0]) ; | 
					
						
							|  |  |  |   stacked_r1  = ((unsigned long)hardfault_args[1]) ; | 
					
						
							|  |  |  |   stacked_r2  = ((unsigned long)hardfault_args[2]) ; | 
					
						
							|  |  |  |   stacked_r3  = ((unsigned long)hardfault_args[3]) ; | 
					
						
							|  |  |  |   stacked_r12 = ((unsigned long)hardfault_args[4]) ; | 
					
						
							|  |  |  |   stacked_lr  = ((unsigned long)hardfault_args[5]) ; | 
					
						
							|  |  |  |   stacked_pc  = ((unsigned long)hardfault_args[6]) ; | 
					
						
							|  |  |  |   stacked_psr = ((unsigned long)hardfault_args[7]) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Configurable Fault Status Register
 | 
					
						
							|  |  |  |   // Consists of MMSR, BFSR and UFSR
 | 
					
						
							|  |  |  |   _CFSR = (*((volatile unsigned long *)(0xE000ED28))) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Hard Fault Status Register
 | 
					
						
							|  |  |  |   _HFSR = (*((volatile unsigned long *)(0xE000ED2C))) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Debug Fault Status Register
 | 
					
						
							|  |  |  |   _DFSR = (*((volatile unsigned long *)(0xE000ED30))) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Auxiliary Fault Status Register
 | 
					
						
							|  |  |  |   _AFSR = (*((volatile unsigned long *)(0xE000ED3C))) ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   // Read the Fault Address Registers. These may not contain valid values.
 | 
					
						
							|  |  |  |   // Check BFARVALID/MMARVALID to see if they are valid values
 | 
					
						
							|  |  |  |   // MemManage Fault Address Register
 | 
					
						
							|  |  |  |   _MMAR = (*((volatile unsigned long *)(0xE000ED34))) ; | 
					
						
							|  |  |  |   // Bus Fault Address Register
 | 
					
						
							|  |  |  |   _BFAR = (*((volatile unsigned long *)(0xE000ED38))) ; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-03-22 17:08:51 +07:00
										 |  |  | //  if ((CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk)==CoreDebug_DHCSR_C_DEBUGEN_Msk) /* if there is debugger connected */
 | 
					
						
							|  |  |  | //  {
 | 
					
						
							|  |  |  | //    __asm("BKPT #0\n");
 | 
					
						
							|  |  |  | //  }
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   hal_debugger_breakpoint(); | 
					
						
							| 
									
										
										
										
											2013-03-13 10:57:30 +07:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2013-07-03 13:48:11 +07:00
										 |  |  | #endif
 |