Ejemplo n.º 1
0
//I would love to get rid of the allocations in the while loop below but sadly 
//I can't predict the size of data blocks well enough to be able to and feel 
//comfortable with it (I could however reduce the number of times I need to 
//reallocate with a little clever logic which i think I will do
bool PFSArchive::Get(std::string filename, char **buffer, size_t& buffer_size) {
    size_t sz = _filenames.size();
    for(size_t index = 0; index < sz; ++index) {
        if(!_filenames[index].compare(filename)) {
            PFSDirectory* directory = NULL;
            PFSDataBlock* data_block = NULL;
            char *temp = NULL;

            size_t position = _files[index];
            BufferRead(directory, PFSDirectory);
            position = directory->offset;

            *buffer = new char[directory->size];
            buffer_size = directory->size;

            size_t inflate = 0;
            while(inflate < directory->size) {
                BufferRead(data_block, PFSDataBlock);
                temp = new char[data_block->deflate_length];
                
                memcpy(temp, &_buffer[position], data_block->deflate_length);
                position += data_block->deflate_length;
                
                decompress(temp, data_block->deflate_length, *buffer + inflate, data_block->inflate_length);
                delete[] temp;
                inflate += data_block->inflate_length;
            }
            buffer_size = inflate;
            return true;
        }
    }

    return false;
}
Ejemplo n.º 2
0
//*****************************************************************************
//
// Prepares a font in the CFSfs file system for use by the graphics library.
//
// This function must be called to prepare a font for use by the graphics
// library.  It opens the font file whose name is passed and reads the
// header information.  The value returned should be written into the
// pucFontId field of the tFontWrapper structure that will be passed to
// graphics library.
//
// This is a very simple (and slow) implementation.  More complex wrappers
// may also initialize a glyph cache here.
//
// \return On success, returns a non-zero pointer identifying the font.  On
// error, zero is returned.
//
//*****************************************************************************
unsigned char *
CFSFontWrapperLoad()
{
    //
    // Make sure a font is not already open.
    //
    if(g_sFontFile.bInUse)
    {
        //
        // Oops - someone tried to load a new font without unloading the
        // previous one.
        //
        printf("Another font is already loaded!\n");
        return(0);
    }

    //
    // We opened the file successfully.  Does it seem to contain a valid
    // font?  Read the header and see.
    //
    BufferRead((uint8_t*)&g_sFontFile.sFontHeader,
                         0,
                         sizeof(tFontWide));
    
    {
        //
        // We read the font header.  Is the format correct? We only support
        // wide fonts via wrappers.
        //
        if((g_sFontFile.sFontHeader.ucFormat != FONT_FMT_WIDE_UNCOMPRESSED) &&
           (g_sFontFile.sFontHeader.ucFormat != FONT_FMT_WIDE_PIXEL_RLE))
        {
            //
            // This is not a supported font format.
            //
            printf("Unrecognized font format. Failing "
                       "CFSFontWrapperLoad.\n");
            return(0);
        }

        //
        // The format seems to be correct so read as many block headers as we
        // have storage for.
        //
        int ulToRead = (g_sFontFile.sFontHeader.usNumBlocks > MAX_FONT_BLOCKS) ?
                    MAX_FONT_BLOCKS * sizeof(tFontBlock) :
                    g_sFontFile.sFontHeader.usNumBlocks * sizeof(tFontBlock);

        BufferRead((uint8_t*)&g_sFontFile.pBlocks, sizeof(tFontWide), ulToRead);
        {
            //
            // All is well.  Tell the caller the font was opened successfully.
            //
            printf("\n$$OK FONT\n");
            g_sFontFile.bInUse = true;
            return((unsigned char *)&g_sFontFile);
        }
    }
}
Ejemplo n.º 3
0
//*****************************************************************************
// @brief  Reboot memory content of LSM303
// @param  None
// @retval None
//*****************************************************************************
void LSM303_Acc_Reboot_Cmd(void)
{
	uint8_t tmpreg;
	BufferRead(LSM_A_ADDRESS, &tmpreg, LSM_A_CTRL_REG2_ADDR, 1);
	tmpreg |= 0x80;
	ByteWrite(LSM_A_ADDRESS, &tmpreg, LSM_A_CTRL_REG2_ADDR);
}
Ejemplo n.º 4
0
//*****************************************************************************
// @brief  Change the lowpower mode for Accelerometer of LSM303
// @param  LowPowerMode : new state for the lowpower mode. 
//		This parameter can be: LSM303_Lowpower_x see LSM303_SPI.h file
// @retval None
//*****************************************************************************
void LSM303_Acc_Lowpower_Cmd(uint8_t LowPowerMode)
{
	uint8_t tmpreg;
	BufferRead(LSM_A_ADDRESS, &tmpreg, LSM_A_CTRL_REG1_ADDR, 1);
	tmpreg &= 0x1F;
	tmpreg |= LowPowerMode;
	ByteWrite(LSM_A_ADDRESS,&tmpreg, LSM_A_CTRL_REG1_ADDR);
}
Ejemplo n.º 5
0
//*****************************************************************************
// @brief  Change the ODR(Output data rate) for Acceleromter of LSM303
// @param  DataRateValue : new ODR value. This parameter can be: 
//		LSM303_ODR_x see LSM303_SPI.h file
// @retval None
//*****************************************************************************
void LSM303_Acc_DataRate_Cmd(uint8_t DataRateValue)
{
	uint8_t tmpreg;
	BufferRead(LSM_A_ADDRESS, &tmpreg, LSM_A_CTRL_REG1_ADDR, 1);
	tmpreg &= 0xE7;
	tmpreg |= DataRateValue;
	ByteWrite(LSM_A_ADDRESS,&tmpreg, LSM_A_CTRL_REG1_ADDR);
}
Ejemplo n.º 6
0
//*****************************************************************************
// @brief  Change the Full Scale of LSM303
// @param  FS_value : new full scale value. This parameter can be: 
//		LSM303_FS_x  see LSM303_SPI.h file
// @retval None
//*****************************************************************************
void LSM303_Acc_FullScale_Cmd(uint8_t FS_value)
{
	uint8_t tmpreg;
	BufferRead(LSM_A_ADDRESS, &tmpreg, LSM_A_CTRL_REG4_ADDR, 1);
	tmpreg &= 0xCF;
	tmpreg |= FS_value;
	ByteWrite(LSM_A_ADDRESS,&tmpreg, LSM_A_CTRL_REG4_ADDR);
}
Ejemplo n.º 7
0
//*****************************************************************************
// @brief  Read LSM303 output register, and calculate the magnetic field 
//		   Magn[Ga]=(out_h*256+out_l)*1000/ SENSITIVITY
// @param  out : buffer to store data
// @retval None
//*****************************************************************************
void LSM303_Magn_Read_Magn(int16_t* out)
{
	uint8_t buffer[6];
	uint8_t crtlB;
	int i;
	double scaleXY, scaleZ;

	BufferRead(LSM_M_ADDRESS, &crtlB, LSM_M_CRB_REG_ADDR, 1);
	
 	switch(crtlB & 0xE0) {
	 	case 0x40:
			scaleXY = LSM_Magn_Sensitivity_XY_1_3Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_1_3Ga;
			break;

	 	case 0x60:
			scaleXY = LSM_Magn_Sensitivity_XY_1_9Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_1_9Ga;
			break;

	 	case 0x80:
			scaleXY = LSM_Magn_Sensitivity_XY_2_5Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_2_5Ga;
			break;

	 	case 0xA0:
			scaleXY = LSM_Magn_Sensitivity_XY_4Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_4Ga;
			break;

	 	case 0xB0:
			scaleXY = LSM_Magn_Sensitivity_XY_4_7Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_4_7Ga;
			break;

	 	case 0xC0:
			scaleXY = LSM_Magn_Sensitivity_XY_5_6Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_5_6Ga;
			break;

	 	case 0xE0:
			scaleXY = LSM_Magn_Sensitivity_XY_8_1Ga;
			scaleZ = LSM_Magn_Sensitivity_Z_8_1Ga;
			break;
	}

 	LSM303_Magn_Read_RawData(out);

	for(i = 0; i < 2; i++){
		out[i] = (uint16_t)(out[i] * scaleXY);
	}

	out[2] *= (uint16_t)(out[2] * scaleZ);
}
Ejemplo n.º 8
0
//*****************************************************************************
// @brief  Read LSM303 magnetic field output register and compute the int16_t value
// @param  out : buffer to store data
// @retval None
//*****************************************************************************
static void LSM303_Magn_Read_RawData(int16_t* out)
{
	uint8_t buffer[6];
	int i;

	BufferRead(LSM_M_ADDRESS, buffer, LSM_M_OUT_X_H_ADDR, 6);

	for(i = 0; i < 3; i++){
		out[i] = ((uint16_t)buffer[2 * i] << 8) | buffer[2 * i + 1];
	}
}
Ejemplo n.º 9
0
void passCircular(CircularBuffer *cb) {
	sn=4;
	int i;
	
	for(i=0;i<MAX_LINE;i++) {
		
		BufferRead(cb, &saved_samples[i]);
		
	}
	
}
Ejemplo n.º 10
0
//*****************************************************************************
// @brief   Read LSM303 output register, and calculate the raw  
//			acceleration [LSB] ACC= (out_h*256+out_l)/16 (12 bit rappresentation)
// @param  out : buffer to store data
// @retval None
//*****************************************************************************
static uint8_t LSM303_Acc_Read_RawData(int16_t* out)
{
	uint8_t buffer[6];
	uint8_t crtl4;
	int i;

	BufferRead(LSM_A_ADDRESS, &crtl4, LSM_A_CTRL_REG4_ADDR, 1);
	BufferRead(LSM_A_ADDRESS, &buffer[0], LSM_A_OUT_X_L_ADDR, 6);

	/* check in the control register4 the data alignment*/
	if(crtl4 & 0x40) {
		for(i = 0; i < 3; i++){
			out[i] = (((uint16_t)buffer[2 * i + 1] << 8) | buffer[2 * i]);
		}
	} else {
		for(i=0; i<3; i++){
			out[i]=((int16_t)((uint16_t)buffer[2*i] << 8) | buffer[2 * i + 1]) >> 4;
		}
	}
	return crtl4;
}
Ejemplo n.º 11
0
//*****************************************************************************
//
// Read a given font block header from the provided file.
//
//*****************************************************************************
static tBoolean
CFSWrapperFontBlockHeaderGet(FILEHANDLE pFile, tFontBlock *pBlock,
                             unsigned long ulIndex)
{
    BufferRead((uint8_t*)pBlock,  
                         sizeof(tFontWide) + (sizeof(tFontBlock) * ulIndex),
                         sizeof(tFontBlock));
    //
    // If we get here, we experienced an error so return a bad return code.
    //
    return(true);
}
Ejemplo n.º 12
0
void BufferClear(Buffer *buffer) {
    int32_t fillCount;
    if ( BufferTail(buffer, &fillCount) ) {
        BufferRead(buffer, fillCount);
    }
}
Ejemplo n.º 13
0
//*****************************************************************************
// @brief  Read LSM303 linear acceleration output register
// @param  out : buffer to store data
// @retval None
//*****************************************************************************
void I2CLSM_Acc_Read_OutReg(uint8_t* out)
{
	BufferRead(LSM_A_ADDRESS, out, (LSM_A_OUT_X_L_ADDR | 0x80), 6);
}
Ejemplo n.º 14
0
bool PFSArchive::Open(std::string filename)
{
    if(!ReadIntoBuffer(filename)) {
        Close();
        return false;
    }

    PFSHeader *header = NULL;
    PFSDirectoryHeader *directory_header = NULL;
    PFSDirectory *directory = NULL;
    PFSDataBlock *data_block = NULL;
    PFSFilenameHeader *filename_header = NULL;
    PFSFilenameEntry *filename_entry = NULL;
    size_t position = 0;

    BufferRead(header, PFSHeader);

    if(header->magic[0] != 'P' ||
        header->magic[1] != 'F' ||
        header->magic[2] != 'S' ||
        header->magic[3] != ' ') 
    {
        Close();
        return false;
    }

    position = header->offset;
    BufferRead(directory_header, PFSDirectoryHeader);

    std::vector<uint32_t> offsets(directory_header->count, 0);
    _filenames.resize(directory_header->count);
    _files.resize(directory_header->count);

    size_t i = 0;
    size_t j = 0;
    size_t running = 0;
    size_t temp_position = 0;
    size_t inflate = 0;
    char temp_buffer[32768];
    char temp_buffer2[32768];
    char temp_string[MAX_FILENAME_SIZE];
    for(; i < directory_header->count; ++i) {
        BufferRead(directory, PFSDirectory);
        if(directory->crc == ntohl(0xC90A5861)) {
            temp_position = position;
            position = directory->offset;
            memset(temp_buffer, 0, directory->size);
            inflate = 0;
            
            while(inflate < directory->size) {
                BufferRead(data_block, PFSDataBlock);
                BufferReadLength(temp_buffer2, data_block->deflate_length);
                decompress(temp_buffer2, data_block->deflate_length, temp_buffer + inflate, data_block->inflate_length);
				inflate += data_block->inflate_length;
            }

            position = temp_position;
            filename_header = (PFSFilenameHeader*)&temp_buffer[0];
            temp_position = sizeof(PFSFilenameHeader);
            
            for(j = 0; j < filename_header->filename_count; ++j)
			{
				filename_entry = (PFSFilenameEntry*)&temp_buffer[temp_position];
                if(filename_entry->filename_length + 1 >= MAX_FILENAME_SIZE) {
                    Close();
                    return false;
                }
				temp_string[filename_entry->filename_length] = 0;
				memcpy(temp_string, &temp_buffer[temp_position + sizeof(PFSFilenameEntry)], filename_entry->filename_length);
                _filenames[j] = temp_string;
				temp_position += sizeof(PFSFilenameEntry) + filename_entry->filename_length;
			}
        } else {
            _files[running] = position - 12;
			offsets[running] = directory->offset;
			++running;
        }
    }

    uint32_t temp = 0;
    for(i = directory_header->count - 2; i > 0; i--) {
        for(j = 0; j < i; j++) {
            if(offsets[j] > offsets[j + 1]) {
                temp = offsets[j];
				offsets[j] = offsets[j + 1];
				offsets[j + 1] = temp;
				temp = _files[j];
				_files[j] = _files[j + 1];
				_files[j + 1] = temp;
            }
        }
    }

    return true;
}
Ejemplo n.º 15
0
/*******************************************************************************
 *  @fn     encodeProcess
 *  @brief  Encode an input video file and output encoded H.264 video file
 *  @param[in] encodeHandle : Hanlde for the encoder
 *  @param[out] outFile		: output encoded H.264 video file
 *  @param[in] oveContext   : Hanlde to the encoder context
 *  @param[in] deviceID     : Device on which encoder context to be created
 *  @param[in] pConfig      : OvConfigCtrl
 *  @return bool : true if successful; otherwise false.
 ******************************************************************************/
bool encodeProcess(OVEncodeHandle *encodeHandle, char *outFile,
			OPContextHandle oveContext, unsigned int deviceId, OvConfigCtrl *pConfig)
{
    cl_int err;
    unsigned int numEventInWaitList = 0;
    OPMemHandle inputSurface;
    OVresult res = 0;


    // Initilizes encoder session & buffers
    // Create an OVE Session (Platform context, id, mode, profile, format, ...)
    // encode task priority. FOR POSSIBLY LOW LATENCY OVE_ENCODE_TASK_PRIORITY_LEVEL2 */
    encodeHandle->session = OVEncodeCreateSession(oveContext, deviceId,
                                pConfig->encodeMode, pConfig->profileLevel,
                                pConfig->pictFormat, info->width,
                                info->height, pConfig->priority);

    if (encodeHandle->session == NULL)
    {
        fprintf(stderr, "OVEncodeCreateSession failed.\n");
        return false;
    }

    // Configure the encoding engine based upon the config file specifications
    res = setEncodeConfig(encodeHandle->session, pConfig);
    if (!res)
    {
        fprintf(stderr, "OVEncodeSendConfig returned error\n");
        return false;
    }

    // Create a command queue
    encodeHandle->clCmdQueue = clCreateCommandQueue((cl_context)oveContext, clDeviceID, 0, &err);
    if(err != CL_SUCCESS)
    {
        fprintf(stderr, "Create command queue failed! Error :%d\n", err);
        return false;
    }


    for(int i = 0; i < MAX_INPUT_SURFACE; i++)
    {
        encodeHandle->inputSurfaces[i] = clCreateBuffer((cl_context)oveContext, CL_MEM_READ_WRITE, hostPtrSize, NULL, &err);

        if (err != CL_SUCCESS)
        {
            fprintf(stderr, "clCreateBuffer returned error %d\n", err);
            return false;
        }
    }

    // Output file handle
    FILE *fw = fopen(outFile, "wb");
    if (fw == NULL)
    {
        printf("Error opening the output file %s\n", outFile);
        return false;
    }

    // Setup the picture parameters
    OVE_ENCODE_PARAMETERS_H264 pictureParameter;
    unsigned int numEncodeTaskInputBuffers = 1;
    OVE_INPUT_DESCRIPTION *encodeTaskInputBufferList
			= (OVE_INPUT_DESCRIPTION *) malloc(sizeof(OVE_INPUT_DESCRIPTION) *
				numEncodeTaskInputBuffers);

	OVE_OUTPUT_DESCRIPTION taskDescriptionList = {sizeof(OVE_OUTPUT_DESCRIPTION), 0, OVE_TASK_STATUS_NONE, 0, 0};

	// Setup the picture parameters
	memset(&pictureParameter, 0, sizeof(OVE_ENCODE_PARAMETERS_H264));
	pictureParameter.size = sizeof(OVE_ENCODE_PARAMETERS_H264);
	pictureParameter.flags.value = 0;
	pictureParameter.flags.flags.reserved = 0;
	pictureParameter.insertSPS = (OVE_BOOL)(currentFrame == 0);
	pictureParameter.pictureStructure = OVE_PICTURE_STRUCTURE_H264_FRAME;
	pictureParameter.forceRefreshMap = (OVE_BOOL)true;
	pictureParameter.forceIMBPeriod = 0;
	pictureParameter.forcePicType = OVE_PICTURE_TYPE_H264_NONE;


	// Go!
    for (currentFrame = 0; currentFrame < (unsigned)info->num_frames; currentFrame++)
    {
    	if (GetAsyncKeyState(VK_F8))
			break;

		while (BufferIsEmpty(frameBuffer))
			Sleep(250); // only bad if encodes more than 1000fps

        inputSurface = encodeHandle->inputSurfaces[currentFrame % MAX_INPUT_SURFACE];

        cl_int status;
		cl_event inMapEvt, unmapEvent;
        void* mapPtr = clEnqueueMapBuffer(encodeHandle->clCmdQueue, (cl_mem)inputSurface,
										CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0,
										hostPtrSize, 0, NULL, &inMapEvt, &status);

        clFlush(encodeHandle->clCmdQueue);
        waitForEvent(inMapEvt);
        clReleaseEvent(inMapEvt);

		//Read into the input surface buffer
        BufferType pBuf = 0;
        BufferRead(frameBuffer, &pBuf);
        memcpy((BYTE*)mapPtr, (BYTE*)pBuf, hostPtrSize);
        free(pBuf);

        clEnqueueUnmapMemObject(encodeHandle->clCmdQueue, (cl_mem)inputSurface, mapPtr, 0, NULL, &unmapEvent);
        clFlush(encodeHandle->clCmdQueue);
        waitForEvent(unmapEvent);
        clReleaseEvent(unmapEvent);

        // use the input surface buffer as our Picture
        encodeTaskInputBufferList[0].bufferType = OVE_BUFFER_TYPE_PICTURE;
        encodeTaskInputBufferList[0].buffer.pPicture =  (OVE_SURFACE_HANDLE) inputSurface;

        // Encode a single picture.
        // calling VCE for frame encode

		// http://stackoverflow.com/questions/9618369/h-264-over-rtp-identify-sps-and-pps-frames
        // pictureParameter.insertSPS = (OVE_BOOL)(currentFrame == 0);

		OPEventHandle event;
		unsigned int iTaskID;

        res = OVEncodeTask(encodeHandle->session, numEncodeTaskInputBuffers,
                  encodeTaskInputBufferList, &pictureParameter, &iTaskID,
                  numEventInWaitList, NULL, &event);

        if (!res)
        {
            fprintf(stderr, "OVEncodeTask returned error %d\n", res);
            return false;
        }

        // Wait for Encode session completes
        err = clWaitForEvents(1, (cl_event*)&(event));
        if (err != CL_SUCCESS)
        {
        	fprintf(stderr, "clWaitForEvents returned error %d\n", err);
            return false;
        }

        // Query output
		unsigned int numTaskDescriptionsRequested = 1;
		unsigned int numTaskDescriptionsReturned = 0;

        //do
        //{
            res = OVEncodeQueryTaskDescription(encodeHandle->session, numTaskDescriptionsRequested,
                                               &numTaskDescriptionsReturned, &taskDescriptionList);
            if (!res)
            {
                fprintf(stderr, "OVEncodeQueryTaskDescription returned error %d\n", err);
                return false;
            }
        //}
        //while (taskDescriptionList.status == OVE_TASK_STATUS_NONE);


		#ifdef DEBUG
        if (numTaskDescriptionsReturned > 1)
			fprintf(stderr, "Warning: numTaskDescriptions returned: %d\n", numTaskDescriptionsReturned);

		if (taskDescriptionList.status != OVE_TASK_STATUS_COMPLETE)
			fprintf(stderr, "Warning: taskDescriptionList.status returned: %d\n", taskDescriptionList.status);
		#endif

        // Write compressed frame to the output file
		if (taskDescriptionList.status == OVE_TASK_STATUS_COMPLETE &&
				taskDescriptionList.size_of_bitstream_data > 0)
		{
			// Write output data
			fwrite(taskDescriptionList.bitstream_data, 1,
				   taskDescriptionList.size_of_bitstream_data, fw);

			OVEncodeReleaseTask(encodeHandle->session, taskDescriptionList.taskID);
		}

        if (event)
            clReleaseEvent((cl_event) event);
    }


	// Free memory resources
    fclose(fw);
    free(encodeTaskInputBufferList);

    return true;
}
Ejemplo n.º 16
0
/**
  * @brief  Main program
  * @param  None
  * @retval None
  */
int main(void)
{
  TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
  TIM_OCInitTypeDef  TIM_OCInitStructure;
  
  BufferInit(&TxRingBuf);
  BufferInit(&RxRingBuf);


  /*!< At this stage the microcontroller clock setting is already configured, 
  this is done through SystemInit() function which is called from startup
  file (startup_stm32f401xx.s) before to branch to application main.
  To reconfigure the default setting of SystemInit() function, refer to
  system_stm32f4xx.c file
  */
  
  /* TIM Configuration */
  //TIM_Config();
  
  /* -----------------------------------------------------------------------
  TIM3 Configuration: generate 4 PWM signals with 4 different duty cycles.
  
  In this example TIM3 input clock (TIM3CLK) is set to 2 * APB1 clock (PCLK1), 
  since APB1 prescaler is different from 1.   
  TIM3CLK = 2 * PCLK1  
  PCLK1 = HCLK / 4 
  => TIM3CLK = HCLK / 2 = SystemCoreClock /2
  
  To get TIM3 counter clock at 14 MHz, the prescaler is computed as follows:
  Prescaler = (TIM3CLK / TIM3 counter clock) - 1
  Prescaler = ((SystemCoreClock /2) /14 MHz) - 1
  
  To get TIM3 output clock at 21 KHz, the period (ARR)) is computed as follows:
  ARR = (TIM3 counter clock / TIM3 output clock) - 1
  = 665
  
  TIM3 Channel1 duty cycle = (TIM3_CCR1/ TIM3_ARR)* 100 = 50%
  TIM3 Channel2 duty cycle = (TIM3_CCR2/ TIM3_ARR)* 100 = 37.5%
  TIM3 Channel3 duty cycle = (TIM3_CCR3/ TIM3_ARR)* 100 = 25%
  TIM3 Channel4 duty cycle = (TIM3_CCR4/ TIM3_ARR)* 100 = 12.5%
  
  Note: 
  SystemCoreClock variable holds HCLK frequency and is defined in system_stm32f4xx.c file.
  Each time the core clock (HCLK) changes, user had to call SystemCoreClockUpdate()
  function to update SystemCoreClock variable value. Otherwise, any configuration
  based on this variable will be incorrect.    
  ----------------------------------------------------------------------- */  
  //===========================================================
  //UART config
  //===========================================================

  USART_InitTypeDef UartHandle;
  GPIO_InitTypeDef GPIO_InitStructure;
  NVIC_InitTypeDef NVIC_InitStructure;
  USART_ClockInitTypeDef USART_ClockInitStruct;
  RCC_ClocksTypeDef RCC_Clocks;
  
  RCC_GetClocksFreq(&RCC_Clocks);
  SysTick_Config(RCC_Clocks.HCLK_Frequency / 100);

  USART_StructInit(&UartHandle);
  USART_ClockStructInit(&USART_ClockInitStruct);

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE);

  GPIO_PinAFConfig(GPIOD, GPIO_PinSource5, GPIO_AF_USART2);
  GPIO_PinAFConfig(GPIOD, GPIO_PinSource6, GPIO_AF_USART2);



  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ;
  GPIO_Init(GPIOD, &GPIO_InitStructure);

  USART_Init(USART2,&UartHandle);

  USART_ClockInit(USART2,&USART_ClockInitStruct);
  USART_ITConfig(USART2,USART_IT_RXNE,ENABLE);
  USART_ITConfig(USART2, USART_IT_TC,ENABLE);


  NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);

  NVIC_InitStructure.NVIC_IRQChannel = USART2_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);

  USART_Cmd(USART2, ENABLE);
  Delay(40);




  Sevenseg_Setup();
  Delay(40);



  USART_SendData(USART2,0xaaaa);
  //GPIO_SetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1);
  GPIO_SetBits(GPIOD,GPIO_Pin_0);
  //======================================================
  //----------------------------------------------------
  //========================================================






//  /* Compute the prescaler value */
//  PrescalerValue = (uint16_t) (SystemCoreClock / 1000000) - 1;
//
//  /* Time base configuration */
//  TIM_TimeBaseStructure.TIM_Period = 5000;
//  TIM_TimeBaseStructure.TIM_Prescaler = PrescalerValue;
//  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
//  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
//
//  TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);
//
//  /* PWM1 Mode configuration: Channel1 */
//  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;
//  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//  TIM_OCInitStructure.TIM_Pulse = CCR1_Val;
//  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
//
//  TIM_OC1Init(TIM3, &TIM_OCInitStructure);
//
//  TIM_OC1PreloadConfig(TIM3, TIM_OCPreload_Enable);
//
//
//  /* PWM1 Mode configuration: Channel2 */
//  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//  TIM_OCInitStructure.TIM_Pulse = CCR2_Val;
//
//  TIM_OC2Init(TIM3, &TIM_OCInitStructure);
//
//  TIM_OC2PreloadConfig(TIM3, TIM_OCPreload_Enable);
//
//  /* PWM1 Mode configuration: Channel3 */
//  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//  TIM_OCInitStructure.TIM_Pulse = CCR3_Val;
//
//  TIM_OC3Init(TIM3, &TIM_OCInitStructure);
//
//  TIM_OC3PreloadConfig(TIM3, TIM_OCPreload_Enable);
//
//  /* PWM1 Mode configuration: Channel4 */
//  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
//  TIM_OCInitStructure.TIM_Pulse = CCR4_Val;
//
//  TIM_OC4Init(TIM3, &TIM_OCInitStructure);
//
//  TIM_OC4PreloadConfig(TIM3, TIM_OCPreload_Enable);
//
//  TIM_ARRPreloadConfig(TIM3, ENABLE);
//
//  /* TIM3 enable counter */
//  TIM_Cmd(TIM3, ENABLE);
  int bts = 0;



  Sevenseg_Send(0x33);

  while (1)
  {

	if(RxRingBuf.length > 10) {
		int i;
		int ntosend = RxRingBuf.length;
		for(i = 0; i < ntosend;i++)
		{
			bts = BufferRead(&RxRingBuf);
			//if(bts == -1) break;
			USART2_SendByte(bts);
		}
		/*
		while(TxRingBuf.length > 0)
		{
			if((TxRingBuf.length > 0) && (USART_GetFlagStatus(USART2, USART_FLAG_TXE) == SET)) {
				BufferSend(&TxRingBuf);
			}
		}
		*/
	}
	  /*
	  GPIO_ResetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1);
	  GPIO_ResetBits(GPIOA,GPIO_Pin_0);


	  //GPIO_ToggleBits(GPIOB, GPIO_Pin_0);
	  GPIO_SetBits(GPIOB,GPIO_Pin_0 | GPIO_Pin_1);
	  GPIO_SetBits(GPIOA,GPIO_Pin_0);
	  */
	  //USART_SendData(USART2,0x0051);
	  //USART_SendData(USART2,0x003b);
  }
}
Ejemplo n.º 17
0
//*****************************************************************************
//
// Retrieves the data for a particular font glyph.  This function returns
// a pointer to the glyph data in linear, random access memory if the glyph
// exists or NULL if not.
//
//*****************************************************************************
static const unsigned char *
CFSWrapperFontGlyphDataGet(unsigned char *pucFontId,
                           unsigned long ulCodepoint,
                           unsigned char *pucWidth)
{
    tFontFile *pFont;
    unsigned long ulLoop, ulGlyphOffset, ulTableOffset;

    tFontBlock sBlock;
    tFontBlock *pBlock;
    tBoolean bRetcode;

    //
    // Parameter sanity check.
    //
    ASSERT(pucFontId);
    ASSERT(pucWidth);

    //
    // If passed a NULL codepoint, return immediately.
    //
    if(!ulCodepoint)
    {
        return(0);
    }

    //
    // Get a pointer to our instance data.
    //
    pFont = (tFontFile *)pucFontId;

    ASSERT(pFont->bInUse);

    //
    // Look for the trivial case - do we have this glyph in our glyph store
    // already?
    //
    if(pFont->ulCurrentGlyph == ulCodepoint)
    {
        //
        // We struck gold - we already have this glyph in our buffer.  Return
        // the width (from the second byte of the data) and a pointer to the
        // glyph data.
        //
        *pucWidth = pFont->pucGlyphStore[1];
        return(pFont->pucGlyphStore);
    }

    //
    // First find the block that contains the glyph we've been asked for.
    //
    for(ulLoop = 0; ulLoop < pFont->sFontHeader.usNumBlocks; ulLoop++)
    {
        if(ulLoop < MAX_FONT_BLOCKS)
        {
            pBlock = &pFont->pBlocks[ulLoop];
        }
        else
        {
            bRetcode = CFSWrapperFontBlockHeaderGet(pFont->sFile, &sBlock,
                                                    ulLoop);
            pBlock = &sBlock;
            if(!bRetcode)
            {
                //
                // We failed to read the block header so return an error.
                //
                return(0);
            }
        }

        //
        // Does the requested character exist in this block?
        //
        if((ulCodepoint >= (pBlock->ulStartCodepoint)) &&
          ((ulCodepoint < (pBlock->ulStartCodepoint +
            pBlock->ulNumCodepoints))))
        {
            //
            // The glyph is in this block. Calculate the offset of it's
            // glyph table entry in the file.
            //
            ulTableOffset = pBlock->ulGlyphTableOffset +
                            ((ulCodepoint - pBlock->ulStartCodepoint) *
                            sizeof(unsigned long));
            
            BufferRead((uint8_t*)&ulGlyphOffset, 
                                 ulTableOffset,
                                 sizeof(unsigned long));

            //
            // Return if there was an error or if the offset is 0 (which
            // indicates that the character is not included in the font.
            //
            if(!ulGlyphOffset)
            {
                return(0);
            }

            //
            // Move the file pointer to the start of the glyph data remembering
            // that the glyph table offset is relative to the start of the
            // block not the start of the file (so we add the table offset
            // here).
            //
            BufferRead(pFont->pucGlyphStore,
                                 pBlock->ulGlyphTableOffset + ulGlyphOffset,
                                 1);
            //
            // Now read the glyph data.
            //
            BufferRead(pFont->pucGlyphStore + 1, 
                                 pBlock->ulGlyphTableOffset + ulGlyphOffset + 1,
                                 pFont->pucGlyphStore[0] - 1);

            //
            // If we get here, things are good. Return a pointer to the glyph
            // store data.
            //
            pFont->ulCurrentGlyph = ulCodepoint;
            *pucWidth = pFont->pucGlyphStore[1];
            return(pFont->pucGlyphStore);
        }
    }

    //
    // If we get here, the codepoint doesn't exist in the font so return an
    // error.
    //
    return(0);
}