示例#1
0
int uart_close(uart_socket_t *u)
{
	if(!u){
		uart_printf("uart_close(): u is NULL!\r\n");
		return -1;
	}
	/* Close uart socket */
	if(lwip_close(u->fd) == -1){
		uart_printf("%s(): close uart failed!", __func__);
	}
	/* Delete uart_action task */
	u->fd = -1;
	RtlUpSema(&u->action_sema);
	RtlMsleepOS(20);

	/* Free uart related semaphore */
	RtlFreeSema(&u->action_sema);
	RtlFreeSema(&u->tx_sema);
	RtlFreeSema(&u->dma_tx_sema);
	
	/* Free serial */
	serial_free(&u->sobj);
	
	RtlMfree((u8 *)u, sizeof(uart_socket_t));

	return 0;
}
示例#2
0
void sys_adc_calibration(u8 write, u16 *offset, u16 *gain)
{
	flash_t		flash;
	u8*			pbuf;
	
	if(write){
		// backup
		pbuf = (unsigned char*)RtlMalloc(FLASH_SECTOR_SIZE);
		if(!pbuf) return;
		flash_stream_read(&flash, FLASH_SYSTEM_DATA_ADDR, FLASH_SECTOR_SIZE, pbuf);
		memcpy((char*)pbuf+FLASH_ADC_PARA_OFFSET, offset, 2);
		memcpy((char*)pbuf+FLASH_ADC_PARA_OFFSET+2, gain, 2);
		flash_erase_sector(&flash, FLASH_RESERVED_DATA_BASE);
		flash_stream_write(&flash, FLASH_RESERVED_DATA_BASE, FLASH_SECTOR_SIZE, pbuf);
		// Write
		flash_stream_read(&flash, FLASH_RESERVED_DATA_BASE, FLASH_SECTOR_SIZE, pbuf);
		flash_erase_sector(&flash, FLASH_SYSTEM_DATA_ADDR);
		flash_stream_write(&flash, FLASH_SYSTEM_DATA_ADDR, FLASH_SECTOR_SIZE, pbuf);
		RtlMfree(pbuf, FLASH_SECTOR_SIZE);
		printf("\n\rStore ADC calibration success.");
	}
	flash_stream_read(&flash, FLASH_ADC_PARA_BASE, 2, (u8*)offset);
	flash_stream_read(&flash, FLASH_ADC_PARA_BASE+2, 2, (u8*)gain);
	printf("\n\rADC offset = 0x%04X, gain = 0x%04X.\n\r", *offset, *gain);
}
示例#3
0
uart_socket_t* uart_open(uart_set_str *puartpara)
{
	PinName uart_tx = PA_7;//PA_4; //PA_7
	PinName uart_rx = PA_6;//PA_0; //PA_6
	uart_socket_t *u;

	u = (uart_socket_t *)RtlZmalloc(sizeof(uart_socket_t));
	if(!u){
		uart_printf("%s(): Alloc memory for uart_socket failed!\n", __func__);
		return NULL;
	}
	
	/*initial uart */
	serial_init(&u->sobj, uart_tx,uart_rx);
	serial_baud(&u->sobj,puartpara->BaudRate);
	serial_format(&u->sobj, puartpara->number, (SerialParity)puartpara->parity, puartpara->StopBits);

	/*uart irq handle*/
	serial_irq_handler(&u->sobj, uart_irq, (int)u);
	serial_irq_set(&u->sobj, RxIrq, 1);
	serial_irq_set(&u->sobj, TxIrq, 1);

#if UART_SOCKET_USE_DMA_TX
   	serial_send_comp_handler(&u->sobj, (void*)uart_send_stream_done, (uint32_t)u);
#endif

	/*alloc a socket*/
 	u->fd = lwip_allocsocketsd();
	if(u->fd == -1){
		uart_printf("Failed to alloc uart socket!\n");
		goto Exit2;
	}
	/*init uart related semaphore*/
	RtlInitSema(&u->action_sema, 0);
	RtlInitSema(&u->tx_sema, 1);
	RtlInitSema(&u->dma_tx_sema, 1);
	
	/*create uart_thread to handle send&recv data*/
	{
#define	UART_ACTION_STACKSIZE 512
#define	UART_ACTION_PRIORITY	1
		if(xTaskCreate(uart_action_handler, ((const char*)"uart_action"), UART_ACTION_STACKSIZE, u, UART_ACTION_PRIORITY, NULL) != pdPASS){
			uart_printf("%s xTaskCreate(uart_action) failed", __FUNCTION__);
			goto Exit1;
		}
	}
	return u;
Exit1:
	/* Free uart related semaphore */
	RtlFreeSema(&u->action_sema);
	RtlFreeSema(&u->tx_sema);	
	RtlFreeSema(&u->dma_tx_sema);		
Exit2:
	RtlMfree((u8*)u, sizeof(uart_socket_t));
	return NULL;
}
示例#4
0
void serial_free(serial_t *obj) 
{
    PHAL_RUART_ADAPTER pHalRuartAdapter;
    PHAL_RUART_OP      pHalRuartOp;

    pHalRuartAdapter = &(obj->hal_uart_adp);
    pHalRuartOp = &(obj->hal_uart_op);

    pHalRuartOp->HalRuartDeInit(pHalRuartAdapter);
    

    // TODO: recovery Pin Mux

#if 0
    RtlMfree((unsigned char *)(obj->uart_adp.pHalRuartOp), sizeof(HAL_RUART_OP));
    RtlMfree((unsigned char *)(obj->uart_adp.pHalRuartAdapter), sizeof(HAL_RUART_ADAPTER));    
    obj->uart_adp.pHalRuartOp = NULL;
    obj->uart_adp.pHalRuartAdapter = NULL;
#endif    
}
示例#5
0
/******************************************************************************
 * Function: RtlMailboxCreate
 * Desc: To create a mailbox with a given mailbox ID and size
 * Para:
 * 	MboxID: A number to identify this created mailbox. A message block can 
 *          be send to a mailbox by a given MboxID. The MboxID must be unique 
 *          in the whole system. If this MboxID is conflict with a created 
 *          mailbox, the mailbox creation will fail and return NULL.
 *  MboxSize: The size of this mailbox to be created. It means maximum number 
 *          of message blocks can be stored in this mailbox.
 *  pWakeSema: The semaphore to wake up the receiving task to receive the new 
 *          message. If the receiving task doesn't need a semaphore to wakeup 
 *          it, then just let this pointer is NULL.
 * Return: The created mailbox pointer. If it failed, return NULL.
 ******************************************************************************/
PRTL_MAILBOX RtlMailboxCreate(
    IN u8 MboxID, 
    IN u32 MboxSize, 
    IN _Sema *pWakeSema
)
{
	PRTL_MAILBOX pMBox=NULL;

    // if the Mailbox root entry initialed ? if not, initial it
    if (!MBox_Entry.isInitialed) {
        RtlMutexInit(&MBox_Entry.Mutex);   // Init the Mutex for the mailbox add/delete procedure protection
        RtlInitListhead(&MBox_Entry.mbox_list);    // Init the link list head to chain all created mailbox
        MBox_Entry.isInitialed = 1;
        MSG_MBOX_INFO("MBox Entry Initial...\n");
    }
    
	// check if this mailbox ID is ocupied ?
	pMBox = RtlMBoxIdToHdl(MboxID);
	if (NULL != pMBox) {
		MSG_MBOX_ERR("RtlMailboxCreate: The Mailbox ID %d is used by someone!!\n", MboxID);
		return NULL;
	}

	pMBox = (RTL_MAILBOX *)RtlZmalloc(sizeof(RTL_MAILBOX));
	if (NULL==pMBox) {
		MSG_MBOX_ERR("RtlMailboxCreate: MAlloc Failed\n");
		return NULL;
	}

	RtlInitListhead(&pMBox->mbox_list);	// Init the link list to be chained into the created mailbox list
	pMBox->mbox_id = MboxID;
	pMBox->pWakeSema = pWakeSema;
#ifdef PLATFORM_FREERTOS
    pMBox->mbox_hdl = xQueueCreate(MboxSize, sizeof(MSG_BLK));
    if (NULL == pMBox->mbox_hdl) {
		MSG_MBOX_ERR("RtlMailboxCreate: xQueueCreate Failed\n");
        RtlMfree((void *)pMBox, sizeof(RTL_MAILBOX));        
        return NULL;
    }
#endif
#ifdef PLATFORM_ECOS
// TODO: Create mailbox
#endif

	// Add this mailbox to the link list of created mailbox
	RtlDownMutex(&MBox_Entry.Mutex);
	RtlListInsertTail(&pMBox->mbox_list, &MBox_Entry.mbox_list);
	RtlUpMutex(&MBox_Entry.Mutex);

    MSG_MBOX_INFO("A Mailbox Created: Size=%d\n", MboxSize);

	return pMBox;
}
示例#6
0
//---------------------------------------------------------------------------------------------------
//Function Name:
//		RtkI2CFreeMngtAdpt
//
// Description:
//		Free all the previous allocated memory space.
//
// Arguments:
//		[in] PSAL_I2C_MNGT_ADPT  pSalI2CMngtAdpt -
//			I2C SAL management adapter pointer
//         
//
// Return:
//		The status of the enable process.
//          _EXIT_SUCCESS if the RtkI2CFreeMngtAdpt succeeded.
//          _EXIT_FAILURE if the RtkI2CFreeMngtAdpt failed.
//
// Note:
//		NA
//
// See Also:
//		NA
//
// Author:
// 		By Jason Deng, 2014-04-02.
//
//---------------------------------------------------------------------------------------------------
RTK_STATUS
RtkDACFreeMngtAdpt(
    IN  PSAL_DAC_MNGT_ADPT  pSalDACMngtAdpt
){
#ifdef CONFIG_KERNEL
    RtlMfree((u8 *)pSalDACMngtAdpt->pUserCB->pTXCB, (sizeof(SAL_DAC_USERCB_ADPT)*SAL_DAC_USER_CB_NUM));
    RtlMfree((u8 *)pSalDACMngtAdpt->pIrqGdmaHnd, sizeof(IRQ_HANDLE));
    RtlMfree((u8 *)pSalDACMngtAdpt->pHalGdmaOp, sizeof(HAL_GDMA_OP));
    RtlMfree((u8 *)pSalDACMngtAdpt->pHalGdmaAdp, sizeof(HAL_GDMA_ADAPTER));
    RtlMfree((u8 *)pSalDACMngtAdpt->pUserCB, sizeof(SAL_DAC_USER_CB));
    RtlMfree((u8 *)pSalDACMngtAdpt->pIrqHnd, sizeof(IRQ_HANDLE));
    RtlMfree((u8 *)pSalDACMngtAdpt->pHalOp, sizeof(HAL_DAC_OP));
    RtlMfree((u8 *)pSalDACMngtAdpt->pHalInitDat, sizeof(HAL_DAC_INIT_DAT));
    RtlMfree((u8 *)pSalDACMngtAdpt->pSalHndPriv, sizeof(SAL_DAC_HND_PRIV));    
    RtlMfree((u8 *)pSalDACMngtAdpt, sizeof(SAL_DAC_MNGT_ADPT));
#else
    ;
#endif

    return _EXIT_SUCCESS;
}
示例#7
0
void sys_recover_ota_signature(void)
{
	flash_t		flash;
	u32			ota_offset=0xFFFFFFFF, part1_offset, part2_offset;
	u8			signature[OTA_Signature_len+1];
	u8*			pbuf;
	
	flash_stream_read(&flash, 0x18, 4, (u8*)&part1_offset);
	part1_offset = (part1_offset&0xFFFF) * 1024;
	flash_stream_read(&flash, part1_offset+OTA_Signature_offset, OTA_Signature_len, signature);
	if(!memcmp((char const*)signature, OTA_Clear, OTA_Signature_len)){
		ota_offset = part1_offset;
	}
	
	flash_stream_read(&flash, FLASH_SYSTEM_DATA_ADDR, 4, (u8*)&part2_offset);
	flash_stream_read(&flash, part2_offset+OTA_Signature_offset, OTA_Signature_len, signature);
	if(!memcmp((char const*)signature, OTA_Clear, OTA_Signature_len)){
		ota_offset = part2_offset;
	}
	
	printf("\n\rOTA offset = 0x%08X", ota_offset);
	
	if(ota_offset < OTA_valid_offset){
		flash_stream_read(&flash, ota_offset+OTA_Signature_offset, OTA_Signature_len, signature);
		signature[OTA_Signature_len] = '\0';
		printf("\n\rSignature = %s", signature);
		if(!memcmp((char const*)signature, OTA_Clear, OTA_Signature_len)){
			// backup
			pbuf = (unsigned char*)RtlMalloc(FLASH_SECTOR_SIZE);
			if(!pbuf) return;
			flash_stream_read(&flash, ota_offset, FLASH_SECTOR_SIZE, pbuf);
			memcpy((char*)pbuf+OTA_Signature_offset, OTA_Signature, OTA_Signature_len);
			flash_erase_sector(&flash, FLASH_RESERVED_DATA_BASE);
			flash_stream_write(&flash, FLASH_RESERVED_DATA_BASE, FLASH_SECTOR_SIZE, pbuf);
			// Write
			flash_stream_read(&flash, FLASH_RESERVED_DATA_BASE, FLASH_SECTOR_SIZE, pbuf);
			flash_erase_sector(&flash, ota_offset);
			flash_stream_write(&flash, ota_offset, FLASH_SECTOR_SIZE, pbuf);
			flash_stream_read(&flash, ota_offset+OTA_Signature_offset, OTA_Signature_len, signature);
			signature[OTA_Signature_len] = '\0';
			printf("\n\rSignature = %s", signature);
			RtlMfree(pbuf, FLASH_SECTOR_SIZE);
			printf("\n\rRecover OTA signature success.");
		}
	}
}
示例#8
0
/******************************************************************************
 * Function: RtlMailboxDel
 * Desc: To delete a mailbox by a given mailbox handle.
 * Para:
 *	MboxHdl: The handle of the mailbox to be deleted.
 * Return: None.
 ******************************************************************************/
VOID RtlMailboxDel(
    IN PRTL_MAILBOX MboxHdl
)
{
	if (NULL == MboxHdl) {
		MSG_MBOX_ERR("RtlMailboxDel: Try to delete a NULL mailbox\n");
		return;
	}

	// Remove this mailbox from the link list of created mailbox
	RtlDownMutex(&MBox_Entry.Mutex);
	RtlListDelete(&MboxHdl->mbox_list);
	RtlUpMutex(&MBox_Entry.Mutex);

    // delete the Queue/Mailbox
#ifdef PLATFORM_FREERTOS
    vQueueDelete((xQueueHandle)(MboxHdl->mbox_hdl));
#endif
#ifdef PLATFORM_ECOS
    // TODO: Delete mailbox
#endif

	RtlMfree((void *)MboxHdl, sizeof(RTL_MAILBOX));
}