Ejemplo n.º 1
0
void server_event_start(int socket)
{
	int efd = epoll_create1 (0);
	struct epoll_event event;
	event.data.fd = socket;
	event.events = EPOLLIN | EPOLLET;
	epoll_ctl(efd,EPOLL_CTL_ADD, socket,&event);

	struct epoll_event *recv_events;
	recv_events = (epoll_event*) calloc(MAX_EVENTS , sizeof(epoll_event));

	while(true)
	{
		int n = epoll_wait(efd, recv_events, MAX_EVENTS, -1);
		printf("epoll_wait return %d\n",n);
		for(int i = 0; i<n; i++)
		{
			if(socket == recv_events[i].data.fd)
			{
				accept_handle(efd,socket);
			}else{
				read_handle(recv_events[i].data.fd);
			}
		}
	}

}
Ejemplo n.º 2
0
int cxl_of_read_afu_handle(struct cxl_afu *afu, struct device_node *afu_np)
{
	if (read_handle(afu_np, &afu->guest->handle))
		return -EINVAL;
	pr_devel("AFU handle: 0x%.16llx\n", afu->guest->handle);

	return 0;
}
Ejemplo n.º 3
0
 /// \brief Closes the read handle, if not already closed
 void close_read()
 {
     if(-1 != read_handle())
     {
         ::close(m_handles[0]);
         m_handles[0] = -1;
     }
 }
Ejemplo n.º 4
0
void EXTI_DSR(EXTI_DRIVER_INFO* drv_info, HANDLE hnd)
{
	PIN_DESC* pin;

	pin = (PIN_DESC*)hnd->mode.as_voidptr;
	if(hnd->cmd & FLAG_WRITE)
    {
		pin = (PIN_DESC*)hnd->mode.as_voidptr;
		while( *pin && hnd->len > 1)
		{
			// write on virtual ports is not supported through handles
			if (PD_PORT_Get(*pin) <= PD_LAST_PORT)
				PIO_Write(*pin, *hnd->src.as_shortptr);
			pin ++;
			hnd->src.as_shortptr++;
			hnd->len -=2;
		}
		svc_HND_SET_STATUS(hnd, RES_SIG_OK);
		return;
    }

	if(hnd->cmd & FLAG_READ)
	{
		if(hnd->cmd & FLAG_LOCK)
		{
			if(!(hnd->mode0 == PIOHND_INTPENDING))
			{
				hnd->mode0 = PIOHND_WAITING;
				hnd->res = RES_BUSY;
				return;
			}
		}
		hnd->mode0 = PIOHND_IDLE;
		read_handle(hnd);
		svc_HND_SET_STATUS(hnd, RES_SIG_OK);
	}
}
Ejemplo n.º 5
0
void EXTI_DCR(EXTI_DRIVER_INFO* drv_info, unsigned int reason, HANDLE hnd)
{
	EXTI_DRIVER_DATA * drv_data = drv_info->drv_data ;
	const PIN_DESC* pin;
	unsigned int lines;

	switch( reason )
	{
		case DCR_ISR:
		{
			lines = (unsigned int)hnd; //lines with edge

			// loop waiting handles
			for(hnd = drv_data->waiting; hnd; hnd = hnd->next)
			{
				// loop pin description list in the handle
				for(pin = (PIN_DESC*)hnd->mode.as_voidptr; *pin; pin++)
				{
					if(lines & *pin)
					{
						if(hnd->mode0 == PIOHND_WAITING)
						{
							hnd->mode0 = PIOHND_IDLE;
							read_handle(hnd);
							svc_HND_SET_STATUS(hnd, RES_SIG_OK);
						}
						else
							hnd->mode0 = PIOHND_INTPENDING;

						break; //done with this handle
					}
				}
			}
		}
		break;

		case DCR_OPEN:
		{
			//Enable AFIO/SYSCFG...
			RCCPeripheralEnable(drv_info->info.peripheral_indx);

			pin = (PIN_DESC *)hnd->mode.as_voidptr;
			hnd->list_add(drv_data->waiting);
			hnd->mode0 = PIOHND_IDLE;
			while(*pin)
			{
				unsigned int pin_pattern, pos;

				PIO_Cfg(*pin);
				if(PD_MODE_Get(*pin) == PD_MODE_INPUT)
				{
					if(PD_INT_Get(*pin))
					{
						pin_pattern = PD_PINS_Get(*pin);
						while(pin_pattern)
						{
							pos = 31 - __CLZ(pin_pattern);
							lines = 1 << pos;
							pin_pattern ^= lines;

							pos = stm_get_drv_indx(pos);

							// Handles can be open with any EXTI driver, so check
							// here if the actual driver is installed

							int adr = (int)DRV_TABLE[pos];
							adr &= ~3;

							const EXTI_DRIVER_INFO* info;
							info = (const EXTI_DRIVER_INFO*)adr;
							if(info->info.isr == (DRV_ISR)EXTI_ISR)
							{
		        				drv_enable_isr(&info->info);

							    /* Clear Rising Falling edge configuration */
								info->hw_base->EXTI_RTSR &= ~lines;
								info->hw_base->EXTI_FTSR &= ~lines;

								exti_set_line_source(31 - __CLZ(lines), PD_PORT_Get(*pin));

							    /* Select the trigger for the selected external interrupts */
								if(*pin & PD_INT_FE) // falling edge
									info->hw_base->EXTI_FTSR |= lines;
								if(*pin & PD_INT_RE) // rising edge
									info->hw_base->EXTI_RTSR |= lines;

							    /* Enable line interrupt */
								info->hw_base->EXTI_IMR |= lines;
							}
						}
					}
				}
				pin++;
			}
			hnd->res = RES_OK;
		}
		break;

		case DCR_CLOSE:
		{
			PIO_Cfg_List((PIN_DESC*)hnd->mode.as_voidptr);
			hnd->list_remove(drv_data->waiting);
		}
		break;

		case DCR_CANCEL:
			if (hnd->res & FLG_BUSY)
			{
				read_handle(hnd);
				svc_HND_SET_STATUS(hnd, RES_SIG_CANCEL);
			}
			break;

		case DCR_RESET:
			NVIC_DisableIRQ(drv_info->info.drv_index);
			RCCPeripheralReset(drv_info->info.peripheral_indx);
			RCCPeripheralDisable(drv_info->info.peripheral_indx); // turn off
			break;
		default:
			break;
	}
}
Ejemplo n.º 6
0
handle_t _alloc_blk(ALLOC * a, void *buf, size_t len)
{
	handle_t req = len2atom(len), h;
	int idx;

	if (len > CTBLK_MAXLONG) {
		xerrno = FATAL_BLKSIZE;
		return 0;
	}
	if ((h = flt_find(a, req, &idx)) == 0) {	// no free blocks
		off_t tail = fsize(a->fd);

		if (tail <= 0 || tail % ATOM_LEN != 0) {
			xerrno = FATAL_INVDB;
			return 0;
		}
		h = off2hdl(tail);
		if (alloc(a->fd, tail, req * ATOM_LEN) == -1)
			return 0;
		if (use_blk(a, h, buf, len) != 0)
			return 0;
		return h;
	}

	unsigned char tag;
	handle_t prev, next, atoms, h_free, atoms_free;
	unsigned char atom[16];

	if (readat(a->fd, atom, 16, hdl2off(h)) != 16)
		return 0;
	tag = atom[0];
	switch (tag) {
	case FRBLK_SINGLE:
		atoms = 1;
		prev = b2hdl(&atom[1]);
		next = b2hdl(&atom[8]);
		// TODO: verify last byte
		break;
	case FRBLK_LONG:
		if ((atoms = read_handle(a->fd, hdl2off(h) + 16)) == 0) {
			xerrno = FATAL_BLKSIZE;
			return 0;
		}
		prev = b2hdl(&atom[1]);
		next = b2hdl(&atom[8]);
		// TODO: verify last byte
		break;
	default:
		xerrno = FATAL_BLKTAG;
		return 0;
	}
	if (flt_remove(a, idx, prev, next) != 0)
		return 0;
	if (atoms > req) {
		h_free = h + req;
		atoms_free = atoms - req;
		if (free_blk(a, h_free, atoms_free) != 0)
			return 0;
	}
	if (alloc(a->fd, hdl2off(h), req * ATOM_LEN) == -1)
		return 0;
	if (use_blk(a, h, buf, len) != 0)
		return 0;
	return h;
}