| 1 | /*************************************************************************** |
|---|
| 2 | * Copyright (c) 2012, Broadcom Corporation |
|---|
| 3 | * All Rights Reserved |
|---|
| 4 | * Confidential Property of Broadcom Corporation |
|---|
| 5 | * |
|---|
| 6 | * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE |
|---|
| 7 | * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR |
|---|
| 8 | * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. |
|---|
| 9 | * |
|---|
| 10 | * $brcm_Workfile: $ |
|---|
| 11 | * $brcm_Revision: $ |
|---|
| 12 | * $brcm_Date: $ |
|---|
| 13 | * |
|---|
| 14 | * Module Description: |
|---|
| 15 | * |
|---|
| 16 | * Revision History: |
|---|
| 17 | * |
|---|
| 18 | * $brcm_Log: $ |
|---|
| 19 | * |
|---|
| 20 | ***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #include "nexus_platform.h" |
|---|
| 23 | #include "nexus_types.h" |
|---|
| 24 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 25 | #include "nexus_rfm.h" |
|---|
| 26 | #endif |
|---|
| 27 | #include "bsettop_rfm.h" |
|---|
| 28 | #include "bos_task_priorities.h" |
|---|
| 29 | #include "nexus_gpio.h" |
|---|
| 30 | |
|---|
| 31 | #define BRFM_TASK_STACK_WORDS 256 |
|---|
| 32 | struct brfm |
|---|
| 33 | { |
|---|
| 34 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 35 | NEXUS_RfmHandle rfmHandle; |
|---|
| 36 | #else |
|---|
| 37 | NEXUS_I2cHandle i2cHandle; |
|---|
| 38 | #endif |
|---|
| 39 | NEXUS_GpioHandle gpio; |
|---|
| 40 | BKNI_EventHandle event; |
|---|
| 41 | NEXUS_GpioValue lastValue; |
|---|
| 42 | |
|---|
| 43 | unsigned int task_stack[BRFM_TASK_STACK_WORDS]; |
|---|
| 44 | b_task_t task_h; |
|---|
| 45 | }; |
|---|
| 46 | |
|---|
| 47 | static struct brfm s_rfm; |
|---|
| 48 | |
|---|
| 49 | #if (BCHP_CHIP==7552) |
|---|
| 50 | #define BRFM_GPIO_NUM 20 |
|---|
| 51 | #elif (BCHP_CHIP==7344) |
|---|
| 52 | #define BRFM_GPIO_NUM 5 |
|---|
| 53 | #endif |
|---|
| 54 | |
|---|
| 55 | BDBG_MODULE(brfm); |
|---|
| 56 | |
|---|
| 57 | static void rfm_gpio_interrupt(void *context, int param) |
|---|
| 58 | { |
|---|
| 59 | BSTD_UNUSED(param); |
|---|
| 60 | BKNI_SetEvent((BKNI_EventHandle)context); |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | |
|---|
| 64 | static void rfm_task(void *arg) |
|---|
| 65 | { |
|---|
| 66 | NEXUS_GpioStatus gpioStatus; |
|---|
| 67 | NEXUS_Error err; |
|---|
| 68 | |
|---|
| 69 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 70 | NEXUS_RfmSettings rfmSettings; |
|---|
| 71 | #else |
|---|
| 72 | static uint8_t channel3Data[4] = {0x80,0x00,0x1e,0xa3}; |
|---|
| 73 | static uint8_t channel4Data[4] = {0x80,0x00,0x21,0xa3}; |
|---|
| 74 | uint8_t *pData; |
|---|
| 75 | #endif |
|---|
| 76 | brfm_t rfm = (brfm_t)arg; |
|---|
| 77 | |
|---|
| 78 | while (1) |
|---|
| 79 | { |
|---|
| 80 | BKNI_WaitForEvent(rfm->event, 0xFFFFFFFF); |
|---|
| 81 | err = NEXUS_Gpio_GetStatus(s_rfm.gpio, &gpioStatus); |
|---|
| 82 | if (err != NEXUS_SUCCESS) { |
|---|
| 83 | BDBG_WRN(("NEXUS_Gpio_GetStatus failed")); |
|---|
| 84 | continue; |
|---|
| 85 | } |
|---|
| 86 | if (gpioStatus.value != rfm->lastValue) |
|---|
| 87 | { |
|---|
| 88 | rfm->lastValue = gpioStatus.value; |
|---|
| 89 | BDBG_ERR(("%s:%d, value = %d", __FUNCTION__, __LINE__, rfm->lastValue)); |
|---|
| 90 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 91 | NEXUS_Rfm_GetSettings(rfm->rfmHandle, &rfmSettings); |
|---|
| 92 | if (rfm->lastValue == NEXUS_GpioValue_eHigh) { |
|---|
| 93 | rfmSettings.channel = 4; |
|---|
| 94 | } |
|---|
| 95 | else { |
|---|
| 96 | rfmSettings.channel = 3; |
|---|
| 97 | } |
|---|
| 98 | NEXUS_Rfm_SetSettings(rfm->rfmHandle, &rfmSettings); |
|---|
| 99 | #else |
|---|
| 100 | if (rfm->lastValue == NEXUS_GpioValue_eHigh) { |
|---|
| 101 | pData = channel4Data; |
|---|
| 102 | } |
|---|
| 103 | else { |
|---|
| 104 | pData = channel3Data; |
|---|
| 105 | } |
|---|
| 106 | NEXUS_I2c_WriteNoAddr(rfm->i2cHandle, 0x65, pData, 4); |
|---|
| 107 | #endif |
|---|
| 108 | } |
|---|
| 109 | } |
|---|
| 110 | } |
|---|
| 111 | |
|---|
| 112 | /* |
|---|
| 113 | * Summary: |
|---|
| 114 | * Open and allocate RFM resources. |
|---|
| 115 | * |
|---|
| 116 | * Description: |
|---|
| 117 | * On most platforms, the rfm_id is simply an index of the rf modulator. |
|---|
| 118 | * |
|---|
| 119 | **/ |
|---|
| 120 | brfm_t brfm_open( |
|---|
| 121 | int rfm_id /* - index used to identify a particular rfm */ |
|---|
| 122 | ) |
|---|
| 123 | { |
|---|
| 124 | |
|---|
| 125 | NEXUS_GpioSettings gpioSettings; |
|---|
| 126 | NEXUS_PlatformConfiguration platformConfig; |
|---|
| 127 | NEXUS_GpioStatus gpioStatus; |
|---|
| 128 | b_task_params task_params; |
|---|
| 129 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 130 | NEXUS_RfmSettings rfmSettings; |
|---|
| 131 | #endif |
|---|
| 132 | BSTD_UNUSED(rfm_id); |
|---|
| 133 | |
|---|
| 134 | BKNI_Memset(&s_rfm, 0, sizeof(s_rfm)); |
|---|
| 135 | |
|---|
| 136 | BKNI_CreateEvent(&s_rfm.event); |
|---|
| 137 | |
|---|
| 138 | NEXUS_Gpio_GetDefaultSettings(NEXUS_GpioType_eStandard, &gpioSettings); |
|---|
| 139 | gpioSettings.mode = NEXUS_GpioMode_eInput; |
|---|
| 140 | gpioSettings.interruptMode = NEXUS_GpioInterrupt_eEdge; |
|---|
| 141 | gpioSettings.interrupt.callback = rfm_gpio_interrupt; |
|---|
| 142 | gpioSettings.interrupt.context = s_rfm.event; |
|---|
| 143 | s_rfm.gpio = NEXUS_Gpio_Open(NEXUS_GpioType_eAonStandard, BRFM_GPIO_NUM, &gpioSettings); |
|---|
| 144 | |
|---|
| 145 | NEXUS_Platform_GetConfiguration(&platformConfig); |
|---|
| 146 | #if NEXUS_NUM_RFM_OUTPUTS |
|---|
| 147 | NEXUS_Rfm_GetDefaultSettings(&rfmSettings); |
|---|
| 148 | |
|---|
| 149 | NEXUS_Gpio_GetStatus(s_rfm.gpio, &gpioStatus); |
|---|
| 150 | if (gpioStatus.value == NEXUS_GpioValue_eHigh) { |
|---|
| 151 | /* channel 4 */ |
|---|
| 152 | BDBG_WRN(("Channel 4")); |
|---|
| 153 | rfmSettings.channel = 4; |
|---|
| 154 | } |
|---|
| 155 | else { |
|---|
| 156 | BDBG_WRN(("Channel 3")); |
|---|
| 157 | rfmSettings.channel = 3; |
|---|
| 158 | } |
|---|
| 159 | s_rfm.rfmHandle = platformConfig.outputs.rfm[0]; |
|---|
| 160 | |
|---|
| 161 | NEXUS_Rfm_SetSettings(s_rfm.rfmHandle, &rfmSettings); |
|---|
| 162 | #else |
|---|
| 163 | /* in nexus, set the correct channel when initializing platform */ |
|---|
| 164 | s_rfm.i2cHandle = platformConfig.i2c[NEXUS_I2C_CHANNEL_EXT_RFM]; |
|---|
| 165 | #endif |
|---|
| 166 | s_rfm.lastValue = gpioStatus.value; |
|---|
| 167 | |
|---|
| 168 | task_params.name = "RFM_TASK"; |
|---|
| 169 | task_params.priority = RFM_PRIORITY; |
|---|
| 170 | task_params.stack_size = BRFM_TASK_STACK_WORDS; |
|---|
| 171 | task_params.stack = s_rfm.task_stack; |
|---|
| 172 | bos_start_task(&(s_rfm.task_h), &task_params, rfm_task, &s_rfm); |
|---|
| 173 | |
|---|
| 174 | /* set initial RF channel */ |
|---|
| 175 | BKNI_SetEvent((BKNI_EventHandle)s_rfm.event); |
|---|
| 176 | return &s_rfm; |
|---|
| 177 | } |
|---|
| 178 | |
|---|
| 179 | void brfm_close(brfm_t rfm) |
|---|
| 180 | { |
|---|
| 181 | BDBG_ASSERT(rfm); |
|---|
| 182 | if (rfm->task_h) |
|---|
| 183 | bos_stop_task(rfm->task_h); |
|---|
| 184 | if (rfm->gpio) |
|---|
| 185 | NEXUS_Gpio_Close(rfm->gpio); |
|---|
| 186 | |
|---|
| 187 | rfm->gpio = NULL; |
|---|
| 188 | rfm->task_h = 0; |
|---|
| 189 | BKNI_DestroyEvent(rfm->event); |
|---|
| 190 | } |
|---|