Ejemplo n.º 1
0
static BT_HANDLE fullfat_mount(BT_HANDLE hFS, BT_HANDLE hVolume, BT_ERROR *pError) {

	FF_ERROR ffError;
	BT_ERROR Error = BT_ERR_GENERIC;
	BT_FF_MOUNT *pMount = (BT_FF_MOUNT *) BT_CreateHandle(&oHandleInterface, sizeof(BT_FF_MOUNT), pError);
	if(!pMount) {
		return NULL;
	}

	pMount->pBlockCache = BT_kMalloc(8192);
	pMount->hVolume = hVolume;
	pMount->pIoman = FF_CreateIOMAN(pMount->pBlockCache, 8192, 512, &ffError);
	if(!pMount->pIoman) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	ffError = FF_RegisterBlkDevice(pMount->pIoman, 512, fullfat_writeblocks, fullfat_readblocks, pMount);

	ffError = FF_MountPartition(pMount->pIoman, 0);

return (BT_HANDLE) pMount;

err_free_out:
	BT_kFree(pMount->pBlockCache);
	BT_DestroyHandle((BT_HANDLE)pMount);

	*pError = Error;
	return NULL;
}
Ejemplo n.º 2
0
static BT_HANDLE ext2_opendir(BT_HANDLE hMount, const BT_i8 *szpPath, BT_ERROR *pError) {
	if(!hMount) {
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_out;
	}
	BT_EXT2_DIR *pDir = (BT_EXT2_DIR *) BT_CreateHandle(&oDirHandleInterface, sizeof(BT_EXT2_DIR), pError);
	if(!pDir) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_out;
	}
	pDir->pMount = (BT_EXT2_MOUNT *)hMount;
	pDir->szpFname = BT_kMalloc(BT_EXT2_FNAME_MAX_STRLEN);
	if(!pDir->szpFname) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}
	if(ext2fs_open_dir((char *)szpPath) < 0)
	{
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_free_out;
	}
#if 0
	if(ext2fs_ls((char *)szpPath) < 0)
	{
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_free_out;
	}
#endif
	return (BT_HANDLE) pDir;
err_free_out:
	if(pDir->szpFname) BT_kFree(pDir->szpFname);
	BT_DestroyHandle((BT_HANDLE)pDir);
err_out:
	return NULL;
}
Ejemplo n.º 3
0
BT_HANDLE BT_FifoCreate(BT_u32 ulElements, BT_u32 ulElementWidth, BT_ERROR *pError) {

	BT_HANDLE hFifo;
	BT_ERROR Error = BT_ERR_NONE;

	hFifo = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hFifo) {
		Error = BT_ERR_NO_MEMORY;
		goto err_out;
	}

	hFifo->hQueue = BT_CreateQueue(ulElements, ulElementWidth, &Error);
	if (!hFifo->hQueue) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hFifo->ulElementWidth = ulElementWidth;
	hFifo->ulElements     = ulElements;

	return hFifo;

err_free_out:
	BT_DestroyHandle(hFifo);

err_out:
	if (pError) {
		*pError = Error;
	}

	return NULL;
}
Ejemplo n.º 4
0
static BT_HANDLE fullfat_opendir(BT_HANDLE hMount, const BT_i8 *szpPath, BT_ERROR *pError) {

	BT_FF_DIR *pDir = (BT_FF_DIR *) BT_CreateHandle(&oDirHandleInterface, sizeof(BT_FF_DIR), pError);
	if(!pDir) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_out;
	}

	BT_FF_MOUNT *pMount = (BT_FF_MOUNT *) hMount;
	FF_ERROR ffError = FF_FindFirst(pMount->pIoman, &pDir->oDirent, szpPath);
	if(ffError) {
		*pError = BT_ERR_GENERIC;
		goto err_free_out;
	}

	pDir->pMount = pMount;

	return (BT_HANDLE) pDir;

err_free_out:
	BT_DestroyHandle((BT_HANDLE)pDir);

err_out:
	return NULL;
}
Ejemplo n.º 5
0
static BT_HANDLE devcfg_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error;

	if(g_bInUse) {
		Error = BT_ERR_GENERIC;
		goto err_set_out;
	}

	g_bInUse = BT_TRUE;

	BT_HANDLE hDevcfg = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hDevcfg) {
		goto err_set_out;
	}

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hDevcfg->pRegs = (volatile ZYNQ_DEVCFG_REGS *) bt_ioremap((void *) pResource->ulStart, sizeof(ZYNQ_DEVCFG_REGS));

	hDevcfg->pRegs->UNLOCK = 0x757BDF0D;				// Unlock the DEVCFG interface.

	hDevcfg->pRegs->INT_STS = 0xFFFFFFFF;				// Clear all interrupt status signals.

	hDevcfg->pRegs->CTRL |= CTRL_PCFG_PROG_B;
	hDevcfg->pRegs->CTRL |= CTRL_PCAP_MODE;				// Enable PCAP transfer mode.
	hDevcfg->pRegs->CTRL |= CTRL_PCAP_PR;				// Select PCAP for reconfiguration, (disables ICAP).
	hDevcfg->pRegs->CTRL &= ~CTRL_QUARTER_PCAP_RATE;	// Set full bandwidth PCAP loading rate.

	hDevcfg->pRegs->MCTRL &= ~MCTRL_PCAP_LPBK; 			// Ensure internal PCAP looback is disabled.

	hDevcfg->pSLCR = (volatile ZYNQ_SLCR_REGS *) bt_ioremap((void *) ZYNQ_SLCR_BASE, sizeof(ZYNQ_SLCR_REGS));

	zynq_slcr_unlock(hDevcfg->pSLCR);
	zynq_slcr_preload_fpga(hDevcfg->pSLCR);
	zynq_slcr_lock(hDevcfg->pSLCR);

	devcfg_reset_pl(hDevcfg);

	if(pError) {
		*pError = BT_ERR_NONE;
	}

	return hDevcfg;

err_free_out:
	BT_DestroyHandle(hDevcfg);

err_set_out:
	if(pError) {
		*pError = Error;
	}

	return NULL;
}
Ejemplo n.º 6
0
static BT_ERROR ext2_init() {
	BT_ERROR Error;
	BT_HANDLE hFsExt2 = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), &Error);
	if(!hFsExt2) {
		return Error;
	}

	return BT_RegisterFilesystem(hFsExt2);
}
Ejemplo n.º 7
0
static BT_ERROR fullfat_init() {
	BT_ERROR Error;
	BT_HANDLE hFullFAT = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), &Error);
	if(!hFullFAT) {
		return Error;
	}

	return BT_RegisterFilesystem(hFullFAT);
}
Ejemplo n.º 8
0
BT_HANDLE BT_CreateMutex(BT_ERROR *pError) {
	BT_HANDLE hMutex = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hMutex) {
		return NULL;
	}

	hMutex->pMutex = BT_kMutexCreate();

	return hMutex;
}
Ejemplo n.º 9
0
static BT_HANDLE gpio_probe(const BT_I2C_BUS *pBus, const BT_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;

	BT_HANDLE hGPIO = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hGPIO) {
		Error = BT_ERR_NO_MEMORY;
		goto err_out;
	}

	hGPIO->oClient.pBus = pBus;

	const BT_RESOURCE *pResource = BT_GetDeviceResource(pDevice, BT_RESOURCE_BUSID, 0);
	if(!pResource) {
		Error = BT_ERR_INVALID_RESOURCE;
		goto err_free_out;
	}

	hGPIO->oClient.addr = pResource->ulStart;

	pResource = BT_GetDeviceResource(pDevice, BT_RESOURCE_IO, 0);
	if(!pResource) {
		Error = BT_ERR_INVALID_RESOURCE;
		goto err_free_out;
	}

	BT_u32 base 	= pResource->ulStart;
	BT_u32 total 	= (pResource->ulEnd - pResource->ulStart) + 1;

	Error = BT_RegisterGpioController(base, total, hGPIO);
	if(Error) {
		goto err_free_out;
	}

	BT_kPrint("MAX7312 : Initialising GPIO Port Expander.");

	BT_u8 in1, in2;
	in1 = gpio_read_register(hGPIO, 0x00, &Error);
	in2 = gpio_read_register(hGPIO, 0x01, &Error);

	BT_kPrint("MAX7312 : in1 : %02X", in1);
	BT_kPrint("MAX7312 : in2 : %02X", in2);

	return hGPIO;

err_free_out:
	BT_DestroyHandle(hGPIO);

err_out:
	if(pError) {
		*pError = Error;
	}

	return NULL;
}
Ejemplo n.º 10
0
BT_HANDLE gpio_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error;
	if(pError) {
		*pError = BT_ERR_NONE;
	}

	BT_HANDLE hGPIO = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hGPIO) {
		goto err_out;
	}

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IO, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	BT_u32 base 	= pResource->ulStart;
	BT_u32 total 	= (pResource->ulEnd - pResource->ulStart) + 1;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hGPIO->pRegs = (LPC11Axx_GPIO_REGS *) pResource->ulStart;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	//Error = BT_EnableInterrupt(pResource->ulStart);

	Error = BT_RegisterGpioController(base, total, hGPIO);
	if(Error) {
		goto err_free_out;
	}

	return hGPIO;

err_free_out:
	BT_DestroyHandle(hGPIO);

	if(pError) {
		*pError = Error;
	}

err_out:
	return NULL;
}
Ejemplo n.º 11
0
static BT_HANDLE timer_register_callback(BT_HANDLE hTimer, BT_TIMER_CALLBACK pfnCallback, void *pParam, BT_ERROR *pError) {
	struct _TIMER_CALLBACK_HANDLE *pCallback = (struct _TIMER_CALLBACK_HANDLE*)BT_CreateHandle(&oCallbackHandleInterface, sizeof(struct _TIMER_CALLBACK_HANDLE),pError);

	if (pCallback) {
		pCallback->pfnCallback = pfnCallback;
		pCallback->pParam	   = pParam;

		hTimer->pCallback      = pCallback;
	}

	return (BT_HANDLE)pCallback;
}
Ejemplo n.º 12
0
static BT_HANDLE mcpwm_register_callback(BT_HANDLE hMCPWM, BT_MCPWM_CALLBACK pfnCallback, void *pParam, BT_ERROR *pError) {
	struct _MCPWM_CALLBACK_HANDLE *pCallback = (struct _MCPWM_CALLBACK_HANDLE*)BT_CreateHandle(&oCallbackHandleInterface, sizeof(struct _MCPWM_CALLBACK_HANDLE),pError);

	if (pCallback) {
		pCallback->pfnCallback = pfnCallback;
		pCallback->pParam	   = pParam;

		hMCPWM->pCallback      = pCallback;
	}

	return (BT_HANDLE)pCallback;
}
Ejemplo n.º 13
0
static BT_HANDLE nvic_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error;

	if(g_hActiveHandle) {
		if(pError) {
			*pError = BT_ERR_GENERIC;
		}
		return NULL;
	}

	BT_HANDLE hNVIC = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hNVIC) {
		goto err_out;
	}

	const BT_RESOURCE *pResource;
	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto  err_free_chip;
	}

	hNVIC->pRegs = (NVIC_REGS *) pResource->ulStart;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_chip;
	}

	BT_u32 base, total;
 	base = pResource->ulStart;
	total = (pResource->ulEnd - pResource->ulStart) + 1;

	Error = BT_RegisterInterruptController(base, total, hNVIC);
	if(Error) {
		goto err_free_chip;
	}

	return hNVIC;

err_free_chip:
	BT_DestroyHandle(hNVIC);

	if(pError) {
		*pError = Error;
	}

err_out:
	return hNVIC;
}
Ejemplo n.º 14
0
static BT_HANDLE timer_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;

	BT_HANDLE hTimer = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hTimer) {
		Error = BT_ERR_NO_MEMORY;
		goto err_out;
	}

	const BT_RESOURCE *pResource;
	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hTimer->pRegs = (SYSTICK_REGS *) pResource->ulStart;

	hTimer->pRegs->CTRL &= ~0x04;
	hTimer->pRegs->CTRL |= BT_CONFIG_ARCH_ARM_SYSTICK_CLKSRC;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	/*
	 *	In normal timer drivers we might register the interrupt here.
	 *	By default we want the linker to patch our vector table for us
	 *	and therefore its up to the Kernel to override the
	 *	correct symbol name... i.e. BT_NVIC_SysTick_Handler
	 *
	 */

	return hTimer;

err_free_out:
	BT_DestroyHandle(hTimer);

err_out:
	if(pError) {
		*pError = Error;
	}

	return NULL;
}
Ejemplo n.º 15
0
int socket(int domain, int type, int protocol) {

	if(!BT_isNetworkingReady()) {
		return -1;
	}

	BT_ERROR Error;
	BT_HANDLE hSocket = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), &Error);
	if(!hSocket) {
		return 0;
	}

	hSocket->socket = lwip_socket(domain, type, protocol);

	return (int)hSocket;
}
Ejemplo n.º 16
0
static struct _MII_HANDLE* mii_init(BT_HANDLE hMac, BT_ERROR *pError) {
	struct _MII_HANDLE *pMII = (struct _MII_HANDLE *) BT_CreateHandle(&oMIIHandleInterface, sizeof(struct _MII_HANDLE), pError);
	if(!pMII) {
		if(pError) {
			*pError = BT_ERR_NO_MEMORY;
		}
		return NULL;
	}

	hMac->hMII = (BT_HANDLE) pMII;

	pMII->mii.hMAC = hMac;
	pMII->mii.name = "LM3Sxx mac-mii bus";

	return pMII;
}
Ejemplo n.º 17
0
int accept(int s, struct sockaddr *addr, socklen_t *addrlen) {
	BT_HANDLE hSocket = (BT_HANDLE)s;

	int new_socket = lwip_accept(hSocket->socket, addr, addrlen);
	if(new_socket) {
		BT_ERROR Error;
		BT_HANDLE h = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), &Error);
		if(!h) {
			lwip_close(new_socket);
			return 0;
		}
		h->socket = new_socket;
		return (int)h;
	}

	return 0;
}
Ejemplo n.º 18
0
static BT_HANDLE ext2_open_inode(BT_HANDLE hMount, const BT_i8 *szpPath, BT_ERROR *pError) {
	if(!hMount) {
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_out;
	}
	BT_EXT2_INODE *pInode = (BT_EXT2_INODE *) BT_CreateHandle(&oInodeHandleInterface, sizeof(BT_EXT2_INODE), pError);
	if(!pInode) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_out;
	}
	pInode->pMount = (BT_EXT2_MOUNT *)hMount;
	pInode->szpPath = szpPath;

	return (BT_HANDLE) pInode;
err_out:
	return NULL;
}
Ejemplo n.º 19
0
static BT_HANDLE fullfat_open(BT_HANDLE hMount, const BT_i8 *szpPath, BT_u32 ulModeFlags, BT_ERROR *pError) {

	FF_ERROR ffError;

	BT_FF_FILE *pFile = (BT_FF_FILE *) BT_CreateHandle(&oFileHandleInterface, sizeof(BT_FF_FILE), pError);
	if(!pFile) {
		return NULL;
	}

	BT_FF_MOUNT *pMount = (BT_FF_MOUNT *) hMount;

	pFile->pFile = FF_Open(pMount->pIoman, szpPath, FF_MODE_READ, &ffError);
	if(!pFile->pFile) {
		return NULL;
	}

	pFile->pMount = pMount;

	return (BT_HANDLE) pFile;
}
Ejemplo n.º 20
0
static BT_HANDLE ext2_mount(BT_HANDLE hFS, BT_HANDLE hVolume, const void *data, BT_ERROR *pError) {
	if(!hFS || !hVolume) {
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_out;
	}
	BT_EXT2_MOUNT *pMount = (BT_EXT2_MOUNT *) BT_CreateHandle(&oHandleInterface, sizeof(BT_EXT2_MOUNT), pError);
	if(!pMount) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_out;
	}
	pMount->hVolume = hVolume;
	ext2fs_set_readblocks(ext2_readblocks, hVolume);
	if(ext2fs_mount(0) < 0) {
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_free_out;
	}
	return (BT_HANDLE) pMount;
err_free_out:
	BT_DestroyHandle((BT_HANDLE)pMount);
err_out:
	return NULL;
}
Ejemplo n.º 21
0
static BT_HANDLE ext2_open(BT_HANDLE hMount, const BT_i8 *szpPath, BT_u32 ulModeFlags, BT_ERROR *pError) {
	if(!hMount) {
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_out;
	}
	BT_EXT2_FILE *pFile = (BT_EXT2_FILE *) BT_CreateHandle(&oFileHandleInterface, sizeof(BT_EXT2_FILE), pError);
	if(!pFile) {
		*pError = BT_ERR_NO_MEMORY;
		goto err_out;
	}
	pFile->pMount = (BT_EXT2_MOUNT *)hMount;
	if(ext2fs_open((char *)szpPath) < 0)
	{
		if(pError) *pError = BT_ERR_GENERIC;
		goto err_free_out;
	}
	return (BT_HANDLE) pFile;
err_free_out:
	BT_DestroyHandle((BT_HANDLE)pFile);
err_out:
	return NULL;
}
Ejemplo n.º 22
0
static BT_HANDLE fullfat_open_inode(BT_HANDLE hMount, const BT_i8 *szpPath, BT_ERROR *pError) {

	BT_FF_INODE *pInode = (BT_FF_INODE *) BT_CreateHandle(&oInodeHandleInterface, sizeof(BT_FF_INODE), pError);
	if(!pInode) {
		goto err_out;
	}

	BT_FF_MOUNT *pMount = (BT_FF_MOUNT *) hMount;
	FF_ERROR ffError = FF_FindFirst(pMount->pIoman, &pInode->oDirent, szpPath);
	if(ffError) {
		goto err_free_out;
	}

	pInode->pMount = pMount;

	return (BT_HANDLE) pInode;

err_free_out:
	BT_DestroyHandle((BT_HANDLE)pInode);

err_out:
	return NULL;
}
Ejemplo n.º 23
0
static BT_HANDLE timer_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hTimer = NULL;

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_ENUM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	if (g_TIMER_HANDLES[pResource->ulStart]){
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hTimer = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hTimer) {
		goto err_out;
	}

	g_TIMER_HANDLES[pResource->ulStart] = hTimer;

	hTimer->pDevice = pDevice;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hTimer->pRegs = (LM3Sxx_TIMER_REGS *) pResource->ulStart;

	TimerSetPowerState(hTimer, BT_POWER_STATE_AWAKE);

	ResetTimer(hTimer);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

/*	On NVIC we don't need to register interrupts, LINKER has patched vector for us
 * Error = BT_RegisterInterrupt(pResource->ulStart, timer_irq_handler, hTimer);
	if(Error) {
		goto err_free_out;
	}*/


	Error = BT_EnableInterrupt(pResource->ulStart);

	return hTimer;

err_free_out:
	BT_kFree(hTimer);

err_out:
	if(pError) {
		*pError = Error;
	}
	return NULL;
}
Ejemplo n.º 24
0
static BT_HANDLE gic_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error;

	if(g_hActiveHandle) {
		if(pError) {
			*pError = BT_ERR_GENERIC;
		}
		return NULL;
	}

	BT_HANDLE hGic = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hGic) {
		goto err_out;
	}

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto  err_free_chip;
	}

	hGic->pGICC = (GICC_REGS *) bt_ioremap((void *)pResource->ulStart, BT_SIZE_4K);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 1);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_chip;
	}

	hGic->pGICD = (GICD_REGS *) bt_ioremap((void *)pResource->ulStart, BT_SIZE_4K);

	// Set private members.

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_chip;
	}

	BT_u32 base 	= pResource->ulStart;
	BT_u32 total 	= (pResource->ulEnd - pResource->ulStart) + 1;

	hGic->ulBaseIRQ = base;

	BT_u32 i;
	for(i = 0; i < total; i++) {
		g_oVectorTable[i].pfnHandler 	= gic_stubhandler;
		g_oVectorTable[i].pParam 	 	= NULL;
	}

	Error = BT_RegisterInterruptController(base, total, hGic);
	if(Error) {
		goto err_free_chip;
	}

	g_hActiveHandle = hGic;

	// Enable the Distributor and CPU interfaces.

	BT_u32 ulGicIRQs = (hGic->pGICD->TYPER & 0x1F);
	ulGicIRQs = (ulGicIRQs + 1) * 32;

	/*
	 *	GIC can support a mximum 1020 IRQs.
	 */
	if(ulGicIRQs > 1020) {
		ulGicIRQs = 1020;
	}

	hGic->ulGicIRQs = ulGicIRQs;

//#ifdef BT_CONFIG_ARCH_ARM_GIC_INIT_DISTRIBUTOR
	gic_dist_init(hGic);
//#endif
	gic_cpu_init(hGic);

	return hGic;

err_free_chip:
	BT_DestroyHandle(hGic);

	if(pError) {
		*pError = Error;
	}

err_out:
	return NULL;
}
Ejemplo n.º 25
0
static BT_HANDLE i2c_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hI2C = NULL;

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hI2C = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hI2C) {
		goto err_out;
	}

	hI2C->pRegs = (LPC11xx_I2C_REGS *) pResource->ulStart;


	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_ENUM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hI2C->i2c_master.pDevice = pDevice;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_INTEGER, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	i2cSetPowerState(hI2C, BT_POWER_STATE_AWAKE);

	// Reset all registers to their defaults!
	ResetI2C(hI2C);

	i2cEnable(hI2C);

	i2c_set_clock_rate(hI2C, pResource->ulStart);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

/*	On NVIC we don't need to register interrupts, LINKER has patched vector for us
 * Error = BT_RegisterInterrupt(pResource->ulStart, I2C_irq_handler, hI2C);
	if(Error) {
		goto err_free_out;
	}*/


	//@@Error = BT_EnableInterrupt(pResource->ulStart);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_BUSID, 0);
	if(!pResource) {
		goto err_free_out;
	}

	BT_u32 ulBusID = pResource->ulStart;

	hI2C->i2c_master.ulBusID	= ulBusID;
	hI2C->i2c_master.hBus 		= hI2C;		// Save pointer to bus's private data.
	hI2C->i2c_master.pDevice 	= pDevice;


	BT_I2C_RegisterBus(&hI2C->i2c_master);

	if(pError) {
		*pError = Error;
	}

	return hI2C;

err_free_out:
	BT_DestroyHandle(hI2C);

err_out:
	if(pError) {
		*pError = Error;
	}
	return NULL;
}
Ejemplo n.º 26
0
static BT_HANDLE uart_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hUart = NULL;

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_ENUM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	if (g_USART_HANDLES[pResource->ulStart]){
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hUart = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hUart) {
		goto err_out;
	}

	g_USART_HANDLES[pResource->ulStart] = hUart;

	hUart->pDevice = pDevice;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hUart->pRegs = (LM3Sxx_UART_REGS *) pResource->ulStart;

	uartSetPowerState(hUart, BT_POWER_STATE_AWAKE);

	// Reset all registers to their defaults!

	ResetUart(hUart);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

/*	On NVIC we don't need to register interrupts, LINKER has patched vector for us
 * Error = BT_RegisterInterrupt(pResource->ulStart, uart_irq_handler, hUart);
	if(Error) {
		goto err_free_out;
	}*/


	BT_SetInterruptPriority(pResource->ulStart, ((0x01 << BT_CONFIG_MACH_PRIORITY_BITS)-1));
	Error = BT_EnableInterrupt(pResource->ulStart);

	return hUart;

err_free_out:
	BT_DestroyHandle(hUart);

err_out:
	if(pError) {
		*pError = Error;
	}
	return NULL;
}
Ejemplo n.º 27
0
static BT_HANDLE can_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hCan = NULL;


	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_ENUM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	if (g_CAN_HANDLES[pResource->ulStart]){
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hCan = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hCan) {
		goto err_out;
	}

	g_CAN_HANDLES[pResource->ulStart] = hCan;

	hCan->pDevice = pDevice;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hCan->pRegs = (LPC17xx_CAN_REGS *) pResource->ulStart;

	canSetPowerState(hCan, BT_POWER_STATE_AWAKE);

	// Reset all registers to their defaults!

	canDisable(hCan);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

/*	On NVIC we don't need to register interrupts, LINKER has patched vector for us
 * Error = BT_RegisterInterrupt(pResource->ulStart, uart_irq_handler, hCan);
	if(Error) {
		goto err_free_out;
	}*/


	Error = BT_EnableInterrupt(pResource->ulStart);

	return hCan;

err_free_out:
	BT_DestroyHandle(hCan);

err_out:
	if(pError) {
		*pError = Error;
	}
	return NULL;
}
Ejemplo n.º 28
0
static BT_HANDLE gpio_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_u32 i;

	BT_ERROR Error;
	if(pError) {
		*pError = BT_ERR_NONE;
	}

	BT_HANDLE hGPIO = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hGPIO) {
		goto err_out;
	}

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IO, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	BT_u32 base 	= pResource->ulStart;
	BT_u32 total 	= (pResource->ulEnd - pResource->ulStart) + 1;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hGPIO->pRegs = (ZYNQ_GPIO_REGS *) pResource->ulStart;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	Error = BT_RegisterInterrupt(pResource->ulStart, gpio_irq_handler, hGPIO);
	if(Error) {
		goto err_free_out;
	}

	// Prevent Pending Interrupts
	for(i = 0; i < total; i += 32) {
		hGPIO->pRegs->bank[i/32].INT_DIS = 0xFFFFFFFF;
	}

	Error = BT_EnableInterrupt(pResource->ulStart);

	Error = BT_RegisterGpioController(base, total, hGPIO);
	if(Error) {
		goto err_free_irq;
	}

	return hGPIO;

err_free_irq:
	BT_UnregisterInterrupt(pResource->ulStart, gpio_irq_handler, hGPIO);

err_free_out:
	BT_DestroyHandle(hGPIO);

	if(pError) {
		*pError = Error;
	}

err_out:
	return NULL;
}
Ejemplo n.º 29
0
static BT_HANDLE i2c_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hI2C = NULL;

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_INVALID_RESOURCE;
		goto err_out;
	}

	hI2C = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hI2C) {
		Error = BT_ERR_NO_MEMORY;
		goto err_out;
	}

	hI2C->pRegs = (ZYNQ_I2C_REGS *) bt_ioremap((void *)pResource->ulStart, BT_SIZE_4K);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_INVALID_RESOURCE;
		goto err_free_out;
	}

	BT_u32 ulIRQ = pResource->ulStart;

	Error = BT_RegisterInterrupt(ulIRQ, i2c_irq_handler, hI2C);
	if(Error) {
		Error = BT_ERR_GENERIC;	// Device already in use!
		goto err_free_out;
	}

	BT_EnableInterrupt(ulIRQ);

	hI2C->pDevice = pDevice;
	i2c_set_clock_rate(hI2C, BT_I2C_CLOCKRATE_400kHz);

	hI2C->pMutex = BT_kMutexCreate();
	if(!hI2C->pMutex) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_int_out;
	}

	BT_kMutexPend(hI2C->pMutex, 0);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_BUSID, 0);
	if(!pResource) {
		Error = BT_ERR_INVALID_RESOURCE;
		goto err_free_int_out;
	}

	BT_u32 ulBusID = pResource->ulStart;

	hI2C->pRegs->CONTROL |= 0x0000000E;

	BT_I2C_RegisterBusWithID(hI2C, ulBusID);

	if(pError) {
		*pError = Error;
	}

	return hI2C;

err_free_int_out:
	BT_UnregisterInterrupt(ulIRQ, i2c_irq_handler, hI2C);

err_free_out:
	BT_DestroyHandle(hI2C);

err_out:
	if(pError) {
		*pError = Error;
	}

	return NULL;
}
Ejemplo n.º 30
0
static BT_HANDLE pwm_probe(const BT_INTEGRATED_DEVICE *pDevice, BT_ERROR *pError) {

	BT_ERROR Error = BT_ERR_NONE;
	BT_HANDLE hPwm = NULL;

	const BT_RESOURCE *pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_ENUM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	if (g_PWM_HANDLES[pResource->ulStart]){
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

	hPwm = BT_CreateHandle(&oHandleInterface, sizeof(struct _BT_OPAQUE_HANDLE), pError);
	if(!hPwm) {
		goto err_out;
	}

	hPwm->id = pResource->ulStart;

	g_PWM_HANDLES[pResource->ulStart] = hPwm;

	hPwm->pDevice = pDevice;

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_MEM, 0);
	if(!pResource) {
		Error = BT_ERR_NO_MEMORY;
		goto err_free_out;
	}

	hPwm->pRegs = (LPC17xx_PWM_REGS *) pResource->ulStart;

	PwmSetPowerState(hPwm, BT_POWER_STATE_AWAKE);

	ResetPwm(hPwm);

	pResource = BT_GetIntegratedResource(pDevice, BT_RESOURCE_IRQ, 0);
	if(!pResource) {
		Error = BT_ERR_GENERIC;
		goto err_free_out;
	}

/*	On NVIC we don't need to register interrupts, LINKER has patched vector for us
 * Error = BT_RegisterInterrupt(pResource->ulStart, pwm_irq_handler, hPwm);
	if(Error) {
		goto err_free_out;
	}*/


	Error = BT_EnableInterrupt(pResource->ulStart);

	return hPwm;

err_free_out:
	BT_DestroyHandle(hPwm);

err_out:
	if(pError) {
		*pError = Error;
	}
	return NULL;
}