This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Data which is pointed by pointer is changing...

/*
 * ctrl_uart.c
 *
 *  Created on: 2013. 12. 5.
 *      Author: 70805
 */

#include "ctrl_uart.h"
#include "gcu_type.h"
#include <stdio.h>
#include <stdlib.h>
#include "tactical_pcfg.h" /////dsp bios module include
#include <csl.h>
#include <std.h>
#include <log.h>


static  uint32_t 						*pTx, *pTxReset;
static  uint32_t						*pRx, *pRxReset;


ST_rcv_uart_msg		ST_receive_uart_msg;
ST_uartTmsg_struct	ST_transmit_uart_msg;
ST_tuart_data	ST_uart_inform_data;



uint32_t rcv_uart_msg(ST_rcv_uart_msg* RCV_data)
{

	uint16_t			sum=0;
	uint16_t			i, k, j;
	uint32_t			temp_rx_32=0x18181818;
	uint16_t			temp_rx_16;
	uint16_t			rxBuf[100];
	uint8_t				crc_temp[200];
	pRx		=		(uint32_t*)UART_RX;
	LOG_printf(&trace_debug1,"%x",*pRx);

	
	/* numOfData ����*/
	temp_rx_32 = *pRx;
	LOG_printf(&trace_debug1,"%x",*pRx);
	temp_rx_32 = temp_rx_32 & 0x0000FFFF;
	rxBuf[0] = (uint16_t)temp_rx_32;
	LOG_printf(&trace_debug1,"%x",*pRx);
	RCV_data->Num_data =	rxBuf[0];
	LOG_printf(&trace_debug1,"%x",*pRx);

	/* controlWord + data ���� */
	for(k=0; k<RCV_data->Num_data; k++)
	{
		temp_rx_32 = *pRx;
		temp_rx_16 = (uint16_t)(temp_rx_32 & 0x0000FFFF);
		LOG_printf(&trace_debug1,"%x",*pRx);
		rxBuf[k+1] = temp_rx_16;
	}

	RCV_data->Opcode_uart_data =	(uint8_t)(rxBuf[1]>>8);
	RCV_data->Status_uart_data =	rxBuf[1];
	RCV_data->Code = (uint8_t)(rxBuf[2]>>8);
	RCV_data->target = rxBuf[2];

	trv_uart_msg(0x000d, 0x01, 0x02, &ST_uart_inform_data );

	for(i=0; i<RCV_data->Num_data - 2; i++)
	{
		RCV_data->data[i] = rxBuf[i+3];
	}


	/* crc check */
	RCV_data->crc_data = rxBuf[RCV_data->Num_data + 1];
	for(i=0,j=0; j<RCV_data->Num_data + 1; i+=2,j++)
	{
	       crc_temp[i] = (uint8_t)(rxBuf[j]>>8);
	       crc_temp[i+1] = (uint8_t)(rxBuf[j]&0xFF);
	}

	for(i=0; i<(RCV_data->Num_data + 1)*2; i++)
	{
			sum = calc_crc16((uint16_t)crc_temp[i],sum);
	}

	if(RCV_data->crc_data != sum)
	{
			return 0;
	}

	pRxReset = (uint32_t*)(UART_RX_RESET);
	*pRxReset				= 0x5A5A5A5A;
	decode_opcode();
	return 1;

}


uint16_t calc_crc16(uint16_t data_byte, uint16_t crc)
{
	int32_t 				i;
	uint32_t 				tmp, data_int;

	data_int = (uint16_t)data_byte << 8;
	for(i=0 ; i < 8 ; i++)
	{
		tmp = data_int ^ crc ;
		crc <<= 1;
		if(tmp & 0x8000) crc ^= POLY16;
		data_int <<= 1;
	}
	return crc;
}


void	trv_uart_msg(uint16_t msgSize, uint8_t opcode , uint8_t status, ST_tuart_data*  data)
{

	ST_transmit_uart_msg.Num_data = msgSize;
	ST_transmit_uart_msg.Opcode_uart_data = opcode;
	ST_transmit_uart_msg.Status_uart_data = status;
	uint32_t				i, j;
	uint16_t				sum = 0;
	uint16_t				TxBuf[200];
	uint8_t				crcBuf[200];
	pTxReset	=	(uint32_t*)UART_TX_RESET;
	*pTxReset			= 0x5A5A5A5A;
	pTx	=	(uint32_t*)UART_TX;
	


	TxBuf[0] = ST_transmit_uart_msg.Num_data;
	TxBuf[1] = ((int16_t)(ST_transmit_uart_msg.Opcode_uart_data<<8))|((int16_t)(ST_transmit_uart_msg.Status_uart_data));

	/* uart data�� txBuf ���� */ 
	for(i=0; i<ST_transmit_uart_msg.Num_data-1;i++)		//	numOfData���� Control Word 1 ����
	{
		TxBuf[i+2] = data->inform[i];
	}

 	/* crc check */
 	for(i=0,j=0; j<ST_transmit_uart_msg.Num_data + 1; i+=2,j++)
 	{
 	       crcBuf[i] = (uint8_t)(TxBuf[j]>>8);
 	       crcBuf[i+1] = (uint8_t)(TxBuf[j]&0xFF);
 	}

	/* CRC16 */
	for(i=0; i<(ST_transmit_uart_msg.Num_data + 1)*2; i++)
	{
			sum = calc_crc16((uint16_t)crcBuf[i],sum);
	}

	/* CRC load*/

	TxBuf[ST_transmit_uart_msg.Num_data+1] = sum;

	/* load tx data */
	for(i=0; i<ST_transmit_uart_msg.Num_data+2; i++)
	{
		*pTx = (uint32_t)TxBuf[i];

	}


	return;
}



void decode_opcode(void)
{
	uint8_t	opcode;
	opcode = ST_receive_uart_msg.Opcode_uart_data;
	switch(opcode)
		{
			case FLASH_CMD:
				flash_mode();
				break;
			case EPA_BIT:
			//	bit_mode();
				break;
			case IMU_TEST:
			//	imu_test_mode();
				break;
			default:
				trv_uart_msg(0x0007, 0x18, 0x18, &ST_uart_inform_data);
				break;
		}
}






hi

my problem is pointer.

i am using ccs5.5.   and data is pointed by Pointer(pRx) is changing without calling in the debug mode.

following is function with problem.

Pointer pRx is pointing FIFO Address in the FPGA.

so pRx have address single address which is not chaning address.

but DATA pointed by pRx is changing after  pRx  =  (uint32_t*)UART_RX; execute.

you can see the *pRx is changing with logprintf...

please help me

uint32_t rcv_uart_msg(ST_rcv_uart_msg* RCV_data) is sem posted by SWI module.

uint32_t rcv_uart_msg(ST_rcv_uart_msg* RCV_data)
{

 uint16_t   sum=0;
 uint16_t   i, k, j;
 uint32_t   temp_rx_32=0x18181818;
 uint16_t   temp_rx_16;
 uint16_t   rxBuf[100];
 uint8_t    crc_temp[200];
 pRx  =  (uint32_t*)UART_RX;
 LOG_printf(&trace_debug1,"%x",*pRx);

 
 /* numOfData 수신*/
 temp_rx_32 = *pRx;
 LOG_printf(&trace_debug1,"%x",*pRx);
 temp_rx_32 = temp_rx_32 & 0x0000FFFF;
 rxBuf[0] = (uint16_t)temp_rx_32;
 LOG_printf(&trace_debug1,"%x",*pRx);
 RCV_data->Num_data = rxBuf[0];
 LOG_printf(&trace_debug1,"%x",*pRx);

 /* controlWord + data 수신 */
 for(k=0; k<RCV_data->Num_data; k++)
 {
  temp_rx_32 = *pRx
  temp_rx_16 = (uint16_t)(temp_rx_32 & 0x0000FFFF);
  LOG_printf(&trace_debug1,"%x",*pRx);
  rxBuf[k+1] = temp_rx_16;
 }

  • What is the definition of UART_RX? Is a volatile uint32_t pointer to literal address? If so, then you should use

    pRx  =  &UART_RX;

    Also, if UART_RX is a FIFO, then "LOG_printf(&trace_debug1,"%x",*pRx);" has the side effect of removing data from the FIFO. Data would have the appearance of being lost.

  • Choi,

    You do not show the declaration for pRx, but if it is pointing to a peripheral location that will change over time, it must be declared as a pointer to a volatile data type. For example,

    (volatile unsigned int) * pRx;

    I am not sure if the () are required; I tend to overuse them to make sure the compiler knows I want the target data to be volatile and not the pointer variable.

    Regards,
    RandyP