├── .github └── workflows │ └── sync_issues.yml ├── .gitignore ├── BLE_API ├── common │ ├── BLEDevice.cpp │ ├── BLEDeviceInstanceBase.h │ ├── GapAdvertisingData.cpp │ ├── GapAdvertisingParams.cpp │ ├── GattService.cpp │ ├── UUID.cpp │ ├── blecommon.h │ └── readme.txt ├── public │ ├── BLEDevice.h │ ├── CallChainOfFunctionPointersWithContext.h │ ├── FunctionPointerWithContext.h │ ├── Gap.h │ ├── GapAdvertisingData.h │ ├── GapAdvertisingParams.h │ ├── GapEvents.h │ ├── GattAttribute.h │ ├── GattCharacteristic.h │ ├── GattCharacteristicWriteCBParams.h │ ├── GattServer.h │ ├── GattServerEvents.h │ ├── GattService.h │ ├── UUID.h │ └── readme.txt └── services │ ├── BatteryService.h │ ├── DFUService.cpp │ ├── DFUService.h │ ├── DeviceInformationService.h │ ├── HealthThermometerService.h │ ├── HeartRateService.h │ ├── UARTService.cpp │ └── UARTService.h ├── LICENSE ├── Makefile ├── README.md ├── color_pixels ├── color_pixels.cpp └── color_pixels.h ├── demos ├── beacon │ ├── Makefile │ └── main.cpp ├── ble_uart_loopback │ ├── Makefile │ └── main.cpp ├── color_pixels │ ├── Makefile │ └── main.cpp └── grove_node │ ├── Makefile │ ├── main.cpp │ ├── nrf_delay.h │ └── power.c ├── mbed-src ├── api │ ├── AnalogIn.h │ ├── AnalogOut.h │ ├── BusIn.h │ ├── BusInOut.h │ ├── BusOut.h │ ├── CAN.h │ ├── CallChain.h │ ├── DigitalIn.h │ ├── DigitalInOut.h │ ├── DigitalOut.h │ ├── DirHandle.h │ ├── Ethernet.h │ ├── FileBase.h │ ├── FileHandle.h │ ├── FileLike.h │ ├── FilePath.h │ ├── FileSystemLike.h │ ├── FunctionPointer.h │ ├── I2C.h │ ├── I2CSlave.h │ ├── InterruptIn.h │ ├── InterruptManager.h │ ├── LocalFileSystem.h │ ├── PortIn.h │ ├── PortInOut.h │ ├── PortOut.h │ ├── PwmOut.h │ ├── RawSerial.h │ ├── SPI.h │ ├── SPISlave.h │ ├── Serial.h │ ├── SerialBase.h │ ├── Stream.h │ ├── Ticker.h │ ├── Timeout.h │ ├── Timer.h │ ├── TimerEvent.h │ ├── can_helper.h │ ├── mbed.h │ ├── mbed_assert.h │ ├── mbed_debug.h │ ├── mbed_error.h │ ├── mbed_interface.h │ ├── platform.h │ ├── rtc_time.h │ ├── semihost_api.h │ ├── toolchain.h │ └── wait_api.h ├── common │ ├── BusIn.cpp │ ├── BusInOut.cpp │ ├── BusOut.cpp │ ├── CAN.cpp │ ├── CallChain.cpp │ ├── Ethernet.cpp │ ├── FileBase.cpp │ ├── FileLike.cpp │ ├── FilePath.cpp │ ├── FileSystemLike.cpp │ ├── FunctionPointer.cpp │ ├── I2C.cpp │ ├── I2CSlave.cpp │ ├── InterruptIn.cpp │ ├── InterruptManager.cpp │ ├── LocalFileSystem.cpp │ ├── RawSerial.cpp │ ├── SPI.cpp │ ├── SPISlave.cpp │ ├── Serial.cpp │ ├── SerialBase.cpp │ ├── Stream.cpp │ ├── Ticker.cpp │ ├── Timeout.cpp │ ├── Timer.cpp │ ├── TimerEvent.cpp │ ├── assert.c │ ├── board.c │ ├── error.c │ ├── exit.c │ ├── gpio.c │ ├── mbed_interface.c │ ├── pinmap_common.c │ ├── retarget.cpp │ ├── rtc_time.c │ ├── semihost_api.c │ ├── us_ticker_api.c │ └── wait_api.c ├── hal │ ├── analogin_api.h │ ├── analogout_api.h │ ├── can_api.h │ ├── ethernet_api.h │ ├── gpio_api.h │ ├── gpio_irq_api.h │ ├── i2c_api.h │ ├── pinmap.h │ ├── port_api.h │ ├── pwmout_api.h │ ├── rtc_api.h │ ├── serial_api.h │ ├── sleep_api.h │ ├── spi_api.h │ └── us_ticker_api.h └── targets │ ├── cmsis │ ├── TARGET_NORDIC │ │ └── TARGET_MCU_NRF51822 │ │ │ ├── TOOLCHAIN_ARM_STD │ │ │ ├── TARGET_MCU_NORDIC_16K │ │ │ │ ├── nRF51822.sct │ │ │ │ └── startup_nRF51822.s │ │ │ ├── TARGET_MCU_NORDIC_32K │ │ │ │ ├── nRF51822.sct │ │ │ │ └── startup_nRF51822.s │ │ │ └── sys.cpp │ │ │ ├── TOOLCHAIN_GCC_ARM │ │ │ ├── TARGET_MCU_NORDIC_16K │ │ │ │ └── NRF51822.ld │ │ │ ├── TARGET_MCU_NORDIC_32K │ │ │ │ └── NRF51822.ld │ │ │ └── startup_NRF51822.s │ │ │ ├── cmsis.h │ │ │ ├── cmsis_nvic.c │ │ │ ├── cmsis_nvic.h │ │ │ ├── compiler_abstraction.h │ │ │ ├── nordic_global.h │ │ │ ├── nrf51.h │ │ │ ├── nrf51822.h │ │ │ ├── nrf51_bitfields.h │ │ │ ├── system_nrf51822.c │ │ │ └── system_nrf51822.h │ ├── core_cm0.h │ ├── core_cm0plus.h │ ├── core_cm3.h │ ├── core_cm4.h │ ├── core_cm4_simd.h │ ├── core_cmFunc.h │ └── core_cmInstr.h │ └── hal │ └── TARGET_NORDIC │ └── TARGET_MCU_NRF51822 │ ├── Lib │ ├── app_common │ │ └── app_timer.c │ ├── nrf-sdk │ │ ├── app_common │ │ │ ├── app_button.h │ │ │ ├── app_error.h │ │ │ ├── app_fifo.h │ │ │ ├── app_gpiote.h │ │ │ ├── app_scheduler.h │ │ │ ├── app_timer.h │ │ │ ├── app_trace.h │ │ │ ├── app_uart.h │ │ │ ├── app_util.h │ │ │ ├── crc16.h │ │ │ ├── hal_transport.h │ │ │ ├── hci_mem_pool.h │ │ │ ├── hci_mem_pool_internal.h │ │ │ ├── hci_slip.h │ │ │ ├── hci_transport.h │ │ │ └── pstorage.h │ │ ├── nrf_delay.h │ │ └── sd_common │ │ │ └── app_util_platform.h │ └── s110_nrf51822_7_0_0 │ │ ├── s110_nrf51822_7.0.0_API │ │ ├── doc │ │ │ └── ble_api.dox │ │ └── include │ │ │ ├── ble.h │ │ │ ├── ble_err.h │ │ │ ├── ble_gap.h │ │ │ ├── ble_gatt.h │ │ │ ├── ble_gattc.h │ │ │ ├── ble_gatts.h │ │ │ ├── ble_hci.h │ │ │ ├── ble_l2cap.h │ │ │ ├── ble_ranges.h │ │ │ ├── ble_types.h │ │ │ ├── nrf_error.h │ │ │ ├── nrf_error_sdm.h │ │ │ ├── nrf_error_soc.h │ │ │ ├── nrf_mbr.h │ │ │ ├── nrf_sdm.h │ │ │ ├── nrf_soc.h │ │ │ ├── nrf_svc.h │ │ │ └── softdevice_assert.h │ │ ├── s110_nrf51822_7.0.0_licence_agreement.pdf │ │ ├── s110_nrf51822_7.0.0_migration-document.pdf │ │ ├── s110_nrf51822_7.0.0_readme.txt │ │ ├── s110_nrf51822_7.0.0_releasenotes.pdf │ │ └── s110_nrf51822_7.0.0_softdevice.hex │ ├── PeripheralNames.h │ ├── PortNames.h │ ├── TARGET_ARCH_BLE │ ├── PinNames.h │ └── device.h │ ├── analogin_api.c │ ├── gpio_api.c │ ├── gpio_irq_api.c │ ├── gpio_object.h │ ├── i2c_api.c │ ├── objects.h │ ├── pinmap.c │ ├── port_api.c │ ├── pwmout_api.c │ ├── serial_api.c │ ├── sleep.c │ ├── spi_api.c │ └── us_ticker.c └── nRF51822 ├── btle ├── btle.cpp ├── btle.h ├── btle_advertising.cpp ├── btle_advertising.h ├── btle_gap.cpp ├── btle_gap.h └── custom │ ├── custom_helper.cpp │ └── custom_helper.h ├── common ├── ansi_escape.h ├── assertion.h ├── binary.h ├── ble_error.h ├── common.h └── compiler.h ├── nRF51822n.cpp ├── nRF51822n.h ├── nRF51Gap.cpp ├── nRF51Gap.h ├── nRF51GattServer.cpp ├── nRF51GattServer.h ├── nordic ├── app_common │ ├── app_gpiote.c │ ├── app_scheduler.c │ ├── crc16.cpp │ ├── hci_mem_pool.c │ └── pstorage.cpp ├── ble │ ├── ble_advdata.cpp │ ├── ble_advdata_parser.cpp │ ├── ble_bondmngr.cpp │ ├── ble_conn_params.cpp │ ├── ble_debug_assert_handler.cpp │ ├── ble_error_log.cpp │ └── ble_services │ │ └── ble_srv_common.cpp ├── ble_bondmngr_cfg.h ├── bootloader_dfu │ ├── bootloader_util_arm.c │ └── dfu_app_handler.c ├── nordic_global.h ├── nrf-sdk │ ├── app_common │ │ ├── app_button.h │ │ ├── app_error.h │ │ ├── app_fifo.h │ │ ├── app_gpiote.h │ │ ├── app_scheduler.h │ │ ├── app_timer.h │ │ ├── app_trace.h │ │ ├── app_uart.h │ │ ├── app_util.h │ │ ├── crc16.h │ │ ├── hal_transport.h │ │ ├── hci_mem_pool.h │ │ ├── hci_mem_pool_internal.h │ │ ├── hci_slip.h │ │ ├── hci_transport.h │ │ └── pstorage.h │ ├── ble │ │ ├── ble_advdata.h │ │ ├── ble_advdata_parser.h │ │ ├── ble_central_bondmngr.h │ │ ├── ble_conn_params.h │ │ ├── ble_date_time.h │ │ ├── ble_db_discovery.h │ │ ├── ble_debug_assert_handler.h │ │ ├── ble_dtm.h │ │ ├── ble_error_log.h │ │ ├── ble_flash.h │ │ ├── ble_racp.h │ │ ├── ble_radio_notification.h │ │ ├── ble_sensorsim.h │ │ ├── ble_services │ │ │ ├── ble_ans_c.h │ │ │ ├── ble_bas.h │ │ │ ├── ble_bas_c.h │ │ │ ├── ble_bps.h │ │ │ ├── ble_cscs.h │ │ │ ├── ble_dfu.h │ │ │ ├── ble_dis.h │ │ │ ├── ble_gls.h │ │ │ ├── ble_gls_db.h │ │ │ ├── ble_hids.h │ │ │ ├── ble_hrs.h │ │ │ ├── ble_hrs_c.h │ │ │ ├── ble_hts.h │ │ │ ├── ble_ias.h │ │ │ ├── ble_ias_c.h │ │ │ ├── ble_lls.h │ │ │ ├── ble_rscs.h │ │ │ ├── ble_sc_ctrlpt.h │ │ │ ├── ble_sensor_location.h │ │ │ ├── ble_srv_common.h │ │ │ └── ble_tps.h │ │ └── device_manager │ │ │ └── device_manager.h │ ├── bootloader_dfu │ │ ├── bootloader_types.h │ │ ├── bootloader_util.h │ │ └── dfu_app_handler.h │ ├── nordic_common.h │ ├── nrf_assert.h │ ├── nrf_delay.h │ ├── nrf_ecb.h │ ├── nrf_gpio.h │ ├── nrf_nvmc.h │ ├── nrf_temp.h │ ├── s110 │ │ ├── ble.h │ │ ├── ble_err.h │ │ ├── ble_gap.h │ │ ├── ble_gatt.h │ │ ├── ble_gattc.h │ │ ├── ble_gatts.h │ │ ├── ble_hci.h │ │ ├── ble_l2cap.h │ │ ├── ble_ranges.h │ │ ├── ble_types.h │ │ ├── nrf_error.h │ │ ├── nrf_error_sdm.h │ │ ├── nrf_error_soc.h │ │ ├── nrf_mbr.h │ │ ├── nrf_sdm.h │ │ ├── nrf_soc.h │ │ ├── nrf_svc.h │ │ └── softdevice_assert.h │ ├── sd_common │ │ ├── ant_stack_handler_types.h │ │ ├── app_util_platform.h │ │ ├── ble_stack_handler_types.h │ │ └── softdevice_handler.h │ └── system_nrf51.h ├── pstorage_platform.h └── softdevice_handler.cpp └── projectconfig.h /.github/workflows/sync_issues.yml: -------------------------------------------------------------------------------- 1 | name: Automate Issue Management 2 | 3 | on: 4 | issues: 5 | types: 6 | - opened 7 | - edited 8 | - assigned 9 | - unassigned 10 | - labeled 11 | - unlabeled 12 | - reopened 13 | 14 | jobs: 15 | add_issue_to_project: 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Add issue to GitHub Project 19 | uses: actions/add-to-project@v1.0.2 20 | with: 21 | project-url: https://github.com/orgs/Seeed-Studio/projects/17 22 | github-token: ${{ secrets.ISSUE_ASSEMBLE }} 23 | labeled: bug 24 | label-operator: NOT -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Compiled Dynamic libraries 8 | *.so 9 | *.dylib 10 | *.dll 11 | 12 | # Compiled Static libraries 13 | *.lai 14 | *.la 15 | *.a 16 | *.lib 17 | 18 | # Executables 19 | *.exe 20 | *.out 21 | *.app 22 | *.bin 23 | *.hex 24 | *.elf 25 | 26 | # hg 27 | *.hg 28 | *.hgignore 29 | -------------------------------------------------------------------------------- /BLE_API/common/BLEDevice.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "BLEDevice.h" 18 | 19 | #if defined(TARGET_OTA_ENABLED) 20 | #include "DFUService.h" 21 | #endif 22 | 23 | ble_error_t 24 | BLEDevice::init() 25 | { 26 | ble_error_t err = transport->init(); 27 | if (err != BLE_ERROR_NONE) { 28 | return err; 29 | } 30 | 31 | /* Platforms enabled for DFU should introduce the DFU Service into 32 | * applications automatically. */ 33 | #if defined(TARGET_OTA_ENABLED) 34 | static DFUService dfu(*this); // defined static so that the object remains alive 35 | #endif // TARGET_OTA_ENABLED 36 | 37 | return BLE_ERROR_NONE; 38 | } 39 | -------------------------------------------------------------------------------- /BLE_API/common/BLEDeviceInstanceBase.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __BLE_DEVICE_INSTANCE_BASE__ 18 | #define __BLE_DEVICE_INSTANCE_BASE__ 19 | 20 | /** 21 | * The interface for the transport object to be created by the target library's 22 | * createBLEDeviceInstance(). 23 | */ 24 | class BLEDeviceInstanceBase 25 | { 26 | public: 27 | virtual const char *getVersion(void) = 0; 28 | virtual Gap& getGap() = 0; 29 | virtual GattServer& getGattServer() = 0; 30 | virtual ble_error_t init(void) = 0; 31 | virtual ble_error_t reset(void) = 0; 32 | virtual ble_error_t setTxPower(int8_t txPower) = 0; 33 | virtual void waitForEvent(void) = 0; 34 | }; 35 | 36 | /** 37 | * BLEDevice uses composition to hide an interface object encapsulating the 38 | * backend transport. 39 | * 40 | * The following API is used to create the singleton interface object. An 41 | * implementation for this function must be provided by the device-specific 42 | * library, otherwise there will be a linker error. 43 | */ 44 | extern BLEDeviceInstanceBase *createBLEDeviceInstance(void); 45 | 46 | #endif // ifndef __BLE_DEVICE_INSTANCE_BASE__ 47 | -------------------------------------------------------------------------------- /BLE_API/common/GattService.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #include 19 | #include 20 | 21 | #include "GattService.h" 22 | 23 | /**************************************************************************/ 24 | /*! 25 | @brief Creates a new GattService using the specified 128-bit UUID 26 | 27 | @note The UUID value must be unique on the device 28 | 29 | @param[in] uuid 30 | The 16 byte (128-bit) UUID to use for this characteristic 31 | 32 | @section EXAMPLE 33 | 34 | @code 35 | 36 | @endcode 37 | */ 38 | /**************************************************************************/ 39 | GattService::GattService(const UUID &uuid, GattCharacteristic *characteristics[], unsigned numCharacteristics) : 40 | _primaryServiceID(uuid), _characteristicCount(numCharacteristics), _characteristics(characteristics), _handle(0) 41 | { 42 | /* empty */ 43 | } 44 | -------------------------------------------------------------------------------- /BLE_API/common/readme.txt: -------------------------------------------------------------------------------- 1 | These files are common to all implementations of the BLE_API. -------------------------------------------------------------------------------- /BLE_API/public/GapEvents.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __GAP_EVENTS_H__ 18 | #define __GAP_EVENTS_H__ 19 | 20 | #include "blecommon.h" 21 | #include "mbed.h" 22 | 23 | /**************************************************************************/ 24 | /*! 25 | \brief 26 | The base class used to abstract away the callback events that can be 27 | triggered with the GAP. 28 | */ 29 | /**************************************************************************/ 30 | class GapEvents 31 | { 32 | public: 33 | /******************************************************************/ 34 | /*! 35 | \brief 36 | Identifies GAP events generated by the radio HW when an event 37 | callback occurs 38 | */ 39 | /******************************************************************/ 40 | typedef enum gapEvent_e { 41 | GAP_EVENT_TIMEOUT = 1, /**< Advertising timed out before a connection was established */ 42 | GAP_EVENT_CONNECTED = 2, /**< A connection was established with a central device */ 43 | GAP_EVENT_DISCONNECTED = 3 /**< A connection was closed or lost with a central device */ 44 | } gapEvent_t; 45 | }; 46 | 47 | #endif // ifndef __GAP_EVENTS_H__ 48 | -------------------------------------------------------------------------------- /BLE_API/public/GattCharacteristicWriteCBParams.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__ 18 | #define __GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__ 19 | 20 | struct GattCharacteristicWriteCBParams { 21 | GattAttribute::Handle_t charHandle; 22 | enum Type { 23 | GATTS_CHAR_OP_INVALID = 0x00, /**< Invalid Operation. */ 24 | GATTS_CHAR_OP_WRITE_REQ = 0x01, /**< Write Request. */ 25 | GATTS_CHAR_OP_WRITE_CMD = 0x02, /**< Write Command. */ 26 | GATTS_CHAR_OP_SIGN_WRITE_CMD = 0x03, /**< Signed Write Command. */ 27 | GATTS_CHAR_OP_PREP_WRITE_REQ = 0x04, /**< Prepare Write Request. */ 28 | GATTS_CHAR_OP_EXEC_WRITE_REQ_CANCEL = 0x05, /**< Execute Write Request: Cancel all prepared writes. */ 29 | GATTS_CHAR_OP_EXEC_WRITE_REQ_NOW = 0x06, /**< Execute Write Request: Immediately execute all prepared writes. */ 30 | } op; /**< Type of write operation, */ 31 | uint16_t offset; /**< Offset for the write operation. */ 32 | uint16_t len; /**< Length of the incoming data. */ 33 | const uint8_t *data; /**< Incoming data, variable length. */ 34 | }; 35 | 36 | #endif /*__GATT_CHARACTERISTIC_WRITE_CB_PARAMS_H__*/ 37 | -------------------------------------------------------------------------------- /BLE_API/public/GattServerEvents.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __GATT_SERVER_EVENTS_H__ 18 | #define __GATT_SERVER_EVENTS_H__ 19 | 20 | #include "blecommon.h" 21 | #include "mbed.h" 22 | 23 | /**************************************************************************/ 24 | /*! 25 | \brief 26 | The base class used to abstract away the callback events that can be 27 | triggered with the GATT Server. 28 | */ 29 | /**************************************************************************/ 30 | class GattServerEvents 31 | { 32 | public: 33 | /******************************************************************/ 34 | /*! 35 | \brief 36 | Identifies GATT events generated by the radio HW when an event 37 | callback occurs 38 | */ 39 | /******************************************************************/ 40 | typedef enum gattEvent_e { 41 | GATT_EVENT_DATA_SENT = 1, /**< Fired when a msg was successfully sent out (notify only?) */ 42 | GATT_EVENT_DATA_WRITTEN = 2, /**< Client wrote data to Server (separate into char and descriptor writes?) */ 43 | GATT_EVENT_UPDATES_ENABLED = 3, /**< Notify/Indicate Enabled in CCCD */ 44 | GATT_EVENT_UPDATES_DISABLED = 4, /**< Notify/Indicate Disabled in CCCD */ 45 | GATT_EVENT_CONFIRMATION_RECEIVED = 5 /**< Response received from Indicate message */ 46 | } gattEvent_t; 47 | }; 48 | 49 | #endif // ifndef __GATT_SERVER_EVENTS_H__ 50 | -------------------------------------------------------------------------------- /BLE_API/public/UUID.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | 18 | #ifndef __UUID_H__ 19 | #define __UUID_H__ 20 | 21 | #include "blecommon.h" 22 | 23 | const unsigned LENGTH_OF_LONG_UUID = 16; 24 | typedef uint16_t ShortUUIDBytes_t; 25 | typedef uint8_t LongUUIDBytes_t[LENGTH_OF_LONG_UUID]; 26 | 27 | class UUID 28 | { 29 | public: 30 | enum { 31 | UUID_TYPE_SHORT = 0, // Short BLE UUID 32 | UUID_TYPE_LONG = 1 // Full 128-bit UUID 33 | }; 34 | 35 | public: 36 | UUID(const LongUUIDBytes_t); 37 | UUID(ShortUUIDBytes_t); 38 | virtual ~UUID(void); 39 | 40 | public: 41 | uint8_t shortOrLong(void) const { 42 | return type; 43 | } 44 | const uint8_t* getBaseUUID(void) const { 45 | return baseUUID; 46 | } 47 | ShortUUIDBytes_t getShortUUID(void) const { 48 | return shortUUID; 49 | } 50 | 51 | private: 52 | uint8_t type; // UUID_TYPE_SHORT or UUID_TYPE_LONG 53 | LongUUIDBytes_t baseUUID; /* the base of the long UUID (if 54 | * used). Note: bytes 12 and 13 (counting from LSB) 55 | * are zeroed out to allow comparison with other long 56 | * UUIDs which differ only in the 16-bit relative 57 | * part.*/ 58 | ShortUUIDBytes_t shortUUID; // 16 bit uuid (byte 2-3 using with base) 59 | }; 60 | 61 | #endif // ifndef __UUID_H__ 62 | -------------------------------------------------------------------------------- /BLE_API/public/readme.txt: -------------------------------------------------------------------------------- 1 | The public API exposed through header files. -------------------------------------------------------------------------------- /BLE_API/services/DFUService.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "DFUService.h" 18 | 19 | const uint8_t DFUServiceBaseUUID[] = { 20 | 0x00, 0x00, 0x00, 0x00, 0x12, 0x12, 0xEF, 0xDE, 21 | 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, 22 | }; 23 | const uint16_t DFUServiceShortUUID = 0x1530; 24 | const uint16_t DFUServiceControlCharacteristicShortUUID = 0x1531; 25 | const uint16_t DFUServicePacketCharacteristicShortUUID = 0x1532; 26 | 27 | const uint8_t DFUServiceUUID[] = { 28 | 0x00, 0x00, (uint8_t)(DFUServiceShortUUID >> 8), (uint8_t)(DFUServiceShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, 29 | 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, 30 | }; 31 | const uint8_t DFUServiceControlCharacteristicUUID[] = { 32 | 0x00, 0x00, (uint8_t)(DFUServiceControlCharacteristicShortUUID >> 8), (uint8_t)(DFUServiceControlCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, 33 | 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, 34 | }; 35 | const uint8_t DFUServicePacketCharacteristicUUID[] = { 36 | 0x00, 0x00, (uint8_t)(DFUServicePacketCharacteristicShortUUID >> 8), (uint8_t)(DFUServicePacketCharacteristicShortUUID & 0xFF), 0x12, 0x12, 0xEF, 0xDE, 37 | 0x15, 0x23, 0x78, 0x5F, 0xEA, 0xBC, 0xD1, 0x23, 38 | }; 39 | 40 | DFUService::ResetPrepare_t DFUService::handoverCallback = NULL; 41 | -------------------------------------------------------------------------------- /BLE_API/services/UARTService.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include "UARTService.h" 18 | 19 | const uint8_t UARTServiceBaseUUID[LENGTH_OF_LONG_UUID] = { 20 | 0x6E, 0x40, 0x00, 0x00, 0xB5, 0xA3, 0xF3, 0x93, 21 | 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, 22 | }; 23 | const uint16_t UARTServiceShortUUID = 0x0001; 24 | const uint16_t UARTServiceTXCharacteristicShortUUID = 0x0002; 25 | const uint16_t UARTServiceRXCharacteristicShortUUID = 0x0003; 26 | const uint8_t UARTServiceUUID[LENGTH_OF_LONG_UUID] = { 27 | 0x6E, 0x40, (uint8_t)(UARTServiceShortUUID >> 8), (uint8_t)(UARTServiceShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, 28 | 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, 29 | }; 30 | const uint8_t UARTServiceUUID_reversed[LENGTH_OF_LONG_UUID] = { 31 | 0x9E, 0xCA, 0xDC, 0x24, 0x0E, 0xE5, 0xA9, 0xE0, 32 | 0x93, 0xF3, 0xA3, 0xB5, (uint8_t)(UARTServiceShortUUID & 0xFF), (uint8_t)(UARTServiceShortUUID >> 8), 0x40, 0x6E 33 | }; 34 | const uint8_t UARTServiceTXCharacteristicUUID[LENGTH_OF_LONG_UUID] = { 35 | 0x6E, 0x40, (uint8_t)(UARTServiceTXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceTXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, 36 | 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, 37 | }; 38 | const uint8_t UARTServiceRXCharacteristicUUID[LENGTH_OF_LONG_UUID] = { 39 | 0x6E, 0x40, (uint8_t)(UARTServiceRXCharacteristicShortUUID >> 8), (uint8_t)(UARTServiceRXCharacteristicShortUUID & 0xFF), 0xB5, 0xA3, 0xF3, 0x93, 40 | 0xE0, 0xA9, 0xE5, 0x0E, 0x24, 0xDC, 0xCA, 0x9E, 41 | }; 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | mbed BLE 2 | ======== 3 | 4 | This repo contains mbed SDK, mbed BLE API and demos for nRF51822. The [gcc-arm-embedded][] toolchain is used. 5 | 6 | This branch uses Nordic SoftDevice V7. If you prefer to use SoftDevice V6, just use [softdevice_v6][] branch 7 | 8 | ### How To 9 | ``` 10 | git clone https://github.com/Seeed-Studio/mbed_ble.git 11 | cd mbed_ble/demos/ble_uart_loopback # or mbed_ble/demos/beacon 12 | make 13 | ``` 14 | 15 | To merge softdevice hex file and application hex file, please download srecord from http://srecord.sourceforge.net/. 16 | or if Ubuntu is used, run `sudo apt-get install srecord`. Then run: 17 | 18 | ``` 19 | make merge 20 | ``` 21 | 22 | The repo is licensed under [The Apache License](http://www.apache.org/licenses/LICENSE-2.0). 23 | 24 | Contributing to this software is warmly welcomed. You can do this basically by
25 | [forking](https://help.github.com/articles/fork-a-repo), committing modifications and then [pulling requests](https://help.github.com/articles/using-pull-requests) (follow the links above
26 | for operating guide). Adding change log and your contact into file header is encouraged.
27 | Thanks for your contribution. 28 | 29 | Seeedstudio is an open hardware facilitation company based in Shenzhen, China.
30 | Benefiting from local manufacture power and convenient global logistic system,
31 | we integrate resources to serve new era of innovation. Seeedstudio also works with
32 | global distributors and partners to push open hardware movement.
33 | 34 | 35 | [gcc-arm-embedded]: https://launchpad.net/gcc-arm-embedded 36 | [softdevice_v6]: https://github.com/Seeed-Studio/mbed_ble/tree/softdevice_v6 37 | 38 | [![Analytics](https://ga-beacon.appspot.com/UA-46589105-3/mbed_ble)](https://github.com/igrigorik/ga-beacon) 39 | -------------------------------------------------------------------------------- /demos/beacon/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROJECT = ble_beacon 4 | MBED_BLE = ../.. 5 | OBJECTS += main.o 6 | include $(MBED_BLE)/Makefile 7 | -------------------------------------------------------------------------------- /demos/ble_uart_loopback/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROJECT = ble_uart_loopback 4 | MBED_BLE = ../.. 5 | OBJECTS += main.o 6 | include $(MBED_BLE)/Makefile 7 | -------------------------------------------------------------------------------- /demos/color_pixels/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROJECT = ble_color_pixels 4 | MBED_BLE = ../.. 5 | OBJECTS += main.o $(MBED_BLE)/color_pixels/color_pixels.o 6 | INCLUDE_PATHS += -I$(MBED_BLE)/color_pixels 7 | 8 | include $(MBED_BLE)/Makefile 9 | 10 | # optimization for time is required by ../../color_pixels/color_pixels.cpp 11 | CC_FLAGS += -Ofast 12 | -------------------------------------------------------------------------------- /demos/grove_node/Makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | PROJECT = ble_grove_node 4 | MBED_BLE = ../.. 5 | OBJECTS += main.o power.o 6 | include $(MBED_BLE)/Makefile 7 | -------------------------------------------------------------------------------- /demos/grove_node/nrf_delay.h: -------------------------------------------------------------------------------- 1 | #ifndef _NRF_DELAY_H 2 | #define _NRF_DELAY_H 3 | 4 | #include "nrf51.h" 5 | 6 | /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */ 7 | #if defined ( __CC_ARM ) 8 | static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 9 | { 10 | loop 11 | SUBS R0, R0, #1 12 | NOP 13 | NOP 14 | NOP 15 | NOP 16 | NOP 17 | NOP 18 | NOP 19 | NOP 20 | NOP 21 | NOP 22 | NOP 23 | NOP 24 | BNE loop 25 | BX LR 26 | } 27 | #elif defined ( __ICCARM__ ) 28 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 29 | { 30 | __ASM ( 31 | "loop:\n\t" 32 | " SUBS R0, R0, #1\n\t" 33 | " NOP\n\t" 34 | " NOP\n\t" 35 | " NOP\n\t" 36 | " NOP\n\t" 37 | " NOP\n\t" 38 | " NOP\n\t" 39 | " NOP\n\t" 40 | " NOP\n\t" 41 | " NOP\n\t" 42 | " NOP\n\t" 43 | " NOP\n\t" 44 | " NOP\n\t" 45 | " BNE loop\n\t"); 46 | } 47 | #elif defined ( __GNUC__ ) 48 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 49 | { 50 | do 51 | { 52 | __ASM volatile ( 53 | "NOP\n\t" 54 | "NOP\n\t" 55 | "NOP\n\t" 56 | "NOP\n\t" 57 | "NOP\n\t" 58 | "NOP\n\t" 59 | "NOP\n\t" 60 | "NOP\n\t" 61 | "NOP\n\t" 62 | "NOP\n\t" 63 | "NOP\n\t" 64 | "NOP\n\t" 65 | "NOP\n\t" 66 | "NOP\n\t" 67 | ); 68 | } while (--number_of_us); 69 | } 70 | #endif 71 | 72 | void nrf_delay_ms(uint32_t volatile number_of_ms); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /demos/grove_node/power.c: -------------------------------------------------------------------------------- 1 | 2 | #include "nrf51.h" 3 | #include "nrf51_bitfields.h" 4 | 5 | #define POWER_PIN 8 6 | 7 | void power_on() 8 | { 9 | NRF_GPIO->PIN_CNF[POWER_PIN] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 10 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 11 | | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) 12 | | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) 13 | | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); 14 | NRF_GPIO->OUTSET = (1UL << POWER_PIN); 15 | } 16 | 17 | 18 | void power_down() 19 | { 20 | NRF_GPIO->OUTCLR = (1UL << POWER_PIN); 21 | 22 | // Enter system OFF. After wakeup the chip will be reset, and the MCU will run from the top 23 | NRF_POWER->SYSTEMOFF = 1; 24 | } 25 | -------------------------------------------------------------------------------- /mbed-src/api/BusIn.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_BUSIN_H 17 | #define MBED_BUSIN_H 18 | 19 | #include "platform.h" 20 | #include "DigitalIn.h" 21 | 22 | namespace mbed { 23 | 24 | /** A digital input bus, used for reading the state of a collection of pins 25 | */ 26 | class BusIn { 27 | 28 | public: 29 | /* Group: Configuration Methods */ 30 | 31 | /** Create an BusIn, connected to the specified pins 32 | * 33 | * @param DigitalIn pin to connect to bus bit (p5-p30, NC) 34 | * 35 | * @note 36 | * It is only required to specify as many pin variables as is required 37 | * for the bus; the rest will default to NC (not connected) 38 | */ 39 | BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC, 40 | PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC, 41 | PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC, 42 | PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC); 43 | 44 | BusIn(PinName pins[16]); 45 | 46 | virtual ~BusIn(); 47 | 48 | /** Read the value of the input bus 49 | * 50 | * @returns 51 | * An integer with each bit corresponding to the value read from the associated DigitalIn pin 52 | */ 53 | int read(); 54 | 55 | /** Set the input pin mode 56 | * 57 | * @param mode PullUp, PullDown, PullNone 58 | */ 59 | void mode(PinMode pull); 60 | 61 | #ifdef MBED_OPERATORS 62 | /** A shorthand for read() 63 | */ 64 | operator int(); 65 | #endif 66 | 67 | protected: 68 | DigitalIn* _pin[16]; 69 | 70 | /* disallow copy constructor and assignment operators */ 71 | private: 72 | BusIn(const BusIn&); 73 | BusIn & operator = (const BusIn&); 74 | }; 75 | 76 | } // namespace mbed 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /mbed-src/api/FileBase.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_FILEBASE_H 17 | #define MBED_FILEBASE_H 18 | 19 | typedef int FILEHANDLE; 20 | 21 | #include 22 | 23 | #if defined(__ARMCC_VERSION) || defined(__ICCARM__) 24 | # define O_RDONLY 0 25 | # define O_WRONLY 1 26 | # define O_RDWR 2 27 | # define O_CREAT 0x0200 28 | # define O_TRUNC 0x0400 29 | # define O_APPEND 0x0008 30 | 31 | # define NAME_MAX 255 32 | 33 | typedef int mode_t; 34 | typedef int ssize_t; 35 | typedef long off_t; 36 | 37 | #else 38 | # include 39 | # include 40 | # include 41 | #endif 42 | 43 | #include "platform.h" 44 | 45 | namespace mbed { 46 | 47 | typedef enum { 48 | FilePathType, 49 | FileSystemPathType 50 | } PathType; 51 | 52 | class FileBase { 53 | public: 54 | FileBase(const char *name, PathType t); 55 | 56 | virtual ~FileBase(); 57 | 58 | const char* getName(void); 59 | PathType getPathType(void); 60 | 61 | static FileBase *lookup(const char *name, unsigned int len); 62 | 63 | static FileBase *get(int n); 64 | 65 | protected: 66 | static FileBase *_head; 67 | 68 | FileBase *_next; 69 | const char *_name; 70 | PathType _path_type; 71 | 72 | /* disallow copy constructor and assignment operators */ 73 | private: 74 | FileBase(const FileBase&); 75 | FileBase & operator = (const FileBase&); 76 | }; 77 | 78 | } // namespace mbed 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /mbed-src/api/FileLike.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_FILELIKE_H 17 | #define MBED_FILELIKE_H 18 | 19 | #include "FileBase.h" 20 | #include "FileHandle.h" 21 | 22 | namespace mbed { 23 | 24 | /* Class FileLike 25 | * A file-like object is one that can be opened with fopen by 26 | * fopen("/name", mode). It is intersection of the classes Base and 27 | * FileHandle. 28 | */ 29 | class FileLike : public FileHandle, public FileBase { 30 | 31 | public: 32 | /* Constructor FileLike 33 | * 34 | * Variables 35 | * name - The name to use to open the file. 36 | */ 37 | FileLike(const char *name); 38 | 39 | virtual ~FileLike(); 40 | }; 41 | 42 | } // namespace mbed 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /mbed-src/api/FilePath.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_FILEPATH_H 17 | #define MBED_FILEPATH_H 18 | 19 | #include "platform.h" 20 | 21 | #include "FileSystemLike.h" 22 | #include "FileLike.h" 23 | 24 | namespace mbed { 25 | 26 | class FilePath { 27 | public: 28 | FilePath(const char* file_path); 29 | 30 | const char* fileName(void); 31 | 32 | bool isFileSystem(void); 33 | FileSystemLike* fileSystem(void); 34 | 35 | bool isFile(void); 36 | FileLike* file(void); 37 | bool exists(void); 38 | 39 | private: 40 | const char* file_name; 41 | FileBase* fb; 42 | }; 43 | 44 | } // namespace mbed 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /mbed-src/api/PortIn.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PORTIN_H 17 | #define MBED_PORTIN_H 18 | 19 | #include "platform.h" 20 | 21 | #if DEVICE_PORTIN 22 | 23 | #include "port_api.h" 24 | 25 | namespace mbed { 26 | 27 | /** A multiple pin digital input 28 | * 29 | * Example: 30 | * @code 31 | * // Switch on an LED if any of mbed pins 21-26 is high 32 | * 33 | * #include "mbed.h" 34 | * 35 | * PortIn p(Port2, 0x0000003F); // p21-p26 36 | * DigitalOut ind(LED4); 37 | * 38 | * int main() { 39 | * while(1) { 40 | * int pins = p.read(); 41 | * if(pins) { 42 | * ind = 1; 43 | * } else { 44 | * ind = 0; 45 | * } 46 | * } 47 | * } 48 | * @endcode 49 | */ 50 | class PortIn { 51 | public: 52 | 53 | /** Create an PortIn, connected to the specified port 54 | * 55 | * @param port Port to connect to (Port0-Port5) 56 | * @param mask A bitmask to identify which bits in the port should be included (0 - ignore) 57 | */ 58 | PortIn(PortName port, int mask = 0xFFFFFFFF) { 59 | port_init(&_port, port, mask, PIN_INPUT); 60 | } 61 | 62 | /** Read the value currently output on the port 63 | * 64 | * @returns 65 | * An integer with each bit corresponding to associated port pin setting 66 | */ 67 | int read() { 68 | return port_read(&_port); 69 | } 70 | 71 | /** Set the input pin mode 72 | * 73 | * @param mode PullUp, PullDown, PullNone, OpenDrain 74 | */ 75 | void mode(PinMode mode) { 76 | port_mode(&_port, mode); 77 | } 78 | 79 | /** A shorthand for read() 80 | */ 81 | operator int() { 82 | return read(); 83 | } 84 | 85 | private: 86 | port_t _port; 87 | }; 88 | 89 | } // namespace mbed 90 | 91 | #endif 92 | 93 | #endif 94 | -------------------------------------------------------------------------------- /mbed-src/api/Serial.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_SERIAL_H 17 | #define MBED_SERIAL_H 18 | 19 | #include "platform.h" 20 | 21 | #if DEVICE_SERIAL 22 | 23 | #include "Stream.h" 24 | #include "SerialBase.h" 25 | #include "serial_api.h" 26 | 27 | namespace mbed { 28 | 29 | /** A serial port (UART) for communication with other serial devices 30 | * 31 | * Can be used for Full Duplex communication, or Simplex by specifying 32 | * one pin as NC (Not Connected) 33 | * 34 | * Example: 35 | * @code 36 | * // Print "Hello World" to the PC 37 | * 38 | * #include "mbed.h" 39 | * 40 | * Serial pc(USBTX, USBRX); 41 | * 42 | * int main() { 43 | * pc.printf("Hello World\n"); 44 | * } 45 | * @endcode 46 | */ 47 | class Serial : public SerialBase, public Stream { 48 | 49 | public: 50 | /** Create a Serial port, connected to the specified transmit and receive pins 51 | * 52 | * @param tx Transmit pin 53 | * @param rx Receive pin 54 | * 55 | * @note 56 | * Either tx or rx may be specified as NC if unused 57 | */ 58 | Serial(PinName tx, PinName rx, const char *name=NULL); 59 | 60 | protected: 61 | virtual int _getc(); 62 | virtual int _putc(int c); 63 | }; 64 | 65 | } // namespace mbed 66 | 67 | #endif 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /mbed-src/api/Stream.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_STREAM_H 17 | #define MBED_STREAM_H 18 | 19 | #include "platform.h" 20 | #include "FileLike.h" 21 | 22 | namespace mbed { 23 | 24 | class Stream : public FileLike { 25 | 26 | public: 27 | Stream(const char *name=NULL); 28 | virtual ~Stream(); 29 | 30 | int putc(int c); 31 | int puts(const char *s); 32 | int getc(); 33 | char *gets(char *s, int size); 34 | int printf(const char* format, ...); 35 | int scanf(const char* format, ...); 36 | 37 | operator std::FILE*() {return _file;} 38 | 39 | protected: 40 | virtual int close(); 41 | virtual ssize_t write(const void* buffer, size_t length); 42 | virtual ssize_t read(void* buffer, size_t length); 43 | virtual off_t lseek(off_t offset, int whence); 44 | virtual int isatty(); 45 | virtual int fsync(); 46 | virtual off_t flen(); 47 | 48 | virtual int _putc(int c) = 0; 49 | virtual int _getc() = 0; 50 | 51 | std::FILE *_file; 52 | 53 | /* disallow copy constructor and assignment operators */ 54 | private: 55 | Stream(const Stream&); 56 | Stream & operator = (const Stream&); 57 | }; 58 | 59 | } // namespace mbed 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /mbed-src/api/Timeout.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_TIMEOUT_H 17 | #define MBED_TIMEOUT_H 18 | 19 | #include "Ticker.h" 20 | 21 | namespace mbed { 22 | 23 | /** A Timeout is used to call a function at a point in the future 24 | * 25 | * You can use as many seperate Timeout objects as you require. 26 | * 27 | * Example: 28 | * @code 29 | * // Blink until timeout. 30 | * 31 | * #include "mbed.h" 32 | * 33 | * Timeout timeout; 34 | * DigitalOut led(LED1); 35 | * 36 | * int on = 1; 37 | * 38 | * void attimeout() { 39 | * on = 0; 40 | * } 41 | * 42 | * int main() { 43 | * timeout.attach(&attimeout, 5); 44 | * while(on) { 45 | * led = !led; 46 | * wait(0.2); 47 | * } 48 | * } 49 | * @endcode 50 | */ 51 | class Timeout : public Ticker { 52 | 53 | protected: 54 | virtual void handler(); 55 | }; 56 | 57 | } // namespace mbed 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /mbed-src/api/Timer.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_TIMER_H 17 | #define MBED_TIMER_H 18 | 19 | #include "platform.h" 20 | 21 | namespace mbed { 22 | 23 | /** A general purpose timer 24 | * 25 | * Example: 26 | * @code 27 | * // Count the time to toggle a LED 28 | * 29 | * #include "mbed.h" 30 | * 31 | * Timer timer; 32 | * DigitalOut led(LED1); 33 | * int begin, end; 34 | * 35 | * int main() { 36 | * timer.start(); 37 | * begin = timer.read_us(); 38 | * led = !led; 39 | * end = timer.read_us(); 40 | * printf("Toggle the led takes %d us", end - begin); 41 | * } 42 | * @endcode 43 | */ 44 | class Timer { 45 | 46 | public: 47 | Timer(); 48 | 49 | /** Start the timer 50 | */ 51 | void start(); 52 | 53 | /** Stop the timer 54 | */ 55 | void stop(); 56 | 57 | /** Reset the timer to 0. 58 | * 59 | * If it was already counting, it will continue 60 | */ 61 | void reset(); 62 | 63 | /** Get the time passed in seconds 64 | */ 65 | float read(); 66 | 67 | /** Get the time passed in mili-seconds 68 | */ 69 | int read_ms(); 70 | 71 | /** Get the time passed in micro-seconds 72 | */ 73 | int read_us(); 74 | 75 | #ifdef MBED_OPERATORS 76 | operator float(); 77 | #endif 78 | 79 | protected: 80 | int slicetime(); 81 | int _running; // whether the timer is running 82 | unsigned int _start; // the start time of the latest slice 83 | int _time; // any accumulated time from previous slices 84 | }; 85 | 86 | } // namespace mbed 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /mbed-src/api/TimerEvent.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_TIMEREVENT_H 17 | #define MBED_TIMEREVENT_H 18 | 19 | #include "us_ticker_api.h" 20 | 21 | namespace mbed { 22 | 23 | /** Base abstraction for timer interrupts 24 | */ 25 | class TimerEvent { 26 | public: 27 | TimerEvent(); 28 | 29 | /** The handler registered with the underlying timer interrupt 30 | */ 31 | static void irq(uint32_t id); 32 | 33 | /** Destruction removes it... 34 | */ 35 | virtual ~TimerEvent(); 36 | 37 | protected: 38 | // The handler called to service the timer event of the derived class 39 | virtual void handler() = 0; 40 | 41 | // insert in to linked list 42 | void insert(timestamp_t timestamp); 43 | 44 | // remove from linked list, if in it 45 | void remove(); 46 | 47 | ticker_event_t event; 48 | }; 49 | 50 | } // namespace mbed 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /mbed-src/api/can_helper.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_CAN_HELPER_H 17 | #define MBED_CAN_HELPER_H 18 | 19 | #if DEVICE_CAN 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | enum CANFormat { 26 | CANStandard = 0, 27 | CANExtended = 1, 28 | CANAny = 2 29 | }; 30 | typedef enum CANFormat CANFormat; 31 | 32 | enum CANType { 33 | CANData = 0, 34 | CANRemote = 1 35 | }; 36 | typedef enum CANType CANType; 37 | 38 | struct CAN_Message { 39 | unsigned int id; // 29 bit identifier 40 | unsigned char data[8]; // Data field 41 | unsigned char len; // Length of data field in bytes 42 | CANFormat format; // 0 - STANDARD, 1- EXTENDED IDENTIFIER 43 | CANType type; // 0 - DATA FRAME, 1 - REMOTE FRAME 44 | }; 45 | typedef struct CAN_Message CAN_Message; 46 | 47 | #ifdef __cplusplus 48 | }; 49 | #endif 50 | 51 | #endif 52 | 53 | #endif // MBED_CAN_HELPER_H 54 | -------------------------------------------------------------------------------- /mbed-src/api/mbed.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_H 17 | #define MBED_H 18 | 19 | #define MBED_LIBRARY_VERSION 89 20 | 21 | #include "platform.h" 22 | 23 | // Useful C libraries 24 | #include 25 | #include 26 | 27 | // mbed Debug libraries 28 | #include "mbed_error.h" 29 | #include "mbed_interface.h" 30 | 31 | // mbed Peripheral components 32 | #include "DigitalIn.h" 33 | #include "DigitalOut.h" 34 | #include "DigitalInOut.h" 35 | #include "BusIn.h" 36 | #include "BusOut.h" 37 | #include "BusInOut.h" 38 | #include "PortIn.h" 39 | #include "PortInOut.h" 40 | #include "PortOut.h" 41 | #include "AnalogIn.h" 42 | #include "AnalogOut.h" 43 | #include "PwmOut.h" 44 | #include "Serial.h" 45 | #include "SPI.h" 46 | #include "SPISlave.h" 47 | #include "I2C.h" 48 | #include "I2CSlave.h" 49 | #include "Ethernet.h" 50 | #include "CAN.h" 51 | #include "RawSerial.h" 52 | 53 | // mbed Internal components 54 | #include "Timer.h" 55 | #include "Ticker.h" 56 | #include "Timeout.h" 57 | #include "LocalFileSystem.h" 58 | #include "InterruptIn.h" 59 | #include "wait_api.h" 60 | #include "sleep_api.h" 61 | #include "rtc_time.h" 62 | 63 | using namespace mbed; 64 | using namespace std; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /mbed-src/api/mbed_assert.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_ASSERT_H 17 | #define MBED_ASSERT_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** Internal mbed assert function which is invoked when MBED_ASSERT macro failes. 24 | * This function is active only if NDEBUG is not defined prior to including this 25 | * assert header file. 26 | * In case of MBED_ASSERT failing condition, the assertation message is printed 27 | * to stderr and mbed_die() is called. 28 | * @param expr Expresion to be checked. 29 | * @param file File where assertation failed. 30 | * @param line Failing assertation line number. 31 | */ 32 | void mbed_assert_internal(const char *expr, const char *file, int line); 33 | 34 | #ifdef __cplusplus 35 | } 36 | #endif 37 | 38 | #ifdef NDEBUG 39 | #define MBED_ASSERT(expr) ((void)0) 40 | 41 | #else 42 | #define MBED_ASSERT(expr) \ 43 | do { \ 44 | if (!(expr)) { \ 45 | mbed_assert_internal(#expr, __FILE__, __LINE__); \ 46 | } \ 47 | } while (0) 48 | #endif 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /mbed-src/api/mbed_debug.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_DEBUG_H 17 | #define MBED_DEBUG_H 18 | #include "device.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #if DEVICE_STDIO_MESSAGES 25 | #include 26 | #include 27 | 28 | /** Output a debug message 29 | * 30 | * @param format printf-style format string, followed by variables 31 | */ 32 | static inline void debug(const char *format, ...) { 33 | va_list args; 34 | va_start(args, format); 35 | vfprintf(stderr, format, args); 36 | va_end(args); 37 | } 38 | 39 | /** Conditionally output a debug message 40 | * 41 | * NOTE: If the condition is constant false (!= 1) and the compiler optimization 42 | * level is greater than 0, then the whole function will be compiled away. 43 | * 44 | * @param condition output only if condition is true (== 1) 45 | * @param format printf-style format string, followed by variables 46 | */ 47 | static inline void debug_if(int condition, const char *format, ...) { 48 | if (condition == 1) { 49 | va_list args; 50 | va_start(args, format); 51 | vfprintf(stderr, format, args); 52 | va_end(args); 53 | } 54 | } 55 | 56 | #else 57 | static inline void debug(const char *format, ...) {} 58 | static inline void debug_if(int condition, const char *format, ...) {} 59 | 60 | #endif 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /mbed-src/api/mbed_error.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_ERROR_H 17 | #define MBED_ERROR_H 18 | 19 | /** To generate a fatal compile-time error, you can use the pre-processor #error directive. 20 | * 21 | * @code 22 | * #error "That shouldn't have happened!" 23 | * @endcode 24 | * 25 | * If the compiler evaluates this line, it will report the error and stop the compile. 26 | * 27 | * For example, you could use this to check some user-defined compile-time variables: 28 | * 29 | * @code 30 | * #define NUM_PORTS 7 31 | * #if (NUM_PORTS > 4) 32 | * #error "NUM_PORTS must be less than 4" 33 | * #endif 34 | * @endcode 35 | * 36 | * Reporting Run-Time Errors: 37 | * To generate a fatal run-time error, you can use the mbed error() function. 38 | * 39 | * @code 40 | * error("That shouldn't have happened!"); 41 | * @endcode 42 | * 43 | * If the mbed running the program executes this function, it will print the 44 | * message via the USB serial port, and then die with the blue lights of death! 45 | * 46 | * The message can use printf-style formatting, so you can report variables in the 47 | * message too. For example, you could use this to check a run-time condition: 48 | * 49 | * @code 50 | * if(x >= 5) { 51 | * error("expected x to be less than 5, but got %d", x); 52 | * } 53 | * #endcode 54 | */ 55 | 56 | #ifdef __cplusplus 57 | extern "C" { 58 | #endif 59 | 60 | void error(const char* format, ...); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /mbed-src/api/platform.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PLATFORM_H 17 | #define MBED_PLATFORM_H 18 | 19 | #define MBED_OPERATORS 1 20 | 21 | #include "device.h" 22 | #include "PinNames.h" 23 | #include "PeripheralNames.h" 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /mbed-src/api/rtc_time.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** Implementation of the C time.h functions 24 | * 25 | * Provides mechanisms to set and read the current time, based 26 | * on the microcontroller Real-Time Clock (RTC), plus some 27 | * standard C manipulation and formating functions. 28 | * 29 | * Example: 30 | * @code 31 | * #include "mbed.h" 32 | * 33 | * int main() { 34 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 35 | * 36 | * while(1) { 37 | * time_t seconds = time(NULL); 38 | * 39 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); 40 | * 41 | * printf("Time as a basic string = %s", ctime(&seconds)); 42 | * 43 | * char buffer[32]; 44 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); 45 | * printf("Time as a custom formatted string = %s", buffer); 46 | * 47 | * wait(1); 48 | * } 49 | * } 50 | * @endcode 51 | */ 52 | 53 | /** Set the current time 54 | * 55 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) 56 | * to the time represented by the number of seconds since January 1, 1970 57 | * (the UNIX timestamp). 58 | * 59 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) 60 | * 61 | * Example: 62 | * @code 63 | * #include "mbed.h" 64 | * 65 | * int main() { 66 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 67 | * } 68 | * @endcode 69 | */ 70 | void set_time(time_t t); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | -------------------------------------------------------------------------------- /mbed-src/api/toolchain.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_TOOLCHAIN_H 17 | #define MBED_TOOLCHAIN_H 18 | 19 | #if defined(TOOLCHAIN_ARM) 20 | #include 21 | #endif 22 | 23 | #ifndef FILEHANDLE 24 | typedef int FILEHANDLE; 25 | #endif 26 | 27 | #if defined (__ICCARM__) 28 | # define WEAK __weak 29 | # define PACKED __packed 30 | #else 31 | # define WEAK __attribute__((weak)) 32 | # define PACKED __attribute__((packed)) 33 | #endif 34 | 35 | #endif 36 | -------------------------------------------------------------------------------- /mbed-src/api/wait_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_WAIT_API_H 17 | #define MBED_WAIT_API_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | /** Generic wait functions. 24 | * 25 | * These provide simple NOP type wait capabilities. 26 | * 27 | * Example: 28 | * @code 29 | * #include "mbed.h" 30 | * 31 | * DigitalOut heartbeat(LED1); 32 | * 33 | * int main() { 34 | * while (1) { 35 | * heartbeat = 1; 36 | * wait(0.5); 37 | * heartbeat = 0; 38 | * wait(0.5); 39 | * } 40 | * } 41 | */ 42 | 43 | /** Waits for a number of seconds, with microsecond resolution (within 44 | * the accuracy of single precision floating point). 45 | * 46 | * @param s number of seconds to wait 47 | */ 48 | void wait(float s); 49 | 50 | /** Waits a number of milliseconds. 51 | * 52 | * @param ms the whole number of milliseconds to wait 53 | */ 54 | void wait_ms(int ms); 55 | 56 | /** Waits a number of microseconds. 57 | * 58 | * @param us the whole number of microseconds to wait 59 | */ 60 | void wait_us(int us); 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /mbed-src/common/BusIn.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "BusIn.h" 17 | 18 | namespace mbed { 19 | 20 | BusIn::BusIn(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) { 21 | PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15}; 22 | 23 | for (int i=0; i<16; i++) { 24 | _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0; 25 | } 26 | } 27 | 28 | BusIn::BusIn(PinName pins[16]) { 29 | for (int i=0; i<16; i++) { 30 | _pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0; 31 | } 32 | } 33 | 34 | BusIn::~BusIn() { 35 | for (int i=0; i<16; i++) { 36 | if (_pin[i] != 0) { 37 | delete _pin[i]; 38 | } 39 | } 40 | } 41 | 42 | int BusIn::read() { 43 | int v = 0; 44 | for (int i=0; i<16; i++) { 45 | if (_pin[i] != 0) { 46 | v |= _pin[i]->read() << i; 47 | } 48 | } 49 | return v; 50 | } 51 | 52 | void BusIn::mode(PinMode pull) { 53 | for (int i=0; i<16; i++) { 54 | if (_pin[i] != 0) { 55 | _pin[i]->mode(pull); 56 | } 57 | } 58 | } 59 | 60 | #ifdef MBED_OPERATORS 61 | BusIn::operator int() { 62 | return read(); 63 | } 64 | #endif 65 | 66 | } // namespace mbed 67 | -------------------------------------------------------------------------------- /mbed-src/common/BusOut.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "BusOut.h" 17 | 18 | namespace mbed { 19 | 20 | BusOut::BusOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) { 21 | PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15}; 22 | 23 | for (int i=0; i<16; i++) { 24 | _pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0; 25 | } 26 | } 27 | 28 | BusOut::BusOut(PinName pins[16]) { 29 | for (int i=0; i<16; i++) { 30 | _pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0; 31 | } 32 | } 33 | 34 | BusOut::~BusOut() { 35 | for (int i=0; i<16; i++) { 36 | if (_pin[i] != 0) { 37 | delete _pin[i]; 38 | } 39 | } 40 | } 41 | 42 | void BusOut::write(int value) { 43 | for (int i=0; i<16; i++) { 44 | if (_pin[i] != 0) { 45 | _pin[i]->write((value >> i) & 1); 46 | } 47 | } 48 | } 49 | 50 | int BusOut::read() { 51 | int v = 0; 52 | for (int i=0; i<16; i++) { 53 | if (_pin[i] != 0) { 54 | v |= _pin[i]->read() << i; 55 | } 56 | } 57 | return v; 58 | } 59 | 60 | #ifdef MBED_OPERATORS 61 | BusOut& BusOut::operator= (int v) { 62 | write(v); 63 | return *this; 64 | } 65 | 66 | BusOut& BusOut::operator= (BusOut& rhs) { 67 | write(rhs.read()); 68 | return *this; 69 | } 70 | 71 | BusOut::operator int() { 72 | return read(); 73 | } 74 | #endif 75 | 76 | } // namespace mbed 77 | -------------------------------------------------------------------------------- /mbed-src/common/CAN.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "CAN.h" 17 | 18 | #if DEVICE_CAN 19 | 20 | #include "cmsis.h" 21 | 22 | namespace mbed { 23 | 24 | CAN::CAN(PinName rd, PinName td) : _can(), _irq() { 25 | can_init(&_can, rd, td); 26 | can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this); 27 | } 28 | 29 | CAN::~CAN() { 30 | can_irq_free(&_can); 31 | can_free(&_can); 32 | } 33 | 34 | int CAN::frequency(int f) { 35 | return can_frequency(&_can, f); 36 | } 37 | 38 | int CAN::write(CANMessage msg) { 39 | return can_write(&_can, msg, 0); 40 | } 41 | 42 | int CAN::read(CANMessage &msg, int handle) { 43 | return can_read(&_can, &msg, handle); 44 | } 45 | 46 | void CAN::reset() { 47 | can_reset(&_can); 48 | } 49 | 50 | unsigned char CAN::rderror() { 51 | return can_rderror(&_can); 52 | } 53 | 54 | unsigned char CAN::tderror() { 55 | return can_tderror(&_can); 56 | } 57 | 58 | void CAN::monitor(bool silent) { 59 | can_monitor(&_can, (silent) ? 1 : 0); 60 | } 61 | 62 | int CAN::mode(Mode mode) { 63 | return can_mode(&_can, (CanMode)mode); 64 | } 65 | 66 | int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) { 67 | return can_filter(&_can, id, mask, format, handle); 68 | } 69 | 70 | void CAN::attach(void (*fptr)(void), IrqType type) { 71 | if (fptr) { 72 | _irq[(CanIrqType)type].attach(fptr); 73 | can_irq_set(&_can, (CanIrqType)type, 1); 74 | } else { 75 | can_irq_set(&_can, (CanIrqType)type, 0); 76 | } 77 | } 78 | 79 | void CAN::_irq_handler(uint32_t id, CanIrqType type) { 80 | CAN *handler = (CAN*)id; 81 | handler->_irq[type].call(); 82 | } 83 | 84 | } // namespace mbed 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /mbed-src/common/CallChain.cpp: -------------------------------------------------------------------------------- 1 | #include "CallChain.h" 2 | #include "cmsis.h" 3 | 4 | namespace mbed { 5 | 6 | CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) { 7 | _chain = new pFunctionPointer_t[size](); 8 | } 9 | 10 | CallChain::~CallChain() { 11 | clear(); 12 | delete _chain; 13 | } 14 | 15 | pFunctionPointer_t CallChain::add(void (*function)(void)) { 16 | return common_add(new FunctionPointer(function)); 17 | } 18 | 19 | pFunctionPointer_t CallChain::add_front(void (*function)(void)) { 20 | return common_add_front(new FunctionPointer(function)); 21 | } 22 | 23 | int CallChain::size() const { 24 | return _elements; 25 | } 26 | 27 | pFunctionPointer_t CallChain::get(int i) const { 28 | if (i < 0 || i >= _elements) 29 | return NULL; 30 | return _chain[i]; 31 | } 32 | 33 | int CallChain::find(pFunctionPointer_t f) const { 34 | for (int i = 0; i < _elements; i++) 35 | if (f == _chain[i]) 36 | return i; 37 | return -1; 38 | } 39 | 40 | void CallChain::clear() { 41 | for(int i = 0; i < _elements; i ++) { 42 | delete _chain[i]; 43 | _chain[i] = NULL; 44 | } 45 | _elements = 0; 46 | } 47 | 48 | bool CallChain::remove(pFunctionPointer_t f) { 49 | int i; 50 | 51 | if ((i = find(f)) == -1) 52 | return false; 53 | if (i != _elements - 1) 54 | memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t)); 55 | delete f; 56 | _elements --; 57 | return true; 58 | } 59 | 60 | void CallChain::call() { 61 | for(int i = 0; i < _elements; i++) 62 | _chain[i]->call(); 63 | } 64 | 65 | void CallChain::_check_size() { 66 | if (_elements < _size) 67 | return; 68 | _size = (_size < 4) ? 4 : _size + 4; 69 | pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size](); 70 | memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t)); 71 | delete _chain; 72 | _chain = new_chain; 73 | } 74 | 75 | pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { 76 | _check_size(); 77 | _chain[_elements] = pf; 78 | _elements ++; 79 | return pf; 80 | } 81 | 82 | pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) { 83 | _check_size(); 84 | memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t)); 85 | _chain[0] = pf; 86 | _elements ++; 87 | return pf; 88 | } 89 | 90 | } // namespace mbed 91 | -------------------------------------------------------------------------------- /mbed-src/common/Ethernet.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Ethernet.h" 17 | 18 | #if DEVICE_ETHERNET 19 | 20 | #include "ethernet_api.h" 21 | 22 | namespace mbed { 23 | 24 | Ethernet::Ethernet() { 25 | ethernet_init(); 26 | } 27 | 28 | Ethernet::~Ethernet() { 29 | ethernet_free(); 30 | } 31 | 32 | int Ethernet::write(const char *data, int size) { 33 | return ethernet_write(data, size); 34 | } 35 | 36 | int Ethernet::send() { 37 | return ethernet_send(); 38 | } 39 | 40 | int Ethernet::receive() { 41 | return ethernet_receive(); 42 | } 43 | 44 | int Ethernet::read(char *data, int size) { 45 | return ethernet_read(data, size); 46 | } 47 | 48 | void Ethernet::address(char *mac) { 49 | return ethernet_address(mac); 50 | } 51 | 52 | int Ethernet::link() { 53 | return ethernet_link(); 54 | } 55 | 56 | void Ethernet::set_link(Mode mode) { 57 | int speed = -1; 58 | int duplex = 0; 59 | 60 | switch(mode) { 61 | case AutoNegotiate : speed = -1; duplex = 0; break; 62 | case HalfDuplex10 : speed = 0; duplex = 0; break; 63 | case FullDuplex10 : speed = 0; duplex = 1; break; 64 | case HalfDuplex100 : speed = 1; duplex = 0; break; 65 | case FullDuplex100 : speed = 1; duplex = 1; break; 66 | } 67 | 68 | ethernet_set_link(speed, duplex); 69 | } 70 | 71 | } // namespace mbed 72 | 73 | #endif 74 | -------------------------------------------------------------------------------- /mbed-src/common/FileLike.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "FileLike.h" 17 | 18 | namespace mbed { 19 | 20 | FileLike::FileLike(const char *name) : FileHandle(), FileBase(name, FilePathType) { 21 | 22 | } 23 | 24 | FileLike::~FileLike() { 25 | 26 | } 27 | 28 | } // namespace mbed 29 | -------------------------------------------------------------------------------- /mbed-src/common/FilePath.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "FilePath.h" 17 | 18 | namespace mbed { 19 | 20 | FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) { 21 | if ((file_path[0] != '/') || (file_path[1] == 0)) return; 22 | 23 | const char* file_system = &file_path[1]; 24 | file_name = file_system; 25 | int len = 0; 26 | while (true) { 27 | char c = *file_name; 28 | if (c == '/') { // end of object name 29 | file_name++; // point to one char after the '/' 30 | break; 31 | } 32 | if (c == 0) { // end of object name, with no filename 33 | break; 34 | } 35 | len++; 36 | file_name++; 37 | } 38 | 39 | fb = FileBase::lookup(file_system, len); 40 | } 41 | 42 | const char* FilePath::fileName(void) { 43 | return file_name; 44 | } 45 | 46 | bool FilePath::isFileSystem(void) { 47 | if (NULL == fb) 48 | return false; 49 | return (fb->getPathType() == FileSystemPathType); 50 | } 51 | 52 | FileSystemLike* FilePath::fileSystem(void) { 53 | if (isFileSystem()) { 54 | return (FileSystemLike*)fb; 55 | } 56 | return NULL; 57 | } 58 | 59 | bool FilePath::isFile(void) { 60 | if (NULL == fb) 61 | return false; 62 | return (fb->getPathType() == FilePathType); 63 | } 64 | 65 | FileLike* FilePath::file(void) { 66 | if (isFile()) { 67 | return (FileLike*)fb; 68 | } 69 | return NULL; 70 | } 71 | 72 | bool FilePath::exists(void) { 73 | return fb != NULL; 74 | } 75 | 76 | } // namespace mbed 77 | -------------------------------------------------------------------------------- /mbed-src/common/FileSystemLike.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "FileSystemLike.h" 17 | 18 | namespace mbed { 19 | 20 | class BaseDirHandle : public DirHandle { 21 | public: 22 | /* 23 | We keep track of our current location as the n'th object in the 24 | FileSystemLike list. Using a Base* instead would cause problems if that 25 | object were to be destroyed between readdirs. 26 | Using this method does mean though that destroying/creating objects can 27 | give unusual results from readdir. 28 | */ 29 | off_t n; 30 | struct dirent cur_entry; 31 | 32 | BaseDirHandle() : n(0), cur_entry() { 33 | } 34 | 35 | virtual int closedir() { 36 | delete this; 37 | return 0; 38 | } 39 | 40 | virtual struct dirent *readdir() { 41 | FileBase *ptr = FileBase::get(n); 42 | if (ptr == NULL) return NULL; 43 | 44 | /* Increment n, so next readdir gets the next item */ 45 | n++; 46 | 47 | /* Setup cur entry and return a pointer to it */ 48 | std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX); 49 | return &cur_entry; 50 | } 51 | 52 | virtual off_t telldir() { 53 | return n; 54 | } 55 | 56 | virtual void seekdir(off_t offset) { 57 | n = offset; 58 | } 59 | 60 | virtual void rewinddir() { 61 | n = 0; 62 | } 63 | }; 64 | 65 | FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) { 66 | 67 | } 68 | 69 | FileSystemLike::~FileSystemLike() { 70 | 71 | } 72 | 73 | DirHandle *FileSystemLike::opendir() { 74 | return new BaseDirHandle(); 75 | } 76 | 77 | } // namespace mbed 78 | -------------------------------------------------------------------------------- /mbed-src/common/FunctionPointer.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "FunctionPointer.h" 17 | 18 | namespace mbed { 19 | 20 | FunctionPointer::FunctionPointer(void (*function)(void)): _function(), 21 | _object(), 22 | _membercaller() { 23 | attach(function); 24 | } 25 | 26 | void FunctionPointer::attach(void (*function)(void)) { 27 | _function = function; 28 | _object = 0; 29 | } 30 | 31 | void FunctionPointer::call(void) { 32 | if (_function) { 33 | _function(); 34 | } else if (_object) { 35 | _membercaller(_object, _member); 36 | } 37 | } 38 | 39 | #ifdef MBED_OPERATORS 40 | void FunctionPointer::operator ()(void) { 41 | call(); 42 | } 43 | #endif 44 | 45 | } // namespace mbed 46 | -------------------------------------------------------------------------------- /mbed-src/common/I2CSlave.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "I2CSlave.h" 17 | 18 | #if DEVICE_I2CSLAVE 19 | 20 | namespace mbed { 21 | 22 | I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() { 23 | i2c_init(&_i2c, sda, scl); 24 | i2c_frequency(&_i2c, 100000); 25 | i2c_slave_mode(&_i2c, 1); 26 | } 27 | 28 | void I2CSlave::frequency(int hz) { 29 | i2c_frequency(&_i2c, hz); 30 | } 31 | 32 | void I2CSlave::address(int address) { 33 | int addr = (address & 0xFF) | 1; 34 | i2c_slave_address(&_i2c, 0, addr, 0); 35 | } 36 | 37 | int I2CSlave::receive(void) { 38 | return i2c_slave_receive(&_i2c); 39 | } 40 | 41 | int I2CSlave::read(char *data, int length) { 42 | return i2c_slave_read(&_i2c, data, length) != length; 43 | } 44 | 45 | int I2CSlave::read(void) { 46 | return i2c_byte_read(&_i2c, 0); 47 | } 48 | 49 | int I2CSlave::write(const char *data, int length) { 50 | return i2c_slave_write(&_i2c, data, length) != length; 51 | } 52 | 53 | int I2CSlave::write(int data) { 54 | return i2c_byte_write(&_i2c, data); 55 | } 56 | 57 | void I2CSlave::stop(void) { 58 | i2c_stop(&_i2c); 59 | } 60 | 61 | } 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /mbed-src/common/RawSerial.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "RawSerial.h" 17 | #include "wait_api.h" 18 | #include 19 | 20 | #if DEVICE_SERIAL 21 | 22 | #define STRING_STACK_LIMIT 120 23 | 24 | namespace mbed { 25 | 26 | RawSerial::RawSerial(PinName tx, PinName rx) : SerialBase(tx, rx) { 27 | } 28 | 29 | int RawSerial::getc() { 30 | return _base_getc(); 31 | } 32 | 33 | int RawSerial::putc(int c) { 34 | return _base_putc(c); 35 | } 36 | 37 | int RawSerial::puts(const char *str) { 38 | while (*str) 39 | putc(*str ++); 40 | return 0; 41 | } 42 | 43 | // Experimental support for printf in RawSerial. No Stream inheritance 44 | // means we can't call printf() directly, so we use sprintf() instead. 45 | // We only call malloc() for the sprintf() buffer if the buffer 46 | // length is above a certain threshold, otherwise we use just the stack. 47 | int RawSerial::printf(const char *format, ...) { 48 | std::va_list arg; 49 | va_start(arg, format); 50 | int len = vsnprintf(NULL, 0, format, arg); 51 | if (len < STRING_STACK_LIMIT) { 52 | char temp[STRING_STACK_LIMIT]; 53 | vsprintf(temp, format, arg); 54 | puts(temp); 55 | } else { 56 | char *temp = new char[len + 1]; 57 | vsprintf(temp, format, arg); 58 | puts(temp); 59 | delete[] temp; 60 | } 61 | va_end(arg); 62 | return len; 63 | } 64 | 65 | } // namespace mbed 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /mbed-src/common/SPI.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "SPI.h" 17 | 18 | #if DEVICE_SPI 19 | 20 | namespace mbed { 21 | 22 | SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName _unused) : 23 | _spi(), 24 | _bits(8), 25 | _mode(0), 26 | _hz(1000000) { 27 | spi_init(&_spi, mosi, miso, sclk, NC); 28 | spi_format(&_spi, _bits, _mode, 0); 29 | spi_frequency(&_spi, _hz); 30 | } 31 | 32 | void SPI::format(int bits, int mode) { 33 | _bits = bits; 34 | _mode = mode; 35 | SPI::_owner = NULL; // Not that elegant, but works. rmeyer 36 | aquire(); 37 | } 38 | 39 | void SPI::frequency(int hz) { 40 | _hz = hz; 41 | SPI::_owner = NULL; // Not that elegant, but works. rmeyer 42 | aquire(); 43 | } 44 | 45 | SPI* SPI::_owner = NULL; 46 | 47 | // ignore the fact there are multiple physical spis, and always update if it wasnt us last 48 | void SPI::aquire() { 49 | if (_owner != this) { 50 | spi_format(&_spi, _bits, _mode, 0); 51 | spi_frequency(&_spi, _hz); 52 | _owner = this; 53 | } 54 | } 55 | 56 | int SPI::write(int value) { 57 | aquire(); 58 | return spi_master_write(&_spi, value); 59 | } 60 | 61 | } // namespace mbed 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /mbed-src/common/SPISlave.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "SPISlave.h" 17 | 18 | #if DEVICE_SPISLAVE 19 | 20 | namespace mbed { 21 | 22 | SPISlave::SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) : 23 | _spi(), 24 | _bits(8), 25 | _mode(0), 26 | _hz(1000000) 27 | { 28 | spi_init(&_spi, mosi, miso, sclk, ssel); 29 | spi_format(&_spi, _bits, _mode, 1); 30 | spi_frequency(&_spi, _hz); 31 | } 32 | 33 | void SPISlave::format(int bits, int mode) { 34 | _bits = bits; 35 | _mode = mode; 36 | spi_format(&_spi, _bits, _mode, 1); 37 | } 38 | 39 | void SPISlave::frequency(int hz) { 40 | _hz = hz; 41 | spi_frequency(&_spi, _hz); 42 | } 43 | 44 | int SPISlave::receive(void) { 45 | return(spi_slave_receive(&_spi)); 46 | } 47 | 48 | int SPISlave::read(void) { 49 | return(spi_slave_read(&_spi)); 50 | } 51 | 52 | void SPISlave::reply(int value) { 53 | spi_slave_write(&_spi, value); 54 | } 55 | 56 | } // namespace mbed 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /mbed-src/common/Serial.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Serial.h" 17 | #include "wait_api.h" 18 | 19 | #if DEVICE_SERIAL 20 | 21 | namespace mbed { 22 | 23 | Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), Stream(name) { 24 | } 25 | 26 | int Serial::_getc() { 27 | return _base_getc(); 28 | } 29 | 30 | int Serial::_putc(int c) { 31 | return _base_putc(c); 32 | } 33 | 34 | } // namespace mbed 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /mbed-src/common/Ticker.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Ticker.h" 17 | 18 | #include "TimerEvent.h" 19 | #include "FunctionPointer.h" 20 | 21 | namespace mbed { 22 | 23 | void Ticker::detach() { 24 | remove(); 25 | _function.attach(0); 26 | } 27 | 28 | void Ticker::setup(timestamp_t t) { 29 | remove(); 30 | _delay = t; 31 | insert(_delay + us_ticker_read()); 32 | } 33 | 34 | void Ticker::handler() { 35 | insert(event.timestamp + _delay); 36 | _function.call(); 37 | } 38 | 39 | } // namespace mbed 40 | -------------------------------------------------------------------------------- /mbed-src/common/Timeout.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Timeout.h" 17 | 18 | namespace mbed { 19 | 20 | void Timeout::handler() { 21 | _function.call(); 22 | } 23 | 24 | } // namespace mbed 25 | -------------------------------------------------------------------------------- /mbed-src/common/Timer.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "Timer.h" 17 | #include "us_ticker_api.h" 18 | 19 | namespace mbed { 20 | 21 | Timer::Timer() : _running(), _start(), _time() { 22 | reset(); 23 | } 24 | 25 | void Timer::start() { 26 | _start = us_ticker_read(); 27 | _running = 1; 28 | } 29 | 30 | void Timer::stop() { 31 | _time += slicetime(); 32 | _running = 0; 33 | } 34 | 35 | int Timer::read_us() { 36 | return _time + slicetime(); 37 | } 38 | 39 | float Timer::read() { 40 | return (float)read_us() / 1000000.0f; 41 | } 42 | 43 | int Timer::read_ms() { 44 | return read_us() / 1000; 45 | } 46 | 47 | int Timer::slicetime() { 48 | if (_running) { 49 | return us_ticker_read() - _start; 50 | } else { 51 | return 0; 52 | } 53 | } 54 | 55 | void Timer::reset() { 56 | _start = us_ticker_read(); 57 | _time = 0; 58 | } 59 | 60 | #ifdef MBED_OPERATORS 61 | Timer::operator float() { 62 | return read(); 63 | } 64 | #endif 65 | 66 | } // namespace mbed 67 | -------------------------------------------------------------------------------- /mbed-src/common/TimerEvent.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "TimerEvent.h" 17 | #include "cmsis.h" 18 | 19 | #include 20 | 21 | namespace mbed { 22 | 23 | TimerEvent::TimerEvent() : event() { 24 | us_ticker_set_handler((&TimerEvent::irq)); 25 | } 26 | 27 | void TimerEvent::irq(uint32_t id) { 28 | TimerEvent *timer_event = (TimerEvent*)id; 29 | timer_event->handler(); 30 | } 31 | 32 | TimerEvent::~TimerEvent() { 33 | remove(); 34 | } 35 | 36 | // insert in to linked list 37 | void TimerEvent::insert(timestamp_t timestamp) { 38 | us_ticker_insert_event(&event, timestamp, (uint32_t)this); 39 | } 40 | 41 | void TimerEvent::remove() { 42 | us_ticker_remove_event(&event); 43 | } 44 | 45 | } // namespace mbed 46 | -------------------------------------------------------------------------------- /mbed-src/common/assert.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mbed_assert.h" 17 | #include "device.h" 18 | 19 | #if DEVICE_STDIO_MESSAGES 20 | #include 21 | #endif 22 | 23 | #include 24 | #include "mbed_interface.h" 25 | 26 | void mbed_assert_internal(const char *expr, const char *file, int line) 27 | { 28 | #if DEVICE_STDIO_MESSAGES 29 | fprintf(stderr, "mbed assertation failed: %s, file: %s, line %d \n", expr, file, line); 30 | #endif 31 | mbed_die(); 32 | } 33 | -------------------------------------------------------------------------------- /mbed-src/common/board.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "gpio_api.h" 17 | #include "wait_api.h" 18 | #include "toolchain.h" 19 | #include "mbed_interface.h" 20 | 21 | WEAK void mbed_die(void) { 22 | #ifndef NRF51_H 23 | __disable_irq(); // dont allow interrupts to disturb the flash pattern 24 | #endif 25 | #if (DEVICE_ERROR_RED == 1) 26 | gpio_t led_red; gpio_init_out(&led_red, LED_RED); 27 | #elif (DEVICE_ERROR_PATTERN == 1) 28 | gpio_t led_1; gpio_init_out(&led_1, LED1); 29 | gpio_t led_2; gpio_init_out(&led_2, LED2); 30 | gpio_t led_3; gpio_init_out(&led_3, LED3); 31 | gpio_t led_4; gpio_init_out(&led_4, LED4); 32 | #endif 33 | 34 | while (1) { 35 | #if (DEVICE_ERROR_RED == 1) 36 | gpio_write(&led_red, 1); 37 | 38 | #elif (DEVICE_ERROR_PATTERN == 1) 39 | gpio_write(&led_1, 1); 40 | gpio_write(&led_2, 0); 41 | gpio_write(&led_3, 0); 42 | gpio_write(&led_4, 1); 43 | #endif 44 | 45 | wait_ms(150); 46 | 47 | #if (DEVICE_ERROR_RED == 1) 48 | gpio_write(&led_red, 0); 49 | 50 | #elif (DEVICE_ERROR_PATTERN == 1) 51 | gpio_write(&led_1, 0); 52 | gpio_write(&led_2, 1); 53 | gpio_write(&led_3, 1); 54 | gpio_write(&led_4, 0); 55 | #endif 56 | 57 | wait_ms(150); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /mbed-src/common/error.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include 17 | #include 18 | #include "device.h" 19 | #include "toolchain.h" 20 | #include "mbed_error.h" 21 | #if DEVICE_STDIO_MESSAGES 22 | #include 23 | #endif 24 | 25 | WEAK void error(const char* format, ...) { 26 | #if DEVICE_STDIO_MESSAGES 27 | va_list arg; 28 | va_start(arg, format); 29 | vfprintf(stderr, format, arg); 30 | va_end(arg); 31 | #endif 32 | exit(1); 33 | } 34 | -------------------------------------------------------------------------------- /mbed-src/common/exit.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "semihost_api.h" 17 | #include "mbed_interface.h" 18 | #if DEVICE_STDIO_MESSAGES 19 | #include 20 | #endif 21 | 22 | #ifdef TOOLCHAIN_GCC_CW 23 | // TODO: Ideally, we would like to define directly "_ExitProcess" 24 | void mbed_exit(int return_code) { 25 | #else 26 | void exit(int return_code) { 27 | #endif 28 | 29 | #if DEVICE_STDIO_MESSAGES 30 | fflush(stdout); 31 | fflush(stderr); 32 | #endif 33 | 34 | #if DEVICE_SEMIHOST 35 | if (mbed_interface_connected()) { 36 | semihost_exit(); 37 | } 38 | #endif 39 | if (return_code) { 40 | mbed_die(); 41 | } 42 | 43 | while (1); 44 | } 45 | -------------------------------------------------------------------------------- /mbed-src/common/gpio.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "gpio_api.h" 17 | 18 | static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode) 19 | { 20 | gpio_init(gpio, pin); 21 | if (pin != NC) { 22 | gpio_dir(gpio, PIN_INPUT); 23 | gpio_mode(gpio, mode); 24 | } 25 | } 26 | 27 | static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value) 28 | { 29 | gpio_init(gpio, pin); 30 | if (pin != NC) { 31 | gpio_write(gpio, value); 32 | gpio_dir(gpio, PIN_OUTPUT); 33 | gpio_mode(gpio, mode); 34 | } 35 | } 36 | 37 | void gpio_init_in(gpio_t* gpio, PinName pin) { 38 | gpio_init_in_ex(gpio, pin, PullDefault); 39 | } 40 | 41 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { 42 | _gpio_init_in(gpio, pin, mode); 43 | } 44 | 45 | void gpio_init_out(gpio_t* gpio, PinName pin) { 46 | gpio_init_out_ex(gpio, pin, 0); 47 | } 48 | 49 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { 50 | _gpio_init_out(gpio, pin, PullNone, value); 51 | } 52 | 53 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { 54 | if (direction == PIN_INPUT) { 55 | _gpio_init_in(gpio, pin, mode); 56 | if (pin != NC) 57 | gpio_write(gpio, value); // we prepare the value in case it is switched later 58 | } else { 59 | _gpio_init_out(gpio, pin, mode, value); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /mbed-src/common/pinmap_common.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "pinmap.h" 17 | #include "mbed_error.h" 18 | 19 | void pinmap_pinout(PinName pin, const PinMap *map) { 20 | if (pin == NC) 21 | return; 22 | 23 | while (map->pin != NC) { 24 | if (map->pin == pin) { 25 | pin_function(pin, map->function); 26 | 27 | pin_mode(pin, PullNone); 28 | return; 29 | } 30 | map++; 31 | } 32 | error("could not pinout"); 33 | } 34 | 35 | uint32_t pinmap_merge(uint32_t a, uint32_t b) { 36 | // both are the same (inc both NC) 37 | if (a == b) 38 | return a; 39 | 40 | // one (or both) is not connected 41 | if (a == (uint32_t)NC) 42 | return b; 43 | if (b == (uint32_t)NC) 44 | return a; 45 | 46 | // mis-match error case 47 | error("pinmap mis-match"); 48 | return (uint32_t)NC; 49 | } 50 | 51 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { 52 | while (map->pin != NC) { 53 | if (map->pin == pin) 54 | return map->peripheral; 55 | map++; 56 | } 57 | return (uint32_t)NC; 58 | } 59 | 60 | uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { 61 | uint32_t peripheral = (uint32_t)NC; 62 | 63 | if (pin == (PinName)NC) 64 | return (uint32_t)NC; 65 | peripheral = pinmap_find_peripheral(pin, map); 66 | if ((uint32_t)NC == peripheral) // no mapping available 67 | error("pinmap not found for peripheral"); 68 | return peripheral; 69 | } 70 | -------------------------------------------------------------------------------- /mbed-src/common/rtc_time.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "rtc_api.h" 17 | 18 | #include 19 | #include "rtc_time.h" 20 | #include "us_ticker_api.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | #if defined (__ICCARM__) 26 | time_t __time32(time_t *timer) 27 | #else 28 | time_t time(time_t *timer) 29 | #endif 30 | 31 | { 32 | #if DEVICE_RTC 33 | if (!(rtc_isenabled())) { 34 | set_time(0); 35 | } 36 | time_t t = rtc_read(); 37 | 38 | #else 39 | time_t t = 0; 40 | #endif 41 | 42 | if (timer != NULL) { 43 | *timer = t; 44 | } 45 | return t; 46 | } 47 | 48 | void set_time(time_t t) { 49 | #if DEVICE_RTC 50 | rtc_init(); 51 | rtc_write(t); 52 | #endif 53 | } 54 | 55 | clock_t clock() { 56 | clock_t t = us_ticker_read(); 57 | t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time 58 | return t; 59 | } 60 | 61 | #ifdef __cplusplus 62 | } 63 | #endif 64 | -------------------------------------------------------------------------------- /mbed-src/common/wait_api.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "wait_api.h" 17 | #include "us_ticker_api.h" 18 | 19 | void wait(float s) { 20 | wait_us(s * 1000000.0f); 21 | } 22 | 23 | void wait_ms(int ms) { 24 | wait_us(ms * 1000); 25 | } 26 | 27 | void wait_us(int us) { 28 | uint32_t start = us_ticker_read(); 29 | while ((us_ticker_read() - start) < (uint32_t)us); 30 | } 31 | -------------------------------------------------------------------------------- /mbed-src/hal/analogin_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_ANALOGIN_API_H 17 | #define MBED_ANALOGIN_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_ANALOGIN 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct analogin_s analogin_t; 28 | 29 | void analogin_init (analogin_t *obj, PinName pin); 30 | float analogin_read (analogin_t *obj); 31 | uint16_t analogin_read_u16(analogin_t *obj); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif 36 | 37 | #endif 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /mbed-src/hal/analogout_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_ANALOGOUT_API_H 17 | #define MBED_ANALOGOUT_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_ANALOGOUT 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct dac_s dac_t; 28 | 29 | void analogout_init (dac_t *obj, PinName pin); 30 | void analogout_free (dac_t *obj); 31 | void analogout_write (dac_t *obj, float value); 32 | void analogout_write_u16(dac_t *obj, uint16_t value); 33 | float analogout_read (dac_t *obj); 34 | uint16_t analogout_read_u16 (dac_t *obj); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /mbed-src/hal/can_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_CAN_API_H 17 | #define MBED_CAN_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_CAN 22 | 23 | #include "PinNames.h" 24 | #include "PeripheralNames.h" 25 | #include "can_helper.h" 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | typedef enum { 32 | IRQ_RX, 33 | IRQ_TX, 34 | IRQ_ERROR, 35 | IRQ_OVERRUN, 36 | IRQ_WAKEUP, 37 | IRQ_PASSIVE, 38 | IRQ_ARB, 39 | IRQ_BUS, 40 | IRQ_READY 41 | } CanIrqType; 42 | 43 | 44 | typedef enum { 45 | MODE_RESET, 46 | MODE_NORMAL, 47 | MODE_SILENT, 48 | MODE_TEST_GLOBAL, 49 | MODE_TEST_LOCAL, 50 | MODE_TEST_SILENT 51 | } CanMode; 52 | 53 | typedef void (*can_irq_handler)(uint32_t id, CanIrqType type); 54 | 55 | typedef struct can_s can_t; 56 | 57 | void can_init (can_t *obj, PinName rd, PinName td); 58 | void can_free (can_t *obj); 59 | int can_frequency(can_t *obj, int hz); 60 | 61 | void can_irq_init (can_t *obj, can_irq_handler handler, uint32_t id); 62 | void can_irq_free (can_t *obj); 63 | void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable); 64 | 65 | int can_write (can_t *obj, CAN_Message, int cc); 66 | int can_read (can_t *obj, CAN_Message *msg, int handle); 67 | int can_mode (can_t *obj, CanMode mode); 68 | int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle); 69 | void can_reset (can_t *obj); 70 | unsigned char can_rderror (can_t *obj); 71 | unsigned char can_tderror (can_t *obj); 72 | void can_monitor (can_t *obj, int silent); 73 | 74 | #ifdef __cplusplus 75 | }; 76 | #endif 77 | 78 | #endif // MBED_CAN_API_H 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /mbed-src/hal/ethernet_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_ETHERNET_API_H 17 | #define MBED_ETHERNET_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_ETHERNET 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | // Connection constants 28 | 29 | int ethernet_init(void); 30 | void ethernet_free(void); 31 | 32 | // write size bytes from data to ethernet buffer 33 | // return num bytes written 34 | // or -1 if size is too big 35 | int ethernet_write(const char *data, int size); 36 | 37 | // send ethernet write buffer, returning the packet size sent 38 | int ethernet_send(void); 39 | 40 | // recieve from ethernet buffer, returning packet size, or 0 if no packet 41 | int ethernet_receive(void); 42 | 43 | // read size bytes in to data, return actual num bytes read (0..size) 44 | // if data == NULL, throw the bytes away 45 | int ethernet_read(char *data, int size); 46 | 47 | // get the ethernet address 48 | void ethernet_address(char *mac); 49 | 50 | // see if the link is up 51 | int ethernet_link(void); 52 | 53 | // force link settings 54 | void ethernet_set_link(int speed, int duplex); 55 | 56 | #ifdef __cplusplus 57 | } 58 | #endif 59 | 60 | #endif 61 | 62 | #endif 63 | 64 | -------------------------------------------------------------------------------- /mbed-src/hal/gpio_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_GPIO_API_H 17 | #define MBED_GPIO_API_H 18 | 19 | #include "device.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | /* Set the given pin as GPIO 26 | * @param pin The pin to be set as GPIO 27 | * @return The GPIO port mask for this pin 28 | **/ 29 | uint32_t gpio_set(PinName pin); 30 | 31 | /* GPIO object */ 32 | void gpio_init(gpio_t *obj, PinName pin); 33 | 34 | void gpio_mode (gpio_t *obj, PinMode mode); 35 | void gpio_dir (gpio_t *obj, PinDirection direction); 36 | 37 | void gpio_write(gpio_t *obj, int value); 38 | int gpio_read (gpio_t *obj); 39 | 40 | // the following set of functions are generic and are implemented in the common gpio.c file 41 | void gpio_init_in(gpio_t* gpio, PinName pin); 42 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode); 43 | void gpio_init_out(gpio_t* gpio, PinName pin); 44 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value); 45 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /mbed-src/hal/gpio_irq_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_GPIO_IRQ_API_H 17 | #define MBED_GPIO_IRQ_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_INTERRUPTIN 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef enum { 28 | IRQ_NONE, 29 | IRQ_RISE, 30 | IRQ_FALL 31 | } gpio_irq_event; 32 | 33 | typedef struct gpio_irq_s gpio_irq_t; 34 | 35 | typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event); 36 | 37 | int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); 38 | void gpio_irq_free(gpio_irq_t *obj); 39 | void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); 40 | void gpio_irq_enable(gpio_irq_t *obj); 41 | void gpio_irq_disable(gpio_irq_t *obj); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /mbed-src/hal/i2c_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_I2C_API_H 17 | #define MBED_I2C_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_I2C 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct i2c_s i2c_t; 28 | 29 | enum { 30 | I2C_ERROR_NO_SLAVE = -1, 31 | I2C_ERROR_BUS_BUSY = -2 32 | }; 33 | 34 | void i2c_init (i2c_t *obj, PinName sda, PinName scl); 35 | void i2c_frequency (i2c_t *obj, int hz); 36 | int i2c_start (i2c_t *obj); 37 | int i2c_stop (i2c_t *obj); 38 | int i2c_read (i2c_t *obj, int address, char *data, int length, int stop); 39 | int i2c_write (i2c_t *obj, int address, const char *data, int length, int stop); 40 | void i2c_reset (i2c_t *obj); 41 | int i2c_byte_read (i2c_t *obj, int last); 42 | int i2c_byte_write (i2c_t *obj, int data); 43 | 44 | #if DEVICE_I2CSLAVE 45 | void i2c_slave_mode (i2c_t *obj, int enable_slave); 46 | int i2c_slave_receive(i2c_t *obj); 47 | int i2c_slave_read (i2c_t *obj, char *data, int length); 48 | int i2c_slave_write (i2c_t *obj, const char *data, int length); 49 | void i2c_slave_address(i2c_t *obj, int idx, uint32_t address, uint32_t mask); 50 | #endif 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /mbed-src/hal/pinmap.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PINMAP_H 17 | #define MBED_PINMAP_H 18 | 19 | #include "PinNames.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef struct { 26 | PinName pin; 27 | int peripheral; 28 | int function; 29 | } PinMap; 30 | 31 | void pin_function(PinName pin, int function); 32 | void pin_mode (PinName pin, PinMode mode); 33 | 34 | uint32_t pinmap_peripheral(PinName pin, const PinMap* map); 35 | uint32_t pinmap_merge (uint32_t a, uint32_t b); 36 | void pinmap_pinout (PinName pin, const PinMap *map); 37 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /mbed-src/hal/port_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PORTMAP_H 17 | #define MBED_PORTMAP_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_PORTIN || DEVICE_PORTOUT 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct port_s port_t; 28 | 29 | PinName port_pin(PortName port, int pin_n); 30 | 31 | void port_init (port_t *obj, PortName port, int mask, PinDirection dir); 32 | void port_mode (port_t *obj, PinMode mode); 33 | void port_dir (port_t *obj, PinDirection dir); 34 | void port_write(port_t *obj, int value); 35 | int port_read (port_t *obj); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /mbed-src/hal/pwmout_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PWMOUT_API_H 17 | #define MBED_PWMOUT_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_PWMOUT 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct pwmout_s pwmout_t; 28 | 29 | void pwmout_init (pwmout_t* obj, PinName pin); 30 | void pwmout_free (pwmout_t* obj); 31 | 32 | void pwmout_write (pwmout_t* obj, float percent); 33 | float pwmout_read (pwmout_t* obj); 34 | 35 | void pwmout_period (pwmout_t* obj, float seconds); 36 | void pwmout_period_ms (pwmout_t* obj, int ms); 37 | void pwmout_period_us (pwmout_t* obj, int us); 38 | 39 | void pwmout_pulsewidth (pwmout_t* obj, float seconds); 40 | void pwmout_pulsewidth_ms(pwmout_t* obj, int ms); 41 | void pwmout_pulsewidth_us(pwmout_t* obj, int us); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /mbed-src/hal/rtc_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_RTC_API_H 17 | #define MBED_RTC_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_RTC 22 | 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | void rtc_init(void); 30 | void rtc_free(void); 31 | int rtc_isenabled(void); 32 | 33 | time_t rtc_read(void); 34 | void rtc_write(time_t t); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /mbed-src/hal/serial_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_SERIAL_API_H 17 | #define MBED_SERIAL_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_SERIAL 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef enum { 28 | ParityNone = 0, 29 | ParityOdd = 1, 30 | ParityEven = 2, 31 | ParityForced1 = 3, 32 | ParityForced0 = 4 33 | } SerialParity; 34 | 35 | typedef enum { 36 | RxIrq, 37 | TxIrq 38 | } SerialIrq; 39 | 40 | typedef enum { 41 | FlowControlNone, 42 | FlowControlRTS, 43 | FlowControlCTS, 44 | FlowControlRTSCTS 45 | } FlowControl; 46 | 47 | typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event); 48 | 49 | typedef struct serial_s serial_t; 50 | 51 | void serial_init (serial_t *obj, PinName tx, PinName rx); 52 | void serial_free (serial_t *obj); 53 | void serial_baud (serial_t *obj, int baudrate); 54 | void serial_format (serial_t *obj, int data_bits, SerialParity parity, int stop_bits); 55 | 56 | void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id); 57 | void serial_irq_set (serial_t *obj, SerialIrq irq, uint32_t enable); 58 | 59 | int serial_getc (serial_t *obj); 60 | void serial_putc (serial_t *obj, int c); 61 | int serial_readable (serial_t *obj); 62 | int serial_writable (serial_t *obj); 63 | void serial_clear (serial_t *obj); 64 | 65 | void serial_break_set (serial_t *obj); 66 | void serial_break_clear(serial_t *obj); 67 | 68 | void serial_pinout_tx(PinName tx); 69 | 70 | void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); 71 | 72 | #ifdef __cplusplus 73 | } 74 | #endif 75 | 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /mbed-src/hal/spi_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_SPI_API_H 17 | #define MBED_SPI_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_SPI 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | typedef struct spi_s spi_t; 28 | 29 | void spi_init (spi_t *obj, PinName mosi, PinName miso, PinName sclk, PinName ssel); 30 | void spi_free (spi_t *obj); 31 | void spi_format (spi_t *obj, int bits, int mode, int slave); 32 | void spi_frequency (spi_t *obj, int hz); 33 | int spi_master_write (spi_t *obj, int value); 34 | int spi_slave_receive(spi_t *obj); 35 | int spi_slave_read (spi_t *obj); 36 | void spi_slave_write (spi_t *obj, int value); 37 | int spi_busy (spi_t *obj); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /mbed-src/hal/us_ticker_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_US_TICKER_API_H 17 | #define MBED_US_TICKER_API_H 18 | 19 | #include 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef uint64_t timestamp_t; 26 | 27 | uint32_t us_ticker_read(void); 28 | 29 | typedef void (*ticker_event_handler)(uint32_t id); 30 | void us_ticker_set_handler(ticker_event_handler handler); 31 | 32 | typedef struct ticker_event_s { 33 | timestamp_t timestamp; 34 | uint32_t id; 35 | struct ticker_event_s *next; 36 | } ticker_event_t; 37 | 38 | void us_ticker_init(void); 39 | void us_ticker_set_interrupt(timestamp_t timestamp); 40 | void us_ticker_disable_interrupt(void); 41 | void us_ticker_clear_interrupt(void); 42 | void us_ticker_irq_handler(void); 43 | 44 | void us_ticker_insert_event(ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 45 | void us_ticker_remove_event(ticker_event_t *obj); 46 | 47 | #ifdef __cplusplus 48 | } 49 | #endif 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/TARGET_MCU_NORDIC_16K/nRF51822.sct: -------------------------------------------------------------------------------- 1 | ;WITHOUT SOFTDEVICE: 2 | ;LR_IROM1 0x00000000 0x00040000 { 3 | ; ER_IROM1 0x00000000 0x00040000 { 4 | ; *.o (RESET, +First) 5 | ; *(InRoot$$Sections) 6 | ; .ANY (+RO) 7 | ; } 8 | ; RW_IRAM1 0x20000000 0x00004000 { 9 | ; .ANY (+RW +ZI) 10 | ; } 11 | ;} 12 | ; 13 | ;WITH SOFTDEVICE: 14 | 15 | LR_IROM1 0x16000 0x002A000 { 16 | ER_IROM1 0x16000 0x002A000 { 17 | *.o (RESET, +First) 18 | *(InRoot$$Sections) 19 | .ANY (+RO) 20 | } 21 | RW_IRAM1 0x20002000 0x00002000 { 22 | .ANY (+RW +ZI) 23 | } 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/TARGET_MCU_NORDIC_32K/nRF51822.sct: -------------------------------------------------------------------------------- 1 | ;WITHOUT SOFTDEVICE: 2 | ;LR_IROM1 0x00000000 0x00040000 { 3 | ; ER_IROM1 0x00000000 0x00040000 { 4 | ; *.o (RESET, +First) 5 | ; *(InRoot$$Sections) 6 | ; .ANY (+RO) 7 | ; } 8 | ; RW_IRAM1 0x20000000 0x00004000 { 9 | ; .ANY (+RW +ZI) 10 | ; } 11 | ;} 12 | ; 13 | ;WITH SOFTDEVICE: 14 | 15 | LR_IROM1 0x16000 0x002A000 { 16 | ER_IROM1 0x16000 0x002A000 { 17 | *.o (RESET, +First) 18 | *(InRoot$$Sections) 19 | .ANY (+RO) 20 | } 21 | RW_IRAM1 0x20002000 0x00006000 { 22 | .ANY (+RW +ZI) 23 | } 24 | } 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/TOOLCHAIN_ARM_STD/sys.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library - stackheap 2 | * Copyright (C) 2009-2011 ARM Limited. All rights reserved. 3 | * 4 | * Setup a fixed single stack/heap memory model, 5 | * between the top of the RW/ZI region and the stackpointer 6 | */ 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | #include 13 | #include 14 | 15 | extern char Image$$RW_IRAM1$$ZI$$Limit[]; 16 | 17 | extern __value_in_regs struct __initial_stackheap __user_setup_stackheap(uint32_t R0, uint32_t R1, uint32_t R2, uint32_t R3) { 18 | uint32_t zi_limit = (uint32_t)Image$$RW_IRAM1$$ZI$$Limit; 19 | uint32_t sp_limit = __current_sp(); 20 | 21 | zi_limit = (zi_limit + 7) & ~0x7; // ensure zi_limit is 8-byte aligned 22 | 23 | struct __initial_stackheap r; 24 | r.heap_base = zi_limit; 25 | r.heap_limit = sp_limit; 26 | return r; 27 | } 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/cmsis.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library - CMSIS 2 | * Copyright (C) 2009-2011 ARM Limited. All rights reserved. 3 | * 4 | * A generic CMSIS include header, pulling in LPC407x_8x specifics 5 | */ 6 | 7 | #ifndef MBED_CMSIS_H 8 | #define MBED_CMSIS_H 9 | 10 | #include "nrf51822.h" 11 | #include "cmsis_nvic.h" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/cmsis_nvic.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library - cmsis_nvic 2 | * Copyright (c) 2009-2011 ARM Limited. All rights reserved. 3 | * 4 | * CMSIS-style functionality to support dynamic vectors 5 | */ 6 | 7 | #ifndef MBED_CMSIS_NVIC_H 8 | #define MBED_CMSIS_NVIC_H 9 | 10 | #define NVIC_NUM_VECTORS (16 + 32) // CORE + MCU Peripherals 11 | #define NVIC_USER_IRQ_OFFSET 16 12 | 13 | #include "nrf51822.h" 14 | #include "cmsis.h" 15 | 16 | 17 | #ifdef __cplusplus 18 | extern "C" { 19 | #endif 20 | 21 | void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector); 22 | uint32_t NVIC_GetVector(IRQn_Type IRQn); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/compiler_abstraction.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is confidential property of Nordic 4 | * Semiconductor ASA.Terms and conditions of usage are described in detail 5 | * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #ifndef _COMPILER_ABSTRACTION_H 14 | #define _COMPILER_ABSTRACTION_H 15 | 16 | /*lint ++flb "Enter library region" */ 17 | 18 | #if defined ( __CC_ARM ) 19 | #define __ASM __asm /*!< asm keyword for ARM Compiler */ 20 | #define __INLINE __inline /*!< inline keyword for ARM Compiler */ 21 | #define __STATIC_INLINE static __inline 22 | 23 | #elif defined ( __ICCARM__ ) 24 | #define __ASM __asm /*!< asm keyword for IAR Compiler */ 25 | #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ 26 | #define __STATIC_INLINE static inline 27 | #define __current_sp() __get_SP() 28 | 29 | #elif defined ( __GNUC__ ) 30 | #define __ASM __asm /*!< asm keyword for GNU Compiler */ 31 | #define __INLINE inline /*!< inline keyword for GNU Compiler */ 32 | #define __STATIC_INLINE static inline 33 | 34 | static __INLINE unsigned int __current_sp(void) 35 | { 36 | register unsigned sp asm("sp"); 37 | return sp; 38 | } 39 | 40 | #elif defined ( __TASKING__ ) 41 | #define __ASM __asm /*!< asm keyword for TASKING Compiler */ 42 | #define __INLINE inline /*!< inline keyword for TASKING Compiler */ 43 | #define __STATIC_INLINE static inline 44 | 45 | #endif 46 | 47 | /*lint --flb "Leave library region" */ 48 | 49 | #endif 50 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/nordic_global.h: -------------------------------------------------------------------------------- 1 | #ifndef _NORDIC_GLOBAL_H_ 2 | #define _NORDIC_GLOBAL_H_ 3 | 4 | /* There are no global defines in mbed, so we need to define */ 5 | /* mandatory conditional compilation flags here */ 6 | //#define NRF51 7 | #ifndef DEBUG_NRF_USER 8 | #define DEBUG_NRF_USER 9 | #endif 10 | #ifndef BLE_STACK_SUPPORT_REQD 11 | #define BLE_STACK_SUPPORT_REQD 12 | #endif 13 | #ifndef BOARD_PCA10001 14 | #define BOARD_PCA10001 15 | #endif 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/nrf51822.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | 3 | * Copyright (c) 2013 Nordic Semiconductor. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | #ifndef NRF_H 20 | #define NRF_H 21 | 22 | #include "nordic_global.h" 23 | #include "compiler_abstraction.h" 24 | #include "nrf51.h" 25 | #include "nrf51_bitfields.h" 26 | #endif /* NRF_H */ 27 | 28 | -------------------------------------------------------------------------------- /mbed-src/targets/cmsis/TARGET_NORDIC/TARGET_MCU_NRF51822/system_nrf51822.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | 3 | * Copyright (c) 2013 Nordic Semiconductor. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | 19 | #ifndef SYSTEM_NRF51_H 20 | #define SYSTEM_NRF51_H 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | #include 27 | 28 | 29 | extern uint32_t SystemCoreClock; /*!< System Clock Frequency (Core Clock) */ 30 | 31 | /** 32 | * Initialize the system 33 | * 34 | * @param none 35 | * @return none 36 | * 37 | * @brief Setup the microcontroller system. 38 | * Initialize the System and update the SystemCoreClock variable. 39 | */ 40 | extern void SystemInit (void); 41 | 42 | 43 | /** 44 | * Update SystemCoreClock variable 45 | * 46 | * @param none 47 | * @return none 48 | * 49 | * @brief Updates the SystemCoreClock with current core Clock 50 | * retrieved from cpu registers. 51 | */ 52 | extern void SystemCoreClockUpdate (void); 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif /* SYSTEM_NRF51_H */ 59 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf-sdk/app_common/app_trace.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H_ 2 | #define __DEBUG_H_ 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * @defgroup app_trace Debug Logger 9 | * @ingroup app_common 10 | * @{ 11 | * @brief Enables debug logs/ trace over UART. 12 | * @details Enables debug logs/ trace over UART. Tracing is enabled only if 13 | * ENABLE_DEBUG_LOG_SUPPORT is defined in the project. 14 | */ 15 | #ifdef ENABLE_DEBUG_LOG_SUPPORT 16 | /** 17 | * @brief Module Initialization. 18 | * 19 | * @details Initializes the module to use UART as trace output. 20 | * 21 | * @warning This function will configure UART using default board configuration (described in @ref nrf51_setups). 22 | * Do not call this function if UART is configured from a higher level in the application. 23 | */ 24 | void app_trace_init(void); 25 | 26 | /** 27 | * @brief Log debug messages. 28 | * 29 | * @details This API logs messages over UART. The module must be initialized before using this API. 30 | * 31 | * @note Though this is currently a macro, it should be used used and treated as function. 32 | */ 33 | #define app_trace_log printf 34 | 35 | /** 36 | * @brief Dump auxiliary byte buffer to the debug trace. 37 | * 38 | * @details This API logs messages over UART. The module must be initialized before using this API. 39 | * 40 | * @param[in] p_buffer Buffer to be dumped on the debug trace. 41 | * @param[in] len Size of the buffer. 42 | */ 43 | void app_trace_dump(uint8_t * p_buffer, uint32_t len); 44 | 45 | #else // ENABLE_DEBUG_LOG_SUPPORT 46 | 47 | #define app_trace_init(...) 48 | #define app_trace_log(...) 49 | #define app_trace_dump(...) 50 | 51 | #endif // ENABLE_DEBUG_LOG_SUPPORT 52 | 53 | /** @} */ 54 | 55 | #endif //__DEBUG_H_ 56 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf-sdk/app_common/crc16.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @file 14 | * 15 | * @defgroup crc_compute CRC compute 16 | * @{ 17 | * @ingroup hci_transport 18 | * 19 | * @brief This module implements the CRC-16 calculation in the blocks. 20 | */ 21 | 22 | #ifndef CRC16_H__ 23 | #define CRC16_H__ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /**@brief Function for calculating CRC-16 in blocks. 32 | * 33 | * Feed each consecutive data block into this function, along with the current value of p_crc as 34 | * returned by the previous call of this function. The first call of this function should pass NULL 35 | * as the initial value of the crc in p_crc. 36 | * 37 | * @param[in] p_data The input data block for computation. 38 | * @param[in] size The size of the input data block in bytes. 39 | * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. 40 | * 41 | * @return The updated CRC-16 value, based on the input supplied. 42 | */ 43 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif // CRC16_H__ 51 | 52 | /** @} */ 53 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf-sdk/app_common/hci_mem_pool_internal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @file 14 | * 15 | * @defgroup memory_pool_internal Memory Pool Internal 16 | * @{ 17 | * @ingroup memory_pool 18 | * 19 | * @brief Memory pool internal definitions 20 | */ 21 | 22 | #ifndef MEM_POOL_INTERNAL_H__ 23 | #define MEM_POOL_INTERNAL_H__ 24 | 25 | #define TX_BUF_SIZE 600u /**< TX buffer size in bytes. */ 26 | #define RX_BUF_SIZE TX_BUF_SIZE /**< RX buffer size in bytes. */ 27 | 28 | #define RX_BUF_QUEUE_SIZE 4u /**< RX buffer element size. */ 29 | 30 | #endif // MEM_POOL_INTERNAL_H__ 31 | 32 | /** @} */ 33 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/nrf-sdk/nrf_delay.h: -------------------------------------------------------------------------------- 1 | #ifndef _NRF_DELAY_H 2 | #define _NRF_DELAY_H 3 | 4 | // #include "nrf.h" 5 | 6 | /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */ 7 | #if defined ( __CC_ARM ) 8 | static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 9 | { 10 | loop 11 | SUBS R0, R0, #1 12 | NOP 13 | NOP 14 | NOP 15 | NOP 16 | NOP 17 | NOP 18 | NOP 19 | NOP 20 | NOP 21 | NOP 22 | NOP 23 | NOP 24 | BNE loop 25 | BX LR 26 | } 27 | #elif defined ( __ICCARM__ ) 28 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 29 | { 30 | __ASM ( 31 | "loop:\n\t" 32 | " SUBS R0, R0, #1\n\t" 33 | " NOP\n\t" 34 | " NOP\n\t" 35 | " NOP\n\t" 36 | " NOP\n\t" 37 | " NOP\n\t" 38 | " NOP\n\t" 39 | " NOP\n\t" 40 | " NOP\n\t" 41 | " NOP\n\t" 42 | " NOP\n\t" 43 | " NOP\n\t" 44 | " NOP\n\t" 45 | " BNE loop\n\t"); 46 | } 47 | #elif defined ( __GNUC__ ) 48 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 49 | { 50 | do 51 | { 52 | __ASM volatile ( 53 | "NOP\n\t" 54 | "NOP\n\t" 55 | "NOP\n\t" 56 | "NOP\n\t" 57 | "NOP\n\t" 58 | "NOP\n\t" 59 | "NOP\n\t" 60 | "NOP\n\t" 61 | "NOP\n\t" 62 | "NOP\n\t" 63 | "NOP\n\t" 64 | "NOP\n\t" 65 | "NOP\n\t" 66 | "NOP\n\t" 67 | ); 68 | } while (--number_of_us); 69 | } 70 | #endif 71 | 72 | void nrf_delay_ms(uint32_t volatile number_of_ms); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_API/include/ble_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup BLE_COMMON 11 | @{ 12 | @addtogroup nrf_error 13 | @{ 14 | @ingroup BLE_COMMON 15 | @} 16 | 17 | @defgroup ble_err General error codes 18 | @{ 19 | 20 | @brief General error code definitions for the BLE API. 21 | 22 | @ingroup BLE_COMMON 23 | */ 24 | #ifndef NRF_BLE_ERR_H__ 25 | #define NRF_BLE_ERR_H__ 26 | 27 | #include "nrf_error.h" 28 | 29 | /* @defgroup BLE_ERRORS Error Codes 30 | * @{ */ 31 | #define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */ 32 | #define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */ 33 | #define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */ 34 | #define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x004) /**< Buffer capacity exceeded. */ 35 | /** @} */ 36 | 37 | 38 | /** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges 39 | * @brief Assignment of subranges for module specific error codes. 40 | * @note For specific error codes, see ble_.h or ble_error_.h. 41 | * @{ */ 42 | #define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */ 43 | #define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */ 44 | #define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */ 45 | #define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */ 46 | /** @} */ 47 | 48 | #endif 49 | 50 | 51 | /** 52 | @} 53 | @} 54 | */ 55 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_API/include/nrf_error_sdm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup nrf_sdm_api 11 | @{ 12 | @defgroup nrf_sdm_error SoftDevice Manager Error Codes 13 | @{ 14 | 15 | @brief Error definitions for the SDM API 16 | */ 17 | 18 | /* Header guard */ 19 | #ifndef NRF_ERROR_SDM_H__ 20 | #define NRF_ERROR_SDM_H__ 21 | 22 | #include "nrf_error.h" 23 | 24 | #define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown lfclk source 25 | #define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts) 26 | #define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing) 27 | 28 | #endif // NRF_ERROR_SDM_H__ 29 | 30 | /** 31 | @} 32 | @} 33 | */ 34 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_API/include/nrf_error_soc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup nrf_soc_api 11 | @{ 12 | @defgroup nrf_soc_error SoC Library Error Codes 13 | @{ 14 | 15 | @brief Error definitions for the SoC library 16 | 17 | */ 18 | 19 | /* Header guard */ 20 | #ifndef NRF_ERROR_SOC_H__ 21 | #define NRF_ERROR_SOC_H__ 22 | 23 | #include "nrf_error.h" 24 | 25 | /* Mutex Errors */ 26 | #define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken 27 | 28 | /* NVIC errors */ 29 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available 30 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed 31 | #define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return 32 | 33 | /* Power errors */ 34 | #define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown 35 | #define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown 36 | #define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return 37 | 38 | /* Rand errors */ 39 | #define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values 40 | 41 | /* PPI errors */ 42 | #define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel 43 | #define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group 44 | 45 | #endif // NRF_ERROR_SOC_H__ 46 | /** 47 | @} 48 | @} 49 | */ 50 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_API/include/nrf_svc.h: -------------------------------------------------------------------------------- 1 | #ifndef NRF_SVC__ 2 | #define NRF_SVC__ 3 | 4 | #ifdef SVCALL_AS_NORMAL_FUNCTION 5 | #define SVCALL(number, return_type, signature) return_type signature 6 | #else 7 | 8 | #ifndef SVCALL 9 | #if defined (__CC_ARM) 10 | #define SVCALL(number, return_type, signature) return_type __svc(number) signature 11 | #elif defined (__GNUC__) 12 | #define SVCALL(number, return_type, signature) \ 13 | _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \ 14 | _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \ 15 | __attribute__((naked)) static return_type signature \ 16 | { \ 17 | __asm( \ 18 | "svc %0\n" \ 19 | "bx r14" : : "I" ((uint32_t)number) : "r0" \ 20 | ); \ 21 | } 22 | #elif defined (__ICCARM__) 23 | #define PRAGMA(x) _Pragma(#x) 24 | #define SVCALL(number, return_type, signature) \ 25 | PRAGMA(swi_number = number) \ 26 | __swi return_type signature; 27 | #else 28 | #define SVCALL(number, return_type, signature) return_type signature 29 | #endif 30 | #endif // SVCALL 31 | 32 | #endif // SVCALL_AS_NORMAL_FUNCTION 33 | #endif // NRF_SVC__ 34 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_API/include/softdevice_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | 10 | /** @brief Utilities for verifying program logic 11 | */ 12 | 13 | #ifndef SOFTDEVICE_ASSERT_H_ 14 | #define SOFTDEVICE_ASSERT_H_ 15 | 16 | #include 17 | 18 | /** @brief This function handles assertions. 19 | * 20 | * 21 | * @note 22 | * This function is called when an assertion has triggered. 23 | * 24 | * 25 | * @param line_num The line number where the assertion is called 26 | * @param file_name Pointer to the file name 27 | */ 28 | void assert_softdevice_callback(uint16_t line_num, const uint8_t *file_name); 29 | 30 | 31 | /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 32 | /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ 33 | /** @brief Check intended for production code 34 | * 35 | * Check passes if "expr" evaluates to true. */ 36 | #define ASSERT(expr) \ 37 | if (expr) \ 38 | { \ 39 | } \ 40 | else \ 41 | { \ 42 | assert_softdevice_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ 43 | /*lint -unreachable */ \ 44 | } 45 | 46 | #endif /* SOFTDEVICE_ASSERT_H_ */ 47 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_licence_agreement.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_licence_agreement.pdf -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_migration-document.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_migration-document.pdf -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_readme.txt: -------------------------------------------------------------------------------- 1 | s110_nrf51822_7.0.0 2 | 3 | This release consists of the following: 4 | - This readme file 5 | - The s110_nrf51822_7.0.0 license 6 | - The s110_nrf51822_7.0.0 softdevice (binary hex file) 7 | - The s110_nrf51822_7.0.0 API (softdevice header files) 8 | - The s110_nrf51822_7.0.0 release notes 9 | - The s110_nrf51822_7.0.0 migration document 10 | 11 | 12 | IMPORTANT NOTE: If you intend to use the softdevice with the nRF51 13 | SDK only, you do _not_ need the API files. The API header files are 14 | already installed as part of the nRF51 SDK versions 6.0.0. 15 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_releasenotes.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/Lib/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_releasenotes.pdf -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/PeripheralNames.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2013 Nordic Semiconductor 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PERIPHERALNAMES_H 17 | #define MBED_PERIPHERALNAMES_H 18 | 19 | #include "cmsis.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | #define STDIO_UART_TX TX_PIN_NUMBER 26 | #define STDIO_UART_RX RX_PIN_NUMBER 27 | #define STDIO_UART UART_0 28 | 29 | typedef enum { 30 | UART_0 = (int)NRF_UART0_BASE 31 | } UARTName; 32 | 33 | 34 | typedef enum { 35 | SPI_0 = (int)NRF_SPI0_BASE, 36 | SPI_1 = (int)NRF_SPI1_BASE, 37 | SPIS = (int)NRF_SPIS1_BASE 38 | } SPIName; 39 | 40 | typedef enum { 41 | PWM_1 = 0, 42 | PWM_2 43 | } PWMName; 44 | 45 | typedef enum { 46 | I2C_0 = (int)NRF_TWI0_BASE, 47 | I2C_1 = (int)NRF_TWI1_BASE 48 | } I2CName; 49 | 50 | typedef enum { 51 | ADC0_0 = (int)NRF_ADC_BASE 52 | } ADCName; 53 | 54 | #ifdef __cplusplus 55 | } 56 | #endif 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/PortNames.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2013 Nordic Semiconductor 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_PORTNAMES_H 17 | #define MBED_PORTNAMES_H 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | typedef enum { 24 | Port0 = 0 //GPIO pins 0-31 25 | } PortName; 26 | 27 | #ifdef __cplusplus 28 | } 29 | #endif 30 | #endif 31 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/TARGET_ARCH_BLE/device.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_DEVICE_H 17 | #define MBED_DEVICE_H 18 | 19 | #define DEVICE_PORTIN 1 20 | #define DEVICE_PORTOUT 1 21 | #define DEVICE_PORTINOUT 1 22 | 23 | #define DEVICE_INTERRUPTIN 1 24 | 25 | #define DEVICE_ANALOGIN 1 26 | #define DEVICE_ANALOGOUT 0 27 | 28 | #define DEVICE_SERIAL 1 29 | 30 | #define DEVICE_I2C 1 31 | #define DEVICE_I2CSLAVE 0 32 | 33 | #define DEVICE_SPI 1 34 | #define DEVICE_SPISLAVE 1 35 | 36 | #define DEVICE_CAN 0 37 | 38 | #define DEVICE_RTC 0 39 | 40 | #define DEVICE_ETHERNET 0 41 | 42 | #define DEVICE_PWMOUT 1 43 | 44 | #define DEVICE_SEMIHOST 0 45 | #define DEVICE_LOCALFILESYSTEM 0 46 | 47 | #define DEVICE_SLEEP 1 48 | 49 | #define DEVICE_DEBUG_AWARENESS 0 50 | 51 | #define DEVICE_STDIO_MESSAGES 0 52 | 53 | #define DEVICE_ERROR_PATTERN 1 54 | 55 | #include "objects.h" 56 | 57 | #endif 58 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/gpio_api.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mbed_assert.h" 17 | #include "gpio_api.h" 18 | #include "pinmap.h" 19 | 20 | void gpio_init(gpio_t *obj, PinName pin) 21 | { 22 | obj->pin = pin; 23 | if (pin == (PinName)NC) { 24 | return; 25 | } 26 | 27 | obj->mask = (1ul << pin); 28 | 29 | obj->reg_set = &NRF_GPIO->OUTSET; 30 | obj->reg_clr = &NRF_GPIO->OUTCLR; 31 | obj->reg_in = &NRF_GPIO->IN; 32 | obj->reg_dir = &NRF_GPIO->DIR; 33 | } 34 | 35 | void gpio_mode(gpio_t *obj, PinMode mode) 36 | { 37 | pin_mode(obj->pin, mode); 38 | } 39 | 40 | void gpio_dir(gpio_t *obj, PinDirection direction) 41 | { 42 | MBED_ASSERT(obj->pin != (PinName)NC); 43 | switch (direction) { 44 | case PIN_INPUT: 45 | NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 46 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 47 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 48 | | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 49 | break; 50 | case PIN_OUTPUT: 51 | NRF_GPIO->PIN_CNF[obj->pin] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) 52 | | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) 53 | | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) 54 | | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) 55 | | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); 56 | break; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/gpio_object.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_GPIO_OBJECT_H 17 | #define MBED_GPIO_OBJECT_H 18 | 19 | #include "mbed_assert.h" 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | typedef struct { 26 | PinName pin; 27 | uint32_t mask; 28 | 29 | __IO uint32_t *reg_dir; 30 | __IO uint32_t *reg_set; 31 | __IO uint32_t *reg_clr; 32 | __I uint32_t *reg_in; 33 | } gpio_t; 34 | 35 | static inline void gpio_write(gpio_t *obj, int value) { 36 | MBED_ASSERT(obj->pin != (PinName)NC); 37 | if (value) 38 | *obj->reg_set = obj->mask; 39 | else 40 | *obj->reg_clr = obj->mask; 41 | } 42 | 43 | static inline int gpio_read(gpio_t *obj) { 44 | MBED_ASSERT(obj->pin != (PinName)NC); 45 | return ((*obj->reg_in & obj->mask) ? 1 : 0); 46 | } 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/objects.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2013 Nordic Semiconductor 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #ifndef MBED_OBJECTS_H 17 | #define MBED_OBJECTS_H 18 | 19 | #include "cmsis.h" 20 | #include "PortNames.h" 21 | #include "PeripheralNames.h" 22 | #include "PinNames.h" 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | struct serial_s { 29 | NRF_UART_Type *uart; 30 | int index; 31 | }; 32 | 33 | struct spi_s { 34 | NRF_SPI_Type *spi; 35 | NRF_SPIS_Type *spis; 36 | }; 37 | 38 | struct port_s { 39 | __IO uint32_t *reg_cnf; 40 | __IO uint32_t *reg_out; 41 | __I uint32_t *reg_in; 42 | PortName port; 43 | uint32_t mask; 44 | }; 45 | 46 | struct pwmout_s { 47 | PWMName pwm; 48 | PinName pin; 49 | }; 50 | 51 | struct i2c_s { 52 | NRF_TWI_Type *i2c; 53 | PinName sda; 54 | PinName scl; 55 | int freq; 56 | uint8_t address_set; 57 | }; 58 | 59 | struct analogin_s { 60 | ADCName adc; 61 | uint8_t adc_pin; 62 | }; 63 | 64 | struct gpio_irq_s { 65 | uint32_t ch; 66 | }; 67 | 68 | #include "gpio_object.h" 69 | 70 | #ifdef __cplusplus 71 | } 72 | #endif 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/pinmap.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "mbed_assert.h" 17 | #include "pinmap.h" 18 | #include "mbed_error.h" 19 | 20 | void pin_function(PinName pin, int function) 21 | { 22 | } 23 | 24 | void pin_mode(PinName pin, PinMode mode) 25 | { 26 | MBED_ASSERT(pin != (PinName)NC); 27 | 28 | uint32_t pin_number = (uint32_t)pin; 29 | 30 | NRF_GPIO->PIN_CNF[pin_number] &= ~GPIO_PIN_CNF_PULL_Msk; 31 | NRF_GPIO->PIN_CNF[pin_number] |= (mode << GPIO_PIN_CNF_PULL_Pos); 32 | } 33 | -------------------------------------------------------------------------------- /mbed-src/targets/hal/TARGET_NORDIC/TARGET_MCU_NRF51822/sleep.c: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "sleep_api.h" 17 | #include "cmsis.h" 18 | #include "mbed_interface.h" 19 | 20 | void sleep(void) 21 | { 22 | // ensure debug is disconnected if semihost is enabled.... 23 | NRF_POWER->TASKS_LOWPWR = 1; 24 | // wait for interrupt 25 | __WFE(); 26 | } 27 | 28 | void deepsleep(void) 29 | { 30 | sleep(); 31 | // NRF_POWER->SYSTEMOFF=1; 32 | } 33 | -------------------------------------------------------------------------------- /nRF51822/btle/btle.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _BTLE_H_ 18 | #define _BTLE_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "common/common.h" 25 | 26 | #include "ble_srv_common.h" 27 | #include "ble.h" 28 | 29 | error_t btle_init(void); 30 | 31 | #ifdef __cplusplus 32 | } 33 | #endif 34 | 35 | #endif // ifndef _BTLE_H_ 36 | -------------------------------------------------------------------------------- /nRF51822/btle/btle_advertising.cpp: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | #include "common/common.h" 17 | 18 | #include "ble_advdata.h" 19 | #include "btle.h" 20 | 21 | /**************************************************************************/ 22 | /*! 23 | @brief Starts the advertising process 24 | 25 | @returns 26 | */ 27 | /**************************************************************************/ 28 | error_t btle_advertising_start(void) 29 | { 30 | ble_gap_adv_params_t adv_para = {0}; 31 | 32 | /* Set the default advertising parameters */ 33 | adv_para.type = BLE_GAP_ADV_TYPE_ADV_IND; 34 | adv_para.p_peer_addr = NULL; /* Undirected advertising */ 35 | adv_para.fp = BLE_GAP_ADV_FP_ANY; 36 | adv_para.p_whitelist = NULL; 37 | adv_para.interval = (CFG_GAP_ADV_INTERVAL_MS * 8) / 5; /* Advertising 38 | * interval in 39 | * units of 0.625 40 | * ms */ 41 | adv_para.timeout = CFG_GAP_ADV_TIMEOUT_S; 42 | 43 | ASSERT_STATUS( sd_ble_gap_adv_start(&adv_para)); 44 | 45 | return ERROR_NONE; 46 | } 47 | -------------------------------------------------------------------------------- /nRF51822/btle/btle_advertising.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _BTLE_ADVERTISING_H_ 18 | #define _BTLE_ADVERTISING_H_ 19 | 20 | #include "common/common.h" 21 | 22 | error_t btle_advertising_start(void); 23 | 24 | #endif // ifndef _BTLE_ADVERTISING_H_ 25 | -------------------------------------------------------------------------------- /nRF51822/btle/btle_gap.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _BTLE_GAP_H_ 18 | #define _BTLE_GAP_H_ 19 | 20 | #include "common/common.h" 21 | 22 | error_t btle_gap_init(void); 23 | 24 | #endif // ifndef _BTLE_GAP_H_ 25 | -------------------------------------------------------------------------------- /nRF51822/btle/custom/custom_helper.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef _CUSTOM_HELPER_H_ 18 | #define _CUSTOM_HELPER_H_ 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | #include "common/common.h" 25 | #include "ble.h" 26 | #include "UUID.h" 27 | 28 | uint8_t custom_add_uuid_base(uint8_t const *const p_uuid_base); 29 | error_t custom_decode_uuid(uint8_t const *const p_uuid_base, 30 | ble_uuid_t *p_uuid); 31 | ble_uuid_t custom_convert_to_nordic_uuid(const UUID &uuid); 32 | 33 | error_t custom_add_in_characteristic(uint16_t service_handle, 34 | ble_uuid_t *p_uuid, 35 | uint8_t properties, 36 | uint8_t *p_data, 37 | uint16_t min_length, 38 | uint16_t max_length, 39 | ble_gatts_char_handles_t *p_char_handle); 40 | 41 | error_t custom_add_in_descriptor(uint16_t char_handle, 42 | ble_uuid_t *p_uuid, 43 | uint8_t *p_data, 44 | uint16_t min_length, 45 | uint16_t max_length, 46 | uint16_t *p_desc_handle); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif // ifndef _CUSTOM_HELPER_H_ 53 | -------------------------------------------------------------------------------- /nRF51822/nRF51822n.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __NRF51822_H__ 18 | #define __NRF51822_H__ 19 | 20 | #define NRF51 21 | #define DEBUG_NRF_USER 22 | #define BLE_STACK_SUPPORT_REQD 23 | #define BOARD_PCA10001 24 | 25 | #include "mbed.h" 26 | #include "blecommon.h" 27 | #include "BLEDevice.h" 28 | #include "nRF51Gap.h" 29 | #include "nRF51GattServer.h" 30 | 31 | class nRF51822n : public BLEDeviceInstanceBase 32 | { 33 | public: 34 | nRF51822n(void); 35 | virtual ~nRF51822n(void); 36 | 37 | virtual const char *getVersion(void); 38 | 39 | virtual Gap &getGap() { 40 | return nRF51Gap::getInstance(); 41 | }; 42 | virtual GattServer &getGattServer() { 43 | return nRF51GattServer::getInstance(); 44 | }; 45 | 46 | virtual ble_error_t setTxPower(int8_t txPower); 47 | 48 | virtual ble_error_t init(void); 49 | virtual ble_error_t reset(void); 50 | virtual void waitForEvent(void); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /nRF51822/nRF51GattServer.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2013 ARM Limited 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | #ifndef __NRF51822_GATT_SERVER_H__ 18 | #define __NRF51822_GATT_SERVER_H__ 19 | 20 | #include "mbed.h" 21 | #include "blecommon.h" 22 | #include "ble.h" /* nordic ble */ 23 | #include "GattService.h" 24 | #include "public/GattServer.h" 25 | 26 | #define BLE_TOTAL_CHARACTERISTICS 24 27 | #define BLE_TOTAL_DESCRIPTORS 24 28 | 29 | class nRF51GattServer : public GattServer 30 | { 31 | public: 32 | static nRF51GattServer &getInstance() { 33 | static nRF51GattServer m_instance; 34 | return m_instance; 35 | } 36 | 37 | /* Functions that must be implemented from GattServer */ 38 | virtual ble_error_t addService(GattService &); 39 | virtual ble_error_t readValue(uint16_t handle, uint8_t buffer[], uint16_t *const lengthP); 40 | virtual ble_error_t updateValue(uint16_t, uint8_t[], uint16_t, bool localOnly = false); 41 | 42 | /* nRF51 Functions */ 43 | void eventCallback(void); 44 | void hwCallback(ble_evt_t *p_ble_evt); 45 | 46 | private: 47 | GattCharacteristic *p_characteristics[BLE_TOTAL_CHARACTERISTICS]; 48 | ble_gatts_char_handles_t nrfCharacteristicHandles[BLE_TOTAL_CHARACTERISTICS]; 49 | GattAttribute *p_descriptors[BLE_TOTAL_DESCRIPTORS]; 50 | uint16_t nrfDescriptorHandles[BLE_TOTAL_DESCRIPTORS]; 51 | 52 | nRF51GattServer() { 53 | serviceCount = 0; 54 | characteristicCount = 0; 55 | descriptorCount = 0; 56 | }; 57 | 58 | nRF51GattServer(nRF51GattServer const &); 59 | void operator=(nRF51GattServer const &); 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /nRF51822/nordic/app_common/crc16.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #include "crc16.h" 14 | #include 15 | 16 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc) 17 | { 18 | uint32_t i; 19 | uint16_t crc = (p_crc == NULL) ? 0xffff : *p_crc; 20 | 21 | for (i = 0; i < size; i++) 22 | { 23 | crc = (unsigned char)(crc >> 8) | (crc << 8); 24 | crc ^= p_data[i]; 25 | crc ^= (unsigned char)(crc & 0xff) >> 4; 26 | crc ^= (crc << 8) << 4; 27 | crc ^= ((crc & 0xff) << 4) << 1; 28 | } 29 | 30 | return crc; 31 | } 32 | -------------------------------------------------------------------------------- /nRF51822/nordic/ble/ble_advdata_parser.cpp: -------------------------------------------------------------------------------- 1 | #include "ble_advdata_parser.h" 2 | 3 | uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data) 4 | { 5 | uint32_t index = 0; 6 | 7 | while (index < *len) 8 | { 9 | uint8_t field_length = p_advdata[index]; 10 | uint8_t field_type = p_advdata[index+1]; 11 | 12 | if (field_type == type) 13 | { 14 | *pp_field_data = &p_advdata[index+2]; 15 | *len = field_length-1; 16 | return NRF_SUCCESS; 17 | } 18 | index += field_length+1; 19 | } 20 | return NRF_ERROR_NOT_FOUND; 21 | } 22 | -------------------------------------------------------------------------------- /nRF51822/nordic/ble/ble_debug_assert_handler.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #include "ble_debug_assert_handler.h" 14 | #include 15 | #include "nrf51.h" 16 | #include "ble_error_log.h" 17 | #include "nordic_common.h" 18 | 19 | #define MAX_LENGTH_FILENAME 128 /**< Max length of filename to copy for the debug error handlier. */ 20 | 21 | 22 | // WARNING - DO NOT USE THIS FUNCTION IN END PRODUCT. - WARNING 23 | // WARNING - FOR DEBUG PURPOSES ONLY. - WARNING 24 | void ble_debug_assert_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name) 25 | { 26 | // Copying parameters to static variables because parameters may not be accessible in debugger. 27 | static volatile uint8_t s_file_name[MAX_LENGTH_FILENAME]; 28 | static volatile uint16_t s_line_num; 29 | static volatile uint32_t s_error_code; 30 | 31 | strncpy((char *)s_file_name, (const char *)p_file_name, MAX_LENGTH_FILENAME - 1); 32 | s_file_name[MAX_LENGTH_FILENAME - 1] = '\0'; 33 | s_line_num = line_num; 34 | s_error_code = error_code; 35 | UNUSED_VARIABLE(s_file_name); 36 | UNUSED_VARIABLE(s_line_num); 37 | UNUSED_VARIABLE(s_error_code); 38 | 39 | // WARNING: The PRIMASK register is set to disable ALL interrups during writing the error log. 40 | // 41 | // Do not use __disable_irq() in normal operation. 42 | __disable_irq(); 43 | 44 | // This function will write error code, filename, and line number to the flash. 45 | // In addition, the Cortex-M0 stack memory will also be written to the flash. 46 | //(void) ble_error_log_write(error_code, p_file_name, line_num); 47 | 48 | // For debug purposes, this function never returns. 49 | // Attach a debugger for tracing the error cause. 50 | for (;;) 51 | { 52 | // Do nothing. 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /nRF51822/nordic/ble/ble_error_log.cpp: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #include 14 | #include 15 | #include 16 | #include 17 | #include "ble_error_log.h" 18 | #include "app_util.h" 19 | #include "app_error.h" 20 | #include "nrf_gpio.h" 21 | #include "pstorage.h" 22 | 23 | 24 | // Made static to avoid the error_log to go on the stack. 25 | static ble_error_log_data_t m_ble_error_log; /**< . */ 26 | //lint -esym(526,__Vectors) 27 | extern uint32_t * __Vectors; /**< The initialization vector holds the address to __initial_sp that will be used when fetching the stack. */ 28 | 29 | static void fetch_stack(ble_error_log_data_t * error_log) 30 | { 31 | // KTOWN: Temporarily removed 06022014 32 | /* 33 | uint32_t * p_stack; 34 | uint32_t * initial_sp; 35 | uint32_t length; 36 | 37 | initial_sp = (uint32_t *) __Vectors; 38 | p_stack = (uint32_t *) GET_SP(); 39 | 40 | length = ((uint32_t) initial_sp) - ((uint32_t) p_stack); 41 | memcpy(error_log->stack_info, 42 | p_stack, 43 | (length > STACK_DUMP_LENGTH) ? STACK_DUMP_LENGTH : length); 44 | */ 45 | } 46 | 47 | uint32_t ble_error_log_write(uint32_t err_code, const uint8_t * p_message, uint16_t line_number) 48 | { 49 | m_ble_error_log.failure = true; 50 | m_ble_error_log.err_code = err_code; 51 | m_ble_error_log.line_number = line_number; 52 | 53 | strncpy((char *)m_ble_error_log.message, (const char *)p_message, ERROR_MESSAGE_LENGTH - 1); 54 | m_ble_error_log.message[ERROR_MESSAGE_LENGTH - 1] = '\0'; 55 | 56 | fetch_stack(&m_ble_error_log); 57 | 58 | // Write to flash removed, to be redone. 59 | 60 | return NRF_SUCCESS; 61 | } 62 | -------------------------------------------------------------------------------- /nRF51822/nordic/ble/ble_services/ble_srv_common.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/nRF51822/nordic/ble/ble_services/ble_srv_common.cpp -------------------------------------------------------------------------------- /nRF51822/nordic/ble_bondmngr_cfg.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @cond To make doxygen skip this file */ 14 | 15 | /** @file 16 | * 17 | * @defgroup ble_sdk_app_gls_bondmngr_cfg GLS Bond Manager Configuration 18 | * @{ 19 | * @ingroup ble_sdk_app_gls 20 | * @brief Definition of bond manager configurable parameters 21 | */ 22 | 23 | #ifndef BLE_BONDMNGR_CFG_H__ 24 | #define BLE_BONDMNGR_CFG_H__ 25 | 26 | /**@brief Number of CCCDs used in the GLS application. */ 27 | #define BLE_BONDMNGR_CCCD_COUNT 2 28 | 29 | /**@brief Maximum number of bonded centrals. */ 30 | #define BLE_BONDMNGR_MAX_BONDED_CENTRALS 7 31 | 32 | #endif // BLE_BONDMNGR_CFG_H__ 33 | 34 | /** @} */ 35 | /** @endcond */ 36 | -------------------------------------------------------------------------------- /nRF51822/nordic/bootloader_dfu/dfu_app_handler.c: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #include "dfu_app_handler.h" 14 | #include "bootloader_util.h" 15 | #include "nrf_sdm.h" 16 | #include "app_error.h" 17 | 18 | static void dfu_app_reset_prepare(void); /**< Forward declare of default reset handler. */ 19 | static dfu_app_reset_prepare_t m_reset_prepare = dfu_app_reset_prepare; /**< Callback function to application to prepare for system reset. Allows application to cleanup of service and memory prior to reset. */ 20 | 21 | 22 | /**@brief Default reset prepare handler if application hasn't registered a handler. 23 | */ 24 | static void dfu_app_reset_prepare(void) 25 | { 26 | // Reset prepare should be handled by application. 27 | // This function can be extended to include default handling if application does not implement 28 | // own handler. 29 | } 30 | 31 | 32 | /**@brief Function for preparing the reset, disabling SoftDevice and jump to the bootloader. 33 | */ 34 | void bootloader_start(void) 35 | { 36 | m_reset_prepare(); 37 | 38 | uint32_t err_code = sd_power_gpregret_set(BOOTLOADER_DFU_START); 39 | APP_ERROR_CHECK(err_code); 40 | 41 | NVIC_SystemReset(); 42 | } 43 | 44 | 45 | 46 | void dfu_app_reset_prepare_set(dfu_app_reset_prepare_t reset_prepare_func) 47 | { 48 | m_reset_prepare = reset_prepare_func; 49 | } 50 | -------------------------------------------------------------------------------- /nRF51822/nordic/nordic_global.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * Licensed under the Apache License, Version 2.0 (the "License"); 4 | * you may not use this file except in compliance with the License. 5 | * You may obtain a copy of the License at 6 | * 7 | * http://www.apache.org/licenses/LICENSE-2.0 8 | * 9 | * Unless required by applicable law or agreed to in writing, software 10 | * distributed under the License is distributed on an "AS IS" BASIS, 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | * See the License for the specific language governing permissions and 13 | * limitations under the License. 14 | */ 15 | 16 | #ifndef _NORDIC_GLOBAL_H_ 17 | #define _NORDIC_GLOBAL_H_ 18 | 19 | /* There are no global defines in mbed, so we need to define */ 20 | /* mandatory conditional compilation flags here */ 21 | #define NRF51 22 | #define DEBUG_NRF_USER 23 | #define BLE_STACK_SUPPORT_REQD 24 | #define BOARD_PCA10001 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/app_common/app_trace.h: -------------------------------------------------------------------------------- 1 | #ifndef __DEBUG_H_ 2 | #define __DEBUG_H_ 3 | 4 | #include 5 | #include 6 | 7 | /** 8 | * @defgroup app_trace Debug Logger 9 | * @ingroup app_common 10 | * @{ 11 | * @brief Enables debug logs/ trace over UART. 12 | * @details Enables debug logs/ trace over UART. Tracing is enabled only if 13 | * ENABLE_DEBUG_LOG_SUPPORT is defined in the project. 14 | */ 15 | #ifdef ENABLE_DEBUG_LOG_SUPPORT 16 | /** 17 | * @brief Module Initialization. 18 | * 19 | * @details Initializes the module to use UART as trace output. 20 | * 21 | * @warning This function will configure UART using default board configuration (described in @ref nrf51_setups). 22 | * Do not call this function if UART is configured from a higher level in the application. 23 | */ 24 | void app_trace_init(void); 25 | 26 | /** 27 | * @brief Log debug messages. 28 | * 29 | * @details This API logs messages over UART. The module must be initialized before using this API. 30 | * 31 | * @note Though this is currently a macro, it should be used used and treated as function. 32 | */ 33 | #define app_trace_log printf 34 | 35 | /** 36 | * @brief Dump auxiliary byte buffer to the debug trace. 37 | * 38 | * @details This API logs messages over UART. The module must be initialized before using this API. 39 | * 40 | * @param[in] p_buffer Buffer to be dumped on the debug trace. 41 | * @param[in] len Size of the buffer. 42 | */ 43 | void app_trace_dump(uint8_t * p_buffer, uint32_t len); 44 | 45 | #else // ENABLE_DEBUG_LOG_SUPPORT 46 | 47 | #define app_trace_init(...) 48 | #define app_trace_log(...) 49 | #define app_trace_dump(...) 50 | 51 | #endif // ENABLE_DEBUG_LOG_SUPPORT 52 | 53 | /** @} */ 54 | 55 | #endif //__DEBUG_H_ 56 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/app_common/crc16.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @file 14 | * 15 | * @defgroup crc_compute CRC compute 16 | * @{ 17 | * @ingroup hci_transport 18 | * 19 | * @brief This module implements the CRC-16 calculation in the blocks. 20 | */ 21 | 22 | #ifndef CRC16_H__ 23 | #define CRC16_H__ 24 | 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | /**@brief Function for calculating CRC-16 in blocks. 32 | * 33 | * Feed each consecutive data block into this function, along with the current value of p_crc as 34 | * returned by the previous call of this function. The first call of this function should pass NULL 35 | * as the initial value of the crc in p_crc. 36 | * 37 | * @param[in] p_data The input data block for computation. 38 | * @param[in] size The size of the input data block in bytes. 39 | * @param[in] p_crc The previous calculated CRC-16 value or NULL if first call. 40 | * 41 | * @return The updated CRC-16 value, based on the input supplied. 42 | */ 43 | uint16_t crc16_compute(const uint8_t * p_data, uint32_t size, const uint16_t * p_crc); 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | 50 | #endif // CRC16_H__ 51 | 52 | /** @} */ 53 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/app_common/hci_mem_pool_internal.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @file 14 | * 15 | * @defgroup memory_pool_internal Memory Pool Internal 16 | * @{ 17 | * @ingroup memory_pool 18 | * 19 | * @brief Memory pool internal definitions 20 | */ 21 | 22 | #ifndef MEM_POOL_INTERNAL_H__ 23 | #define MEM_POOL_INTERNAL_H__ 24 | 25 | #define TX_BUF_SIZE 600u /**< TX buffer size in bytes. */ 26 | #define RX_BUF_SIZE TX_BUF_SIZE /**< RX buffer size in bytes. */ 27 | 28 | #define RX_BUF_QUEUE_SIZE 4u /**< RX buffer element size. */ 29 | 30 | #endif // MEM_POOL_INTERNAL_H__ 31 | 32 | /** @} */ 33 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_advdata_parser.h: -------------------------------------------------------------------------------- 1 | #ifndef BLE_ADVDATA_PARSER_H_ 2 | #define BLE_ADVDATA_PARSER_H_ 3 | 4 | #include "ble_advdata.h" 5 | 6 | uint32_t ble_advdata_parse(uint8_t * p_data, uint8_t len, ble_advdata_t * advdata); 7 | uint32_t ble_advdata_parser_field_find(uint8_t type, uint8_t * p_advdata, uint8_t * len, uint8_t ** pp_field_data); 8 | 9 | #endif 10 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_central_bondmngr.h: -------------------------------------------------------------------------------- 1 | #ifndef __BLE_CENTRAL_BONDMNGR_H_ 2 | #define __BLE_CENTRAL_BONDMNGR_H_ 3 | 4 | #include "ble.h" 5 | #include "ble_gap.h" 6 | 7 | #include 8 | #include 9 | 10 | typedef struct 11 | { 12 | ble_gap_sec_params_t * p_sec_params; 13 | } ble_central_bondmngr_t; 14 | 15 | typedef struct 16 | { 17 | ble_gap_sec_params_t * p_sec_params; 18 | bool delete_bonds; 19 | } ble_central_bondmngr_init_t; 20 | 21 | uint32_t ble_central_bondmngr_init(ble_central_bondmngr_t * p_bm, ble_central_bondmngr_init_t * p_bm_init); 22 | void ble_central_bondmngr_on_ble_evt(ble_central_bondmngr_t * p_bm, ble_evt_t * p_ble_evt); 23 | uint32_t ble_central_bondmngr_store(ble_central_bondmngr_t * p_bm); 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_date_time.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/nRF51822/nordic/nrf-sdk/ble/ble_date_time.h -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_debug_assert_handler.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /** @file 14 | * 15 | * @defgroup ble_debug_assert_handler Assert Handler for debug purposes. 16 | * @{ 17 | * @ingroup ble_sdk_lib 18 | * @brief Module for handling of assert during application development when debugging. 19 | * 20 | * @details This module may be used during development of an application to facilitate debugging. 21 | * It contains a function to write file name, line number and the Stack Memory to flash. 22 | * This module is ONLY for debugging purposes and must never be used in final product. 23 | * 24 | */ 25 | 26 | #ifndef BLE_DEBUG_ASSERT_HANDLER_H__ 27 | #define BLE_DEBUG_ASSERT_HANDLER_H__ 28 | 29 | #include 30 | 31 | /**@brief Function for handling the Debug assert, which can be called from an error handler. 32 | * To be used only for debugging purposes. 33 | * 34 | *@details This code will copy the filename and line number into local variables for them to always 35 | * be accessible in Keil debugger. The function will also write the ARM Cortex-M0 stack 36 | * memory into flash where it can be retrieved and manually un-winded in order to 37 | * back-trace the location where the error ocured.
38 | * @warning ALL INTERRUPTS WILL BE DISABLED. 39 | * 40 | * @note This function will never return but loop forever for debug purposes. 41 | * 42 | * @param[in] error_code Error code supplied to the handler. 43 | * @param[in] line_num Line number where the original handler is called. 44 | * @param[in] p_file_name Pointer to the file name. 45 | */ 46 | void ble_debug_assert_handler(uint32_t error_code, uint32_t line_num, const uint8_t * p_file_name); 47 | 48 | #endif /* BLE_DEBUG_ASSERT_HANDLER_H__ */ 49 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_radio_notification.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | */ 11 | 12 | /** @file 13 | * 14 | * @defgroup ble_radio_notification Radio Notification Event Handler 15 | * @{ 16 | * @ingroup ble_sdk_lib 17 | * @brief Module for propagating Radio Notification events to the application. 18 | */ 19 | 20 | #ifndef BLE_RADIO_NOTIFICATION_H__ 21 | #define BLE_RADIO_NOTIFICATION_H__ 22 | 23 | #include 24 | #include 25 | #include "nrf_soc.h" 26 | 27 | /**@brief Application radio notification event handler type. */ 28 | typedef void (*ble_radio_notification_evt_handler_t) (bool radio_active); 29 | 30 | /**@brief Function for initializing the Radio Notification module. 31 | * 32 | * @param[in] irq_priority Interrupt priority for the Radio Notification interrupt handler. 33 | * @param[in] distance The time from an Active event until the radio is activated. 34 | * @param[in] evt_handler Handler to be executed when a radio notification event has been 35 | * received. 36 | * 37 | * @return NRF_SUCCESS on successful initialization, otherwise an error code. 38 | */ 39 | uint32_t ble_radio_notification_init(nrf_app_irq_priority_t irq_priority, 40 | nrf_radio_notification_distance_t distance, 41 | ble_radio_notification_evt_handler_t evt_handler); 42 | 43 | #endif // BLE_RADIO_NOTIFICATION_H__ 44 | 45 | /** @} */ 46 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/ble/ble_services/ble_sensor_location.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Seeed-Studio/mbed_ble/a1c565695018add27ce1210273b86e1692d5acce/nRF51822/nordic/nrf-sdk/ble/ble_services/ble_sensor_location.h -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/bootloader_dfu/bootloader_types.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /**@file 14 | * 15 | * @defgroup nrf_bootloader_types Types and definitions. 16 | * @{ 17 | * 18 | * @ingroup nrf_bootloader 19 | * 20 | * @brief Bootloader module type and definitions. 21 | */ 22 | 23 | #ifndef BOOTLOADER_TYPES_H__ 24 | #define BOOTLOADER_TYPES_H__ 25 | 26 | #include 27 | 28 | #define BOOTLOADER_DFU_START 0xB1 29 | 30 | /**@brief DFU Bank state code, which indicates wether the bank contains: A valid image, invalid image, or an erased flash. 31 | */ 32 | typedef enum 33 | { 34 | BANK_VALID_APP = 0x01, 35 | BANK_VALID_SD = 0xA5, 36 | BANK_VALID_BOOT = 0xAA, 37 | BANK_ERASED = 0xFE, 38 | BANK_INVALID_APP = 0xFF, 39 | } bootloader_bank_code_t; 40 | 41 | /**@brief Structure holding bootloader settings for application and bank data. 42 | */ 43 | typedef struct 44 | { 45 | bootloader_bank_code_t bank_0; /**< Variable to store if bank 0 contains a valid application. */ 46 | uint16_t bank_0_crc; /**< If bank is valid, this field will contain a valid CRC of the total image. */ 47 | bootloader_bank_code_t bank_1; /**< Variable to store if bank 1 has been erased/prepared for new image. Bank 1 is only used in Banked Update scenario. */ 48 | uint32_t bank_0_size; /**< Size of active image in bank0 if present, otherwise 0. */ 49 | uint32_t sd_image_size; /**< Size of SoftDevice image in bank0 if bank_0 code is \ref BANK_VALID_SD. */ 50 | uint32_t bl_image_size; /**< Size of Bootloader image in bank0 if bank_0 code is \ref BANK_VALID_SD. */ 51 | uint32_t app_image_size; /**< Size of Application image in bank0 if bank_0 code is \ref BANK_VALID_SD. */ 52 | uint32_t sd_image_start; /**< Location in flash where SoftDevice image is stored for SoftDevice update. */ 53 | } bootloader_settings_t; 54 | 55 | #endif // BOOTLOADER_TYPES_H__ 56 | 57 | /**@} */ 58 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/bootloader_dfu/bootloader_util.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2013 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | /**@file 14 | * 15 | * @defgroup nrf_bootloader_util Bootloader util API. 16 | * @{ 17 | * 18 | * @brief Bootloader util module interface. 19 | */ 20 | 21 | #ifndef BOOTLOADER_UTIL_H__ 22 | #define BOOTLOADER_UTIL_H__ 23 | 24 | #include 25 | #include "bootloader_types.h" 26 | 27 | /**@brief Function for starting the application (or bootloader) at the provided address. 28 | * 29 | * @param[in] start_addr Start address. 30 | * 31 | * @note This function will never retrun. Instead it will reset into the application of the 32 | * provided address. 33 | */ 34 | void bootloader_util_app_start(uint32_t start_addr); 35 | 36 | #endif // BOOTLOADER_UTIL_H__ 37 | 38 | /**@} */ 39 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/nrf_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | 10 | /** @file 11 | * @brief Utilities for verifying program logic 12 | */ 13 | 14 | #ifndef NRF_ASSERT_H_ 15 | #define NRF_ASSERT_H_ 16 | 17 | #include 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | #if defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) 24 | 25 | /** @brief Function for handling assertions. 26 | * 27 | * 28 | * @note 29 | * This function is called when an assertion has triggered. 30 | * 31 | * 32 | * @post 33 | * All hardware is put into an idle non-emitting state (in particular the radio is highly 34 | * important to switch off since the radio might be in a state that makes it send 35 | * packets continiously while a typical final infinit ASSERT loop is executing). 36 | * 37 | * 38 | * @param line_num The line number where the assertion is called 39 | * @param file_name Pointer to the file name 40 | */ 41 | void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); 42 | 43 | /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 44 | /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ 45 | 46 | /** @brief Function for checking intended for production code. 47 | * 48 | * Check passes if "expr" evaluates to true. */ 49 | #define ASSERT(expr) \ 50 | if (expr) \ 51 | { \ 52 | } \ 53 | else \ 54 | { \ 55 | assert_nrf_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ 56 | } 57 | #else 58 | #define ASSERT(expr) //!< Assert empty when disabled 59 | void assert_nrf_callback(uint16_t line_num, const uint8_t *file_name); 60 | #endif /* defined(DEBUG_NRF) || defined(DEBUG_NRF_USER) */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* NRF_ASSERT_H_ */ 67 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/nrf_delay.h: -------------------------------------------------------------------------------- 1 | #ifndef _NRF_DELAY_H 2 | #define _NRF_DELAY_H 3 | 4 | // #include "nrf.h" 5 | 6 | /*lint --e{438, 522} "Variable not used" "Function lacks side-effects" */ 7 | #if defined ( __CC_ARM ) 8 | static __ASM void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 9 | { 10 | loop 11 | SUBS R0, R0, #1 12 | NOP 13 | NOP 14 | NOP 15 | NOP 16 | NOP 17 | NOP 18 | NOP 19 | NOP 20 | NOP 21 | NOP 22 | NOP 23 | NOP 24 | BNE loop 25 | BX LR 26 | } 27 | #elif defined ( __ICCARM__ ) 28 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 29 | { 30 | __ASM ( 31 | "loop:\n\t" 32 | " SUBS R0, R0, #1\n\t" 33 | " NOP\n\t" 34 | " NOP\n\t" 35 | " NOP\n\t" 36 | " NOP\n\t" 37 | " NOP\n\t" 38 | " NOP\n\t" 39 | " NOP\n\t" 40 | " NOP\n\t" 41 | " NOP\n\t" 42 | " NOP\n\t" 43 | " NOP\n\t" 44 | " NOP\n\t" 45 | " BNE loop\n\t"); 46 | } 47 | #elif defined ( __GNUC__ ) 48 | static void __INLINE nrf_delay_us(uint32_t volatile number_of_us) 49 | { 50 | do 51 | { 52 | __ASM volatile ( 53 | "NOP\n\t" 54 | "NOP\n\t" 55 | "NOP\n\t" 56 | "NOP\n\t" 57 | "NOP\n\t" 58 | "NOP\n\t" 59 | "NOP\n\t" 60 | "NOP\n\t" 61 | "NOP\n\t" 62 | "NOP\n\t" 63 | "NOP\n\t" 64 | "NOP\n\t" 65 | "NOP\n\t" 66 | "NOP\n\t" 67 | ); 68 | } while (--number_of_us); 69 | } 70 | #endif 71 | 72 | void nrf_delay_ms(uint32_t volatile number_of_ms); 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/nrf_ecb.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is confidential property of Nordic 4 | * Semiconductor ASA.Terms and conditions of usage are described in detail 5 | * in NORDIC SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | * $LastChangedRevision: 13999 $ 12 | */ 13 | 14 | /** 15 | * @file 16 | * @brief ECB driver API. 17 | */ 18 | 19 | #ifndef NRF_ECB_H__ 20 | #define NRF_ECB_H__ 21 | 22 | /** 23 | * @defgroup nrf_ecb AES ECB encryption 24 | * @{ 25 | * @ingroup nrf_drivers 26 | * @brief Driver for the nRF51 AES Electronic Code Book (ECB) peripheral. 27 | * 28 | * In order to encrypt and decrypt data the peripheral must be powered on 29 | * using nrf_ecb_init() and then the key set using nrf_ecb_set_key. 30 | */ 31 | 32 | #include 33 | 34 | /** 35 | * Initialize and power on the ECB peripheral. 36 | * 37 | * Allocates memory for the ECBDATAPTR. 38 | * @retval true Initialization was successful. 39 | * @retval false Powering up failed. 40 | */ 41 | bool nrf_ecb_init(void); 42 | 43 | /** 44 | * Encrypt/decrypt 16-byte data using current key. 45 | * 46 | * The function avoids unnecessary copying of data if the point to the 47 | * correct locations in the ECB data structure. 48 | * 49 | * @param dst Result of encryption/decryption. 16 bytes will be written. 50 | * @param src Source with 16-byte data to be encrypted/decrypted. 51 | * 52 | * @retval true If the encryption operation completed. 53 | * @retval false If the encryption operation did not complete. 54 | */ 55 | bool nrf_ecb_crypt(uint8_t * dst, const uint8_t * src); 56 | 57 | /** 58 | * Set the key to be used for encryption/decryption. 59 | * 60 | * @param key Pointer to key. 16 bytes will be read. 61 | */ 62 | void nrf_ecb_set_key(const uint8_t * key); 63 | 64 | #endif // NRF_ECB_H__ 65 | 66 | /** @} */ 67 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/nrf_temp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 2 | * 3 | * The information contained herein is property of Nordic Semiconductor ASA. 4 | * Terms and conditions of usage are described in detail in NORDIC 5 | * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT. 6 | * 7 | * Licensees are granted free, non-transferable use of the information. NO 8 | * WARRANTY of ANY KIND is provided. This heading must NOT be removed from 9 | * the file. 10 | * 11 | */ 12 | 13 | #ifndef NRF_TEMP_H__ 14 | #define NRF_TEMP_H__ 15 | 16 | #include "nrf51.h" 17 | 18 | /** 19 | * @defgroup nrf_temperature TEMP (temperature) abstraction 20 | * @{ 21 | * @ingroup nrf_drivers temperature_example 22 | * @brief Temperature module init and read functions. 23 | * 24 | */ 25 | 26 | 27 | 28 | /** 29 | * @brief Function for preparing the temp module for temperature measurement. 30 | * 31 | * This function initializes the TEMP module and writes to the hidden configuration register. 32 | * 33 | * @param none 34 | */ 35 | static __INLINE void nrf_temp_init(void) 36 | { 37 | /**@note Workaround for PAN_028 rev2.0A anomaly 31 - TEMP: Temperature offset value has to be manually loaded to the TEMP module */ 38 | *(uint32_t *) 0x4000C504 = 0; 39 | } 40 | 41 | 42 | 43 | #define MASK_SIGN (0x00000200UL) 44 | #define MASK_SIGN_EXTENSION (0xFFFFFC00UL) 45 | 46 | /** 47 | * @brief Function for reading temperature measurement. 48 | * 49 | * The function reads the 10 bit 2's complement value and transforms it to a 32 bit 2's complement value. 50 | * 51 | * @param none 52 | */ 53 | static __INLINE int32_t nrf_temp_read(void) 54 | { 55 | /**@note Workaround for PAN_028 rev2.0A anomaly 28 - TEMP: Negative measured values are not represented correctly */ 56 | return ((NRF_TEMP->TEMP & MASK_SIGN) != 0) ? (NRF_TEMP->TEMP | MASK_SIGN_EXTENSION) : (NRF_TEMP->TEMP); 57 | } 58 | 59 | /** @} */ 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/s110/ble_err.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup BLE_COMMON 11 | @{ 12 | @addtogroup nrf_error 13 | @{ 14 | @ingroup BLE_COMMON 15 | @} 16 | 17 | @defgroup ble_err General error codes 18 | @{ 19 | 20 | @brief General error code definitions for the BLE API. 21 | 22 | @ingroup BLE_COMMON 23 | */ 24 | #ifndef NRF_BLE_ERR_H__ 25 | #define NRF_BLE_ERR_H__ 26 | 27 | #include "nrf_error.h" 28 | 29 | /* @defgroup BLE_ERRORS Error Codes 30 | * @{ */ 31 | #define BLE_ERROR_NOT_ENABLED (NRF_ERROR_STK_BASE_NUM+0x001) /**< @ref sd_ble_enable has not been called. */ 32 | #define BLE_ERROR_INVALID_CONN_HANDLE (NRF_ERROR_STK_BASE_NUM+0x002) /**< Invalid connection handle. */ 33 | #define BLE_ERROR_INVALID_ATTR_HANDLE (NRF_ERROR_STK_BASE_NUM+0x003) /**< Invalid attribute handle. */ 34 | #define BLE_ERROR_NO_TX_BUFFERS (NRF_ERROR_STK_BASE_NUM+0x004) /**< Buffer capacity exceeded. */ 35 | /** @} */ 36 | 37 | 38 | /** @defgroup BLE_ERROR_SUBRANGES Module specific error code subranges 39 | * @brief Assignment of subranges for module specific error codes. 40 | * @note For specific error codes, see ble_.h or ble_error_.h. 41 | * @{ */ 42 | #define NRF_L2CAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x100) /**< L2CAP specific errors. */ 43 | #define NRF_GAP_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x200) /**< GAP specific errors. */ 44 | #define NRF_GATTC_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x300) /**< GATT client specific errors. */ 45 | #define NRF_GATTS_ERR_BASE (NRF_ERROR_STK_BASE_NUM+0x400) /**< GATT server specific errors. */ 46 | /** @} */ 47 | 48 | #endif 49 | 50 | 51 | /** 52 | @} 53 | @} 54 | */ 55 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/s110/nrf_error_sdm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup nrf_sdm_api 11 | @{ 12 | @defgroup nrf_sdm_error SoftDevice Manager Error Codes 13 | @{ 14 | 15 | @brief Error definitions for the SDM API 16 | */ 17 | 18 | /* Header guard */ 19 | #ifndef NRF_ERROR_SDM_H__ 20 | #define NRF_ERROR_SDM_H__ 21 | 22 | #include "nrf_error.h" 23 | 24 | #define NRF_ERROR_SDM_LFCLK_SOURCE_UNKNOWN (NRF_ERROR_SDM_BASE_NUM + 0) ///< Unknown lfclk source 25 | #define NRF_ERROR_SDM_INCORRECT_INTERRUPT_CONFIGURATION (NRF_ERROR_SDM_BASE_NUM + 1) ///< Incorrect interrupt configuration (can be caused by using illegal priority levels, or having enabled SoftDevice interrupts) 26 | #define NRF_ERROR_SDM_INCORRECT_CLENR0 (NRF_ERROR_SDM_BASE_NUM + 2) ///< Incorrect CLENR0 (can be caused by erronous SoftDevice flashing) 27 | 28 | #endif // NRF_ERROR_SDM_H__ 29 | 30 | /** 31 | @} 32 | @} 33 | */ 34 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/s110/nrf_error_soc.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | /** 10 | @addtogroup nrf_soc_api 11 | @{ 12 | @defgroup nrf_soc_error SoC Library Error Codes 13 | @{ 14 | 15 | @brief Error definitions for the SoC library 16 | 17 | */ 18 | 19 | /* Header guard */ 20 | #ifndef NRF_ERROR_SOC_H__ 21 | #define NRF_ERROR_SOC_H__ 22 | 23 | #include "nrf_error.h" 24 | 25 | /* Mutex Errors */ 26 | #define NRF_ERROR_SOC_MUTEX_ALREADY_TAKEN (NRF_ERROR_SOC_BASE_NUM + 0) ///< Mutex already taken 27 | 28 | /* NVIC errors */ 29 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_NOT_AVAILABLE (NRF_ERROR_SOC_BASE_NUM + 1) ///< NVIC interrupt not available 30 | #define NRF_ERROR_SOC_NVIC_INTERRUPT_PRIORITY_NOT_ALLOWED (NRF_ERROR_SOC_BASE_NUM + 2) ///< NVIC interrupt priority not allowed 31 | #define NRF_ERROR_SOC_NVIC_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 3) ///< NVIC should not return 32 | 33 | /* Power errors */ 34 | #define NRF_ERROR_SOC_POWER_MODE_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 4) ///< Power mode unknown 35 | #define NRF_ERROR_SOC_POWER_POF_THRESHOLD_UNKNOWN (NRF_ERROR_SOC_BASE_NUM + 5) ///< Power POF threshold unknown 36 | #define NRF_ERROR_SOC_POWER_OFF_SHOULD_NOT_RETURN (NRF_ERROR_SOC_BASE_NUM + 6) ///< Power off should not return 37 | 38 | /* Rand errors */ 39 | #define NRF_ERROR_SOC_RAND_NOT_ENOUGH_VALUES (NRF_ERROR_SOC_BASE_NUM + 7) ///< RAND not enough values 40 | 41 | /* PPI errors */ 42 | #define NRF_ERROR_SOC_PPI_INVALID_CHANNEL (NRF_ERROR_SOC_BASE_NUM + 8) ///< Invalid PPI Channel 43 | #define NRF_ERROR_SOC_PPI_INVALID_GROUP (NRF_ERROR_SOC_BASE_NUM + 9) ///< Invalid PPI Group 44 | 45 | #endif // NRF_ERROR_SOC_H__ 46 | /** 47 | @} 48 | @} 49 | */ 50 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/s110/nrf_svc.h: -------------------------------------------------------------------------------- 1 | #ifndef NRF_SVC__ 2 | #define NRF_SVC__ 3 | 4 | #ifdef SVCALL_AS_NORMAL_FUNCTION 5 | #define SVCALL(number, return_type, signature) return_type signature 6 | #else 7 | 8 | #ifndef SVCALL 9 | #if defined (__CC_ARM) 10 | #define SVCALL(number, return_type, signature) return_type __svc(number) signature 11 | #elif defined (__GNUC__) 12 | #define SVCALL(number, return_type, signature) \ 13 | _Pragma("GCC diagnostic ignored \"-Wreturn-type\"") \ 14 | _Pragma("GCC diagnostic ignored \"-Wunused-function\"") \ 15 | __attribute__((naked)) static return_type signature \ 16 | { \ 17 | __asm( \ 18 | "svc %0\n" \ 19 | "bx r14" : : "I" ((uint32_t)number) : "r0" \ 20 | ); \ 21 | } 22 | #elif defined (__ICCARM__) 23 | #define PRAGMA(x) _Pragma(#x) 24 | #define SVCALL(number, return_type, signature) \ 25 | PRAGMA(swi_number = number) \ 26 | __swi return_type signature; 27 | #else 28 | #define SVCALL(number, return_type, signature) return_type signature 29 | #endif 30 | #endif // SVCALL 31 | 32 | #endif // SVCALL_AS_NORMAL_FUNCTION 33 | #endif // NRF_SVC__ 34 | -------------------------------------------------------------------------------- /nRF51822/nordic/nrf-sdk/s110/softdevice_assert.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2012 Nordic Semiconductor. All Rights Reserved. 3 | * 4 | * The information contained herein is confidential property of Nordic Semiconductor. The use, 5 | * copying, transfer or disclosure of such information is prohibited except by express written 6 | * agreement with Nordic Semiconductor. 7 | * 8 | */ 9 | 10 | /** @brief Utilities for verifying program logic 11 | */ 12 | 13 | #ifndef SOFTDEVICE_ASSERT_H_ 14 | #define SOFTDEVICE_ASSERT_H_ 15 | 16 | #include 17 | 18 | /** @brief This function handles assertions. 19 | * 20 | * 21 | * @note 22 | * This function is called when an assertion has triggered. 23 | * 24 | * 25 | * @param line_num The line number where the assertion is called 26 | * @param file_name Pointer to the file name 27 | */ 28 | void assert_softdevice_callback(uint16_t line_num, const uint8_t *file_name); 29 | 30 | 31 | /*lint -emacro(506, ASSERT) */ /* Suppress "Constant value Boolean */ 32 | /*lint -emacro(774, ASSERT) */ /* Suppress "Boolean within 'if' always evaluates to True" */ \ 33 | /** @brief Check intended for production code 34 | * 35 | * Check passes if "expr" evaluates to true. */ 36 | #define ASSERT(expr) \ 37 | if (expr) \ 38 | { \ 39 | } \ 40 | else \ 41 | { \ 42 | assert_softdevice_callback((uint16_t)__LINE__, (uint8_t *)__FILE__); \ 43 | /*lint -unreachable */ \ 44 | } 45 | 46 | #endif /* SOFTDEVICE_ASSERT_H_ */ 47 | --------------------------------------------------------------------------------