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