示例#1
0
文件: interrupt.c 项目: poinu/ZeOS
void keyboard_routine(void) {
  char c = inb(0x60); /* Read from port 0x60 into c */
  char press = !(c & 0x80); /* First bit indicates whether pressed or released */
  if (press) {
    c = char_map[c & 0x7f];
    if (c != '\0')printc_xy(0, 0, c);
    else printc_xy(0, 0, 'C');

    cb_write(&keyboard_buffer, &c, 1);

    if (remaining_characters > 0) {				/* Some process is waiting */
      if (cb_size(&keyboard_buffer) >= remaining_characters)	/* Buffer holds enough characters */
        unblock(&blocked);
      else if (cb_full(&keyboard_buffer))			/* Buffer doesn't hold enough characters but is full */
        unblock(&blocked);
    }
    else if (cb_full(&keyboard_buffer))				/* No process is waiting and buffer is full */
      cb_overwrite(&keyboard_buffer, &c, 1);
  }
}
示例#2
0
/*******************************************************************************
** 函数: cb_write
** 功能: 将datptr所指向的地址中的datlen长度的数据写入到pmngr->bufptr中
** 返回: 返回实际写入的数据长度, 字节为单位
** 作者: avrbase_lei
*******/
static cb_u32 cb_write(CircleBufferMngr *pmngr, cb_u8 *datptr, cb_u32 datlen)
{
    cb_u32 writelen = 0, tmplen = 0;
    
    CB_ASSERT(NULL != pmngr);
    CB_ASSERT(NULL != pmngr->bufptr);

    if(cb_full(pmngr))
        return 0;
    
    CB_GLOBAL_LOCK;
    tmplen = pmngr->buflen - pmngr->datalen;
    writelen = tmplen > datlen ? datlen : tmplen;

    if(pmngr->writepos < pmngr->readpos)
    {
        CB_MEMCPY(
            (void*)&pmngr->bufptr[pmngr->writepos],
            (void*)datptr,
            writelen);
    }
    else
    {
        tmplen = pmngr->buflen - pmngr->writepos;
        if(writelen <= tmplen)
        {
            CB_MEMCPY(
                (void*)&pmngr->bufptr[pmngr->writepos],
                (void*)datptr,
                writelen);
        }
        else
        {
            CB_MEMCPY(
                (void*)&pmngr->bufptr[pmngr->writepos],
                (void*)datptr,
                tmplen);
            CB_MEMCPY(
                (void*)pmngr->bufptr,
                (void*)&datptr[tmplen],
                writelen - tmplen);
        }
    }

    pmngr->writepos = (pmngr->writepos + writelen) % pmngr->buflen;
    pmngr->datalen += writelen;
    CB_GLOBAL_UNLOCK;
        
    return writelen;
}