├── source ├── pins.c ├── pins.cmake └── pins.py ├── .gitignore ├── LICENSE ├── mbed-hal ├── buffer.h ├── init_api.h ├── dma_api.h ├── pinmap.h ├── GeneratedPinNames.h ├── sleep_api.h ├── rtc_api.h ├── analogin_api.h ├── us_ticker_api.h ├── lp_ticker_api.h ├── port_api.h ├── gpio_irq_api.h ├── analogout_api.h ├── gpio_api.h ├── pwmout_api.h ├── ticker_api.h ├── i2c_api.h ├── spi_api.h └── serial_api.h ├── module.json ├── pins.md ├── readme.md ├── DOXYGEN_FRONTPAGE.md └── apache-2.0.txt /source/pins.c: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | build 2 | yotta_targets 3 | yotta_modules 4 | upload.tar.gz 5 | .DS_Store 6 | .yotta.json 7 | generated/ 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Unless specifically indicated otherwise in a file, files are licensed 2 | under the Apache 2.0 license, as can be found in: apache-2.0.txt 3 | 4 | -------------------------------------------------------------------------------- /mbed-hal/buffer.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2014-2015 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_BUFFER_H 17 | #define MBED_BUFFER_H 18 | 19 | #include 20 | 21 | /** Generic buffer structure 22 | */ 23 | typedef struct buffer_s { 24 | void *buffer; /**< the pointer to a buffer */ 25 | size_t length; /**< the buffer length */ 26 | size_t pos; /**< actual buffer position */ 27 | uint8_t width; /**< The buffer unit width (8, 16, 32, 64), used for proper *buffer casting */ 28 | } buffer_t; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /mbed-hal/init_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2015 ARM Limited 3 | * SPDX-License-Identifier: Apache-2.0 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 | #ifndef INIT_API_H 18 | #define INIT_API_H 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | /** 25 | * @defgroup hal_init Init hal functions 26 | * 27 | * @{ 28 | */ 29 | 30 | /** This function should implement hal specific initialization 31 | * 32 | * It runs before the application starts. 33 | */ 34 | void mbed_hal_init(void); 35 | 36 | /**@}*/ 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /module.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mbed-hal", 3 | "version": "1.3.0", 4 | "description": "mbed low-level Hardware Abstraction Layer", 5 | "keywords": [ 6 | "mbed", 7 | "HAL", 8 | "mbed-official" 9 | ], 10 | "author": "Martin Kojtal ", 11 | "repository": { 12 | "url": "git@github.com:ARMmbed/mbed-hal.git", 13 | "type": "git" 14 | }, 15 | "homepage": "https://github.com/ARMmbed/mbed-hal", 16 | "license": "Apache-2.0", 17 | "extraIncludes": [ 18 | "mbed-hal" 19 | ], 20 | "dependencies": { 21 | "mbed-drivers": "*" 22 | }, 23 | "targetDependencies": { 24 | "silabs": { 25 | "mbed-hal-silabs": "^1.0.0" 26 | }, 27 | "freescale": { 28 | "mbed-hal-freescale": "^1.0.0" 29 | }, 30 | "st": { 31 | "mbed-hal-st": "^1.0.0" 32 | }, 33 | "nordic": { 34 | "mbed-hal-nordic": "^2.0.0" 35 | }, 36 | "cordio": { 37 | "mbed-hal-cordio": "~0.0.5" 38 | }, 39 | "nuvoton": { 40 | "mbed-hal-nuvoton": "^1.0.0" 41 | }, 42 | "nxp": { 43 | "mbed-hal-nxp": "~0.1.0" 44 | }, 45 | "arm-ssg": { 46 | "mbed-hal-arm-ssg": "^1.0.0" 47 | }, 48 | "atmel": { 49 | "mbed-hal-atmel": "^1.0.0" 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /source/pins.cmake: -------------------------------------------------------------------------------- 1 | set(pinScript "${CMAKE_CURRENT_LIST_DIR}/pins.py") 2 | set(genIncRoot "${CMAKE_BINARY_DIR}/generated/include") 3 | set(pinFileDir "${genIncRoot}/${PROJECT_NAME}") 4 | set(pinFile "${pinFileDir}/pins.array") 5 | 6 | file(MAKE_DIRECTORY "${pinFileDir}") 7 | 8 | set_source_files_properties("${pinFile}" PROPERTIES HEADER_FILE_ONLY TRUE 9 | OBJECT_DEPENDS "${YOTTA_CONFIG_MERGED_JSON_FILE}") 10 | set_source_files_properties("../mbed-hal/PinNames.h" PROPERTIES HEADER_FILE_ONLY TRUE 11 | OBJECT_DEPENDS "${pinFile}") 12 | set_source_files_properties("pins.c" PROPERTIES 13 | OBJECT_DEPENDS "${pinFile}") 14 | 15 | add_custom_target(mbed-hal_pinnames ALL DEPENDS "${pinFile}" "${YOTTA_CONFIG_MERGED_JSON_FILE}") 16 | 17 | # make sure mbed-hal depends on the dummy pinNames target, so that even if 18 | # "ALL" isn't being built, the pins file still gets generated 19 | add_dependencies(mbed-hal mbed-hal_pinnames) 20 | 21 | add_custom_command(OUTPUT "${pinFile}" 22 | MAIN_DEPENDENCY "${YOTTA_CONFIG_MERGED_JSON_FILE}" 23 | DEPENDS "${YOTTA_CONFIG_MERGED_JSON_FILE}" 24 | COMMAND python "${pinScript}" "${YOTTA_CONFIG_MERGED_JSON_FILE}" "${pinFile}" 25 | COMMENT "Generating ${pinFile}") 26 | -------------------------------------------------------------------------------- /mbed-hal/dma_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2014-2015 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_DMA_API_H 17 | #define MBED_DMA_API_H 18 | 19 | #include 20 | 21 | // TODO: deprecated. DMA support will be added to mbed-hal 22 | 23 | #define DMA_ERROR_OUT_OF_CHANNELS (-1) 24 | 25 | typedef enum { 26 | DMA_USAGE_NEVER, 27 | DMA_USAGE_OPPORTUNISTIC, 28 | DMA_USAGE_ALWAYS, 29 | DMA_USAGE_TEMPORARY_ALLOCATED, 30 | DMA_USAGE_ALLOCATED 31 | } DMAUsage; 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | void dma_init(void); 38 | 39 | int dma_channel_allocate(uint32_t capabilities); 40 | 41 | int dma_channel_free(int channelid); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /mbed-hal/pinmap.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 ARM Limited 3 | * SPDX-License-Identifier: Apache-2.0 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 | #ifndef MBED_PINMAP_H 18 | #define MBED_PINMAP_H 19 | 20 | #include "PinNames.h" 21 | #include "mbed-drivers/pinmap_common.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** 28 | * \defgroup hal_pin Pin hal functions 29 | * @{ 30 | */ 31 | 32 | /** Set the pin function 33 | * 34 | * @param pin The pin name 35 | * @param function The function value 36 | */ 37 | void pin_function(PinName pin, int function); 38 | 39 | /** Set pin mode 40 | * 41 | * @param pin The pin name 42 | * @param mode The pin mode to be set 43 | */ 44 | void pin_mode(PinName pin, PinMode mode); 45 | 46 | /**@}*/ 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /mbed-hal/GeneratedPinNames.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 ARM Limited 3 | * SPDX-License-Identifier: Apache-2.0 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 | #ifndef MBED_GENERATEDPINNAMES_H 18 | #define MBED_GENERATEDPINNAMES_H 19 | 20 | #include "cmsis.h" 21 | 22 | /* A target should define yotta config hardware pins. 23 | The chip pins are defined in chip_pins.array file which should be located 24 | in the chip hal. The pins.array is the generated file 25 | */ 26 | 27 | #ifdef YOTTA_CFG_HARDWARE_PINS 28 | # include "mbed-hal/PinDefs.h" 29 | # ifdef __cplusplus 30 | extern "C" { 31 | # endif 32 | typedef enum { 33 | // Not connected 34 | NC = (int)0xFFFFFFFF, 35 | # include "mbed-hal/chip_pins.array" 36 | # include "mbed-hal/pins.array" 37 | } PinName; 38 | # ifdef __cplusplus 39 | } 40 | # endif 41 | #else 42 | # include "PinNames.h" 43 | #endif 44 | 45 | 46 | #endif // MBED_GENERATEDPINNAMES_H 47 | -------------------------------------------------------------------------------- /mbed-hal/sleep_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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_SLEEP_API_H 17 | #define MBED_SLEEP_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_SLEEP 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | /** Sleep HAL structure. sleep_s is declared in the target's HAL 28 | */ 29 | typedef struct sleep_s sleep_t; 30 | 31 | /** 32 | * \defgroup hal_sleep Sleep HAL functions 33 | * @{ 34 | */ 35 | 36 | /** Enter the sleep mode 37 | * 38 | * @param obj The sleep object that stores required data to restore from sleep 39 | */ 40 | void mbed_enter_sleep(sleep_t *obj); 41 | 42 | /** Restore the MCU from the specified sleep mode 43 | * 44 | * @param obj The sleep object that stores required data to restore from sleep 45 | */ 46 | void mbed_exit_sleep(sleep_t *obj); 47 | 48 | /**@}*/ 49 | 50 | #ifdef __cplusplus 51 | } 52 | #endif 53 | 54 | #endif 55 | 56 | #endif 57 | -------------------------------------------------------------------------------- /mbed-hal/rtc_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** 30 | * \defgroup hal_rtc RTC hal functions 31 | * @{ 32 | */ 33 | 34 | /** Initialize the RTC peripheral 35 | * 36 | */ 37 | void rtc_init(void); 38 | 39 | /** Deinitialize RTC 40 | * 41 | * TODO: The function is not used by rtc api in mbed-drivers. 42 | */ 43 | void rtc_free(void); 44 | 45 | /** Get the RTC enable status 46 | * 47 | * @retval 0 disabled 48 | * @retval 1 enabled 49 | */ 50 | int rtc_isenabled(void); 51 | 52 | /** Get the current time from the RTC peripheral 53 | * 54 | * @return The current time 55 | */ 56 | time_t rtc_read(void); 57 | 58 | /** Set the current time to the RTC peripheral 59 | * 60 | * @param t The current time to be set 61 | */ 62 | void rtc_write(time_t t); 63 | 64 | /**@}*/ 65 | 66 | #ifdef __cplusplus 67 | } 68 | #endif 69 | 70 | #endif 71 | 72 | #endif 73 | -------------------------------------------------------------------------------- /mbed-hal/analogin_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** Analogin hal structure. analogin_s is declared in the target's hal 28 | */ 29 | typedef struct analogin_s analogin_t; 30 | 31 | /** 32 | * \defgroup hal_analogin Analogin hal functions 33 | * @{ 34 | */ 35 | 36 | /** Initialize the analogin peripheral 37 | * 38 | * Configures the pin used by analogin. 39 | * @param obj The analogin object to initialize 40 | * @param pin The analogin pin name 41 | */ 42 | void analogin_init(analogin_t *obj, PinName pin); 43 | 44 | /** Read the input voltage, represented as a float in the range [0.0, 1.0] 45 | * 46 | * @param obj The analogin object 47 | * @return A floating value representing the current input voltage 48 | */ 49 | float analogin_read(analogin_t *obj); 50 | 51 | /** Read the value from analogin pin, represented as an unsigned 16bit value 52 | * 53 | * @param obj The analogin object 54 | * @return An unsigned 16bit value representing the current input voltage 55 | */ 56 | uint16_t analogin_read_u16(analogin_t *obj); 57 | 58 | /**@}*/ 59 | 60 | #ifdef __cplusplus 61 | } 62 | #endif 63 | 64 | #endif 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /mbed-hal/us_ticker_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | #include "ticker_api.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * \defgroup hal_UsTicker Microseconds Ticker Functions 28 | * @{ 29 | */ 30 | 31 | /** Get ticker's data 32 | * 33 | * @return The low power ticker data 34 | */ 35 | const ticker_data_t* get_us_ticker_data(void); 36 | 37 | 38 | /** The wrapper for ticker_irq_handler, to pass us ticker's data 39 | * 40 | */ 41 | void us_ticker_irq_handler(void); 42 | 43 | /* HAL us ticker */ 44 | 45 | /** Initialize the ticker 46 | * 47 | */ 48 | void us_ticker_init(void); 49 | 50 | /** Read the current counter 51 | * 52 | * @return The current timer's counter value in microseconds 53 | */ 54 | uint32_t us_ticker_read(void); 55 | 56 | /** Set interrupt for specified timestamp 57 | * 58 | * @param timestamp The time in microseconds to be set 59 | */ 60 | void us_ticker_set_interrupt(timestamp_t timestamp); 61 | 62 | /** Disable us ticker interrupt 63 | * 64 | */ 65 | void us_ticker_disable_interrupt(void); 66 | 67 | /** Clear us ticker interrupt 68 | * 69 | */ 70 | void us_ticker_clear_interrupt(void); 71 | 72 | /**@}*/ 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif 79 | -------------------------------------------------------------------------------- /pins.md: -------------------------------------------------------------------------------- 1 | # Pin Names in mbed OS 2 | In mbed OS, pin mapping is provided by two sources: the chip HAL and yotta config. This means that targets can provide pin names, but that applications can override pin naming. 3 | 4 | ## Introduction 5 | mbed OS does not provide a HAL layer for boards. Boards should be effectively the same as the chip they are based on. Because of this, only the pin naming and oscillator configuration is dependent on the board. To reflect this appropriately, the oscillator configuration and pin naming can be defined by the target using the yotta config mechanism. 6 | 7 | ## Pin Naming in yotta config 8 | To name, alias, or rename pins in yotta config, add the following entries to the yotta config: 9 | 10 | ```json 11 | { 12 | "config" : { 13 | "hardware" : { 14 | "pins" : { 15 | "" : "" 16 | } 17 | } 18 | } 19 | } 20 | ``` 21 | 22 | Pin naming adheres to the override mechanism documented in http://yottadocs.mbed.com/reference/config.html. Pin names can be imported into a C/C++ file by: 23 | 24 | ```C 25 | #include "mbed-hal/PinNames.h" 26 | ``` 27 | 28 | Pin names are an exception from typical yotta config, in that the pin names declared in yotta config are reproduced verbatim in the C namespace. As such, care must be taken to name pins well, so that they do not generate namespace collisions. 29 | 30 | ## Pin Naming Mechanism 31 | Pin names are generated during the build by a python script which is shipped with mbed-hal. This script uses the yotta config output (yotta_config.json) to generate a list of pin names. These are included inside the "pins" enum declaration. 32 | 33 | ## PinName file 34 | The chip hal implementation should contain PinNames header file. This header should just include mbed-hal/GenereatedPinNames.h for backwards-compatibility. 35 | We would like to remove PinNames from chip hal modules in the future, GeneratedPinNames header file will be renamed to PinNames. 36 | -------------------------------------------------------------------------------- /mbed-hal/lp_ticker_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2015 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_LPTICKER_API_H 17 | #define MBED_LPTICKER_API_H 18 | 19 | #include "device.h" 20 | 21 | #if DEVICE_LOWPOWERTIMER 22 | 23 | #include "ticker_api.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * \defgroup hal_LpTicker Low Power Ticker Functions 31 | * @{ 32 | */ 33 | 34 | /** Initialize the low power ticker 35 | * 36 | */ 37 | void lp_ticker_init(void); 38 | 39 | /** Read the current counter 40 | * 41 | * @return The current timer's counter value 42 | */ 43 | uint32_t lp_ticker_read(void); 44 | 45 | /** Set interrupt for specified time 46 | * 47 | * @param now The current time 48 | * @param time The time to be matched 49 | */ 50 | void lp_ticker_set_interrupt(uint32_t now, uint32_t time); 51 | 52 | /** Get the overflows counter 53 | * 54 | * @return The timer's overflow counter 55 | */ 56 | uint32_t lp_ticker_get_overflows_counter(void); 57 | 58 | /** Get compare match register 59 | * 60 | * @return The next lp ticker interrupt scheduled time 61 | */ 62 | uint32_t lp_ticker_get_compare_match(void); 63 | 64 | /** Set lp ticker interrupt and enter mbed sleep. 65 | * 66 | * @param now The current time 67 | * @param time The time to be matched 68 | */ 69 | void lp_ticker_sleep_until(uint32_t now, uint32_t time); 70 | 71 | /**@}*/ 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /mbed-hal/port_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** Port HAL structure. port_s is declared in the target's HAL 28 | */ 29 | typedef struct port_s port_t; 30 | 31 | /** 32 | * \defgroup hal_port Port HAL functions 33 | * @{ 34 | */ 35 | 36 | /** Get the pin name from the port's pin number 37 | * 38 | * @param port The port name 39 | * @param pin_n The pin number within the specified port 40 | * @return The pin name for the port's pin number 41 | */ 42 | PinName port_pin(PortName port, int pin_n); 43 | 44 | /** Initilize the port 45 | * 46 | * @param obj The port object to initialize 47 | * @param port The port name 48 | * @param mask The bitmask to identify which bits in the port should be included (0 - ignore) 49 | * @param dir The port direction 50 | */ 51 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir); 52 | 53 | /** Set the input port mode 54 | * 55 | * @param obj The port object 56 | * @param mode THe port mode to be set 57 | */ 58 | void port_mode(port_t *obj, PinMode mode); 59 | 60 | /** Set port direction (in/out) 61 | * 62 | * @param obj The port object 63 | * @param dir The port direction to be set 64 | */ 65 | void port_dir(port_t *obj, PinDirection dir); 66 | 67 | /** Write value to the port 68 | * 69 | * @param obj The port object 70 | * @param value The value to be set 71 | */ 72 | void port_write(port_t *obj, int value); 73 | 74 | /** Read the current value on the port 75 | * 76 | * @param obj The port object 77 | * @return An integer with each bit corresponding to an associated port pin setting 78 | */ 79 | int port_read(port_t *obj); 80 | 81 | /**@}*/ 82 | 83 | #ifdef __cplusplus 84 | } 85 | #endif 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /source/pins.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # Copyright (c) 2015, ARM Limited, All Rights Reserved 3 | # SPDX-License-Identifier: Apache-2.0 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); you may 6 | # 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, WITHOUT 13 | # 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 | import json 17 | import sys 18 | 19 | jsonfile = open(sys.argv[1]) 20 | outputfile = open(sys.argv[2],'w') 21 | 22 | ocfg = json.load(jsonfile) 23 | jsonfile.close() 24 | pins = {} 25 | if 'hardware' in ocfg: 26 | if 'pins' in ocfg['hardware']: 27 | pins = ocfg['hardware']['pins'] 28 | 29 | f = outputfile 30 | 31 | template = ''' 32 | /**************************************************************************** 33 | * Copyright (c) 2015, ARM Limited, All Rights Reserved 34 | * SPDX-License-Identifier: Apache-2.0 35 | * 36 | * Licensed under the Apache License, Version 2.0 (the "License"); you may 37 | * not use this file except in compliance with the License. 38 | * You may obtain a copy of the License at 39 | * 40 | * http://www.apache.org/licenses/LICENSE-2.0 41 | * 42 | * Unless required by applicable law or agreed to in writing, software 43 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 45 | * See the License for the specific language governing permissions and 46 | * limitations under the License. 47 | **************************************************************************** 48 | */ 49 | /* WARNING: THIS FILE IS AUTOMATICALLY GENERATED. DO NOT EDIT. ANY CHANGES 50 | * SHOULD BE MADE IN config.json OR target.json 51 | */ 52 | %s 53 | ''' 54 | 55 | indent = ' ' 56 | pin_array = [] 57 | 58 | if isinstance(pins, dict): 59 | while len(pins.keys()): 60 | for pin in list(pins.keys())[:]: 61 | if pins[pin] in list(pins.keys()): 62 | continue 63 | pin_array += ['{key} = {value}'.format(key=pin, value=pins[pin])] 64 | del pins[pin] 65 | 66 | pin_str = indent + (',\n'+indent).join(pin_array) 67 | 68 | f.write(template%pin_str) 69 | f.close() 70 | -------------------------------------------------------------------------------- /mbed-hal/gpio_irq_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** GPIO IRQ events 28 | */ 29 | typedef enum { 30 | IRQ_NONE, 31 | IRQ_RISE, 32 | IRQ_FALL 33 | } gpio_irq_event; 34 | 35 | /** GPIO IRQ HAL structure. gpio_irq_s is declared in the target's HAL 36 | */ 37 | typedef struct gpio_irq_s gpio_irq_t; 38 | 39 | typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event); 40 | 41 | /** 42 | * \defgroup hal_gpioirq GPIO IRQ HAL functions 43 | * @{ 44 | */ 45 | 46 | /** Initialize the GPIO IRQ pin 47 | * 48 | * @param obj The GPIO object to initialize 49 | * @param pin The GPIO pin name 50 | * @param handler The handler to be attached to GPIO IRQ 51 | * @param id The object ID (id != 0, 0 is reserved) 52 | * @return -1 if pin is NC, 0 otherwise 53 | */ 54 | int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); 55 | 56 | /** Release the GPIO IRQ PIN 57 | * 58 | * @param obj The gpio object 59 | */ 60 | void gpio_irq_free(gpio_irq_t *obj); 61 | 62 | /** Enable/disable pin IRQ event 63 | * 64 | * @param obj The GPIO object 65 | * @param event The GPIO IRQ event 66 | * @param enable The enable flag 67 | */ 68 | void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); 69 | 70 | /** Enable GPIO IRQ 71 | * 72 | * This is target dependent, as it might enable the entire port or just a pin 73 | * @param obj The GPIO object 74 | */ 75 | void gpio_irq_enable(gpio_irq_t *obj); 76 | 77 | /** Disable GPIO IRQ 78 | * 79 | * This is target dependent, as it might disable the entire port or just a pin 80 | * @param obj The GPIO object 81 | */ 82 | void gpio_irq_disable(gpio_irq_t *obj); 83 | 84 | /**@}*/ 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /mbed-hal/analogout_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** Analogout hal structure. dac_s is declared in the target's hal 28 | */ 29 | typedef struct dac_s dac_t; 30 | 31 | /** 32 | * \defgroup hal_analogout Analogout hal functions 33 | * @{ 34 | */ 35 | 36 | /** Initialize the analogout peripheral 37 | * 38 | * Configures the pin used by analogout. 39 | * @param obj The analogout object to initialize 40 | * @param pin The analogout pin name 41 | */ 42 | void analogout_init(dac_t *obj, PinName pin); 43 | 44 | /** Release the analogout object 45 | * 46 | * Note: This is not currently used in the mbed-drivers 47 | * @param obj The analogout object 48 | */ 49 | void analogout_free(dac_t *obj); 50 | 51 | /** Set the output voltage, specified as a percentage (float) 52 | * 53 | * @param obj The analogin object 54 | * @param value The floating-point output voltage to be set 55 | */ 56 | void analogout_write(dac_t *obj, float value); 57 | 58 | /** Set the output voltage, specified as unsigned 16-bit 59 | * 60 | * @param obj The analogin object 61 | * @param value The unsigned 16-bit output voltage to be set 62 | */ 63 | void analogout_write_u16(dac_t *obj, uint16_t value); 64 | 65 | /** Read the current voltage value on the pin 66 | * 67 | * @param obj The analogin object 68 | * @return A floating-point value representing the current voltage on the pin, 69 | * measured as a percentage 70 | */ 71 | float analogout_read(dac_t *obj); 72 | 73 | /** Read the current voltage value on the pin, as a normalized unsigned 16bit value 74 | * 75 | * @param obj The analogin object 76 | * @return An unsigned 16-bit value representing the current voltage on the pin 77 | */ 78 | uint16_t analogout_read_u16(dac_t *obj); 79 | 80 | /**@}*/ 81 | 82 | #ifdef __cplusplus 83 | } 84 | #endif 85 | 86 | #endif 87 | 88 | #endif 89 | -------------------------------------------------------------------------------- /mbed-hal/gpio_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 20 | #include "device.h" 21 | 22 | #ifdef __cplusplus 23 | extern "C" { 24 | #endif 25 | 26 | /** 27 | * \defgroup hal_gpio GPIO HAL functions 28 | * @{ 29 | */ 30 | 31 | /** Set the given pin as GPIO 32 | * 33 | * @param pin The pin to be set as GPIO 34 | * @return The GPIO port mask for this pin 35 | **/ 36 | uint32_t gpio_set(PinName pin); 37 | 38 | /** Initialize the GPIO pin 39 | * 40 | * @param obj The GPIO object to initialize 41 | * @param pin The GPIO pin to initialize 42 | */ 43 | void gpio_init(gpio_t *obj, PinName pin); 44 | 45 | /** Set the input pin mode 46 | * 47 | * @param obj The GPIO object 48 | * @param mode The pin mode to be set 49 | */ 50 | void gpio_mode(gpio_t *obj, PinMode mode); 51 | 52 | /** Set the pin direction 53 | * 54 | * @param obj The GPIO object 55 | * @param direction The pin direction to be set 56 | */ 57 | void gpio_dir(gpio_t *obj, PinDirection direction); 58 | 59 | /** Set the output value 60 | * 61 | * @param obj The GPIO object 62 | * @param value The value to be set 63 | */ 64 | void gpio_write(gpio_t *obj, int value); 65 | 66 | /** Read the input value 67 | * 68 | * @param obj The GPIO object 69 | * @return An integer value 1 or 0 70 | */ 71 | int gpio_read(gpio_t *obj); 72 | 73 | // the following functions are generic and implemented in the common gpio.c file 74 | // TODO: fix, will be moved to the common gpio header file 75 | 76 | /** Init the input pin and set mode to PullDefault 77 | * 78 | * @param obj The GPIO object 79 | * @param pin The pin name 80 | */ 81 | void gpio_init_in(gpio_t* gpio, PinName pin); 82 | 83 | /** Init the input pin and set the mode 84 | * 85 | * @param obj The GPIO object 86 | * @param pin The pin name 87 | * @param mode The pin mode to be set 88 | */ 89 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode); 90 | 91 | /** Init the output pin as an output, with predefined output value 0 92 | * 93 | * @param obj The GPIO object 94 | * @param pin The pin name 95 | * @return An integer value 1 or 0 96 | */ 97 | void gpio_init_out(gpio_t* gpio, PinName pin); 98 | 99 | /** Init the pin as an output and set the output value 100 | * 101 | * @param obj The GPIO object 102 | * @param pin The pin name 103 | * @param value The value to be set 104 | */ 105 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value); 106 | 107 | /** Init the pin to be in/out 108 | * 109 | * @param obj The GPIO object 110 | * @param pin The pin name 111 | * @param direction The pin direction to be set 112 | * @param mode The pin mode to be set 113 | * @param value The value to be set for an output pin 114 | */ 115 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value); 116 | 117 | /**@}*/ 118 | 119 | #ifdef __cplusplus 120 | } 121 | #endif 122 | 123 | #endif 124 | -------------------------------------------------------------------------------- /mbed-hal/pwmout_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | /** Pwmout hal structure. pwmout_s is declared in the target's hal 28 | */ 29 | typedef struct pwmout_s pwmout_t; 30 | 31 | /** 32 | * \defgroup hal_pwmout Pwmout hal functions 33 | * @{ 34 | */ 35 | 36 | /** Initialize the pwm out peripheral and configure the pin 37 | * 38 | * @param obj The pwmout object to initialize 39 | * @param pin The pwmout pin to initialize 40 | */ 41 | void pwmout_init(pwmout_t *obj, PinName pin); 42 | 43 | /** Deinitialize the pwmout object 44 | * 45 | * @param obj The pwmout object 46 | */ 47 | void pwmout_free(pwmout_t *obj); 48 | 49 | /** Set the output duty-cycle in range <0.0f, 1.0f> 50 | * 51 | * Value 0.0f represents 0 percentage, 1.0f represents 100 percent. 52 | * @param obj The pwmout object 53 | * @param percent The floating-point percentage number 54 | */ 55 | void pwmout_write(pwmout_t *obj, float percent); 56 | 57 | /** Read the current float-point output duty-cycle 58 | * 59 | * @param obj The pwmout object 60 | * @return A floating-point output duty-cycle 61 | */ 62 | float pwmout_read(pwmout_t *obj); 63 | 64 | /** Set the PWM period specified in seconds, keeping the duty cycle the same 65 | * 66 | * Periods smaller than microseconds (the lowest resolution) are set to zero. 67 | * @param obj The pwmout object 68 | * @param seconds The floating-point seconds period 69 | */ 70 | void pwmout_period(pwmout_t *obj, float seconds); 71 | 72 | /** Set the PWM period specified in miliseconds, keeping the duty cycle the same 73 | * 74 | * @param obj The pwmout object 75 | * @param ms The milisecond period 76 | */ 77 | void pwmout_period_ms(pwmout_t *obj, int ms); 78 | 79 | /** Set the PWM period specified in microseconds, keeping the duty cycle the same 80 | * 81 | * @param obj The pwmout object 82 | * @param us The microsecond period 83 | */ 84 | void pwmout_period_us(pwmout_t *obj, int us); 85 | 86 | /** Set the PWM pulsewidth specified in seconds, keeping the period the same. 87 | * 88 | * @param obj The pwmout object 89 | * @param seconds The floating-point pulsewidth in seconds 90 | */ 91 | void pwmout_pulsewidth(pwmout_t *obj, float seconds); 92 | 93 | /** Set the PWM pulsewidth specified in miliseconds, keeping the period the same. 94 | * 95 | * @param obj The pwmout object 96 | * @param ms The floating-point pulsewidth in miliseconds 97 | */ 98 | void pwmout_pulsewidth_ms(pwmout_t *obj, int ms); 99 | 100 | /** Set the PWM pulsewidth specified in microseconds, keeping the period the same. 101 | * 102 | * @param obj The pwmout object 103 | * @param us The floating-point pulsewidth in microseconds 104 | */ 105 | void pwmout_pulsewidth_us(pwmout_t *obj, int us); 106 | 107 | /**@}*/ 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif 114 | 115 | #endif 116 | -------------------------------------------------------------------------------- /mbed-hal/ticker_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2015 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_TICKER_API_H 17 | #define MBED_TICKER_API_H 18 | 19 | #include 20 | #include "device.h" 21 | 22 | typedef uint32_t timestamp_t; 23 | 24 | /** Ticker's event structure 25 | */ 26 | typedef struct ticker_event_s { 27 | timestamp_t timestamp; /**< Event's timestamp */ 28 | uint32_t id; /**< TimerEvent object */ 29 | struct ticker_event_s *next; /**< Next event in the queue */ 30 | } ticker_event_t; 31 | 32 | typedef void (*ticker_event_handler)(uint32_t id); 33 | 34 | /** Ticker's interface structure - required API for a ticker 35 | */ 36 | typedef struct { 37 | void (*init)(void); /**< Init function */ 38 | uint32_t (*read)(void); /**< Read function */ 39 | void (*disable_interrupt)(void); /**< Disable interrupt function */ 40 | void (*clear_interrupt)(void); /**< Clear interrupt function */ 41 | void (*set_interrupt)(timestamp_t timestamp); /**< Set interrupt function */ 42 | } ticker_interface_t; 43 | 44 | /** Ticker's event queue structure 45 | */ 46 | typedef struct { 47 | ticker_event_handler event_handler; /**< Event handler */ 48 | ticker_event_t *head; /**< A pointer to head */ 49 | } ticker_event_queue_t; 50 | 51 | /** Ticker's data structure 52 | */ 53 | typedef struct { 54 | const ticker_interface_t *interface; /**< Ticker's interface */ 55 | ticker_event_queue_t *queue; /**< Ticker's event queue */ 56 | } ticker_data_t; 57 | 58 | #ifdef __cplusplus 59 | extern "C" { 60 | #endif 61 | 62 | /** 63 | * \defgroup hal_ticker Ticker HAL functions 64 | * @{ 65 | */ 66 | 67 | /** Initialize a ticker and set the event handler 68 | * 69 | * @param data The ticker's data 70 | * @param handler A handler to be set 71 | */ 72 | void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler); 73 | 74 | /** IRQ handler that goes through the events to trigger overdue events. 75 | * 76 | * @param data The ticker's data 77 | */ 78 | void ticker_irq_handler(const ticker_data_t *const data); 79 | 80 | /** Remove an event from the queue 81 | * 82 | * @param data The ticker's data 83 | * @param obj The event object to be removed from the queue 84 | */ 85 | void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj); 86 | 87 | /** Insert an event to the queue 88 | * 89 | * @param data The ticker's data 90 | * @param obj The event object to be inserted to the queue 91 | * @param timestamp The event's timestamp 92 | * @param id The event object 93 | */ 94 | void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id); 95 | 96 | /** Read the current ticker's timestamp 97 | * 98 | * @param data The ticker's data 99 | * @return The current timestamp 100 | */ 101 | timestamp_t ticker_read(const ticker_data_t *const data); 102 | 103 | /**@}*/ 104 | 105 | #ifdef __cplusplus 106 | } 107 | #endif 108 | 109 | #endif 110 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## mbed HAL 2 | 3 | This module defines the API for the mbed low-level Hardware Abstraction Layer, 4 | which is implemented by target-specific modules. 5 | 6 | **mbed hal API is considered an internal interface. It is not recommended to depend on this module in an application.** 7 | We are planning to improve mbed-hal in the future, which might require changes in API. 8 | 9 | ### Installation 10 | ``` 11 | yotta install --save ARMmbed/mbed-hal 12 | ``` 13 | 14 | ### API 15 | The mbed HAL defines API for the following peripherals/functionality: 16 | - Analog in 17 | - Analog out 18 | - Buffer 19 | - GPIO 20 | - GPIO IRQ 21 | - Low power timer 22 | - Ticker - high precision timer 23 | - I2C 24 | - Init HAL 25 | - Port 26 | - Pin maping 27 | - PWM out 28 | - RTC 29 | - Serial 30 | - Sleep 31 | - SPI 32 | 33 | ### Porting 34 | mbed-hal requires a number of sub-modules when a port is created. 35 | 36 | For instance, mbed-hal hierarchy might be: 37 | ``` 38 | +----------+ 39 | | mbed-hal | 40 | +----+-----+ 41 | | TD 42 | +--------+----------+ 43 | | mbed-hal- | 44 | +--------+----------+ 45 | | TD 46 | +----------------+----------------+ D +--------------------------------+ 47 | | mbed-hal-- +-------+ mbed-hal-- | 48 | +----------------+----------------+ +--------------------------------+ 49 | | TD 50 | +------------+-------------+ 51 | | mbed-hal-- | 52 | +--------------------------+ 53 | | TD 54 | +------------+---------------+ 55 | | mbed-hal-- | 56 | +----------------------------+ 57 | ``` 58 | 59 | In the diagram above, six hal repositories are defined to support a single target. Each of these repositories should contain specific parts of the mbed hal. 60 | 61 | #### mbed-hal-\ 62 | This repository contains redirections based on target only. mbed-hal- should contain a single file: a module.json. 63 | 64 | Contains: No source/header files required 65 | 66 | Dependencies: None 67 | 68 | Target Dependencies: mbed-hal-\-\ 69 | 70 | #### mbed-hal-\-\ 71 | This repo should contain the files which implement the api defined in mbed-hal, e.g. spi_api.c, uart_api.c, us_ticker.c, etc. 72 | 73 | Contains: 74 | * source 75 | * analogin_api.c 76 | * analogout_api.c 77 | * gpio_api.c 78 | * gpio_irq_api.c 79 | * i2c_api.c 80 | * lp_ticker.c 81 | * pinmap.c 82 | * port_api.c 83 | * pwmout_api.c 84 | * rtc_api.c 85 | * serial_api.c 86 | * sleep.c 87 | * spi_api.c 88 | * us_ticker.c 89 | * mbed-hal-\-\ 90 | * PeripheralNames.h 91 | * PeripheralPins.h 92 | * PortNames.h 93 | * gpio_object.h 94 | * objects.h 95 | 96 | Dependencies: mbed-hal-\-\ 97 | 98 | Target Dependencies: mbed-hal-\-\ 99 | 100 | #### mbed-hal-\-\ 101 | Contains a vendor-specific hal if necessary. This repository is optional. No dependencies are mandated, but most implementations of this repository will include a dependency on mbed-hal-\-\ 102 | 103 | Contains: Vendor-specific HAL 104 | 105 | Dependencies: None required 106 | 107 | Target Dependencies: None required 108 | 109 | #### mbed-hal-\-\ 110 | The chip-specific definitions expected by the vendor HAL and/or mbed-hal-\-\ 111 | 112 | Contains: chip-specific definitions and code 113 | 114 | Dependencies: None required 115 | 116 | Target Dependencies: None required 117 | 118 | This module should define chip pin names. More information about pin names in mbed OS [here](pins.md). 119 | 120 | #### mbed-hal-\-\ 121 | The target-specific definitions expected by the vendor HAL and/or mbed-hal-\-\ 122 | 123 | Contains: 124 | * source 125 | * init_api.c 126 | * PeripheralPins.c 127 | * mbed-hal-\-\ 128 | * device.h 129 | * target_config.h 130 | 131 | Dependencies: None required 132 | 133 | Target Dependencies: None required 134 | -------------------------------------------------------------------------------- /DOXYGEN_FRONTPAGE.md: -------------------------------------------------------------------------------- 1 | ## mbed HAL 2 | 3 | This module defines the API for the mbed low-level Hardware Abstraction Layer, 4 | which is implemented by target-specific modules. 5 | 6 | **mbed hal API is considered an internal interface. It is not recommended to depend on this module in an application.** 7 | We are planning to improve mbed-hal in the future, which might require changes in API. 8 | 9 | ### Installation 10 | ``` 11 | yotta install --save ARMmbed/mbed-hal 12 | ``` 13 | 14 | ### API 15 | The mbed HAL defines API for the following peripherals/functionality: 16 | - Analog in 17 | - Analog out 18 | - Buffer 19 | - GPIO 20 | - GPIO IRQ 21 | - Low power timer 22 | - Ticker - high precision timer 23 | - I2C 24 | - Init HAL 25 | - Port 26 | - Pin maping 27 | - PWM out 28 | - RTC 29 | - Serial 30 | - Sleep 31 | - SPI 32 | 33 | ### Porting 34 | mbed-hal requires a number of sub-modules when a port is created. 35 | 36 | For instance, mbed-hal hierarchy might be: 37 | ``` 38 | +----------+ 39 | | mbed-hal | 40 | +----+-----+ 41 | | TD 42 | +--------+----------+ 43 | | mbed-hal- | 44 | +--------+----------+ 45 | | TD 46 | +----------------+----------------+ D +--------------------------------+ 47 | | mbed-hal-- +-------+ mbed-hal-- | 48 | +----------------+----------------+ +--------------------------------+ 49 | | TD 50 | +------------+-------------+ 51 | | mbed-hal-- | 52 | +--------------------------+ 53 | | TD 54 | +------------+---------------+ 55 | | mbed-hal-- | 56 | +----------------------------+ 57 | ``` 58 | 59 | In the diagram above, six hal repositories are defined to support a single target. Each of these repositories should contain specific parts of the mbed hal. 60 | 61 | #### mbed-hal-\ 62 | This repository contains redirections based on target only. mbed-hal- should contain a single file: a module.json. 63 | 64 | Contains: No source/header files required 65 | 66 | Dependencies: None 67 | 68 | Target Dependencies: mbed-hal-\-\ 69 | 70 | #### mbed-hal-\-\ 71 | This repo should contain the files which implement the api defined in mbed-hal, e.g. spi_api.c, uart_api.c, us_ticker.c, etc. 72 | 73 | Contains: 74 | * source 75 | * analogin_api.c 76 | * analogout_api.c 77 | * gpio_api.c 78 | * gpio_irq_api.c 79 | * i2c_api.c 80 | * lp_ticker.c 81 | * pinmap.c 82 | * port_api.c 83 | * pwmout_api.c 84 | * rtc_api.c 85 | * serial_api.c 86 | * sleep.c 87 | * spi_api.c 88 | * us_ticker.c 89 | * mbed-hal-\-\ 90 | * PeripheralNames.h 91 | * PeripheralPins.h 92 | * PortNames.h 93 | * gpio_object.h 94 | * objects.h 95 | 96 | Dependencies: mbed-hal-\-\ 97 | 98 | Target Dependencies: mbed-hal-\-\ 99 | 100 | #### mbed-hal-\-\ 101 | Contains a vendor-specific hal if necessary. This repository is optional. No dependencies are mandated, but most implementations of this repository will include a dependency on mbed-hal-\-\ 102 | 103 | Contains: Vendor-specific HAL 104 | 105 | Dependencies: None required 106 | 107 | Target Dependencies: None required 108 | 109 | #### mbed-hal-\-\ 110 | The chip-specific definitions expected by the vendor HAL and/or mbed-hal-\-\ 111 | 112 | Contains: chip-specific definitions and code 113 | 114 | Dependencies: None required 115 | 116 | Target Dependencies: None required 117 | 118 | This module should define chip pin names. More information about pin names in mbed OS [here](pins.md). 119 | 120 | #### mbed-hal-\-\ 121 | The target-specific definitions expected by the vendor HAL and/or mbed-hal-\-\ 122 | 123 | Contains: 124 | * source 125 | * init_api.c 126 | * PeripheralPins.c 127 | * mbed-hal-\-\ 128 | * device.h 129 | * target_config.h 130 | 131 | Dependencies: None required 132 | 133 | Target Dependencies: None required 134 | -------------------------------------------------------------------------------- /mbed-hal/i2c_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | #include "buffer.h" 21 | 22 | #if DEVICE_I2C_ASYNCH 23 | #include "dma_api.h" 24 | #endif 25 | 26 | #if DEVICE_I2C 27 | 28 | /** 29 | * @defgroup hal_I2CEvents I2C Events Macros 30 | * 31 | * @{ 32 | */ 33 | #define I2C_EVENT_ERROR (1 << 1) 34 | #define I2C_EVENT_ERROR_NO_SLAVE (1 << 2) 35 | #define I2C_EVENT_TRANSFER_COMPLETE (1 << 3) 36 | #define I2C_EVENT_TRANSFER_EARLY_NACK (1 << 4) 37 | #define I2C_EVENT_ALL (I2C_EVENT_ERROR | I2C_EVENT_TRANSFER_COMPLETE | I2C_EVENT_ERROR_NO_SLAVE | I2C_EVENT_TRANSFER_EARLY_NACK) 38 | 39 | /**@}*/ 40 | 41 | #if DEVICE_I2C_ASYNCH 42 | /** Asynch I2C HAL structure 43 | */ 44 | typedef struct { 45 | struct i2c_s i2c; /**< Target specific I2C structure */ 46 | struct buffer_s tx_buff; /**< Tx buffer */ 47 | struct buffer_s rx_buff; /**< Rx buffer */ 48 | } i2c_t; 49 | 50 | #else 51 | /** Non-asynch I2C HAL structure 52 | */ 53 | typedef struct i2c_s i2c_t; 54 | 55 | #endif 56 | 57 | enum { 58 | I2C_ERROR_NO_SLAVE = -1, 59 | I2C_ERROR_BUS_BUSY = -2 60 | }; 61 | 62 | #ifdef __cplusplus 63 | extern "C" { 64 | #endif 65 | 66 | /** 67 | * \defgroup hal_GeneralI2C I2C Configuration Functions 68 | * @{ 69 | */ 70 | 71 | /** Initialize the I2C peripheral. It sets the default parameters for I2C 72 | * peripheral, and configures its specifieds pins. 73 | * 74 | * @param obj The I2C object 75 | * @param sda The sda pin 76 | * @param scl The scl pin 77 | */ 78 | void i2c_init(i2c_t *obj, PinName sda, PinName scl); 79 | 80 | /** Configure the I2C frequency 81 | * 82 | * @param obj The I2C object 83 | * @param hz Frequency in Hz 84 | */ 85 | void i2c_frequency(i2c_t *obj, int hz); 86 | 87 | /** Send START command 88 | * 89 | * @param obj The I2C object 90 | */ 91 | int i2c_start(i2c_t *obj); 92 | 93 | /** Send STOP command 94 | * 95 | * @param obj The I2C object 96 | */ 97 | int i2c_stop(i2c_t *obj); 98 | 99 | /** Blocking reading data 100 | * 101 | * @param obj The I2C object 102 | * @param address 7-bit address (last bit is 1) 103 | * @param data The buffer for receiving 104 | * @param length Number of bytes to read 105 | * @param stop Stop to be generated after the transfer is done 106 | * @return Number of read bytes 107 | */ 108 | int i2c_read(i2c_t *obj, int address, char *data, int length, int stop); 109 | 110 | /** Blocking sending data 111 | * 112 | * @param obj The I2C object 113 | * @param address 7-bit address (last bit is 0) 114 | * @param data The buffer for sending 115 | * @param length Number of bytes to write 116 | * @param stop Stop to be generated after the transfer is done 117 | * @return Number of written bytes 118 | */ 119 | int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop); 120 | 121 | /** Reset I2C peripheral. TODO: The action here. Most of the implementation sends stop() 122 | * 123 | * @param obj The I2C object 124 | */ 125 | void i2c_reset(i2c_t *obj); 126 | 127 | /** Read one byte 128 | * 129 | * @param obj The I2C object 130 | * @param last Acknoledge 131 | * @return The read byte 132 | */ 133 | int i2c_byte_read(i2c_t *obj, int last); 134 | 135 | /** Write one byte 136 | * 137 | * @param obj The I2C object 138 | * @param data Byte to be written 139 | * @return 1 if NAK was received, 0 if ACK was received, 2 for timeout. 140 | */ 141 | int i2c_byte_write(i2c_t *obj, int data); 142 | 143 | /**@}*/ 144 | 145 | /**@}*/ 146 | 147 | #if DEVICE_I2C_ASYNCH 148 | 149 | /** 150 | * \defgroup hal_AsynchI2C Asynchronous I2C Hardware Abstraction Layer 151 | * @{ 152 | */ 153 | 154 | /** Start I2C asynchronous transfer 155 | * 156 | * @param obj The I2C object 157 | * @param tx The transmit buffer 158 | * @param tx_length The number of bytes to transmit 159 | * @param rx The receive buffer 160 | * @param rx_length The number of bytes to receive 161 | * @param address The address to be set - 7bit or 9bit 162 | * @param stop If true, stop will be generated after the transfer is done 163 | * @param handler The I2C IRQ handler to be set 164 | * @param hint Deprecated argument 165 | */ 166 | void i2c_transfer_asynch(i2c_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t address, uint32_t stop, uint32_t handler, uint32_t event, DMAUsage hint); 167 | 168 | /** The asynchronous IRQ handler 169 | * 170 | * @param obj The I2C object which holds the transfer information 171 | * @return Event flags if a transfer termination condition was met, otherwise return 0. 172 | */ 173 | uint32_t i2c_irq_handler_asynch(i2c_t *obj); 174 | 175 | /** Attempts to determine if the I2C peripheral is already in use 176 | * 177 | * @param obj The I2C object 178 | * @return Non-zero if the I2C module is active or zero if it is not 179 | */ 180 | uint8_t i2c_active(i2c_t *obj); 181 | 182 | /** Abort asynchronous transfer 183 | * 184 | * This function does not perform any check - that should happen in upper layers. 185 | * @param obj The I2C object 186 | */ 187 | void i2c_abort_asynch(i2c_t *obj); 188 | 189 | #endif 190 | 191 | /**@}*/ 192 | 193 | #ifdef __cplusplus 194 | } 195 | #endif 196 | 197 | #endif 198 | 199 | #endif 200 | -------------------------------------------------------------------------------- /mbed-hal/spi_api.h: -------------------------------------------------------------------------------- 1 | /* mbed Microcontroller Library 2 | * Copyright (c) 2006-2015 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 | #include "dma_api.h" 21 | #include "buffer.h" 22 | 23 | #if DEVICE_SPI 24 | 25 | #define SPI_EVENT_ERROR (1 << 1) 26 | #define SPI_EVENT_COMPLETE (1 << 2) 27 | #define SPI_EVENT_RX_OVERFLOW (1 << 3) 28 | #define SPI_EVENT_ALL (SPI_EVENT_ERROR | SPI_EVENT_COMPLETE | SPI_EVENT_RX_OVERFLOW) 29 | 30 | #define SPI_EVENT_INTERNAL_TRANSFER_COMPLETE (1 << 30) // Internal flag to report that an event occurred 31 | 32 | #define SPI_FILL_WORD (0xFFFFFFFF) 33 | 34 | typedef enum { 35 | SPI_MSB, 36 | SPI_LSB 37 | } spi_bitorder_t; 38 | 39 | #if DEVICE_SPI_ASYNCH 40 | /** Asynch SPI HAL structure 41 | */ 42 | typedef struct { 43 | struct spi_s spi; /**< Target specific SPI structure */ 44 | struct buffer_s tx_buff; /**< Tx buffer */ 45 | struct buffer_s rx_buff; /**< Rx buffer */ 46 | } spi_t; 47 | 48 | #else 49 | /** Non-asynch SPI HAL structure 50 | */ 51 | typedef struct spi_s spi_t; 52 | 53 | #endif 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | /** 60 | * \defgroup hal_GeneralSPI SPI Configuration Functions 61 | * @{ 62 | */ 63 | 64 | /** Initialize the SPI peripheral 65 | * 66 | * Configures the pins used by SPI, sets a default format and frequency, and enables the peripheral 67 | * @param[out] obj The SPI object to initialize 68 | * @param[in] mosi The pin to use for MOSI 69 | * @param[in] miso The pin to use for MISO 70 | * @param[in] sclk The pin to use for SCLK 71 | */ 72 | void spi_init(spi_t *obj, PinName mosi, PinName miso, PinName sclk); 73 | 74 | /** Release a SPI object 75 | * 76 | * TODO: spi_free is currently unimplemented 77 | * This will require reference counting at the C++ level to be safe 78 | * 79 | * Return the pins owned by the SPI object to their reset state 80 | * Disable the SPI peripheral 81 | * Disable the SPI clock 82 | * @param[in] obj The SPI object to deinitialize 83 | */ 84 | void spi_free(spi_t *obj); 85 | 86 | /** Configure the SPI format 87 | * 88 | * Set the number of bits per frame, configure clock polarity and phase, shift order 89 | * @param[in,out] obj The SPI object to configure 90 | * @param[in] bits The number of bits per frame 91 | * @param[in] mode The SPI mode (clock polarity, phase, and shift direction) 92 | * @param[in] order Bit order. SPI_MSB (standard) or SPI_LSB. 93 | */ 94 | void spi_format(spi_t *obj, int bits, int mode, spi_bitorder_t order); 95 | 96 | /** Set the SPI baud rate 97 | * 98 | * Actual frequency may differ from the desired frequency due to available dividers and bus clock 99 | * Configures the SPI peripheral's baud rate 100 | * @param[in,out] obj The SPI object to configure 101 | * @param[in] hz The baud rate in Hz 102 | */ 103 | void spi_frequency(spi_t *obj, int hz); 104 | 105 | /**@}*/ 106 | /** 107 | * \defgroup SynchSPI Synchronous SPI Hardware Abstraction Layer 108 | * @{ 109 | */ 110 | 111 | /** Write a byte out in master mode and receive a value 112 | * 113 | * @param[in] obj The SPI peripheral to use for sending 114 | * @param[in] value The value to send 115 | * @return Returns the value received during send 116 | */ 117 | int spi_master_write(spi_t *obj, int value); 118 | 119 | /** Checks if the specified SPI peripheral is in use 120 | * 121 | * @param[in] obj The SPI peripheral to check 122 | * @return Non-zero if the peripheral is currently transmitting 123 | */ 124 | int spi_busy(spi_t *obj); 125 | 126 | /** Get the module number 127 | * 128 | * @param[in] obj The SPI peripheral to check 129 | * @return The module number 130 | */ 131 | uint8_t spi_get_module(spi_t *obj); 132 | 133 | /**@}*/ 134 | 135 | #if DEVICE_SPI_ASYNCH 136 | /** 137 | * \defgroup AsynchSPI Asynchronous SPI Hardware Abstraction Layer 138 | * @{ 139 | */ 140 | 141 | /** Begin the SPI transfer. Buffer pointers and lengths are specified in tx_buff and rx_buff 142 | * 143 | * @param[in] obj The SPI object that holds the transfer information 144 | * @param[in] tx The transmit buffer 145 | * @param[in] tx_length The number of bytes to transmit 146 | * @param[in] rx The receive buffer 147 | * @param[in] rx_length The number of bytes to receive 148 | * @param[in] bit_width Deprecated argument 149 | * @param[in] event The logical OR of events to be registered 150 | * @param[in] handler SPI interrupt handler 151 | * @param[in] hint Deprecated argument 152 | */ 153 | void spi_master_transfer(spi_t *obj, void *tx, size_t tx_length, void *rx, size_t rx_length, uint32_t handler, uint32_t event, DMAUsage hint); 154 | 155 | /** The asynchronous IRQ handler 156 | * 157 | * Reads the received values out of the RX FIFO, writes values into the TX FIFO and checks for transfer termination 158 | * conditions, such as buffer overflows or transfer complete. 159 | * @param[in] obj The SPI object that holds the transfer information 160 | * @return Event flags if a transfer termination condition was met; otherwise 0. 161 | */ 162 | uint32_t spi_irq_handler_asynch(spi_t *obj); 163 | 164 | /** Attempts to determine if the SPI peripheral is already in use 165 | * 166 | * For each assigned buffer, check 167 | * if the corresponding buffer position is less than the buffer length. If buffers do not indicate activity, check if 168 | * there are any bytes in the FIFOs. 169 | * @param[in] obj The SPI object to check for activity 170 | * @return Non-zero if the SPI port is active or zero if it is not. 171 | */ 172 | uint8_t spi_active(spi_t *obj); 173 | 174 | /** Abort an SPI transfer 175 | * 176 | * @param obj The SPI peripheral to stop 177 | */ 178 | void spi_abort_asynch(spi_t *obj); 179 | 180 | 181 | #endif 182 | 183 | /**@}*/ 184 | 185 | #ifdef __cplusplus 186 | } 187 | #endif // __cplusplus 188 | 189 | #endif // SPI_DEVICE 190 | 191 | #endif // MBED_SPI_API_H 192 | -------------------------------------------------------------------------------- /apache-2.0.txt: -------------------------------------------------------------------------------- 1 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 2 | 3 | 1. Definitions. 4 | 5 | "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. 6 | 7 | "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. 8 | 9 | "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. 10 | 11 | "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. 12 | 13 | "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. 14 | 15 | "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. 16 | 17 | "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). 18 | 19 | "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. 20 | 21 | "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." 22 | 23 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 24 | 25 | 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 26 | 27 | 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 28 | 29 | 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: 30 | 31 | (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and 32 | 33 | (b) You must cause any modified files to carry prominent notices stating that You changed the files; and 34 | 35 | (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and 36 | 37 | (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. 38 | 39 | You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 40 | 41 | 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 42 | 43 | 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 44 | 45 | 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 46 | 47 | 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 48 | 49 | 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. 50 | 51 | END OF TERMS AND CONDITIONS 52 | 53 | APPENDIX: How to apply the Apache License to your work. 54 | 55 | To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. 56 | 57 | Copyright [yyyy] [name of copyright owner] 58 | 59 | Licensed under the Apache License, Version 2.0 (the "License"); 60 | you may not use this file except in compliance with the License. 61 | You may obtain a copy of the License at 62 | 63 | http://www.apache.org/licenses/LICENSE-2.0 64 | 65 | Unless required by applicable law or agreed to in writing, software 66 | distributed under the License is distributed on an "AS IS" BASIS, 67 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 68 | See the License for the specific language governing permissions and 69 | limitations under the License. 70 | -------------------------------------------------------------------------------- /mbed-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 | #include "buffer.h" 21 | #include "dma_api.h" 22 | 23 | #if DEVICE_SERIAL 24 | 25 | #define SERIAL_EVENT_TX_SHIFT (2) 26 | #define SERIAL_EVENT_RX_SHIFT (8) 27 | 28 | #define SERIAL_EVENT_TX_MASK (0x00FC) 29 | #define SERIAL_EVENT_RX_MASK (0x3F00) 30 | 31 | #define SERIAL_EVENT_ERROR (1 << 1) 32 | 33 | /** 34 | * @defgroup SerialTXEvents Serial TX Events Macros 35 | * 36 | * @{ 37 | */ 38 | #define SERIAL_EVENT_TX_COMPLETE (1 << (SERIAL_EVENT_TX_SHIFT + 0)) 39 | #define SERIAL_EVENT_TX_ALL (SERIAL_EVENT_TX_COMPLETE) 40 | /**@}*/ 41 | 42 | /** 43 | * @defgroup SerialRXEvents Serial RX Events Macros 44 | * 45 | * @{ 46 | */ 47 | #define SERIAL_EVENT_RX_COMPLETE (1 << (SERIAL_EVENT_RX_SHIFT + 0)) 48 | #define SERIAL_EVENT_RX_OVERRUN_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 1)) 49 | #define SERIAL_EVENT_RX_FRAMING_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 2)) 50 | #define SERIAL_EVENT_RX_PARITY_ERROR (1 << (SERIAL_EVENT_RX_SHIFT + 3)) 51 | #define SERIAL_EVENT_RX_OVERFLOW (1 << (SERIAL_EVENT_RX_SHIFT + 4)) 52 | #define SERIAL_EVENT_RX_CHARACTER_MATCH (1 << (SERIAL_EVENT_RX_SHIFT + 5)) 53 | #define SERIAL_EVENT_RX_ALL (SERIAL_EVENT_RX_OVERFLOW | SERIAL_EVENT_RX_PARITY_ERROR | \ 54 | SERIAL_EVENT_RX_FRAMING_ERROR | SERIAL_EVENT_RX_OVERRUN_ERROR | \ 55 | SERIAL_EVENT_RX_COMPLETE | SERIAL_EVENT_RX_CHARACTER_MATCH) 56 | /**@}*/ 57 | 58 | #define SERIAL_RESERVED_CHAR_MATCH (255) 59 | 60 | typedef enum { 61 | ParityNone = 0, 62 | ParityOdd = 1, 63 | ParityEven = 2, 64 | ParityForced1 = 3, 65 | ParityForced0 = 4 66 | } SerialParity; 67 | 68 | typedef enum { 69 | RxIrq, 70 | TxIrq 71 | } SerialIrq; 72 | 73 | typedef enum { 74 | FlowControlNone, 75 | FlowControlRTS, 76 | FlowControlCTS, 77 | FlowControlRTSCTS 78 | } FlowControl; 79 | 80 | typedef void (*uart_irq_handler)(uint32_t id, SerialIrq event); 81 | 82 | #if DEVICE_SERIAL_ASYNCH 83 | /** Asynch serial HAL structure 84 | */ 85 | typedef struct { 86 | struct serial_s serial; /**< Target specific serial structure */ 87 | struct buffer_s tx_buff; /**< TX buffer */ 88 | struct buffer_s rx_buff; /**< RX buffer */ 89 | uint8_t char_match; /**< Character to be matched */ 90 | uint8_t char_found; /**< State of the matched character */ 91 | } serial_t; 92 | 93 | #else 94 | /** Non-asynch serial HAL structure 95 | */ 96 | typedef struct serial_s serial_t; 97 | 98 | #endif 99 | 100 | #ifdef __cplusplus 101 | extern "C" { 102 | #endif 103 | 104 | /** 105 | * \defgroup hal_GeneralSerial Serial Configuration Functions 106 | * @{ 107 | */ 108 | 109 | /** Initialize the serial peripheral. It sets the default parameters for serial 110 | * peripheral, and configures its specifieds pins. 111 | * 112 | * @param obj The serial object 113 | * @param tx The TX pin name 114 | * @param rx The RX pin name 115 | */ 116 | void serial_init(serial_t *obj, PinName tx, PinName rx); 117 | 118 | /** Release the serial peripheral, not currently invoked. It requires further 119 | * resource management. 120 | * 121 | * @param obj The serial object 122 | */ 123 | void serial_free(serial_t *obj); 124 | 125 | /** Configure the baud rate 126 | * 127 | * @param obj The serial object 128 | * @param baudrate The baud rate to be configured 129 | */ 130 | void serial_baud(serial_t *obj, int baudrate); 131 | 132 | /** Configure the format. Set the number of bits, parity and the number of stop bits 133 | * 134 | * @param obj The serial object 135 | * @param data_bits The number of data bits 136 | * @param parity The parity 137 | * @param stop_bits The number of stop bits 138 | */ 139 | void serial_format(serial_t *obj, int data_bits, SerialParity parity, int stop_bits); 140 | 141 | /** The serial interrupt handler registration 142 | * 143 | * @param obj The serial object 144 | * @param handler The interrupt handler which will be invoked when the interrupt fires 145 | * @param id The SerialBase object 146 | */ 147 | void serial_irq_handler(serial_t *obj, uart_irq_handler handler, uint32_t id); 148 | 149 | /** Configure serial interrupt. This function is used for word-approach 150 | * 151 | * @param obj The serial object 152 | * @param irq The serial IRQ type (RX or TX) 153 | * @param enable Set to non-zero to enable events, or zero to disable them 154 | */ 155 | void serial_irq_set(serial_t *obj, SerialIrq irq, uint32_t enable); 156 | 157 | /** Get character. This is a blocking call, waiting for a character 158 | * 159 | * @param obj The serial object 160 | */ 161 | int serial_getc(serial_t *obj); 162 | 163 | /** Send a character. This is a blocking call, waiting for a peripheral to be available 164 | * for writing 165 | * 166 | * @param obj The serial object 167 | * @param c The character to be sent 168 | */ 169 | void serial_putc(serial_t *obj, int c); 170 | 171 | /** Check if the serial peripheral is readable 172 | * 173 | * @param obj The serial object 174 | * @return Non-zero value if a character can be read, 0 if nothing to read 175 | */ 176 | int serial_readable(serial_t *obj); 177 | 178 | /** Check if the serial peripheral is writable 179 | * 180 | * @param obj The serial object 181 | * @return Non-zero value if a character can be written, 0 otherwise. 182 | */ 183 | int serial_writable(serial_t *obj); 184 | 185 | /** Clear the serial peripheral 186 | * 187 | * @param obj The serial object 188 | */ 189 | void serial_clear(serial_t *obj); 190 | 191 | /** Set the break 192 | * 193 | * @param obj The serial object 194 | */ 195 | void serial_break_set(serial_t *obj); 196 | 197 | /** Clear the break 198 | * 199 | * @param obj The serial object 200 | */ 201 | void serial_break_clear(serial_t *obj); 202 | 203 | /** Configure the TX pin for UART function. 204 | * 205 | * @param tx The pin name used for TX 206 | */ 207 | void serial_pinout_tx(PinName tx); 208 | 209 | /** Configure the serial for the flow control. It sets flow control in the hardware 210 | * if a serial peripheral supports it, otherwise software emulation is used. 211 | * 212 | * @param obj The serial object 213 | * @param type The type of the flow control. Look at the available FlowControl types. 214 | * @param rxflow The TX pin name 215 | * @param txflow The RX pin name 216 | */ 217 | void serial_set_flow_control(serial_t *obj, FlowControl type, PinName rxflow, PinName txflow); 218 | 219 | #if DEVICE_SERIAL_ASYNCH 220 | 221 | /**@}*/ 222 | 223 | /** 224 | * \defgroup hal_AsynchSerial Asynchronous Serial Hardware Abstraction Layer 225 | * @{ 226 | */ 227 | 228 | /** Begin asynchronous TX transfer. The used buffer is specified in the serial object, 229 | * tx_buff 230 | * 231 | * @param obj The serial object 232 | * @param tx The transmit buffer 233 | * @param tx_length The number of bytes to transmit 234 | * @param tx_width Deprecated argument 235 | * @param handler The serial handler 236 | * @param event The logical OR of events to be registered 237 | * @param hint Deprecated argument 238 | * @return Returns number of data transfered, otherwise returns 0 239 | */ 240 | int serial_tx_asynch(serial_t *obj, void *tx, size_t tx_length, uint8_t tx_width, uint32_t handler, uint32_t event, DMAUsage hint); 241 | 242 | /** Begin asynchronous RX transfer (enable interrupt for data collecting) 243 | * The used buffer is specified in the serial object - rx_buff 244 | * 245 | * @param obj The serial object 246 | * @param rx The receive buffer 247 | * @param rx_length The number of bytes to receive 248 | * @param rx_width Deprecated argument 249 | * @param handler The serial handler 250 | * @param event The logical OR of events to be registered 251 | * @param handler The serial handler 252 | * @param char_match A character in range 0-254 to be matched 253 | * @param hint Deprecated argument 254 | */ 255 | void serial_rx_asynch(serial_t *obj, void *rx, size_t rx_length, uint8_t rx_width, uint32_t handler, uint32_t event, uint8_t char_match, DMAUsage hint); 256 | 257 | /** Attempts to determine if the serial peripheral is already in use for TX 258 | * 259 | * @param obj The serial object 260 | * @return Non-zero if the RX transaction is ongoing, 0 otherwise 261 | */ 262 | uint8_t serial_tx_active(serial_t *obj); 263 | 264 | /** Attempts to determine if the serial peripheral is already in use for RX 265 | * 266 | * @param obj The serial object 267 | * @return Non-zero if the RX transaction is ongoing, 0 otherwise 268 | */ 269 | uint8_t serial_rx_active(serial_t *obj); 270 | 271 | /** The asynchronous TX and RX handler. 272 | * 273 | * @param obj The serial object 274 | * @return Returns event flags if an RX transfer termination condition was met; otherwise returns 0 275 | */ 276 | int serial_irq_handler_asynch(serial_t *obj); 277 | 278 | /** Abort the ongoing TX transaction. It disables the enabled interupt for TX and 279 | * flushes the TX hardware buffer if TX FIFO is used 280 | * 281 | * @param obj The serial object 282 | */ 283 | void serial_tx_abort_asynch(serial_t *obj); 284 | 285 | /** Abort the ongoing RX transaction. It disables the enabled interrupt for RX and 286 | * flushes the RX hardware buffer if RX FIFO is used 287 | * 288 | * @param obj The serial object 289 | */ 290 | void serial_rx_abort_asynch(serial_t *obj); 291 | 292 | /**@}*/ 293 | 294 | #endif 295 | 296 | #ifdef __cplusplus 297 | } 298 | #endif 299 | 300 | #endif 301 | 302 | #endif 303 | --------------------------------------------------------------------------------