Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SX127x sx12xx_hal TSL2561
board/board.cpp@18:9ac71c0eb70d, 2017-08-02 (annotated)
- Committer:
- dudmuck
- Date:
- Wed Aug 02 11:42:33 2017 -0700
- Revision:
- 18:9ac71c0eb70d
- Parent:
- 16:915815632c1f
- Child:
- 29:ad409c68c0a6
add pwm commands and 434MHz band
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dudmuck | 0:8f0d0ae0a077 | 1 | /* |
dudmuck | 0:8f0d0ae0a077 | 2 | / _____) _ | | |
dudmuck | 0:8f0d0ae0a077 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
dudmuck | 0:8f0d0ae0a077 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
dudmuck | 0:8f0d0ae0a077 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
dudmuck | 0:8f0d0ae0a077 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
dudmuck | 0:8f0d0ae0a077 | 7 | (C)2015 Semtech |
dudmuck | 0:8f0d0ae0a077 | 8 | |
dudmuck | 0:8f0d0ae0a077 | 9 | Description: Target board general functions implementation |
dudmuck | 0:8f0d0ae0a077 | 10 | |
dudmuck | 0:8f0d0ae0a077 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
dudmuck | 0:8f0d0ae0a077 | 12 | |
dudmuck | 0:8f0d0ae0a077 | 13 | Maintainer: Miguel Luis and Gregory Cristian |
dudmuck | 0:8f0d0ae0a077 | 14 | */ |
dudmuck | 0:8f0d0ae0a077 | 15 | #include "mbed.h" |
dudmuck | 0:8f0d0ae0a077 | 16 | #include "board.h" |
dudmuck | 18:9ac71c0eb70d | 17 | #define __STDC_FORMAT_MACROS |
dudmuck | 18:9ac71c0eb70d | 18 | #include <inttypes.h> |
dudmuck | 0:8f0d0ae0a077 | 19 | |
dudmuck | 3:aead8f8fdc1f | 20 | #if defined(ENABLE_SX1272) |
dudmuck | 3:aead8f8fdc1f | 21 | SX1272MB2xAS Radio( NULL ); |
dudmuck | 3:aead8f8fdc1f | 22 | #elif defined(ENABLE_SX1276) |
dudmuck | 3:aead8f8fdc1f | 23 | SX1276MB1xAS Radio( NULL ); |
dudmuck | 3:aead8f8fdc1f | 24 | #endif |
dudmuck | 0:8f0d0ae0a077 | 25 | |
dudmuck | 0:8f0d0ae0a077 | 26 | /*! |
dudmuck | 0:8f0d0ae0a077 | 27 | * Nested interrupt counter. |
dudmuck | 0:8f0d0ae0a077 | 28 | * |
dudmuck | 0:8f0d0ae0a077 | 29 | * \remark Interrupt should only be fully disabled once the value is 0 |
dudmuck | 0:8f0d0ae0a077 | 30 | */ |
dudmuck | 0:8f0d0ae0a077 | 31 | static uint8_t IrqNestLevel = 0; |
dudmuck | 0:8f0d0ae0a077 | 32 | |
dudmuck | 0:8f0d0ae0a077 | 33 | void BoardDisableIrq( void ) |
dudmuck | 0:8f0d0ae0a077 | 34 | { |
dudmuck | 0:8f0d0ae0a077 | 35 | __disable_irq( ); |
dudmuck | 0:8f0d0ae0a077 | 36 | IrqNestLevel++; |
dudmuck | 0:8f0d0ae0a077 | 37 | } |
dudmuck | 0:8f0d0ae0a077 | 38 | |
dudmuck | 0:8f0d0ae0a077 | 39 | void BoardEnableIrq( void ) |
dudmuck | 0:8f0d0ae0a077 | 40 | { |
dudmuck | 0:8f0d0ae0a077 | 41 | IrqNestLevel--; |
dudmuck | 0:8f0d0ae0a077 | 42 | if( IrqNestLevel == 0 ) |
dudmuck | 0:8f0d0ae0a077 | 43 | { |
dudmuck | 0:8f0d0ae0a077 | 44 | __enable_irq( ); |
dudmuck | 0:8f0d0ae0a077 | 45 | } |
dudmuck | 0:8f0d0ae0a077 | 46 | } |
dudmuck | 0:8f0d0ae0a077 | 47 | |
dudmuck | 0:8f0d0ae0a077 | 48 | void BoardInit( void ) |
dudmuck | 0:8f0d0ae0a077 | 49 | { |
dudmuck | 10:00997daeb0c0 | 50 | uint32_t rtc_freq = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_RTC); |
dudmuck | 10:00997daeb0c0 | 51 | if (rtc_freq != LSE_VALUE) { |
dudmuck | 18:9ac71c0eb70d | 52 | printf("bad rtc clock:%" PRId32 "\r\n", rtc_freq); |
dudmuck | 10:00997daeb0c0 | 53 | for (;;) __NOP(); |
dudmuck | 10:00997daeb0c0 | 54 | } |
dudmuck | 0:8f0d0ae0a077 | 55 | } |
dudmuck | 0:8f0d0ae0a077 | 56 | |
dudmuck | 0:8f0d0ae0a077 | 57 | uint8_t BoardGetBatteryLevel( void ) |
dudmuck | 0:8f0d0ae0a077 | 58 | { |
dudmuck | 0:8f0d0ae0a077 | 59 | return 0xFE; |
dudmuck | 0:8f0d0ae0a077 | 60 | } |
dudmuck | 0:8f0d0ae0a077 | 61 | |
dudmuck | 0:8f0d0ae0a077 | 62 | #ifdef TARGET_STM32L1 /* TARGET_NUCLEO_L152RE */ |
dudmuck | 16:915815632c1f | 63 | /* 0x1ff80050: Cat1, Cat2 */ |
dudmuck | 16:915815632c1f | 64 | #define ID1 ( 0x1ff800d0 ) /* Cat3, Cat4, Cat5 */ |
dudmuck | 16:915815632c1f | 65 | #define ID2 ( ID1 + 0x04 ) |
dudmuck | 16:915815632c1f | 66 | #define ID3 ( ID1 + 0x14 ) |
dudmuck | 0:8f0d0ae0a077 | 67 | DigitalOut rx_debug_pin(PC_3); |
dudmuck | 0:8f0d0ae0a077 | 68 | #elif defined(TARGET_STM32L0) /* TARGET_NUCLEO_L073RZ */ |
dudmuck | 0:8f0d0ae0a077 | 69 | #define ID1 ( 0x1ff80050 ) |
dudmuck | 16:915815632c1f | 70 | #define ID2 ( ID1 + 0x04 ) |
dudmuck | 16:915815632c1f | 71 | #define ID3 ( ID1 + 0x14 ) |
dudmuck | 9:08692264148b | 72 | #ifdef TARGET_DISCO_L072CZ_LRWAN1 |
dudmuck | 1:53c30224eda8 | 73 | DigitalOut rx_debug_pin(PA_0); |
dudmuck | 1:53c30224eda8 | 74 | #else |
dudmuck | 1:53c30224eda8 | 75 | DigitalOut rx_debug_pin(PC_3); |
dudmuck | 1:53c30224eda8 | 76 | #endif |
dudmuck | 16:915815632c1f | 77 | #elif defined(TARGET_STM32L4) /* TARGET_NUCLEO_L476RG */ |
dudmuck | 16:915815632c1f | 78 | #define ID1 ( 0x1fff7590 ) |
dudmuck | 16:915815632c1f | 79 | #define ID2 ( ID1 + 0x04 ) |
dudmuck | 16:915815632c1f | 80 | #define ID3 ( ID1 + 0x08 ) |
dudmuck | 16:915815632c1f | 81 | DigitalOut rx_debug_pin(PC_3); |
dudmuck | 0:8f0d0ae0a077 | 82 | #else |
dudmuck | 0:8f0d0ae0a077 | 83 | #error "provide signature address for target" |
dudmuck | 0:8f0d0ae0a077 | 84 | #endif |
dudmuck | 0:8f0d0ae0a077 | 85 | |
dudmuck | 0:8f0d0ae0a077 | 86 | void BoardGetUniqueId( uint8_t *id ) |
dudmuck | 0:8f0d0ae0a077 | 87 | { |
dudmuck | 0:8f0d0ae0a077 | 88 | id[7] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 24; |
dudmuck | 0:8f0d0ae0a077 | 89 | id[6] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 16; |
dudmuck | 0:8f0d0ae0a077 | 90 | id[5] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ) >> 8; |
dudmuck | 0:8f0d0ae0a077 | 91 | id[4] = ( ( *( uint32_t* )ID1 )+ ( *( uint32_t* )ID3 ) ); |
dudmuck | 0:8f0d0ae0a077 | 92 | id[3] = ( ( *( uint32_t* )ID2 ) ) >> 24; |
dudmuck | 0:8f0d0ae0a077 | 93 | id[2] = ( ( *( uint32_t* )ID2 ) ) >> 16; |
dudmuck | 0:8f0d0ae0a077 | 94 | id[1] = ( ( *( uint32_t* )ID2 ) ) >> 8; |
dudmuck | 0:8f0d0ae0a077 | 95 | id[0] = ( ( *( uint32_t* )ID2 ) ); |
dudmuck | 0:8f0d0ae0a077 | 96 | } |
dudmuck | 0:8f0d0ae0a077 | 97 | |
dudmuck | 1:53c30224eda8 | 98 | #define UART_TX_BUF_SIZE 256 |
dudmuck | 1:53c30224eda8 | 99 | char uart_tx_buf[UART_TX_BUF_SIZE]; |
dudmuck | 16:915815632c1f | 100 | volatile unsigned uart_tx_buf_in; |
dudmuck | 16:915815632c1f | 101 | volatile unsigned uart_tx_buf_out; |
dudmuck | 16:915815632c1f | 102 | volatile bool uart_full; |
dudmuck | 1:53c30224eda8 | 103 | |
dudmuck | 1:53c30224eda8 | 104 | #define PRINT_BUF_SIZE 96 |
dudmuck | 1:53c30224eda8 | 105 | int |
dudmuck | 1:53c30224eda8 | 106 | isr_printf( const char* format, ... ) |
dudmuck | 1:53c30224eda8 | 107 | { |
dudmuck | 1:53c30224eda8 | 108 | va_list arg; |
dudmuck | 1:53c30224eda8 | 109 | char print_buf[PRINT_BUF_SIZE]; |
dudmuck | 1:53c30224eda8 | 110 | unsigned int i, printed_length; |
dudmuck | 1:53c30224eda8 | 111 | |
dudmuck | 1:53c30224eda8 | 112 | va_start(arg, format); |
dudmuck | 1:53c30224eda8 | 113 | printed_length = vsnprintf(print_buf, PRINT_BUF_SIZE, format, arg); |
dudmuck | 1:53c30224eda8 | 114 | va_end(arg); |
dudmuck | 1:53c30224eda8 | 115 | |
dudmuck | 1:53c30224eda8 | 116 | for (i = 0; i < printed_length; i ++) { |
dudmuck | 1:53c30224eda8 | 117 | uart_tx_buf[uart_tx_buf_in] = print_buf[i]; |
dudmuck | 1:53c30224eda8 | 118 | if (++uart_tx_buf_in == UART_TX_BUF_SIZE) |
dudmuck | 1:53c30224eda8 | 119 | uart_tx_buf_in = 0; |
dudmuck | 16:915815632c1f | 120 | if (uart_tx_buf_in == uart_tx_buf_out) |
dudmuck | 16:915815632c1f | 121 | uart_full = true; |
dudmuck | 1:53c30224eda8 | 122 | } |
dudmuck | 1:53c30224eda8 | 123 | |
dudmuck | 1:53c30224eda8 | 124 | return i; |
dudmuck | 1:53c30224eda8 | 125 | } |
dudmuck | 1:53c30224eda8 | 126 | |
dudmuck | 7:e238827f0e47 | 127 | RawSerial pc( USBTX, USBRX ); |
dudmuck | 7:e238827f0e47 | 128 | |
dudmuck | 1:53c30224eda8 | 129 | void bottom_half() |
dudmuck | 1:53c30224eda8 | 130 | { |
dudmuck | 16:915815632c1f | 131 | unsigned in = uart_tx_buf_in; |
dudmuck | 16:915815632c1f | 132 | |
dudmuck | 16:915815632c1f | 133 | while (in != uart_tx_buf_out) { |
dudmuck | 1:53c30224eda8 | 134 | pc.putc(uart_tx_buf[uart_tx_buf_out]); |
dudmuck | 1:53c30224eda8 | 135 | if (++uart_tx_buf_out == UART_TX_BUF_SIZE) |
dudmuck | 1:53c30224eda8 | 136 | uart_tx_buf_out = 0; |
dudmuck | 1:53c30224eda8 | 137 | } |
dudmuck | 16:915815632c1f | 138 | |
dudmuck | 16:915815632c1f | 139 | if (uart_full) { |
dudmuck | 16:915815632c1f | 140 | uart_full = false; |
dudmuck | 16:915815632c1f | 141 | pc.printf("<FULL>"); |
dudmuck | 16:915815632c1f | 142 | } |
dudmuck | 1:53c30224eda8 | 143 | } |