1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
|
//*****************************************************************************
//
// ssitrf79x0.c - SSI Driver for the TI TRF79x0 on the dk-lm3s9b96 board.
//
// Copyright (c) 2010-2014 Texas Instruments Incorporated. All rights reserved.
// Software License Agreement
//
// Texas Instruments (TI) is supplying this software for use solely and
// exclusively on TI's microcontroller products. The software is owned by
// TI and/or its suppliers, and is protected under applicable copyright
// laws. You may not combine this software with "viral" open-source
// software in order to form a larger program.
//
// THIS SOFTWARE IS PROVIDED "AS IS" AND WITH ALL FAULTS.
// NO WARRANTIES, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT
// NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. TI SHALL NOT, UNDER ANY
// CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
// DAMAGES, FOR ANY REASON WHATSOEVER.
//
// This is part of revision 2.1.0.12573 of the Tiva Firmware Development Package.
//
//*****************************************************************************
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_gpio.h"
#include "inc/hw_memmap.h"
#include "inc/hw_ssi.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/rom_map.h"
#include "driverlib/ssi.h"
#include "driverlib/sysctl.h"
#include "ssitrf79x0.h"
#include "trf79x0.h"
#include "trf79x0_hw.h"
//*****************************************************************************
//
// Raw SPI through SSI access API for the TRF79x0. Most user code will not and
// should not call these functions but instead use the provided higher level
// functions in trf79x0.c, directmode.c and iso14443a.c.
//
//*****************************************************************************
//*****************************************************************************
//
// Global that holds the clock speed of the MicroController in Hz.
//
//*****************************************************************************
extern uint32_t g_ui32SysClk;
//*****************************************************************************
//
// The rate of the SSI clock and derived values.
//
//*****************************************************************************
#define SSI_CLKS_PER_MS (SSI_CLK_RATE / 1000)
#define STATUS_READS_PER_MS (SSI_CLKS_PER_MS / 16)
#define SSI_NO_DATA 0
//*****************************************************************************
//
// Internal helper function that sends a buffer of data to the TRF79x0, used
// by all the functions that need to send bytes.
//
//*****************************************************************************
void
SSITRF79x0GenericWrite(unsigned char const *pucBuffer, unsigned int uiLength)
{
uint32_t ulDummyData;
while(uiLength > 0)
{
//
// Write address/command/data and clear SSI register of dummy data.
//
MAP_SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)*pucBuffer);
//
// Wait until the SSI Module is completed sending uiLength bytes to the SSI module.
//
while(SSIBusy(TRF79X0_SSI_BASE) == true);
MAP_SSIDataGet(TRF79X0_SSI_BASE, &ulDummyData);
//
// Post increment counters.
//
pucBuffer++;
uiLength--;
}
}
//*****************************************************************************
//
// Internal helper function used by all the functions that need to send bytes.
//
//*****************************************************************************
void
SSITRF79x0DummyWrite(unsigned char const *pucBuffer, unsigned int uiLength)
{
uint32_t ulDummyData;
while(uiLength > 0)
{
//
// Write address/command/data and clear SSI register of dummy data.
//
SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)*pucBuffer);
SSIDataGet(TRF79X0_SSI_BASE, &ulDummyData);
//
// Post increment counters.
//
pucBuffer++;
uiLength--;
}
}
//*****************************************************************************
//
// Internal helper function that receives a buffer of data from the TRF79x0,
// used by all the functions that need to read bytes.
//
//*****************************************************************************
static void
SSITRF79x0GenericRead(unsigned char *pucBuffer, unsigned int uiLength)
{
uint32_t ulData;
while(uiLength > 0)
{
//
// Write dummy data for SSI clock and read data from SSI register.
//
MAP_SSIDataPut(TRF79X0_SSI_BASE, (unsigned long)SSI_NO_DATA);
//
// Wait until the SSI Module is completed sending uiLength bytes to the SSI module.
//
while(SSIBusy(TRF79X0_SSI_BASE) == true);
MAP_SSIDataGet(TRF79X0_SSI_BASE, &ulData);
// SSIDataGet(TRF79X0_SSI_BASE, &ulData);
//
// Read data into buffers and post increment counters.
//
*pucBuffer++ = (unsigned char)ulData;
uiLength--;
}
}
//*****************************************************************************
//
// Asserts the chip select for the TRF79x0.
//
//*****************************************************************************
void
SSITRF79x0ChipSelectAssert(void)
{
//
// Disable the interrupt associated with the TRF79x0.
//
TRF79x0InterruptDisable();
//
// Assert the chip select for TRF79x0.
//
MAP_GPIOPinWrite(TRF79X0_CS_BASE, TRF79X0_CS_PIN, 0);
}
//*****************************************************************************
//
// Deasserts the chip select for the TRF79x0
//
//*****************************************************************************
void
SSITRF79x0ChipSelectDeAssert(void)
{
//
// Deassert the chip select for the TRF79x0.
//
MAP_GPIOPinWrite(TRF79X0_CS_BASE, TRF79X0_CS_PIN, TRF79X0_CS_PIN);
//
// Enable interrupt associated with the TRF79x0.
//
TRF79x0InterruptEnable();
}
//*****************************************************************************
//
// Initializes the SSI port and determines if the TRF79x0 is available.
//
// This function must be called prior to any other function offered by the
// TRF79x0. It configures the SSI port to run in Motorola/Freescale
// mode.
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0Init(void)
{
//
// Enable the peripherals used to drive the TRF79x0 on SSI.
//
MAP_SysCtlPeripheralEnable(TRF79X0_SSI_PERIPH);
//
// Enable the GPIO peripherals associated with the SSI.
//
MAP_SysCtlPeripheralEnable(TRF79X0_CLK_PERIPH);
MAP_SysCtlPeripheralEnable(TRF79X0_RX_PERIPH);
MAP_SysCtlPeripheralEnable(TRF79X0_TX_PERIPH);
MAP_SysCtlPeripheralEnable(TRF79X0_CS_PERIPH);
//
// Configure the appropriate pins to be SSI instead of GPIO. The CS
// is configured as GPIO to support TRF79x0 SPI requirements for R/W
// access.
//
MAP_GPIOPinConfigure(TRF79X0_CLK_CONFIG);
MAP_GPIOPinConfigure(TRF79X0_RX_CONFIG);
MAP_GPIOPinConfigure(TRF79X0_TX_CONFIG);
MAP_GPIOPinTypeSSI(TRF79X0_CLK_BASE, TRF79X0_CLK_PIN);
MAP_GPIOPinTypeSSI(TRF79X0_RX_BASE, TRF79X0_RX_PIN);
MAP_GPIOPinTypeSSI(TRF79X0_TX_BASE, TRF79X0_TX_PIN);
MAP_GPIOPinTypeGPIOOutput(TRF79X0_CS_BASE, TRF79X0_CS_PIN);
MAP_GPIOPadConfigSet(TRF79X0_CLK_BASE, TRF79X0_CLK_PIN,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
MAP_GPIOPadConfigSet(TRF79X0_RX_BASE, TRF79X0_RX_PIN,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
MAP_GPIOPadConfigSet(TRF79X0_TX_BASE, TRF79X0_TX_PIN,
GPIO_STRENGTH_4MA, GPIO_PIN_TYPE_STD_WPU);
//
// Deassert the SSI chip selects TRF79x0.
//
MAP_GPIOPinWrite(TRF79X0_CS_BASE, TRF79X0_CS_PIN, TRF79X0_CS_PIN);
//
// Configure the SSI port for 2MHz operation.
//
MAP_SSIConfigSetExpClk(TRF79X0_SSI_BASE, g_ui32SysClk,
SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, SSI_CLK_RATE,
8);
if(RF_DAUGHTER_TRF7970)
{
//
// Switch from SPH=0 to SPH=1. Required for TRF7970.
//
HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) |= SSI_CR0_SPH;
}
//
// Enable the SSI controller.
//
MAP_SSIEnable(TRF79X0_SSI_BASE);
}
//*****************************************************************************
//
// Writes a single value to TRF79x0 for address provided.
//
// \param ucAddress is the register address to write and must be between 0
// and 0x1f, inclusive.
// \param ucData is the data byte to write.
//
// This function asserts the TRF79x0 chip select, sends a write command,
// the single data value and then deasserts the chip select.
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0WriteRegister(unsigned char ucAddress, unsigned char ucData)
{
unsigned char pucCommand[2];
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Isolate register address.
//
ucAddress = ucAddress & TRF79X0_ADDRESS_MASK;
//
// Add TRF79x0 write single command.
//
ucAddress |= TRF79X0_CONTROL_REG_WRITE | TRF79X0_REG_MODE_SINGLE;
//
// Put the address and data into the buffer.
//
pucCommand[0] = ucAddress;
pucCommand[1] = ucData;
//
// Start the write.
//
SSITRF79x0GenericWrite(pucCommand, sizeof(pucCommand));
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Starts a continuous write operation to the given address.
//
// \param ucAddress is the register address to start this write command and
// must be between 0 and 0x1f, inclusive.
//
// This function asserts the TRF79x0 chip select and sends a write continuous
// command. The chip select stays asserted when the function returns and must
// be released with SSITRF79x0WriteContinuousStop().
//
// Typical usage for a write to multiple registers at once is: one call to
// SSITRF79x0WriteContinuousStart(), one or more calls to
// SSITRF79x0WriteContinuousData() and one call to
// SSITRF79x0WriteContinuousStop().
//
// \sa SSITRF79x0WriteContinuousData()
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0WriteContinuousStart(unsigned char ucAddress)
{
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Isolate register address.
//
ucAddress = ucAddress & TRF79X0_ADDRESS_MASK;
//
// Add TRF79x0 write continuous command.
//
ucAddress |= TRF79X0_CONTROL_REG_WRITE | TRF79X0_REG_MODE_CONTINUOUS;
SSITRF79x0GenericWrite(&ucAddress, 1);
//
// Keep chip select asserted for follow-up calls to
// SSITRF79x0WriteContinuousData(). Calling code must ensure to finish
// with SSITRF79x0WriteContinuousStop().
//
}
//*****************************************************************************
//
// Starts a direct continous write operation
//
// This function asserts the chip select for the TRF79x0.
//
// \return None
//
//*****************************************************************************
void
SSITRF79x0WriteDirectContinuousStart(void)
{
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
}
//*****************************************************************************
//
// Sends data in continuous write mode.
//
// \param pucBuffer is a pointer to the data buffer to write.
// \param uiLength is the length of the data to write in bytes.
//
// This function sends data from the buffer to the TRF79x0. The write must
// have been previously set up with SSITRF79x0WriteContinuousStart().
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0WriteContinuousData(unsigned char const *pucBuffer,
unsigned int uiLength)
{
SSITRF79x0GenericWrite(pucBuffer, uiLength);
}
//*****************************************************************************
//
// Stops a continuous write operation.
//
// This function deasserts the TRF79x0 chip select.
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0WriteContinuousStop(void)
{
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Reads a single value from TRF79x0 at the address provided.
//
// \param ucAddress is the register address to read and must be between 0
// and 0x1f, inclusive.
//
// This function asserts the TRF79x0 chip select, sends a read command,
// reads a single byte and then deasserts the chip select.
//
// \return This function returns the value that was stored in the given
// register.
//
//*****************************************************************************
unsigned char
SSITRF79x0ReadRegister(unsigned char ucAddress)
{
unsigned char ucData = 0;
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Isolate register address.
//
ucAddress = ucAddress & TRF79X0_ADDRESS_MASK;
//
// Add TRF79x0 read single command.
//
ucAddress |= TRF79X0_CONTROL_REG_READ | TRF79X0_REG_MODE_SINGLE;
SSITRF79x0GenericWrite(&ucAddress, 1);
if(RF_DAUGHTER_TRF7960)
{
//
// Switch from SPH=0 to SPH=1.
//
HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) |= SSI_CR0_SPH;
}
//
// Get the data.
//
SSITRF79x0GenericRead(&ucData, 1);
if(RF_DAUGHTER_TRF7960)
{
//
// Switch from SPH=1 to SPH=0.
//
HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) &= ~SSI_CR0_SPH;
}
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
return(ucData);
}
//*****************************************************************************
//
// Starts a continuous read operation from the given address.
//
// \param ucAddress is the register address to start this read command and must
// be between 0 and 0x1f, inclusive.
//
// This function asserts the TRF79x0 chip select and sends a read continuous
// command. The chip select stays asserted when the function returns and must
// be released with SSITRF79x0ReadContinuousStop().
//
// Typical usage for a read from multiple registers at once is: one call to
// SSITRF79x0ReadContinuousStart(), one or more calls to
// SSITRF79x0ReadContinuousData() and one call to
// SSITRF79x0ReadContinuousStop().
//
// \sa SSITRF79x0ReadContinuousData()
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0ReadContinuousStart(unsigned char ucAddress)
{
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Isolate register address.
//
ucAddress = ucAddress & TRF79X0_ADDRESS_MASK;
//
// Add TRF79x0 read continuous command.
//
ucAddress |= TRF79X0_CONTROL_REG_READ | TRF79X0_REG_MODE_CONTINUOUS;
SSITRF79x0GenericWrite(&ucAddress, 1);
if(RF_DAUGHTER_TRF7960)
{
//
// Switch from SPH=0 to SPH=1.
//
HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) |= SSI_CR0_SPH;
}
}
//*****************************************************************************
//
// Receives data in continuous read mode.
//
// \param pucBuffer is a pointer to the data buffer to receive data.
// \param uiLength is the length of the data to read in bytes.
//
// This function reads data from the the TRF79x0 into the buffer. The read
// must have been previously set up with SSITRF79x0ReadContinuousStart().
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0ReadContinuousData(unsigned char *pucBuffer, unsigned int uiLength)
{
SSITRF79x0GenericRead(pucBuffer, uiLength);
}
//*****************************************************************************
//
// Stop a continuous read operation.
//
// This function deasserts the TRF79x0 chip select.
//
// \return None.
//
//*****************************************************************************
void
SSITRF79x0ReadContinuousStop(void)
{
if(RF_DAUGHTER_TRF7960)
{
//
// Switch from SPH=1 to SPH=0.
//
HWREG(TRF79X0_SSI_BASE + SSI_O_CR0) &= ~SSI_CR0_SPH;
}
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Reads IRQ status value from TRF79x0.
//
// This function reads the TRF79x0 IRQ status register 0x0c and returns its
// contents. This will make the TRF79x0 release its interrupt request.
//
// \note You should use this function instead of a direct read from register
// 0x0c if you want to retrieve the IRQ status since this function applies
// a special workaround as indicated in SLOA140.
//
// \return Returns the IRQ status
//
//*****************************************************************************
unsigned char
SSITRF79x0ReadIRQStatus(void)
{
unsigned char pucData[2];
//
// Workaround as per SLOA140: When reading the IRQ status register, do a
// continuous read with an additional register to ensure at least one
// additional SPI clock after reading the IRQ status. Ignore the second
// read result.
//
SSITRF79x0ReadContinuousStart(TRF79X0_IRQ_STATUS_REG);
SSITRF79x0ReadContinuousData(pucData, sizeof(pucData));
SSITRF79x0ReadContinuousStop();
return(pucData[0]);
}
//*****************************************************************************
//
// Executes a direct command on the TRF79x0.
//
// \param ucCommand is the command to be executed and must be a valid command
// code between 0 and 0x1f. Definitions for command codes are given in
// trf79x0.h.
//
// \note This function applies a special workaround as indicated in SLOA140.
//
// \return Returns void.
//
//*****************************************************************************
void
SSITRF79x0WriteDirectCommand(unsigned char ucCommand)
{
unsigned char pucCommand[2];
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Add TRF79x0 direct command.
//
ucCommand = ucCommand | TRF79X0_CONTROL_CMD;
//
// Workaround as per SLOA140: When sending a command, add a dummy cycle.
//
pucCommand[0] = ucCommand;
pucCommand[1] = SSI_NO_DATA;
if(ucCommand == TRF79X0_RESET_FIFO_CMD)
{
SSITRF79x0GenericWrite(pucCommand, sizeof(pucCommand));
}
else
{
SSITRF79x0GenericWrite(pucCommand, 1);
}
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Write Direct Command Tailored for 7970 chip. Ported for redundancy
//
// \param ucCommand is the command to be executed and must be a valid command
// code between 0 and 0x1f. Definitions for command codes are given in
// trf79x0.h. A dummy command is sent after the direct command to handle
// issues with the last command somtimes not processing.
//
//*****************************************************************************
void
SSITRF79x0WriteDirectCommandWithDummy(unsigned char ucCommand)
{
unsigned char pucCommand[2];
//
// Assert the chip select for TRF7970.
//
SSITRF79x0ChipSelectAssert();
//
// Add TRF7970 direct command.
//
ucCommand = ucCommand | TRF79X0_CONTROL_CMD;
//
// Workaround as per SLOA140: When sending a command, add a dummy cycle.
//
pucCommand[0] = ucCommand;
pucCommand[1] = SSI_NO_DATA;
SSITRF79x0GenericWrite(pucCommand, sizeof(pucCommand));
//
// Deassert the chip select for the TRF7970.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Executes a Reset direct command on the TRF79x0.
//
// \param ucCommand is the command to be executed and must be a valid command
// code between 0 and 0x1f. Definitions for command codes are given in
// trf79x0.h.
//
// \note This function applies a special workaround as indicated in SLOA140.
//
// \return Returns void.
//
//*****************************************************************************
void
SSITRF79x0WriteResetFifoDirectCommand(unsigned char ucCommand)
{
unsigned char pucCommand[1];
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
//
// Add TRF79x0 direct command.
//
ucCommand = ucCommand | TRF79X0_CONTROL_CMD;
//
// Workaround as per SLOA140: When sending a command, add a dummy cycle.
//
pucCommand[0] = ucCommand;
SSITRF79x0GenericWrite(pucCommand, sizeof(pucCommand));
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
//*****************************************************************************
//
// Executes: writes a packet to the TRF79x0
//
// \param pui8Buffer
// \param ui8CRCBit
// \param ui8TotalLength
// \param ui8PayloadLength
// \param bHeaderEnable
//
// \note
//
// \return Returns void.
//
//*****************************************************************************
void SSITRF79x0WritePacket(uint8_t *pui8Buffer, uint8_t ui8CRCBit, \
uint8_t ui8TotalLength, uint8_t ui8PayloadLength, bool bHeaderEnable)
{
uint8_t ui8LengthLowerNibble = (ui8TotalLength & 0x0F) << 4;
uint8_t ui8LengthHigherNibble = (ui8TotalLength & 0xF0) >> 4;
uint8_t pui8HeaderData[2];
//
// Assert the chip select for TRF79x0.
//
SSITRF79x0ChipSelectAssert();
if(bHeaderEnable == true)
{
// RESET FIFO
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = 0x8F; // Previous data to TX, RX
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
// CRC COMMAND
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = 0x90 | (ui8CRCBit & 0x01); // Previous data to TX, RX
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
// WRITE TO LENGTH REG
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = 0x3D;
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
// LENGTH HIGH Nibble
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = ui8LengthHigherNibble; // Previous data to TX, RX
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
// LENGTH LOW Nibble
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = ui8LengthLowerNibble; // Previous data to TX, RX
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
}
else
{
//while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
pui8HeaderData[0] = 0x3F;
SSITRF79x0GenericWrite(pui8HeaderData,1);
//while(UCB0STAT & UCBUSY);
}
SSITRF79x0GenericWrite(pui8Buffer,ui8PayloadLength);
//while(ui8PayloadLength > 0)
//{
// while (!(IFG2 & UCB0TXIFG)); // USCI_B0 TX buffer ready?
// UCB0TXBUF = *pui8Buffer; // Previous data to TX, RX
// while(UCB0STAT & UCBUSY);
// pui8Buffer++;
// ui8PayloadLength--;
//}
//
// Deassert the chip select for the TRF79x0.
//
SSITRF79x0ChipSelectDeAssert();
}
|