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