I32S TcbdDequeue(TcbdQueue_t *_queue, I08U *_chunk, I32S *_size, I32S *_type) { *_size = 0; TcpalSemaphoreLock(&_queue->sem); if(TcbdQueueIsEmpty(_queue)) { TcbdDebug(0, "Queue Empty!! \n"); TcpalSemaphoreUnLock(&_queue->sem); return -1; } else { TcbdDebug(0, "Dequeue! size%d\n", _queue->q[_queue->front].size); } *_size = _queue->q[_queue->front].size; if(_type) *_type = _queue->q[_queue->front].type; TcpalMemoryCopy(_chunk, _queue->q[_queue->front].buffer, *_size); _queue->front = (_queue->front + 1) % _queue->qsize; _queue->pointer -= *_size; TcbdDebug(0, "pos:%d, size:%d\n", _queue->pointer, *_size); TcpalSemaphoreUnLock(&_queue->sem); return 0; }
int tdmb_tcc3170_mdelay(int32 ms) { int rc = 1; /* 0 : false, 1 : ture */ int32 wait_loop =0; int32 wait_ms = ms; mdelay_in_flg = 1; if(ms > 100) { wait_loop = (ms /100); /* 100, 200, 300 more only , Otherwise this must be modified e.g (ms + 40)/50 */ wait_ms = 100; } do { msleep(wait_ms); if(user_stop_flg == 1) { TcbdDebug(DEBUG_ERROR,"~~~~~~~~ Ustop flag is set so return false ms =(%d)~~~~~~~\n", ms); rc = 0; break; } } while((--wait_loop) > 0); mdelay_in_flg = 0; user_stop_flg = 0; if(rc == 0) { TcbdDebug(DEBUG_ERROR,"tdmb_tcc3170_delay return abnormal\n"); } return rc; }
int tdmb_tcc3170_power_on(void) { #if defined(__I2C_STS__) if((TdmbCtrlInfo.pctrl_fun == NULL) ||(TdmbCtrlInfo.pctrl_fun->dmb_power_on == NULL)) { TcbdDebug(DEBUG_ERROR,"tdmb_tcc3170_power_on function NULL\n"); return FALSE; } wake_lock(&TdmbCtrlInfo.wake_lock); TdmbCtrlInfo.pctrl_fun->dmb_power_on( ); #elif defined(__CSPI_ONLY__) if(TdmbCtrlInfo.pwr_state != 1) { wake_lock(&TdmbCtrlInfo.wake_lock); TchalPowerOnDevice(); //TcpalIrqEnable(); } else { TcbdDebug(DEBUG_ERROR, "aready on!! \n"); } #endif //__CSPI_ONLY__ TdmbCtrlInfo.pwr_state = 1; return TRUE; }
static I32S TcbdMovingAvg(TcbdMovingAvg_t *_slot, I32U _value, I32S _windowSize) { I32S movingSum; I32U result; if(MAX_MAVG_ARRAY_SIZE < _windowSize) { TcbdDebug(0, "max window size is %d\n", MAX_MAVG_ARRAY_SIZE); return -TCERR_INVALID_ARG; } if(_slot->movingCnt >= _windowSize) _slot->preSum += _slot->array[_slot->index]; else _slot->movingCnt++; _slot->array[_slot->index] = _value; _slot->index++; _slot->index %= _windowSize; _slot->totalCnt++; _slot->totalSum += _value; movingSum = _slot->totalSum - _slot->preSum; result = movingSum / _slot->movingCnt; if(_slot->index == 0) { _slot->totalSum = movingSum; _slot->preSum = 0; } return result; }
I32S TcbdGetFirstQueuePtr(TcbdQueue_t *_queue, I08U **_chunk, I32S *_size, I32S *_type) { TcpalSemaphoreLock(&_queue->sem); if(TcbdQueueIsEmpty(_queue)) { TcbdDebug(0, "Queue Empty!! \n"); TcpalSemaphoreUnLock(&_queue->sem); return -1; } *_size = _queue->q[_queue->front].size; *_chunk = _queue->q[_queue->front].buffer; if(_type) *_type = _queue->q[_queue->front].type; TcbdDebug(0, "pos:%d, size:%d\n", _queue->pointer, *_size); TcpalSemaphoreUnLock(&_queue->sem); return 0; }
int tdmb_tcc3170_power_off(void) { if(TdmbCtrlInfo.pwr_state == 0) { TcbdDebug(DEBUG_ERROR,"tdmb_tcc3170_power is immediately off\n"); return TRUE; } #if defined(__I2C__) if((TdmbCtrlInfo.pctrl_fun == NULL) ||(TdmbCtrlInfo.pctrl_fun->dmb_power_off == NULL)) { TcbdDebug(DEBUG_ERROR,"tdmb_tcc3170_power_off function NULL\n"); return FALSE; } TdmbCtrlInfo.pctrl_fun->dmb_power_off( ); #elif defined(__CSPI_ONLY__) else {
void TcbdInitQueue(TcbdQueue_t *_queue, I32S _qsize, I08U *_buffer, I32S _buffSize) { _queue->q = (TcbdQueueItem_t*)TcpalMemoryAllocation(sizeof(TcbdQueueItem_t) * _qsize); _queue->front = 0; _queue->rear = 0; _queue->qsize = _qsize; _queue->buffSize = _buffSize; _queue->globalBuffer = _buffer; TcpalCreateSemaphore(&_queue->sem, "TcbdQueue", 0); TcbdDebug(1, "buff :0x%X, size:%d\n", _buffer, _buffSize); }
inline static void TcbdParseStream(TcbdIrqData_t * irqData) { I32S size = TCBD_MAX_THRESHOLD*2, ret = 0; I08S irqStatus; I08S irqError; TcbdDevice_t *device = irqData->device; TcpalSemaphoreLock(&TcbdIrqData.lock); ret = TcbdReadIrqStatus(device, &irqStatus, &irqError); ret |= TcbdClearIrq(device, irqStatus); ret |= TcbdReadStream(device, StreamBuffer, &size); if(ret == 0 && !irqError) { TcbdParser(StreamBuffer, size); } else { TcbdDebug(DEBUG_ERROR, "================================================================================\n" "### buffer is full, skip the data (status=0x%02X, error=0x%02X, ret:%d, time%d) ###\n" "================================================================================\n", irqStatus, irqError, ret, (int)TcpalGetTimeIntervalMs(irqData->startTick)); TcbdInitStreamDataConfig(device, ENABLE_CMD_FIFO, device->lastSelectedBuffer, device->intrThreshold); TcbdInitParser(NULL); } ret = TcbdReadIrqStatus(device, &irqStatus, &irqError); if(irqError) { TcbdDebug(DEBUG_ERROR, "================================================================================\n" "### TcbdReadIrqStatus buffer is full, skip the data (status=0x%02X, error=0x%02X, ret:%d, time%d) ###\n" "================================================================================\n", irqStatus, irqError, (int)ret, (int)TcpalGetTimeIntervalMs(irqData->startTick)); TcbdInitStreamDataConfig(device, ENABLE_CMD_FIFO, device->lastSelectedBuffer, device->intrThreshold); TcbdInitParser(NULL); } TcpalSemaphoreUnLock(&TcbdIrqData.lock); }
void TchalPowerDownDevice(void) { TcbdDebug(DEBUG_TCHAL, "\n"); gpio_set_value(DMB_EN, 0); gpio_set_value(DMB_RESET_N, 0); gpio_direction_output(DMB_INT_N, false); gpio_set_value(DMB_INT_N, 0); TchalIrqSetup(); printk("######### TchalPowerDownDevice\n"); }
I32S TcbdEnqueue(TcbdQueue_t *_queue, I08U *_chunk, I32S _size, I32S _type) { if(_chunk == NULL || _size <= 0) { TcbdDebug(DEBUG_ERROR, "Invalid argument!! \n"); return -1; } TcpalSemaphoreLock(&_queue->sem); if(_queue->pointer + _size > _queue->buffSize) { TcbdDebug(0, "Memory full! \n"); TcbdResetQueue(_queue); TcpalSemaphoreUnLock(&_queue->sem); return -1; } if(TcbdQueueIsFull(_queue)) { TcbdDebug(0, "Queue Full!! \n"); _queue->pointer = 0; } TcpalMemoryCopy(_queue->globalBuffer + _queue->pointer, _chunk, _size); _queue->q[_queue->rear].buffer = _queue->globalBuffer + _queue->pointer; _queue->q[_queue->rear].size = _size; _queue->q[_queue->rear].type = _type; _queue->rear = (_queue->rear + 1) % _queue->qsize; _queue->pointer += _size; TcbdDebug(0, "pos:%d, size:%d\n", _queue->pointer, _size); TcpalSemaphoreUnLock(&_queue->sem); return 0; }
void TchalPowerOnDevice(void) { TcbdDebug(DEBUG_TCHAL, "TchalPowerOnDevice\n"); gpio_direction_output(DMB_EN, false); gpio_direction_output(DMB_INT_N, false); gpio_set_value(DMB_INT_N, 0); gpio_set_value(DMB_EN, 0); msleep(1); gpio_set_value(DMB_EN, 1); msleep(1); TchalResetDevice(); TchalIrqSetup(); printk("######### TchalPowerOnDevice\n"); }
void TchalInit(void) { TcbdDebug(DEBUG_TCHAL, "TchalInit\n"); //gpio_request(101, "DMB_RESET_N"); //gpio_request(102, "DMB_EN"); //gpio_request(107, "DMB_INT_N"); gpio_request(DMB_RESET_N, "dmb_reset"); gpio_request(DMB_EN, "dmb_en"); gpio_request(DMB_INT_N, "dmb_int"); //gpio_request(DMB_EAR_ANT_SEL, "dmb_ear_ant"); gpio_direction_output(DMB_RESET_N, false); gpio_direction_output(DMB_EN, false); //nthyunjin.yang for test gpio_direction_output(DMB_INT_N, false); gpio_direction_input(DMB_INT_N);//nthyunjin.yang for test printk("######### nthyunjin.yang TchalInit\n"); }
static irqreturn_t TcbdIrqHandler(int _irq, void *_param) { #if defined(__WORKQUEUE__) disable_irq_nosync(TcbdIrqData.tcbd_irq); if(TcbdIrqData.isIrqEnable) { TcbdDebug(DEBUG_ERROR,"########### broadcast_tdmb_spi_isr ###########" "######### spi read function is so late skip #########\n"); return IRQ_HANDLED; } TcbdIrqData.startTick = TcpalGetCurrentTimeMs(); queue_work(TcbdIrqData.workQueue, &TcbdIrqData.work); #else //__WORKQUEUE__ TcbdParseStream(&TcbdIrqData); #endif //!__WORKQUEUE__ return IRQ_HANDLED; }
I32S TcpalRegisterIrqHandler(TcbdDevice_t *_device) { #else I32S TcpalRegisterIrqHandler(void) { extern TcbdDevice_t *GetTcbdDevice(void); TcbdDevice_t *_device = GetTcbdDevice(); #endif struct spi_device *spi = TCC_GET_SPI_DRIVER(); TcbdIrqData.isIrqEnable = 0; #if defined(__WORKQUEUE__) TcbdIrqData.workQueue = create_singlethread_workqueue("TcbdStreamParsingWork"); TcbdIrqData.device = _device; TcbdIrqData.tcbd_irq = spi->irq; TcpalCreateSemaphore(&TcbdIrqData.lock, "IRQ", 1); INIT_WORK(&TcbdIrqData.work, TcbdStreamParsingWork); #endif //__WORKQUEUE__ TcbdInitParser(TcbdStreamCallback); TchalIrqSetup(); TcbdDebug(DEBUG_ERROR,"irq:%d\n", TcbdIrqData.tcbd_irq); return request_irq(TcbdIrqData.tcbd_irq, TcbdIrqHandler, IRQF_DISABLED | IRQF_TRIGGER_FALLING, "tc317x_stream", &TcbdIrqData); } I32S TcpalUnRegisterIrqHandler(void) { disable_irq(TcbdIrqData.tcbd_irq); flush_workqueue(TcbdIrqData.workQueue); destroy_workqueue(TcbdIrqData.workQueue); TcpalDeleteSemaphore(&TcbdIrqData.lock); return 0; }
static I32S TcbdParseBootBin(I08U* _data, I32U _size, TcbdBootBin_t *_bootBin) { I32U idx = 0; I32U length; I32S tableIdx = 0; //coldboot 0x00000001 //dagu 0x00000002 //dint 0x00000003 //rand 0x00000004 //col_order: 0x00000005 //sizebyte 4byte //data nbyte TcpalMemorySet(_bootBin, 0, sizeof(TcbdBootBin_t)*MAX_BOOT_TABLE); // cold boot if (_data[idx + 3] != 0x01) { TcbdDebug(DEBUG_ERROR, "# Coldboot_preset_Error\n"); return 0; } idx += 4; length = (_data[idx] << 24) + (_data[idx + 1] << 16) + (_data[idx + 2] << 8) + (_data[idx + 3]); idx += 4; _bootBin[tableIdx].addr = CODE_MEM_BASE; _bootBin[tableIdx].data = _data + idx; _bootBin[tableIdx].crc = *((I32U*)(_data+idx + length-4)); _bootBin[tableIdx++].size = length - 4; idx += length; _size -= (length + 8); // dagu if (_data[idx + 3] != 0x02) { TcbdDebug(DEBUG_ERROR, "# Coldboot_preset_Error\n"); return 0; } idx += 4; length = (_data[idx] << 24) + (_data[idx + 1] << 16) + (_data[idx + 2] << 8) + (_data[idx + 3]); idx += 4; _bootBin[tableIdx].addr = CODE_TABLEBASE_DAGU; _bootBin[tableIdx].data = _data + idx; _bootBin[tableIdx++].size = length; idx += length; _size -= (length + 8); // dint if (_data[idx + 3] != 0x03) { TcbdDebug(DEBUG_ERROR, "# Coldboot_preset_Error\n"); return 0; } idx += 4; length = (_data[idx] << 24) + (_data[idx + 1] << 16) + (_data[idx + 2] << 8) + (_data[idx + 3]); idx += 4; _bootBin[tableIdx].addr = CODE_TABLEBASE_DINT; _bootBin[tableIdx].data = _data + idx; _bootBin[tableIdx++].size = length; idx += length; _size -= (length + 8); // rand if (_data[idx + 3] != 0x04) { TcbdDebug(DEBUG_ERROR, "# Coldboot_preset_Error\n"); return 0; } idx += 4; length = (_data[idx] << 24) + (_data[idx + 1] << 16) + (_data[idx + 2] << 8) + (_data[idx + 3]); idx += 4; _bootBin[tableIdx].addr = CODE_TABLEBASE_RAND; _bootBin[tableIdx].data = _data + idx; _bootBin[tableIdx++].size = length; idx += length; _size -= (length + 8); if (_size >= 8) /* cmmb */ { // col_order if (_data[idx + 3] != 0x05) { TcbdDebug(DEBUG_ERROR, "# Coldboot_preset_Error\n"); return 0; } idx += 4; length = (_data[idx] << 24) + (_data[idx + 1] << 16) + (_data[idx + 2] << 8) + (_data[idx + 3]); idx += 4; _bootBin[tableIdx].addr = CODE_TABLEBASE_COL_ORDER; _bootBin[tableIdx].data = _data + idx; _bootBin[tableIdx++].size = length; idx += length; _size -= (length + 8); } //TcbdDebug(DEBUG_API_COMMON, " # remain size :%d \n", _size); return tableIdx; }
I32S TcpalIrqDisable(void) { disable_irq(TcbdIrqData.tcbd_irq); TcbdDebug(DEBUG_ERROR,"%d\n", TcbdIrqData.tcbd_irq); return 0; }