/*************************************************************************** * Copyright (c) 2012, Broadcom Corporation * All Rights Reserved * Confidential Property of Broadcom Corporation * * THIS SOFTWARE MAY ONLY BE USED SUBJECT TO AN EXECUTED SOFTWARE LICENSE * AGREEMENT BETWEEN THE USER AND BROADCOM. YOU HAVE NO RIGHT TO USE OR * EXPLOIT THIS MATERIAL EXCEPT SUBJECT TO THE TERMS OF SUCH AN AGREEMENT. * * $brcm_Workfile: $ * $brcm_Revision: $ * $brcm_Date: $ * * Module Description: * * Revision History: * * $brcm_Log: $ * ***************************************************************************/ #include "nexus_platform.h" #include "nexus_types.h" #if NEXUS_NUM_RFM_OUTPUTS #include "nexus_rfm.h" #endif #include "bsettop_rfm.h" #include "bos_task_priorities.h" #include "nexus_gpio.h" #define BRFM_TASK_STACK_WORDS 256 struct brfm { #if NEXUS_NUM_RFM_OUTPUTS NEXUS_RfmHandle rfmHandle; #else NEXUS_I2cHandle i2cHandle; #endif NEXUS_GpioHandle gpio; BKNI_EventHandle event; NEXUS_GpioValue lastValue; unsigned int task_stack[BRFM_TASK_STACK_WORDS]; b_task_t task_h; }; static struct brfm s_rfm; #if (BCHP_CHIP==7552) #define BRFM_GPIO_NUM 20 #elif (BCHP_CHIP==7344) #define BRFM_GPIO_NUM 5 #endif BDBG_MODULE(brfm); static void rfm_gpio_interrupt(void *context, int param) { BSTD_UNUSED(param); BKNI_SetEvent((BKNI_EventHandle)context); } static void rfm_task(void *arg) { NEXUS_GpioStatus gpioStatus; NEXUS_Error err; #if NEXUS_NUM_RFM_OUTPUTS NEXUS_RfmSettings rfmSettings; #else static uint8_t channel3Data[4] = {0x80,0x00,0x1e,0xa3}; static uint8_t channel4Data[4] = {0x80,0x00,0x21,0xa3}; uint8_t *pData; #endif brfm_t rfm = (brfm_t)arg; while (1) { BKNI_WaitForEvent(rfm->event, 0xFFFFFFFF); err = NEXUS_Gpio_GetStatus(s_rfm.gpio, &gpioStatus); if (err != NEXUS_SUCCESS) { BDBG_WRN(("NEXUS_Gpio_GetStatus failed")); continue; } if (gpioStatus.value != rfm->lastValue) { rfm->lastValue = gpioStatus.value; BDBG_ERR(("%s:%d, value = %d", __FUNCTION__, __LINE__, rfm->lastValue)); #if NEXUS_NUM_RFM_OUTPUTS NEXUS_Rfm_GetSettings(rfm->rfmHandle, &rfmSettings); if (rfm->lastValue == NEXUS_GpioValue_eHigh) { rfmSettings.channel = 4; } else { rfmSettings.channel = 3; } NEXUS_Rfm_SetSettings(rfm->rfmHandle, &rfmSettings); #else if (rfm->lastValue == NEXUS_GpioValue_eHigh) { pData = channel4Data; } else { pData = channel3Data; } NEXUS_I2c_WriteNoAddr(rfm->i2cHandle, 0x65, pData, 4); #endif } } } /* * Summary: * Open and allocate RFM resources. * * Description: * On most platforms, the rfm_id is simply an index of the rf modulator. * **/ brfm_t brfm_open( int rfm_id /* - index used to identify a particular rfm */ ) { NEXUS_GpioSettings gpioSettings; NEXUS_PlatformConfiguration platformConfig; NEXUS_GpioStatus gpioStatus; b_task_params task_params; #if NEXUS_NUM_RFM_OUTPUTS NEXUS_RfmSettings rfmSettings; #endif BSTD_UNUSED(rfm_id); BKNI_Memset(&s_rfm, 0, sizeof(s_rfm)); BKNI_CreateEvent(&s_rfm.event); NEXUS_Gpio_GetDefaultSettings(NEXUS_GpioType_eStandard, &gpioSettings); gpioSettings.mode = NEXUS_GpioMode_eInput; gpioSettings.interruptMode = NEXUS_GpioInterrupt_eEdge; gpioSettings.interrupt.callback = rfm_gpio_interrupt; gpioSettings.interrupt.context = s_rfm.event; s_rfm.gpio = NEXUS_Gpio_Open(NEXUS_GpioType_eAonStandard, BRFM_GPIO_NUM, &gpioSettings); NEXUS_Platform_GetConfiguration(&platformConfig); #if NEXUS_NUM_RFM_OUTPUTS NEXUS_Rfm_GetDefaultSettings(&rfmSettings); NEXUS_Gpio_GetStatus(s_rfm.gpio, &gpioStatus); if (gpioStatus.value == NEXUS_GpioValue_eHigh) { /* channel 4 */ BDBG_WRN(("Channel 4")); rfmSettings.channel = 4; } else { BDBG_WRN(("Channel 3")); rfmSettings.channel = 3; } s_rfm.rfmHandle = platformConfig.outputs.rfm[0]; NEXUS_Rfm_SetSettings(s_rfm.rfmHandle, &rfmSettings); #else /* in nexus, set the correct channel when initializing platform */ s_rfm.i2cHandle = platformConfig.i2c[NEXUS_I2C_CHANNEL_EXT_RFM]; #endif s_rfm.lastValue = gpioStatus.value; task_params.name = "RFM_TASK"; task_params.priority = RFM_PRIORITY; task_params.stack_size = BRFM_TASK_STACK_WORDS; task_params.stack = s_rfm.task_stack; bos_start_task(&(s_rfm.task_h), &task_params, rfm_task, &s_rfm); /* set initial RF channel */ BKNI_SetEvent((BKNI_EventHandle)s_rfm.event); return &s_rfm; } void brfm_close(brfm_t rfm) { BDBG_ASSERT(rfm); if (rfm->task_h) bos_stop_task(rfm->task_h); if (rfm->gpio) NEXUS_Gpio_Close(rfm->gpio); rfm->gpio = NULL; rfm->task_h = 0; BKNI_DestroyEvent(rfm->event); }