1 /*
2 *
3 * Copyright (C) 2011 Texas Instruments Incorporated - http://www.ti.com/
4 *
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 *
13 * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the
16 * distribution.
17 *
18 * Neither the name of Texas Instruments Incorporated nor the names of
19 * its contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 *
34 */
35 /********************************************************************************************
36 * FILE PURPOSE: Byte swap a CCS data file
37 ********************************************************************************************
38 * FILE NAME: byteswapccs.c
39 *
40 * DESCRIPTION: A CCS file is read in, the data is byte swapped, and a CCS file is written out
41 *
42 * usage: byteswapccs infile outfile
43 *
44 ********************************************************************************************/
45 #include <stdio.h>
46 #include <malloc.h>
49 int main (int argc, char *argv[])
50 {
51 FILE *fin, *fout;
52 unsigned int v, b0, b1, b2, b3;
53 int a, b, c, d, n;
54 int i;
55 char iline[132];
58 if (argc != 3) {
59 fprintf (stderr, "usage: %s infile outfile\n", argv[0]);
60 return (-1);
61 }
64 fin = fopen (argv[1], "r");
65 if (fin == NULL) {
66 fprintf (stderr, "%s: Could not open input file %s\n", argv[1]);
67 return (-1);
68 }
70 fout = fopen (argv[2], "w");
71 if (fout == NULL) {
72 fprintf (stderr, "%s: Could not open output file %s\n", argv[2]);
73 fclose (fin);
74 return (-1);
75 }
78 /* Read the CCS data file header, write it out unchanged */
79 fgets (iline, 132, fin);
80 sscanf (iline, "%x %x %x %x %x", &a, &b, &c, &d, &n);
81 fputs (iline, fout);
83 for (i = 0; i < n; i++) {
84 fgets (iline, 132, fin);
85 sscanf (&iline[2], "%x", &v);
87 b0 = (v >> 24) & 0xff;
88 b1 = (v >> 16) & 0xff;
89 b2 = (v >> 8) & 0xff;
90 b3 = (v >> 0) & 0xff;
92 v = (b3 << 24) | (b2 << 16) | (b1 <<8) | b0;
93 fprintf (fout, "0x%08x\n", v);
94 }
96 fclose (fout);
97 fclose (fin);
99 return (0);
101 }