ver:init
x-nucleo-idb0xa1/bluenrg-hci/ble_hal.h@0:4946262d6030, 2017-06-18 (annotated)
- Committer:
- iv123
- Date:
- Sun Jun 18 16:11:03 2017 +0000
- Revision:
- 0:4946262d6030
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
iv123 | 0:4946262d6030 | 1 | /******************** (C) COPYRIGHT 2012 STMicroelectronics ******************** |
iv123 | 0:4946262d6030 | 2 | * File Name : hal.h |
iv123 | 0:4946262d6030 | 3 | * Author : AMS - HEA&RF BU |
iv123 | 0:4946262d6030 | 4 | * Version : V1.0.0 |
iv123 | 0:4946262d6030 | 5 | * Date : 19-July-2012 |
iv123 | 0:4946262d6030 | 6 | * Description : Header file which defines Hardware abstraction layer APIs |
iv123 | 0:4946262d6030 | 7 | * used by the BLE stack. It defines the set of functions |
iv123 | 0:4946262d6030 | 8 | * which needs to be ported to the target platform. |
iv123 | 0:4946262d6030 | 9 | ******************************************************************************** |
iv123 | 0:4946262d6030 | 10 | * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS |
iv123 | 0:4946262d6030 | 11 | * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME. |
iv123 | 0:4946262d6030 | 12 | * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT, |
iv123 | 0:4946262d6030 | 13 | * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE |
iv123 | 0:4946262d6030 | 14 | * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING |
iv123 | 0:4946262d6030 | 15 | * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS. |
iv123 | 0:4946262d6030 | 16 | *******************************************************************************/ |
iv123 | 0:4946262d6030 | 17 | #ifndef __HAL_H__ |
iv123 | 0:4946262d6030 | 18 | #define __HAL_H__ |
iv123 | 0:4946262d6030 | 19 | |
iv123 | 0:4946262d6030 | 20 | /****************************************************************************** |
iv123 | 0:4946262d6030 | 21 | * Includes |
iv123 | 0:4946262d6030 | 22 | *****************************************************************************/ |
iv123 | 0:4946262d6030 | 23 | #include <ble_hal_types.h> |
iv123 | 0:4946262d6030 | 24 | #include <ble_status.h> |
iv123 | 0:4946262d6030 | 25 | |
iv123 | 0:4946262d6030 | 26 | |
iv123 | 0:4946262d6030 | 27 | /****************************************************************************** |
iv123 | 0:4946262d6030 | 28 | * Macros |
iv123 | 0:4946262d6030 | 29 | *****************************************************************************/ |
iv123 | 0:4946262d6030 | 30 | /* Little Endian buffer to host endianess conversion */ |
iv123 | 0:4946262d6030 | 31 | #define LE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ |
iv123 | 0:4946262d6030 | 32 | *((uint8_t *)ptr)) | \ |
iv123 | 0:4946262d6030 | 33 | ((uint16_t) \ |
iv123 | 0:4946262d6030 | 34 | *((uint8_t *)ptr + 1) << 8 ) ) |
iv123 | 0:4946262d6030 | 35 | |
iv123 | 0:4946262d6030 | 36 | #define LE_TO_HOST_32(ptr) (uint32_t) ( ((uint32_t) \ |
iv123 | 0:4946262d6030 | 37 | *((uint8_t *)ptr)) | \ |
iv123 | 0:4946262d6030 | 38 | ((uint32_t) \ |
iv123 | 0:4946262d6030 | 39 | *((uint8_t *)ptr + 1) << 8) | \ |
iv123 | 0:4946262d6030 | 40 | ((uint32_t) \ |
iv123 | 0:4946262d6030 | 41 | *((uint8_t *)ptr + 2) << 16) | \ |
iv123 | 0:4946262d6030 | 42 | ((uint32_t) \ |
iv123 | 0:4946262d6030 | 43 | *((uint8_t *)ptr + 3) << 24) ) |
iv123 | 0:4946262d6030 | 44 | |
iv123 | 0:4946262d6030 | 45 | /* Big Endian buffer to host endianess conversion */ |
iv123 | 0:4946262d6030 | 46 | #define BE_TO_HOST_16(ptr) (uint16_t) ( ((uint16_t) \ |
iv123 | 0:4946262d6030 | 47 | *((uint8_t *)ptr)) << 8 | \ |
iv123 | 0:4946262d6030 | 48 | ((uint16_t) \ |
iv123 | 0:4946262d6030 | 49 | *((uint8_t *)ptr + 1) ) ) |
iv123 | 0:4946262d6030 | 50 | |
iv123 | 0:4946262d6030 | 51 | /* Store Value into a buffer in Little Endian Format */ |
iv123 | 0:4946262d6030 | 52 | #define HOST_TO_LE_16(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ |
iv123 | 0:4946262d6030 | 53 | ((buf)[1] = (uint8_t) (val>>8) ) ) |
iv123 | 0:4946262d6030 | 54 | |
iv123 | 0:4946262d6030 | 55 | #define HOST_TO_LE_32(buf, val) ( ((buf)[0] = (uint8_t) (val) ) , \ |
iv123 | 0:4946262d6030 | 56 | ((buf)[1] = (uint8_t) (val>>8) ) , \ |
iv123 | 0:4946262d6030 | 57 | ((buf)[2] = (uint8_t) (val>>16) ) , \ |
iv123 | 0:4946262d6030 | 58 | ((buf)[3] = (uint8_t) (val>>24) ) ) |
iv123 | 0:4946262d6030 | 59 | |
iv123 | 0:4946262d6030 | 60 | |
iv123 | 0:4946262d6030 | 61 | /* Store Value into a buffer in Big Endian Format */ |
iv123 | 0:4946262d6030 | 62 | #define HOST_TO_BE_16(buf, val) ( ((buf)[1] = (uint8_t) (val) ) , \ |
iv123 | 0:4946262d6030 | 63 | ((buf)[0] = (uint8_t) (val>>8) ) ) |
iv123 | 0:4946262d6030 | 64 | |
iv123 | 0:4946262d6030 | 65 | #define DISABLE_INTERRUPTS() __disable_interrupt() |
iv123 | 0:4946262d6030 | 66 | #define ENABLE_INTERRUPTS() __enable_interrupt() |
iv123 | 0:4946262d6030 | 67 | #define SAVE_PRIMASK() uint32_t uwPRIMASK_Bit = __get_PRIMASK() |
iv123 | 0:4946262d6030 | 68 | #define ATOMIC_SECTION_BEGIN() uint32_t uwPRIMASK_Bit = __get_PRIMASK(); \ |
iv123 | 0:4946262d6030 | 69 | __disable_interrupt(); \ |
iv123 | 0:4946262d6030 | 70 | /* Must be called in the same or in a lower scope of SUSPEND_INTERRUPTS */ |
iv123 | 0:4946262d6030 | 71 | #define ATOMIC_SECTION_END() __set_PRIMASK(uwPRIMASK_Bit) |
iv123 | 0:4946262d6030 | 72 | |
iv123 | 0:4946262d6030 | 73 | /****************************************************************************** |
iv123 | 0:4946262d6030 | 74 | * Types |
iv123 | 0:4946262d6030 | 75 | *****************************************************************************/ |
iv123 | 0:4946262d6030 | 76 | |
iv123 | 0:4946262d6030 | 77 | /****************************************************************************** |
iv123 | 0:4946262d6030 | 78 | * Function Prototypes |
iv123 | 0:4946262d6030 | 79 | *****************************************************************************/ |
iv123 | 0:4946262d6030 | 80 | |
iv123 | 0:4946262d6030 | 81 | /** |
iv123 | 0:4946262d6030 | 82 | * Writes data to a serial interface. |
iv123 | 0:4946262d6030 | 83 | * |
iv123 | 0:4946262d6030 | 84 | * @param[in] data1 1st buffer |
iv123 | 0:4946262d6030 | 85 | * @param[in] data2 2nd buffer |
iv123 | 0:4946262d6030 | 86 | * @param[in] n_bytes1 number of bytes in 1st buffer |
iv123 | 0:4946262d6030 | 87 | * @param[in] n_bytes2 number of bytes in 2nd buffer |
iv123 | 0:4946262d6030 | 88 | */ |
iv123 | 0:4946262d6030 | 89 | void Hal_Write_Serial(const void* data1, const void* data2, int32_t n_bytes1, int32_t n_bytes2); |
iv123 | 0:4946262d6030 | 90 | |
iv123 | 0:4946262d6030 | 91 | /** |
iv123 | 0:4946262d6030 | 92 | * Enable interrupts from HCI controller. |
iv123 | 0:4946262d6030 | 93 | */ |
iv123 | 0:4946262d6030 | 94 | void Enable_SPI_IRQ(void); |
iv123 | 0:4946262d6030 | 95 | |
iv123 | 0:4946262d6030 | 96 | /** |
iv123 | 0:4946262d6030 | 97 | * Disable interrupts from BLE controller. |
iv123 | 0:4946262d6030 | 98 | */ |
iv123 | 0:4946262d6030 | 99 | void Disable_SPI_IRQ(void); |
iv123 | 0:4946262d6030 | 100 | |
iv123 | 0:4946262d6030 | 101 | void signalEventsToProcess(void); |
iv123 | 0:4946262d6030 | 102 | |
iv123 | 0:4946262d6030 | 103 | void Hal_Init_Timer(void); |
iv123 | 0:4946262d6030 | 104 | uint32_t Hal_Get_Timer_Value(void); |
iv123 | 0:4946262d6030 | 105 | void Hal_Start_Timer(uint32_t timeout); |
iv123 | 0:4946262d6030 | 106 | void Hal_Stop_Timer(void); |
iv123 | 0:4946262d6030 | 107 | |
iv123 | 0:4946262d6030 | 108 | #endif /* __HAL_H__ */ |