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