| [b6aa0ba] | 1 | /*******************************************************************************
|
|---|
| 2 | MODULE : Hardware.c
|
|---|
| 3 | Hardware related functions, detecting hardware type (physical board layout)
|
|---|
| 4 | and revision, manage MAC address, validate application software (as soon as in
|
|---|
| 5 | application flashing is implemented)
|
|---|
| 6 |
|
|---|
| 7 | 20101117 AB Initial
|
|---|
| 8 | 20180808 AB Adapted to CAN-Tester
|
|---|
| 9 | 20191219 AB Adapted for JADE EFM32JG1B test
|
|---|
| 10 | *******************************************************************************/
|
|---|
| 11 |
|
|---|
| 12 | // --- Includes ---------------------------------------------------------------
|
|---|
| 13 | #define LOGGING_TOKEN HW_LOGGING
|
|---|
| 14 | #include "TraceLeUart.h"
|
|---|
| 15 |
|
|---|
| 16 | #include <efm32.h>
|
|---|
| 17 | #include <em_cmu.h>
|
|---|
| 18 | #include <em_gpio.h>
|
|---|
| 19 | #include <em_usart.h>
|
|---|
| 20 | #include <em_timer.h>
|
|---|
| 21 |
|
|---|
| 22 | #include "types.h"
|
|---|
| 23 | #include "Hardware.h"
|
|---|
| 24 |
|
|---|
| 25 | // --- Pin Definitions --------------------------------------------------------
|
|---|
| 26 | /*#define PORT gpioPortB
|
|---|
| 27 | #define PORT_BIT 6
|
|---|
| 28 | #define TESTPIN_INIT(); { GPIO_PinModeSet(PORT, PORT_BIT, gpioModePushPull, 0);}
|
|---|
| 29 | #define TESTPIN( x ); { if ( x ) GPIO->P[PORT].DOUT |= ( 1 << PORT_BIT ); \
|
|---|
| 30 | else GPIO->P[PORT].DOUT &= ~( 1 << PORT_BIT ); }
|
|---|
| 31 | */
|
|---|
| 32 | // --- Defines ----------------------------------------------------------------
|
|---|
| 33 |
|
|---|
| 34 | // --- Typedefs ---------------------------------------------------------------
|
|---|
| 35 |
|
|---|
| 36 | // --- PUBLIC Variables -------------------------------------------------------
|
|---|
| 37 |
|
|---|
| 38 | // --- Variables --------------------------------------------------------------
|
|---|
| 39 | static BYTE bHwType = 0;
|
|---|
| 40 | static BYTE bHwVersion = 0;
|
|---|
| 41 | static BYTE bHwRevision = 0;
|
|---|
| 42 |
|
|---|
| 43 | // --- Macros -----------------------------------------------------------------
|
|---|
| 44 |
|
|---|
| 45 | // --- Functionprototypes -----------------------------------------------------
|
|---|
| 46 |
|
|---|
| 47 | ;
|
|---|
| 48 | // --- Code -------------------------------------------------------------------
|
|---|
| 49 | /******************************************************************************
|
|---|
| 50 | void HwInit (void)
|
|---|
| 51 | Initialize module Hardware part 1
|
|---|
| 52 | ******************************************************************************/
|
|---|
| 53 | void HwInit (void)
|
|---|
| 54 | {
|
|---|
| 55 | TRACE("HW: init");
|
|---|
| 56 |
|
|---|
| 57 | }
|
|---|
| 58 |
|
|---|
| 59 | /******************************************************************************
|
|---|
| 60 | int HwGetType(void);
|
|---|
| 61 | Returns hardware type previously read from config pins
|
|---|
| 62 | ******************************************************************************/
|
|---|
| 63 | int HwGetType(void)
|
|---|
| 64 | {
|
|---|
| 65 | return bHwType;
|
|---|
| 66 | }
|
|---|
| 67 |
|
|---|
| 68 |
|
|---|
| 69 | /******************************************************************************
|
|---|
| 70 | int HwGetVersion(void);
|
|---|
| 71 | Returns hardware version previously read from config pins
|
|---|
| 72 | ******************************************************************************/
|
|---|
| 73 | int HwGetVersion(void)
|
|---|
| 74 | {
|
|---|
| 75 | return bHwVersion;
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | /******************************************************************************
|
|---|
| 79 | int HwGetRevision(void);
|
|---|
| 80 | Returns hardware revision
|
|---|
| 81 | Currently not defined so 0 is returned
|
|---|
| 82 | ******************************************************************************/
|
|---|
| 83 | int HwGetRevision(void)
|
|---|
| 84 | {
|
|---|
| 85 | return bHwRevision;
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | /******************************************************************************
|
|---|
| 89 | void HwTraceHwInfo(void)
|
|---|
| 90 | ******************************************************************************/
|
|---|
| 91 | void HwTraceInfo(void)
|
|---|
| 92 | {
|
|---|
| 93 | TRACE ("HW: switch 0x%02X", HwGetType() );
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | /******************************************************************************
|
|---|
| 97 | void _delay_us (int us)
|
|---|
| 98 | Delays specified number of micro seconds. Valid for EFM32G880 & EFM32GG380
|
|---|
| 99 | running at standard HFRCO frequency (6.6MHz)
|
|---|
| 100 | ******************************************************************************/
|
|---|
| 101 |
|
|---|
| 102 | // have to be at the end of source file cause overrides optimization level
|
|---|
| 103 |
|
|---|
| 104 | // min. is about 4us (including pin H/L before/after)
|
|---|
| 105 | // 10 --> 12us
|
|---|
| 106 | // 6000 --> 5ms
|
|---|
| 107 |
|
|---|
| 108 | #pragma GCC optimize ("-O0")
|
|---|
| 109 |
|
|---|
| 110 | void _delay_us( int us )
|
|---|
| 111 | {
|
|---|
| 112 |
|
|---|
| 113 | // TESTPIN(1);
|
|---|
| 114 | #ifdef HW_MASTER
|
|---|
| 115 | // master runs with 28MHz
|
|---|
| 116 | us <<= 1;
|
|---|
| 117 | #endif
|
|---|
| 118 | while (us--);
|
|---|
| 119 | // TESTPIN(0);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 |
|
|---|
| 123 |
|
|---|