Esempio n. 1
0
/*
 * if uart get data, return 1-readable, 0-unreadable
 */
uint16 suli_uart_readable(void * uart_device, int16 uart_num)
{
    uint32 dataCnt = 0;
    OS_eEnterCriticalSection(mutexRxRb);
    dataCnt = ringbuffer_data_size(&rb_uart_aups);           //handle AUPS's UART ringbuffer
    OS_eExitCriticalSection(mutexRxRb);
    return dataCnt;
}
Esempio n. 2
0
/****************************************************************************
 *
 * NAME: vReleaseLock
 *
 * DESCRIPTION:
 * Implements counting semaphore protection (release routine)
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void vReleaseLock(void)
{
    u32MutexCount--;
    if (u32MutexCount == 0)
    {
        OS_eExitCriticalSection(mutexMEDIA);
    }
}
Esempio n. 3
0
/****************************************************************************
 *
 * NAME: aupsReadable
 *
 * DESCRIPTION:
 * Delay n ms
 *
 * PARAMETERS: Name         RW  Usage
 *             u32Period    R   ms
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PUBLIC uint32 aupsAirPortReadable(void)
{
    uint32 dataCnt = 0;
    OS_eEnterCriticalSection(mutexAirPort);
    dataCnt = ringbuffer_data_size(&rb_air_aups);
    OS_eExitCriticalSection(mutexAirPort);
    return dataCnt;
}
Esempio n. 4
0
/****************************************************************************
 *
 * NAME: SPM_u32PullData
 *
 * DESCRIPTION:
 * SPM pull some data into data pool
 *
 *
 * RETURNS:
 * available data size of SPM
 *
 ****************************************************************************/
uint32 SPM_u32PullData(void *data, int len)
{
	uint32 free_cnt = 0;
	uint32 min_cnt = 0;
	uint32 avlb_cnt = 0;

	/* Cal how much free space do SPM have */
	OS_eEnterCriticalSection(mutexRxRb);
	free_cnt = ringbuffer_free_space(&rb_rx_spm);
	OS_eExitCriticalSection(mutexRxRb);

    min_cnt = MIN(free_cnt, len);
    DBG_vPrintf(TRACE_NODE, "rev_cnt: %u, free_cnt: %u \r\n", len, free_cnt);
    if(min_cnt > 0)
    {
    	OS_eEnterCriticalSection(mutexRxRb);
    	ringbuffer_push(&rb_rx_spm, data, min_cnt);
    	avlb_cnt = ringbuffer_data_size(&rb_rx_spm);
    	OS_eExitCriticalSection(mutexRxRb);
    }
    return avlb_cnt;
}
Esempio n. 5
0
/****************************************************************************
 *
 * NAME: aupsAirPortRead
 *
 * DESCRIPTION:
 * Read len bytes of data to dst
 *
 * PARAMETERS: Name         RW  Usage
 *             dst          W   Pointer to destination of the buffer
 *             len          R   number of the bytes you want to read
 * RETURNS:
 * uint8: real number of bytes you read
 *
 ****************************************************************************/
PUBLIC uint8 aupsAirPortRead(void *dst, int len)
{
    uint32 dataCnt = 0, readCnt = 0;

    OS_eEnterCriticalSection(mutexAirPort);
    dataCnt = ringbuffer_data_size(&rb_air_aups);
    if (dataCnt >= len) readCnt = len;
    else readCnt = dataCnt;

    ringbuffer_pop(&rb_air_aups, dst, dataCnt);
    OS_eExitCriticalSection(mutexAirPort);

    return readCnt;
}
Esempio n. 6
0
/****************************************************************************
 *
 * NAME: SPM_vProcStream
 *
 * DESCRIPTION:
 * Stream Processing Machine(SPM) process stream
 * If receive a valid frame, unpack and execute callback
 * else discard it.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void SPM_vProcStream(uint32 dataCnt)
{
	uint8 tmp[RXFIFOLEN] = {0};
	/* calc the minimal */
	uint32 readCnt = MIN(dataCnt, RXFIFOLEN);

	OS_eEnterCriticalSection(mutexRxRb);
	ringbuffer_read(&rb_rx_spm, tmp, readCnt);
	OS_eExitCriticalSection(mutexRxRb);

	/* Instance an apiSpec */
	tsApiSpec apiSpec;
	bool bValid = FALSE;
	memset(&apiSpec, 0, sizeof(tsApiSpec));

	/* Deassemble apiSpec frame */
	uint16 procSize =  u16DecodeApiSpec(tmp, readCnt, &apiSpec, &bValid);
	if(!bValid)
	{
	/*
	  Invalid frame,discard from ringbuffer
	  Any data received prior to the start delimiter will be discarded.
	  If the frame is not received correctly or if the checksum fails,
	  discard too.And Re-Activate Task 1ms later.
	*/
		vResetATimer(APP_tmrHandleUartRx, APP_TIME_MS(1));
	}
	else
	{
		/* Process API frame using API support layer's api */
		API_i32ApiFrmCmdProc(&apiSpec);
	}
	/* Discard already processed part */
	OS_eEnterCriticalSection(mutexRxRb);
	ringbuffer_pop(&rb_rx_spm, tmp, procSize);
	OS_eExitCriticalSection(mutexRxRb);
}
Esempio n. 7
0
/*
 * read a byte from uart
 */
uint8 suli_uart_read_byte(void * uart_device, int16 uart_num)
{
    uint32 dataCnt = 0;
    char tmp;

    OS_eEnterCriticalSection(mutexRxRb);
    dataCnt = ringbuffer_data_size(&rb_uart_aups);
    if(dataCnt > 0)
    {
        ringbuffer_pop(&rb_uart_aups, &tmp, 1);
    }
    OS_eExitCriticalSection(mutexRxRb);

    if(dataCnt > 0) return tmp;
    else return 0;
}