--- margi2/margi.c 2001/05/15 12:40:21 1.14 +++ margi2/margi.c 2001/06/01 16:43:07 1.15 @@ -189,40 +189,45 @@ void DACSetFrequency(struct cvdv_cards * } -int MargiFreeBuffers(struct cvdv_cards *card) +int MargiFreeBuffers(struct cvdv_cards *card, int isB) { MDEBUG(1, ": -- MargiFreeBuffers\n"); - ring_destroy(&(card->rbufA)); - card->use_ringA = 0; - ring_destroy(&(card->rbufB)); - card->use_ringB = 0; + if(isB){ + ring_destroy(&(card->rbufB)); + card->use_ringB = 0; + } + if (isB == 2 || isB == 0){ + ring_destroy(&(card->rbufA)); + card->use_ringA = 0; + } + return 0; } -int MargiSetABuffers(struct cvdv_cards *card, uint32_t size) +int MargiSetBuffers(struct cvdv_cards *card, uint32_t size, int isB) { - MargiFreeBuffers(card); - MDEBUG(1, ": -- MargiSetABuffers(%d)\n", - size); + int err = 0; - ring_init(&(card->rbufA),size); - card->use_ringA = 1; - return 0; -} + MargiFreeBuffers(card,isB); + MDEBUG(0, ": -- MargiSetBuffers(%d) %d\n", + size, isB); -int MargiSetBBuffers(struct cvdv_cards *card, uint32_t size) -{ - MargiFreeBuffers(card); - MDEBUG(1, ": -- MargiSetBBuffers(%d)\n", - size); - - ring_init(&(card->rbufB),size); - card->use_ringB = 1; - return 0; + if (isB){ + err = ring_init(&(card->rbufB),size); + if (!err) card->use_ringB = 1; + } else { + err = ring_init(&(card->rbufA),size); + if (!err) card->use_ringA = 1; + } + + MDEBUG(0,"error: %d use_ringA: %d use_ringB: %d\n",err, +card->use_ringA,card->use_ringB); + return err; } + int MargiFlush (struct cvdv_cards *card) { int co = 0; @@ -259,14 +264,14 @@ int MargiPushA(struct cvdv_cards *card, if (!card->use_ringA) return 0; - - if (fill > 3*card->rbufA.size/4 && !card->channelrun){ + if ((count>fill || fill > 3*card->rbufA.size/4) + && !card->channelrun){ DecoderStartChannel(card); card->DMAABusy = 1; } count = ring_write(&(card->rbufA),data,count); - + return count; } @@ -278,14 +283,14 @@ int MargiPushB(struct cvdv_cards *card, if (!card->use_ringB) return 0; - - if (fill > 3*card->rbufB.size/4 && !card->channelrun){ + if ((count>fill || fill > 3*card->rbufB.size/4) + && !card->channelrun){ DecoderStartChannel(card); card->DMABBusy = 1; } count = ring_write(&(card->rbufB),data,count); - + return count; } @@ -353,37 +358,23 @@ uint32_t DecoderGetBufferSpace(struct cv } -static int ringDMA_PES (struct cvdv_cards *card){ - - uint32_t size = 0; - u_char stat; - dev_link_t *link = &(((margi_info_t *) card->margi)->link); - uint32_t count=0; - uint8_t data; - - return 0; -} - - static int ringDMA (struct cvdv_cards *card){ uint32_t size = 0; u_char stat; dev_link_t *link = &(((margi_info_t *) card->margi)->link); - uint32_t count=0; + uint32_t acount=0; + uint32_t vcount=0; uint8_t data; - - count = ring_read_rest(&(card->rbufA)); - if (count < 2048) { - wake_up_interruptible(&(card->wqA)); - return 0; - } - + ringbuffy *buffy; + int stype; + wait_queue_head_t *wq; stat = read_lsi_status(card); - MDEBUG( 3, ": -- stat: %d readpos: %d writepos: %d \n", - stat,(int) card->rbufA.read_pos,(int) card->rbufA.write_pos); + + stype = card->setup.streamtype; + if (stat & LSI_ARQ) { stat = read_lsi_status(card); } @@ -396,25 +387,72 @@ static int ringDMA (struct cvdv_cards *c } if ((stat & LSI_ARQ) == 0) { - size = DecoderGetBufferSpace(card); - if (count > size) count = size & 0xfffffffc; - if (count>=2048) count &=0xfffff800; - count &=0xfffffffc; + switch(stype){ + case stream_PES: + case stream_ES: + MDEBUG(0,"write audio\n"); + data = read_indexed_register(card, IIO_LSI_CONTROL); + data &= ~DSVC; + write_indexed_register(card, IIO_LSI_CONTROL, data); + buffy = &card->rbufB; + wq = &(card->wqB); + acount = ring_read_rest(buffy); + size = DecoderGetAudioBufferSpace(card); + if (size > 2048) size -= 2048; + break; + default: + buffy = &card->rbufA; + wq = &(card->wqA); + acount = ring_read_rest(buffy); + size = DecoderGetBufferSpace(card); + break; + } + if (acount > size) acount = size & 0xfffffffc; + if (acount>=2048) acount &=0xfffff800; + acount &=0xfffffffc; - if (count > size) count = size & 0xfffffffc; - MDEBUG(3,": -- stat: %d length: %d size: %d startV: %d startA: %d\n", - stat,count,size, card->startingV, card->startingA); + if (acount > size) acount = size & 0xfffffffc; + if (acount) { + ring_read_direct(buffy, + link->io.BasePort1+DIO_LSI_STATUS, + acount); + } else { + wake_up_interruptible(wq); + acount = 0; + } + } else { + acount = 0; + } - if (count) { - ring_read_direct(&(card->rbufA), + if ((stat & LSI_VRQ) == 0 && + (stype == stream_PES || stype == stream_ES)) { + data = read_indexed_register(card, IIO_LSI_CONTROL); + data |= DSVC; + write_indexed_register(card, IIO_LSI_CONTROL, data); + buffy = &card->rbufA; + wq = &(card->wqA); + vcount = ring_read_rest(buffy); + + size = DecoderGetVideoBufferSpace(card); + if (size > 2048) size -= 2048; + if (vcount > size) vcount = size & 0xfffffffc; + if (vcount>=2048) vcount &=0xfffff800; + vcount &=0xfffffffc; + + if (vcount > size) vcount = size & 0xfffffffc; + if (vcount) { + ring_read_direct(buffy, link->io.BasePort1+DIO_LSI_STATUS, - count); - } + vcount); + } else { + wake_up_interruptible(wq); + vcount = 0; + } } else { - count = 0; + vcount = 0; } - return count; + return vcount+acount; } @@ -492,7 +530,7 @@ void MaskByte(struct cvdv_cards *card, i #define MAXWRITE CHANNELBUFFERSIZE/2 -#define MAX_COUNT 40 +#define MAX_COUNT 400 #ifdef USE_BH struct cvdv_cards *bh_card; @@ -506,12 +544,11 @@ static void do_margi(struct cvdv_cards * { #endif - int countA, countB; + int countA; int try; int stype = card->setup.streamtype; countA = 0; - countB = 0; card->currentType = 0; for ( try = 0; try < MAX_COUNT ;try++) @@ -520,7 +557,6 @@ static void do_margi(struct cvdv_cards * switch (stype){ case stream_PES: case stream_ES: -// count = ringDMA_PES(card); count = ringDMA(card); countA += count; if (!count) @@ -575,10 +611,7 @@ void L64014Intr_function(struct cvdv_car if(card->use_ringA || card->use_ringB){ L64021Intr(card); } - } else { - wake_up_interruptible(&(card->wqA)); - wake_up_interruptible(&(card->wqB)); - } + } } if (stat & DEC_INT) { @@ -604,12 +637,11 @@ void Timerfunction(unsigned long data) { struct cvdv_cards *card = (struct cvdv_cards *) data; - L64014Intr_function(card); card->timer.function = Timerfunction; card->timer.data=(unsigned long) card; - card->timer.expires=jiffies+1; + card->timer.expires=jiffies+10; if ( card->open) add_timer(&card->timer); @@ -673,6 +705,11 @@ void l64020Reset(struct cvdv_cards *card write_indexed_register(card,IIO_GPIO_PINS,data); //write_indexed_register(card, IIO_LSI_CONTROL, DR); + + data = read_indexed_register(card, IIO_LSI_CONTROL); + data &= ~DSVC; + write_indexed_register(card, IIO_LSI_CONTROL, data); + } void ZV_init(struct cvdv_cards *card) @@ -801,7 +838,7 @@ void CardDeInit(struct cvdv_cards *card) { CloseCard(card); MargiFlush(card); - MargiFreeBuffers(card); + MargiFreeBuffers(card,2); L64014RemoveIntr(card); card_init(card, 0);