Part Number: TMS570LC4357
sir i have written a code here i need a help for that
what im doing in that was i want to receive data packets through rs422 to controller tms70ls3137 when im receiving it i should check LRC and CRC for that data packets
/** @file HL_sys_main.c
* @brief Application main file
* @date 11-Dec-2018
* @version 04.07.01
*
* This file contains an empty main function,
* which can be used for the application.
*/
/*
* Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com
*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the
* distribution.
*
* Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
/* USER CODE BEGIN (0) */
#include <stdint.h>
#include <stdbool.h>
#include "HL_sci.h"
#include "HL_system.h"
//#include "HL_LRC.h"
/* USER CODE END */
/* Include Files */
#include "HL_sys_common.h"
/* USER CODE BEGIN (1) */
/*#define NORMAL_TAG_ID 0x9
#define LC_GATE_TAG_ID 0xA
#define ADJACENT_TAG_ID 0xB
#define ADJUSTMENT_TAG_ID 0xC*/
static unsigned char command;
#define TSIZE 254
static uint8 R_Data[TSIZE];
static uint32 size;
//static uint8 Rx_size;
static uint8 TempData[128];
#define BUFFER_SIZE 1024
// uint8_t lrc;
void DataExtraction(const uint8 *text, uint8_t index);
void DataPacket(const uint8_t *Data_Format);
void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length);/*just sci display text is declaration function.*/
void sciSendByte(sciBASE_t *sci, uint8 byte);
void wait(uint32 wait_time); /*waiting function declaration.*/
#define UART sciREG1
#define MAX_PACKET_LENGHT 128
struct DataPacket {
uint8 startValue[4];
uint8 pageData[16];
uint8 dummyDNT[23];
uint8 pageNo[2];
uint8 type[2];
uint8 lrc[2];
};
struct DataPacket datapacket;
/* USER CODE END */
/** @fn void main(void)
* @brief Application main function
* @note This function is empty by default.
*
* This function is called after startup.
* The user can use this function to implement the application.
*/
/* USER CODE BEGIN (2) */
/*uint8_t calculate_lrc(const uint8_t *data, uint32_t size)
{
uint32_t i;
for (i = 0; i < size; i++)
{
lrc ^= data[i];
}
lrc ^= Data_Format.lrc[0];
return lrc;
}*/
void DataPacket(const uint8_t *datapacket)
{
typedef char NullChar;
uint8 i, j = 0, k = 0;
if (datapacket[0] == '$')
{
for (i = 0; i <= size; i++) {
if (datapacket[i] != '|')
{
TempData[j] = datapacket[i];
j++;
}
else
{
TempData[j] = (NullChar)'\0';
k++;
DataExtraction(TempData,k);
j = 0;
}
}
}
// uint8_t lrc = calculate_lrc(packet, size);
//Data_Format.lrc[0] = lrc;
}
void DataExtraction(const uint8 *text, uint8_t index)
{
uint8 i = 0;
switch (index)
{
case 1:
while (text[i] != '\0')
{
datapacket.startValue[i] = text[i];
i++;
}
break;
case 2:
while (text[i] != '\0')
{
datapacket.pageData[i] = text[i];
i++;
}
break;
case 3:
while (text[i] != '\0')
{
datapacket.dummyDNT[i] = text[i];
i++;
}
break;
case 4:
while (text[i] != '\0')
{
datapacket.pageNo[i] = text[i];
i++;
}
break;
case 5:
while (text[i] != '\0')
{
datapacket.type[i] = text[i];
i++;
}
break;
case 6:
while (text[i] != '\0')
{
datapacket.lrc[i] = text[i];
i++;
}
break;
}
sciDisplayText(UART,&TempData[0] ,TSIZE);
}
/*uint8_t DetermainTagType(uint8_t *DataPacket)
{
uint8_t tagType = NORMAL_TAG_ID;
if (DataPacket[0] == LC_GATE_TAG_ID)
{
tagType = LC_GATE_TAG_ID;
} else if (DataPacket[0] == ADJACENT_TAG_ID) {
tagType = ADJACENT_TAG_ID;
} else if (DataPacket[0] == ADJUSTMENT_TAG_ID) {
tagType = ADJUSTMENT_TAG_ID;
}
return tagType;
}*/
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
uint8_t completeBuffer[BUFFER_SIZE * 3];
//uint8_t *dataPacketBytes = (uint8_t *)&Data_Format;
struct DataPacket dataPacket1 = {
.startValue = "$a00",
.pageData = "4699040761993d9e",
.dummyDNT = "0d0c00010400195056005e",
.pageNo = "00",
.type = "04",
.lrc = "b9"
};
memcpy(completeBuffer, &dataPacket1, sizeof(dataPacket1));
// Copy the second data packet into the buffer.
struct DataPacket dataPacket2 = {
.startValue = "$a00",
.pageData = "028e8e82c8b2d05a",
.dummyDNT = "0a0000010400195056005e",
.pageNo = "01",
.type = "04",
.lrc = "2e"
};
memcpy(completeBuffer + sizeof(dataPacket1), &dataPacket2, sizeof(dataPacket2));
// Copy the third data packet into the buffer.
struct DataPacket dataPacket3 = {
.startValue = "$a00",
.pageData = "783a9ccd032c0007",
.dummyDNT = "080000010400195056005e",
.pageNo = "02",
.type = "04",
.lrc = "cc"
};
memcpy(completeBuffer + sizeof(dataPacket1) + sizeof(dataPacket2), &dataPacket3, sizeof(dataPacket3));
int i;
for (i = 0; i <sizeof (completeBuffer) ; i++) {
sciSendByte(sciREG1, completeBuffer[i]);
}
sciInit(); /* initialize sci/sci-lin */
/* even parity , 2 stop bits */
_enable_interrupt_(); /* enable pin intruppt request is access*/
sciEnableNotification(sciREG1, (uint32)SCI_RX_INT);
sciReceive(sciREG1, 1, (unsigned char*) &command);
while(1) /* continious desplay */
{
sciDisplayText(UART,&R_Data[0],TSIZE);
sciDisplayText(UART,&completeBuffer[i],TSIZE);
wait(160000);
size = 0;
};
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
void sciDisplayText(sciBASE_t *sci, uint8 *text, uint32 length)
{
while(length > 0)
{
length--;
while ((UART->FLR & (uint8)0x4) == (uint8)4) /* wait until busy */
{
sciSendByte(UART,*text++); /* send out text */
}
};
}
void sciNotification(sciBASE_t *sci, uint32 flags) /*sci notification function definition is UART and unsigned integers 4byte flags*/
{
if (sci == UART) /*if statements is opened and checking of sci and UART*/
{
sciReceive(sciREG1, 1,(unsigned char*) &command); /*calling function is sci receive communication*/
if (size > MAX_PACKET_LENGHT)
{
size = 0u;
}
if (command == '$') /* validating received data */
{
size = 0u;
}
R_Data[size++] = command; /* Storing in RX variable */
}
}
void wait(uint32 wait_time)
{
while (wait_time > 0)
{
wait_time--;
}
}
/* USER CODE END */

