Exemplo n.º 1
0
/***    uint32_t write(const byte * pb, uint32_t cb)
 *
 *    Parameters:
 *          pb: pointer to a byte stream to write to the bus
 *          cb: the number of bytes to write out
 *              
 *    Return Values:
 *          The number of bytes queued for transmit. This may be smaller than cb. 
 *
 *    Description: 
 *         Writes as many bytes as possible to the the transmit buffer and is queued for transmission. The transmit buffer
 *          is small, so not all bytes may be taken. write() should be continually called until all bytes have been accepted.
 *          code something link.....  cbWritten += write(&rgb[cbWritten], cbTotal-cbWritten); should be called until cbWritten == cbTotal.
 *          Writing out a large buffer could take some time to do.
 *
 *          You can call write() at any time, even before you are writting to the bus; this call only loads the transmit buffer and as long as the buffer
 *          is not full it will take some bytes. However, once full, no more bytes will be accepted until bytes are transmitted. The bus clock will be held
 *          low if the transmit buffer is empty.
 *
 *      Notes:
 * ------------------------------------------------------------ */
uint32_t DTWI::write(const byte * pb, uint32_t cb)
{
    uint8_t iNext       = iWriteNext;   // freeze this, interrupt routine updates this  
    uint8_t cbCopy1     = 0;
    uint8_t cbCopy2     = 0;
    bool    fPrime      = transmitting() == 0;

    if(iWriteLast < sizeof(rgbOut))
    {
        cbCopy1 = sizeof(rgbOut) - iWriteLast;
        cbCopy2 = iNext;
    }
    else
    {
        cbCopy1 = sizeof(rgbOut) - (iWriteLast - iNext);
    }

    // get max copy sizes
    cbCopy1 = min(cb, cbCopy1);
    cb -= cbCopy1;
    cbCopy2 = min(cb, cbCopy2);

    if((cbCopy1 + cbCopy2) == 0)
    {
        return(0);
    }

    // do the copies
    if(cbCopy1 > 0)
    {
        memcpy(&rgbOut[iWriteLast % sizeof(rgbOut)], pb, cbCopy1);
        pb += cbCopy1;
    }

    if(cbCopy2 > 0)
    {
        memcpy(rgbOut, pb, cbCopy2);
    }

    // How many bytes actually transferred
    cbCopy1 += cbCopy2;

    // we are going to modify some interrupt variables
    pregIec->clr = bitMASK; // turn off interrupts
    if(iWriteNext >= sizeof(rgbOut))
    {
        iWriteNext -= sizeof(rgbOut);
        iWriteLast -= sizeof(rgbOut);
    }
    iWriteLast += cbCopy1;
    pregIec->set = bitMASK; // turn interrutps back on

    // kick off the state machine and get things writing
    if(fPrime && cbCopy1 > 0)
    {
        primeMasterSlave();
    }

    return(cbCopy1);
}
Exemplo n.º 2
0
/***    void DTWI::purge(void)
 *
 *    Parameters:
 *          None
  *              
 *    Return Values:
 *          none
 *
 *    Description: 
 *      Purges the transmit buffer and removes all unwritten bytes from the buffer
 *    
 * ------------------------------------------------------------ */
void DTWI::abort(void)
{
    if(transmitting())
    {
        // we are going to modify some interrupt variables
        pregIec->clr = bitMASK; // turn off interrupts
        iWriteNext = iWriteLast;
        if(iWriteNext >= sizeof(rgbOut))
        {
            iWriteNext -= sizeof(rgbOut);
            iWriteLast -= sizeof(rgbOut);
        }
        pregIec->set = bitMASK; // turn interrutps back on
    }
}
Exemplo n.º 3
0
main()
{
	int ret;
	//register signal
	struct sigaction signew;
	
	signew.sa_handler=acquit;
	sigemptyset(&signew.sa_mask);
	signew.sa_flags=0;
  	sigaction(SIGINT,&signew,0);
	
	signew.sa_handler=acquit;
	sigemptyset(&signew.sa_mask);
	signew.sa_flags=0;
	sigaction(SIGTERM,&signew,0);
	
	signew.sa_handler=wakeup;
	sigemptyset(&signew.sa_mask);
	signew.sa_flags=0;
	sigaction(SIGUSR1,&signew,0);


	signew.sa_handler=acalarm;
	sigemptyset(&signew.sa_mask);
	signew.sa_flags=0;
	sigaction(SIGALRM,&signew,0);
	
	//atexit
	if(atexit(&procquit))
	{
	   printf("quit code can't install!");
	   exit(0);
	}
	
	//init mmap
	char tsmmap[128];
	read_config("ts_buffer",tsmmap);
	p_map_ts=init_mmap_use(tsmmap);
	if(p_map_ts==NULL)
	{
		printf("memory map failed!\n");
		exit(0);
	}

	//open log
	char logfile[128];
	read_config("logfile",logfile);
	logfd=open(logfile,O_CREAT|O_WRONLY|O_APPEND,0600);
	if(logfd==-1)
	{
		printf("open logfile error!\n");
		exit(0);
	}
	
	//init transmit
	bst_initial_dev_handle(&DevHandle, 0, 0);
	ret = bst_initial(&DevHandle, 0);
	if (ret < 0)
	{
		printf("bst_initial failed!\n");
		exit(0);
	}
	printf("bst_initial successfully!\n");
	
	ret = bst_get_device_num(&DevHandle);
	
	if (ret <=0) 
	{
		printf("bst_get_device_num failed!\n");
		exit(0);

	}
		printf("Found %d BST device(s)!\n",ret);
	
	
	DevConfig.version=3;
	DevConfig.rate=20.0e+6;
	DevConfig.rate_ori=10.0e+6;
	DevConfig.frame_length=188;
	DevConfig.frame_length_ori=188;
	//DevConfig.spi_asi_select=INTERFACE_ASI_SPI;
	DevConfig.spi_asi_select=INTERFACE_ASI;
	DevConfig.burst_enable=1;
	DevConfig.reference_in_enable=RFCLK_IN_INNER;
	DevConfig.reference_out_enable=RFCLK_OUT_DISABLE;
	DevConfig.raw_data=0;
	DevConfig.pcr_adj=0;

	//bst_start_transmitEx(&DevHandle, &DevConfig, 0);

	/*
	{
		3,   //version
		20.0e+6,//rate
		20.0e+6, //rate_ori
		188, //frame_length
		188, //frame_length
		INTERFACE_ASI_SPI,//only asi or both asi and spi
		ASI_MODE_CONTINUE, //burst_enable  0:continous  1:burst
		RFCLK_IN_INNER, 
		RFCLK_OUT_DISABLE, 
		0,//ts format 
		0
	*/


	//transmitting
	transmitting();
	

	
}