int GetDeviceODRules( int DevHandle )
{
	char commandStr[36];
	int error = 0;

	for(int i = 1; i < MAX_CHANNEL+1; i++)
	{
		//OD_IMax
		putInShowBuffer = TRUE;
		showBufferIndex = 0;
		memset(showBuffer, '\0', sizeof(showBuffer));
		sprintf(commandStr, "?GetImax %d \n\r", i);
		ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);
		Sleep(50);
		deviceIntelliRules[DevHandle][i].IMax = GetParameter(2);

		//OD_Ratio and OD_PulseWidth
		putInShowBuffer = TRUE;
		showBufferIndex = 0;
		memset(showBuffer, '\0', sizeof(showBuffer));
		sprintf(commandStr, "?GetODRules %d \n\r", i);
		ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);
		Sleep(50);
		deviceIntelliRules[DevHandle][i].DCMax = GetParameter(1);
		deviceIntelliRules[DevHandle][i].PWMax = GetParameter(2);
	}

	return error;
}
int MTUSB_BLSDriverSetPulseDetail( int DevHandle, int Channel, int PulseIndex, int Time0, int Time1, int Time2, int Curr0, int Curr1, int Curr2)
{
	char commandStr[36];
	int error;
	int dutyRatio;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;

	if ((Channel <= 0) || (Channel > deviceChannels[DevHandle]))
		return -1;

	if ((PulseIndex < 0) || ( PulseIndex >= devicePulses[DevHandle][Channel]))
		return -1;

	//Normal Pulse Rule Check
	if ((Time0 <= 0) || (Time1 <= 0) || (Time2 <= 0))
		return -1;

	if ((Curr0 > 1000) || (Curr2 > 1000))
		return -1;

	// Intelli Rules Check
	if (Curr1 > 1000)
	{
		if (Curr1 > deviceIntelliRules[DevHandle][Channel].IMax)
			return -1;

		if (Time1 > deviceIntelliRules[DevHandle][Channel].PWMax)
			return -1;

		if ((Curr0 > 100) || (Curr2 > 100))
			return -1;

		dutyRatio = round( Time1 / (Time0 + Time1 + Time2) * 1000);

		if (dutyRatio > deviceIntelliRules[DevHandle][Channel].DCMax)
			return -1;
	}

	// the pulse is valid

    sprintf(commandStr, "TrigP %d %d %d %d\n\r", Channel, PulseIndex * 3, Curr0, Time0);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

   sprintf(commandStr, "TrigP %d %d %d %d\n\r", Channel, PulseIndex * 3 + 1, Curr1, Time1);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

   sprintf(commandStr, "TrigP %d %d %d %d\n\r", Channel, PulseIndex * 3 + 2, Curr2, Time2);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

	if (PulseIndex == devicePulses[DevHandle][Channel] - 1)
	{
		sprintf(commandStr, "TrigP %d %d 0 0 \n\r", Channel, (PulseIndex + 1) * 3);
		ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);
	}

	return error;
}
signed FlashParameters (struct plc * plc, uint32_t options)

{
	struct vs_module_spec vs_module_spec =
	{
		PLC_MODULEID_PARAMETERS,
		0,
		0,
		0
	};
	ModuleSpec (&plc->PIB, &vs_module_spec);
	if (ModuleSession (plc, 1, &vs_module_spec))
	{
		return (-1);
	}
	if (ModuleWrite (plc, &plc->PIB, 0, &vs_module_spec))
	{
		return (-1);
	}
	if (ModuleCommit (plc, options))
	{
		return (-1);
	}
	return (0);
}
signed FlashSoftloader (struct plc * plc, uint32_t options)

{
	struct vs_module_spec vs_module_spec =
	{
		PLC_MODULEID_SOFTLOADER,
		0,
		0,
		0
	};
	ModuleSpec (&plc->SFT, &vs_module_spec);
	if (ModuleSession (plc, 1, &vs_module_spec))
	{
		return (-1);
	}
	if (ModuleWrite (plc, &plc->SFT, 0, &vs_module_spec))
	{
		return (-1);
	}
	if (ModuleCommit (plc, options))
	{
		return (-1);
	}
	return (0);
}
int MTUSB_BLSDriverStorePara( int DevHandle )
{
	char commandStr[36];
	int error;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;
	
	strcpy(commandStr, "STORE\n\r");
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), FALSE, error);

	return error;
}
int MTUSB_BLSDriverSetFollowModeDetail( int DevHandle, int Channel, int ION, int IOFF)
{
	char commandStr[36];
	int error;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;

	if ((Channel != 88) && ((Channel <= 0)||(Channel > deviceChannels[DevHandle])))
		return -1;

    sprintf(commandStr, "TrigP %d 0 %d 9999\n\r", Channel, IOFF);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

    sprintf(commandStr, "TrigP %d 1 %d 9999\n\r", Channel, ION);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

    sprintf(commandStr, "TrigP %d 2 0 0 \n\r", Channel);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

	return error;
}
Beispiel #7
0
signed FlashFirmware (struct plc * plc, uint32_t options) 

{
	struct vs_module_spec vs_module_spec [] = 
	{
		{
			PLC_MODULEID_PARAMETERS,
			0,
			0,
			0
		},
		{
			PLC_MODULEID_FIRMWARE,
			0,
			0,
			0
		}
	};
	ModuleSpec (&plc->PIB, &vs_module_spec [0]);
	ModuleSpec (&plc->NVM, &vs_module_spec [1]);
	if (ModuleSession (plc, (sizeof (vs_module_spec) / sizeof (struct vs_module_spec)), vs_module_spec)) 
	{
		return (-1);
	}
	if (ModuleWrite (plc, &plc->PIB, 0, &vs_module_spec [0])) 
	{
		return (-1);
	}
	if (ModuleWrite (plc, &plc->NVM, 1, &vs_module_spec [1])) 
	{
		return (-1);
	}
	if (ModuleCommit (plc, options)) 
	{
		return (-1);
	}
	return (0);
}
int MTUSB_BLSDriverSoftStart( int DevHandle, int Channel )
{
	char commandStr[36];
	int error;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;

	if ((Channel != 88) && ((Channel <= 0)||(Channel > deviceChannels[DevHandle])))
		return -1;

    sprintf(commandStr, "SoftStart %d\n\r", Channel);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

	return error;
}
Beispiel #9
0
void EXTR::launch_face_detection(void) {
	if (GetVerbose())
		SpacePrint("EXTR: Launching Face Detection\n");
	
	if (++m_currentBitmapImage > MAX_NB_IMAGE)
		m_currentBitmapImage = 1;
	
	JMSG messageToFace;
	messageToFace.command = SCMD_BEGIN_FACE_DETECTION;
	messageToFace.param0 = m_decompressedImageAddr[m_currentBitmapImage-1];
	messageToFace.param1 = m_currentJPEGImageNo;
	computeFor(1);

	ModuleWrite(FACEDETECT_ID, SPACE_BLOCKING, &messageToFace);

	if (GetVerbose())
		SpacePrint("EXTR: Returned from launch face detection for image #%d\n", m_currentBitmapImage);
}
int MTUSB_BLSDriverSetMode( int DevHandle, int Channel, int Mode )
{
	char commandStr[36];
	int error;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;

	if ((Channel != 88) && ((Channel <= 0)||(Channel > deviceChannels[DevHandle])))
		return -1;

	if(Channel == 88)
		sprintf(commandStr, "MODE 88 %d\n\r", Mode);
	else
		sprintf(commandStr, "MODE %d %d\n\r", Channel, Mode);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

	return error;
}
int MTUSB_BLSDriverSetPulseProfile( int DevHandle, int Channel, int Polarity, int PulseCnt, int ReptCnt)
{
	char commandStr[36];
	int error;

	if ((DevHandle < 0) || ( DevHandle >(totalUSBDevices-1) ) || (deviceOpened[DevHandle] == FALSE))
		return -1;

	if ((Channel != 88) && ((Channel <= 0)||(Channel > deviceChannels[DevHandle])))
		return -1;

	if (PulseCnt > MAX_PULSE_COUNT)
		return -1;

	devicePulses[DevHandle][Channel] = PulseCnt ;

    sprintf(commandStr, "Trigger %d 100 %d %d\n\r", Channel, Polarity, ReptCnt);
	ModuleWrite(DevHandle, commandStr, (int) strlen(commandStr), TRUE, error);

	return error;
}
Beispiel #12
0
void matrix_mul::sendResult(unsigned int *result)
{
 ModuleWrite(1, SPACE_BLOCKING, result, 300 * 300);
}
Beispiel #13
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the result
///
//////////////////////////////////////////////////////////////////////////////
void multiplier::sendResult(long data)
{
	ModuleWrite(CONTROLLER_ID, SPACE_BLOCKING, &data);
}
Beispiel #14
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the result
///
//////////////////////////////////////////////////////////////////////////////
void matrix_mul::sendResult() {
 SpacePrint("%d z %d = %d and %d \n", m_operand1[0], m_operand2[0],m_result[0], m_result[100 * 100 - 1]);
 ModuleWrite(1, SPACE_BLOCKING, m_result, 100 * 100);
}
Beispiel #15
0
//////////////////////////////////////////////////////////////////////////////
///
///	send a matrix to matrix_mul
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendMatrixMulOperand(unsigned int* data) {
 ModuleWrite(4, SPACE_BLOCKING, data,
   200 * 200);
}
Beispiel #16
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the matrix multiplication operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendMultiplicationMatOperand(long data)
{
 ModuleWrite(4, SPACE_BLOCKING, matrix_data[data], 30 * 30);
}
Beispiel #17
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the result
///
//////////////////////////////////////////////////////////////////////////////
void matrix_mul::sendResult(long* data)
{
 ModuleWrite(1, SPACE_BLOCKING, data);
}
Beispiel #18
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the addition's operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendAdditionOperand(long data) {
 ModuleWrite(0, SPACE_BLOCKING, &data);
}
Beispiel #19
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the result
///
//////////////////////////////////////////////////////////////////////////////
void multiplier::sendResult(long data)
{
 ModuleWrite(1, SPACE_BLOCKING, &data);
}
Beispiel #20
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the multiplication's operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendMultiplicationOperand(long data) {
 ModuleWrite(5, SPACE_BLOCKING, &data);
}
Beispiel #21
0
void EXTR::thread_extract_jpeg() {
	UINT8 last_marker;
	UINT8 last_returned;
	
    bool end_of_jpeg;
    bool has_at_least_one_jpeg_succeeded;
	
	JMSG outmsg;
	JMSG inmsg;
	
	m_currentJPEGImageNo = 0;
	m_currentBitmapImage = 0;
	m_bufferValid  = false;

	// represents the distance between each jpeg image
	m_jpegDist	= JPEG_IMAGE_SPACER;
	
    has_at_least_one_jpeg_succeeded = false;

	// reset to 0 structures and data related to jpeg decompression
	initialize();

	while(1) {
       end_of_jpeg = false;

		//
		// selection of jpeg preloop - sets pointer on proper image 
		//
        m_currentJPEGImageNo++; 
		if (m_currentJPEGImageNo > MAX_NB_IMAGE)
        {
        	// either we stop when we finish processing the images...
        	launch_face_detection();
        	sc_stop();
			
			// ...or we loop forever (comment out the previous line)
			m_currentJPEGImageNo = 1; 
            if (has_at_least_one_jpeg_succeeded == false)
            {
               SpacePrint("........................................................\n");
               SpacePrint("JPEG DECODER : ALL IMAGES SET FOR DECOMPRESSION\n");
               SpacePrint("HAVE FAILED -- STOPPING\n");
               SpacePrint("........................................................\n");
                sc_stop();
            }
        }

		m_infoImageHeaderAdd = (m_currentJPEGImageNo-1) * m_jpegDist; 	
		m_inputAdd = m_infoImageHeaderAdd + INFO_IMAGE_HEADER;
		m_bufferValid = false;
		computeFor(1);

        if (GetVerbose())
        {
           SpacePrint("EXTR: ********************************************** \n");
           SpacePrint("EXTR: Decompressing JPEG IMAGE no %d\n", m_currentJPEGImageNo);
           SpacePrint("EXTR: Input Address: 0x%x\n", m_inputAdd);
           SpacePrint("EXTR: ********************************************** \n");
        }
        else
        {
           SpacePrint("***JPEG %d\n",m_currentJPEGImageNo);
        }

		//
		// decode jpeg!
		//
		while (!end_of_jpeg) 
		{
			
			//
			// JPEG information is stored in between MARKERS. Each marker tells about 
			// the upcoming information to be read from the data
			//
			// this section scans markers and execute appropriate code according
			// to last marker read
			
			last_marker = read_next_marker();
			computeFor(1);
			
			switch (last_marker)
			{
				
			//
			// START OF FRAME MARKER
			//
			case SOF0:
			case SOF1:
			case SOF2:

                has_at_least_one_jpeg_succeeded = true;
				m_jpeg_decoder_structure.sof = last_marker;

				last_returned = read_sof_marker ();
				if (last_returned != SUCCESS)
				{
					SpacePrint("----------------------------------------\n");
					SpacePrint("EXTRACTOR: JPEG SOF DECODING ERROR no %d - skipping JPEG\n", last_returned); //, this->name(), last_returned);
					initialize();
					end_of_jpeg = true;
				}
					// write image header into memory
					// WORD 1 is X width
					// WORD 2 is Y height
					DeviceWrite(JPEGRAM_ID, m_infoImageHeaderAdd, &m_jpeg_decoder_structure.number_of_samples_per_line);
					DeviceWrite(JPEGRAM_ID, m_infoImageHeaderAdd+0x4ul, &m_jpeg_decoder_structure.number_of_lines);

	                if (GetVerbose())
                    {
					   SpacePrint("EXTR: JPEG STARTING DECOMPRESSION OF IMAGE no%d\n", m_currentJPEGImageNo);
                       SpacePrint("EXTR: Image size: %dx%d\n",
                                      m_jpeg_decoder_structure.number_of_samples_per_line, 
                                      m_jpeg_decoder_structure.number_of_lines);
                    }
                    else
                    {
					   SpacePrint("EXTR:JPEG%d\n", m_currentJPEGImageNo);
                    }


                    communicate_IJPEG(SCMD_NEW_IMAGE);
				//}
				
				break;
				

			//
			// START OF HUFFMAN TABLE MARKER AT 0xffc0
			//	
			case DHT: 
				
				outmsg.command = SCMD_HUFFMAN_DHT;
				outmsg.param0 = m_inputAdd;

				if (GetVerbose())
					SpacePrint("EXTR: Huffman Table found; sending address to HUFF module\n");

				ModuleWrite(HUFF_ID, SPACE_BLOCKING, &outmsg);

				computeFor(1);

				// wait for acknowledgement
				ModuleRead(HUFF_ID, SPACE_BLOCKING, &inmsg);

				if (GetVerbose())
					SpacePrint("EXTR: Return from blocking read - waiting Huffman ACK\n");

				
				// ack received with update with memory pointer
				if (inmsg.command == SCMD_ACK)
				{
					m_inputAdd = inmsg.param0;
					m_bufferValid = false;
				}
				else
				{
					SpacePrint("----------------------------------------\n");
					SpacePrint("EXTRACTOR: JPEG DHT DECODING ERROR no %d - skipping JPEG\n", inmsg.param0); //this->name(), inmsg.param0);
					initialize();
					end_of_jpeg = true;
				}
				break;

			//
			// START OF SCAN MARKER (DATA) AT 0xffda
			//
			case SOS:
				skip_marker ();	
				// extract file information
				/*
				last_returned = read_sos_marker ();
				if (last_returned != SUCCESS)
				{
					SpacePrint("----------------------------------------\n");
					SpacePrint("EXTRACTOR: JPEG SOS DECODING ERROR no %d - skipping JPEG\n", last_returned); //this->name(), last_returned);
					initialize();
					end_of_jpeg = true;
				}
				*/
				
				// this flys through the MCU and keep tracks of the current type of 
				// block being processed - for HUffman_thread. This should be 
				// optimised since it is always 4Y+CB+CR- TODO

				if (GetVerbose())
					SpacePrint("EXTR: Start of Scan Marker found... interleaving scan decoding can start\n");

				decode_interleaved_scan ();

				if (GetVerbose())
				{
					SpacePrint("EXTR: End of Scan Marker... waiting for other modules to finish\n");
				}


				// This is the end of the file, we terminate
				
				communicate_IJPEG(SCMD_END_IMAGE);


				
				// reinitialize buffers for jpeg decompression
				initialize();
				
				// we get off this loop and prepare for next image
				end_of_jpeg = true;

                // we launch execution of face detection - 
                // which emulates somne filters to render
                // new images
                launch_face_detection();
				
				computeFor(1);

				break;
				
			//
			// START OF QUANTIZATION TABLE MARKER AT 0xffdb
			//
			case DQT: 		
				
				// ack received with update with memory pointer
				if (read_dqt_marker() != SUCCESS)
				{
					SpacePrint("----------------------------------------\n");
					SpacePrint("EXTRACTOR: IQTZ DQT DECODING ERROR no %d - skipping JPEG\n", inmsg.param0); //this->name(), inmsg.param0);
					initialize();
					end_of_jpeg = true;
				}
				break;
				
				
			//
			// START OF IMAGE && END OF IMAGE MARKERS
			//
			case SOI:

				if (GetVerbose())
                   SpacePrint("EXTR: START OF IMAGE marker detected - reading image\n");

				break;
				
			//
			// START OF DEFINE RESTORE INTERVAL TABLE MARKER AT 0xffdb
			//
			/*
			case DRI:
				last_returned = read_dri_marker (); // read info and skip
				if (last_returned != SUCCESS)
				{
					SpacePrint("----------------------------------------\n");
					SpacePrint("EXTRACTOR: JPEG DRI DECODING ERROR no %d - skipping JPEG\n", last_returned); //this->name(), last_returned);
					initialize();
					end_of_jpeg = true;
				}
				break;
			*/	
			//
			// END OF IMAGE MARKER - nothing to do
			//
			case MARKER_EOI: // END OF IMAGE MARKER
				break;
				
			//
			// MARKERS WE SKIP
			//
			case APP0:			case APP1:			case APP2:			case APP3:			case APP4:
			case APP5:			case APP6:			case APP7:			case APP8:			case APP9:
			case APP10:			case APP11:			case APP12:			case APP13:			case APP14:
			case APP15:			case COM:			case DRI:
				skip_marker ();				
				break;
				
			//
			// ALL OTHER MARKERS ARE UNSUPPORTED BY THIS APPLICATION
			//
			default: 
				SpacePrint("----------------------------------------\n");
				SpacePrint("EXTRACTOR: JPEG DECODING UNDEFINED MARKER %d - skipping JPEG\n", last_marker); //this->name(), last_marker);
				initialize();
				end_of_jpeg = true;

				break;
			} // switch case
		
		}// while end of jpeg
	
    } // while 1
	
	
	
}
Beispiel #22
0
void matrix_mul::sendResult(unsigned int *result)
{
	ModuleWrite(CONTROLLER_ID, SPACE_BLOCKING, result, MATRIX_ROWS * MATRIX_COLUMNS);
}
Beispiel #23
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the substraction's operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendSubtractionOperand(long data) {
 ModuleWrite(7, SPACE_BLOCKING, &data);
}
Beispiel #24
0
//////////////////////////////////////////////////////////////////////////////
/// 
/// Transmission of New Image command to IQTZ - wait for acknowledgement before
/// continuing
///
//////////////////////////////////////////////////////////////////////////////
void EXTR::communicate_IJPEG(unsigned short command) {
	JMSG newimage_message;

	switch (command)
	{


	case SCMD_NEW_IMAGE:
		
		if (GetVerbose())
			SpacePrint("EXTR: Sending NEW_IMAGE command to IQTZ - waiting for ACK\n");

		newimage_message.command = SCMD_NEW_IMAGE;
		newimage_message.param1 = m_currentJPEGImageNo;		// current image number
		newimage_message.param0 = m_infoImageHeaderAdd;	// current image info header

		computeFor(1);

		// transmitting request for decompressing new jpeg image - 
		// paramete is address of jpeg iomage to decompress
		ModuleWrite(IQTZ_ID, SPACE_BLOCKING, &newimage_message);
		
		computeFor(1);

		// waiting for acknowledgement with a blocking read
		// parameter is address of decompressed-YUV data
		ModuleRead(IQTZ_ID, SPACE_BLOCKING, &newimage_message);

		computeFor(1);

		if (newimage_message.command == SCMD_NEW_IMAGE_ACK) // collect address of bitmap
		{
			m_decompressedImageAddr[m_currentJPEGImageNo-1] = newimage_message.param0;
            //m_decompressedImageAddr[m_currentJPEGImageNo-1][VALID] = FALSE; // image data not valid while decompressing
		}

		if (GetVerbose())
			SpacePrint("EXTR: Return of ACK from IQTZ imageno:%d; address:%d\n", newimage_message.param0, m_decompressedImageAddr[m_currentJPEGImageNo-1]);

		computeFor(1);
		break;	


	case SCMD_END_IMAGE:
		
		if (GetVerbose())
			SpacePrint("EXTR: END_IMAGE command to send to IQTZ\n");


		newimage_message.command = SCMD_END_IMAGE;
		newimage_message.param1 = m_currentJPEGImageNo;
	
		computeFor(1);

		// transmitting end of request decompressing jpeg image - 
		// this tells the IJPEG module it will receive no more data
		
		ModuleWrite(HUFF_ID, SPACE_BLOCKING, &newimage_message);

		computeFor(1);

		// waiting for acknowledgement with a blocking read
		// parameter is address of decompressed-YUV data
		
		ModuleRead(IQTZ_ID, SPACE_BLOCKING, &newimage_message);
		
		computeFor(1);
		
		if (GetVerbose())
			SpacePrint("EXTR: Return of ACK for END_IMAGE command sent\n");

		break;	
	}
}
Beispiel #25
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the division's operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendDivisionOperand(long data) {
 ModuleWrite(2, SPACE_BLOCKING, &data);
}
Beispiel #26
0
//
//  EXTR::decode_interleaved_scan
//////////////////////////////////////////////////////////////////////////////
/// 
/// This is the loop that extracts the jpeg data
/// 
///
/// @return =>  UINT16  : SUCCESS (always)
///
/// @note   =>  
//////////////////////////////////////////////////////////////////////////////
UINT16 EXTR::decode_interleaved_scan() {
	UINT16 i, j, horizontal_mcus, vertical_mcus;
	space_uint2 k, number_of_image_components_in_frame;
	space_uint4 l, m, horizontal_sampling_factor, vertical_sampling_factor;

	JMSG msg;
	
	// use these shortcuts	
	horizontal_mcus = m_jpeg_decoder_structure.horizontal_mcus;
	vertical_mcus = m_jpeg_decoder_structure.vertical_mcus;
	number_of_image_components_in_frame = m_jpeg_decoder_structure.number_of_image_components_in_frame;

	//
	// The jpeg image is stored in minimal component units or mcu. Each unit represents
	// a luminance block (Y) or a chrominance block (C). Since this decoder only supports
	// files that are encoded in the YUV 4:2:0 format, MCUs are stored in groups of 6. 
	// The four first MCUs are luminance component. The two lasts are chrominance Cb and Cr
	// that are colour information for the 4 previous luminance blocks. 
	// This can be seen as follow:
	//
	//		 _____________
	//		|      |      |
	//		|  Y1  |  Y2  |
	//		|   ___|___   |  
	//		|  |   |   |  |
    //      |--|Cb | Cr|--|
    //      |  |___|___|  |
    //      |      |      |
	//		|  Y3  |  Y4  |
	//		|______|______|  
    //


	// we scan all the vertical & horizontal mcus
	for (i=1; i<=vertical_mcus; i++)
	//for (i=1; i<=vertical_mcus/2; i++)
	{
		for (j=1; j<=horizontal_mcus;j++)
		//for (j=1; j<=horizontal_mcus/4;j++)
		{		
			// every mcu is composed of 3 components Y, Cb and Cr
			for (k=0; k<number_of_image_components_in_frame; k ++)
			{
				vertical_sampling_factor = m_jpeg_decoder_structure.vertical_sampling_factor [k];
				horizontal_sampling_factor = m_jpeg_decoder_structure.horizontal_sampling_factor [k];

				computeFor(1);

				for (l=0; l<vertical_sampling_factor; l++)
				{
					for (m=0; m<horizontal_sampling_factor; m++)
					{
						
						// triggers a notification to huffman thread to start Huffman decoding
						m_currentHuffmanComponent = k;

						// send information to HUFF module
						msg.command = SCMD_HUFFMAN_MCU;
						msg.param0 = m_currentHuffmanComponent;
						msg.param1 = m_inputAdd;
						
						computeFor(1);

						// send over request to huffman module
						ModuleWrite(HUFF_ID, SPACE_BLOCKING, &msg);

						computeFor(1);

						ModuleRead(HUFF_ID, SPACE_BLOCKING, &msg);
						
						if (GetVerbose())
						{
							static int roulette = 1;
							switch (roulette)
							{
							case 1: //[
							case 5:
								SpacePrint("|\b");
								break;
							case 2:
							case 7:
								SpacePrint("/\b");
								break;
							case 3:
							case 6:
								SpacePrint("-\b");
								break;
							case 4:
							case 8:
								SpacePrint("\\\b");
								break;
							}

							if (++roulette > 8) roulette = 1;

						}

						if (GetVerbose())
							SpacePrint("EXTR: decode_interleave_scan returned i:%d j:%d k:%d l:%d m:%d\n", i, j, k, l, m);


						if (msg.command != SCMD_ACK)
						{
							SpacePrint("EXTRACTOR ERROR : decode_interleaved has received a FAIL %d from HUFFMAN module\n", msg.param0); //this->name(), msg.param0);
							sc_stop();
						}
						else

						{
							m_inputAdd = msg.param0;
							m_bufferValid = false;
						}

					}
				}
			}
		}
	}
		
	// (.)(.)
	//   <
	//  ____
	// \/  \/
	// when we get here, it's the end of the image!
	
	if (GetVerbose())
		SpacePrint("\n");

 	return SUCCESS;
}
Beispiel #27
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send a character
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendCharacter(unsigned char character) {
 unsigned long data = (unsigned long) character;
 ModuleWrite(6, SPACE_BLOCKING, &data);
}
Beispiel #28
0
//////////////////////////////////////////////////////////////////////////////
///
///	Send the matrix multiplication operand
///
//////////////////////////////////////////////////////////////////////////////
void controller::sendMultiplicationMatOperand(unsigned long data)
{
 ModuleWrite(21, SPACE_BLOCKING, matrix_data[data], 200 * 200);
}