OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [freertos-6.1.1/] [Demo/] [CORTEX_LM3S316_IAR/] [hw_include/] [pdc.c] - Blame information for rev 581

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 581 jeremybenn
//*****************************************************************************
2
//
3
// pdc.c - Driver for the Peripheral Device Controller (PDC) on the Stellaris
4
//         development board.
5
//
6
// Copyright (c) 2005,2006 Luminary Micro, Inc.  All rights reserved.
7
//
8
// Software License Agreement
9
//
10
// Luminary Micro, Inc. (LMI) is supplying this software for use solely and
11
// exclusively on LMI's Stellaris Family of microcontroller products.
12
//
13
// The software is owned by LMI and/or its suppliers, and is protected under
14
// applicable copyright laws.  All rights are reserved.  Any use in violation
15
// of the foregoing restrictions may subject the user to criminal sanctions
16
// under applicable laws, as well as to civil liability for the breach of the
17
// terms and conditions of this license.
18
//
19
// THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
20
// OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
21
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
22
// LMI SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR
23
// CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
24
//
25
// This is part of revision 635 of the Stellaris Driver Library.
26
//
27
//*****************************************************************************
28
 
29
//*****************************************************************************
30
//
31
//! \addtogroup utilities_api
32
//! @{
33
//
34
//*****************************************************************************
35
 
36
#include "hw_memmap.h"
37
#include "hw_types.h"
38
#include "debug.h"
39
#include "gpio.h"
40
#include "ssi.h"
41
#include "sysctl.h"
42
#include "pdc.h"
43
 
44
//*****************************************************************************
45
//
46
//! Initializes the connection to the PDC.
47
//!
48
//! This function will enable clocking to the SSI and GPIO A modules, configure
49
//! the GPIO pins to be used for an SSI interface, and it will configure the
50
//! SSI as a 1 Mbps master device, operating in MOTO mode.  It will also enable
51
//! the SSI module, and will enable the chip select for the PDC on the
52
//! Stellaris development board.
53
//!
54
//! This function is contained in <tt>utils/pdc.c</tt>, with
55
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
56
//!
57
//! \return None.
58
//
59
//*****************************************************************************
60
void
61
PDCInit(void)
62
{
63
    //
64
    // Enable the peripherals used to drive the PDC.
65
    //
66
    SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI);
67
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
68
 
69
    //
70
    // Configure the appropriate pins to be SSI instead of GPIO.
71
    //
72
    GPIODirModeSet(GPIO_PORTA_BASE, SSI_CLK | SSI_TX | SSI_RX,
73
                   GPIO_DIR_MODE_HW);
74
    GPIODirModeSet(GPIO_PORTA_BASE, SSI_CS, GPIO_DIR_MODE_OUT);
75
    GPIOPadConfigSet(GPIO_PORTA_BASE, SSI_CLK, GPIO_STRENGTH_4MA,
76
                     GPIO_PIN_TYPE_STD_WPU);
77
 
78
    //
79
    // Configure the SSI port.
80
    //
81
    SSIConfigSetExpClk(SSI_BASE, SysCtlClockGet(), SSI_FRF_MOTO_MODE_0,
82
                       SSI_MODE_MASTER, 1000000, 8);
83
    SSIEnable(SSI_BASE);
84
 
85
    //
86
    // Reset the PDC SSI state machine.  The chip select needs to be held low
87
    // for 100ns; the procedure call overhead more than accounts for this time.
88
    //
89
    GPIOPinWrite(GPIO_PORTA_BASE, PDC_CS, 0);
90
    GPIOPinWrite(GPIO_PORTA_BASE, PDC_CS, PDC_CS);
91
}
92
 
93
//*****************************************************************************
94
//
95
//! Read a PDC register.
96
//!
97
//! \param ucAddr specifies the PDC register to read.
98
//!
99
//! This function will perform the SSI transfers required to read a register in
100
//! the PDC on the Stellaris development board.
101
//!
102
//! This function is contained in <tt>utils/pdc.c</tt>, with
103
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
104
//!
105
//! \return Returns the value read from the PDC.
106
//
107
//*****************************************************************************
108
unsigned char
109
PDCRead(unsigned char ucAddr)
110
{
111
    unsigned long ulTemp;
112
 
113
    //
114
    // Send address and read command.
115
    //
116
    SSIDataPut(SSI_BASE, (ucAddr & 0x0F) | PDC_RD);
117
 
118
    //
119
    // Dummy write to force read.
120
    //
121
    SSIDataPut(SSI_BASE, 0x00);
122
 
123
    //
124
    // Flush data read during address write.
125
    //
126
    SSIDataGet(SSI_BASE, &ulTemp);
127
 
128
    //
129
    // If the LCD control register or RAM is being read, then an additional
130
    // byte needs to be transferred.
131
    //
132
    if((ucAddr == PDC_LCD_CSR) || (ucAddr == PDC_LCD_RAM))
133
    {
134
        //
135
        // Dummy write to force read.
136
        //
137
        SSIDataPut(SSI_BASE, 0x00);
138
 
139
        //
140
        // Flush read data.
141
        //
142
        SSIDataGet(SSI_BASE, &ulTemp);
143
    }
144
 
145
    //
146
    // Read valid data.
147
    //
148
    SSIDataGet(SSI_BASE, &ulTemp);
149
 
150
    //
151
    // Return the data read.
152
    //
153
    return(ulTemp & 0xFF);
154
}
155
 
156
//*****************************************************************************
157
//
158
//! Write a PDC register.
159
//!
160
//! \param ucAddr specifies the PDC register to write.
161
//! \param ucData specifies the data to write.
162
//!
163
//! This function will perform the SSI transfers required to write a register
164
//! in the PDC on the Stellaris development board.
165
//!
166
//! This function is contained in <tt>utils/pdc.c</tt>, with
167
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
168
//!
169
//! \return None.
170
//
171
//*****************************************************************************
172
void
173
PDCWrite(unsigned char ucAddr, unsigned char ucData)
174
{
175
    unsigned long ulTemp;
176
 
177
    //
178
    // Send address and write command.
179
    //
180
    SSIDataPut(SSI_BASE, (ucAddr & 0x0F) | PDC_WR);
181
 
182
    //
183
    // Write the data.
184
    //
185
    SSIDataPut(SSI_BASE, ucData);
186
 
187
    //
188
    // Flush data read during address write.
189
    //
190
    SSIDataGet(SSI_BASE, &ulTemp);
191
 
192
    //
193
    // Flush data read during data write.
194
    //
195
    SSIDataGet(SSI_BASE, &ulTemp);
196
}
197
 
198
//*****************************************************************************
199
//
200
//! Read the current value of the PDC DIP switches.
201
//!
202
//! This function will read the current value of the DIP switches attached to
203
//! the PDC on the Stellaris development board.
204
//!
205
//! This function is contained in <tt>utils/pdc.c</tt>, with
206
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
207
//!
208
//! \return The current state of the DIP switches.
209
//
210
//*****************************************************************************
211
unsigned char
212
PDCDIPRead(void)
213
{
214
    return(PDCRead(PDC_DSW));
215
}
216
 
217
//*****************************************************************************
218
//
219
//! Write to the PDC LEDs.
220
//!
221
//! \param ucLED value to write to the LEDs.
222
//!
223
//! This function set the state of the LEDs connected to the PDC on the
224
//! Stellaris development board.
225
//!
226
//! This function is contained in <tt>utils/pdc.c</tt>, with
227
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
228
//!
229
//! \return None.
230
//
231
//*****************************************************************************
232
void
233
PDCLEDWrite(unsigned char ucLED)
234
{
235
    PDCWrite(PDC_LED, ucLED);
236
}
237
 
238
//*****************************************************************************
239
//
240
//! Read the current status of the PDC LEDs.
241
//!
242
//! This function will read the state of the LEDs connected to the PDC on the
243
//! Stellaris development board.
244
//!
245
//! This function is contained in <tt>utils/pdc.c</tt>, with
246
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
247
//!
248
//! \return The value currently displayed by the LEDs.
249
//
250
//*****************************************************************************
251
unsigned char
252
PDCLEDRead(void)
253
{
254
    return(PDCRead(PDC_LED));
255
}
256
 
257
//*****************************************************************************
258
//
259
//! Initializes the LCD display.
260
//!
261
//! This function will set up the LCD display for writing. It will set the
262
//! data bus to 8 bits, set the number of lines to 2, and the font size to
263
//! 5x10. It will also turn the display off, clear the display, turn the
264
//! display back on, and enable the backlight.
265
//!
266
//! This function is contained in <tt>utils/pdc.c</tt>, with
267
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
268
//!
269
//! \note The PDC must be initialized via the PDCInit() function before this
270
//! function can be called.  Also, it may be necessary to adjust the contrast
271
//! potentiometer in order to discern any output on the LCD display.
272
//!
273
//! \return None.
274
//
275
//*****************************************************************************
276
void
277
PDCLCDInit(void)
278
{
279
    unsigned char pucCfg[] =
280
    {
281
        0x3C,   // Number of lines = 2 / font = 5x10
282
        0x08,   // Display off
283
        0x01,   // Display clear
284
        0x06,   // Entry mode [cursor dir][shift]
285
        0x0C,   // Display on [display on][curson on][blinking on]
286
    };
287
    unsigned long ulIdx;
288
 
289
    //
290
    // Set the data bus width to eight bits.
291
    //
292
    PDCWrite(PDC_LCD_CSR, 0x30);
293
 
294
    //
295
    // Wait for 4.1ms by reading the PDC version register enough times to
296
    // guarantee that amount of time has passed.
297
    //
298
    for(ulIdx = 0; ulIdx < 257; ulIdx++)
299
    {
300
        PDCRead(PDC_VER);
301
    }
302
 
303
    //
304
    // Set the data bus width to eight bits.
305
    //
306
    PDCWrite(PDC_LCD_CSR, 0x30);
307
 
308
    //
309
    // Wait for 100us by reading the PDC version register enough times to
310
    // guarantee that amount of time has passed.  This works out to 112us plus
311
    // overhead.
312
    //
313
    for(ulIdx = 0; ulIdx < 7; ulIdx++)
314
    {
315
        PDCRead(PDC_VER);
316
    }
317
 
318
    //
319
    // Set the data bus width to eight bits.
320
    //
321
    PDCWrite(PDC_LCD_CSR, 0x30);
322
 
323
    //
324
    // Configure the LCD.
325
    //
326
    for(ulIdx = 0; ulIdx < (sizeof(pucCfg) / sizeof(pucCfg[0])); ulIdx++)
327
    {
328
        //
329
        // Wait until the LCD has finished executing any previous command.
330
        //
331
        while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
332
        {
333
        }
334
 
335
        //
336
        // Write the next configuration byte.
337
        //
338
        PDCWrite(PDC_LCD_CSR, pucCfg[ulIdx]);
339
    }
340
}
341
 
342
//*****************************************************************************
343
//
344
//! Turns on the backlight.
345
//!
346
//! This function turns on the backlight on the LCD.
347
//!
348
//! This function is contained in <tt>utils/pdc.c</tt>, with
349
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
350
//!
351
//! \return None.
352
//
353
//*****************************************************************************
354
void
355
PDCLCDBacklightOn(void)
356
{
357
    PDCWrite(PDC_CSR, 0x01);
358
}
359
 
360
//*****************************************************************************
361
//
362
//! Turn off the backlight.
363
//!
364
//! This function turns off the backlight on the LCD.
365
//!
366
//! This function is contained in <tt>utils/pdc.c</tt>, with
367
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
368
//!
369
//! \return None.
370
//
371
//*****************************************************************************
372
void
373
PDCLCDBacklightOff(void)
374
{
375
    PDCWrite(PDC_CSR, 0x00);
376
}
377
 
378
//*****************************************************************************
379
//
380
//! Clear the screen.
381
//!
382
//! This function clears the contents of the LCD screen.  The cursor will be
383
//! returned to the upper left corner.
384
//!
385
//! This function is contained in <tt>utils/pdc.c</tt>, with
386
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
387
//!
388
//! \return None.
389
//
390
//*****************************************************************************
391
void
392
PDCLCDClear(void)
393
{
394
    //
395
    // Wait until the LCD has finished executing any previous command.
396
    //
397
    while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
398
    {
399
    }
400
 
401
    //
402
    // Write the clear display command.
403
    //
404
    PDCWrite(PDC_LCD_CSR, LCD_CLEAR);
405
}
406
 
407
//*****************************************************************************
408
//
409
//! Write a character pattern to the LCD.
410
//!
411
//! \param ucChar is the character index to create.  Valid values are zero
412
//! through seven.
413
//! \param pucData is the data for the character pattern.  It contains eight
414
//! bytes, with the first byte being the top row of the pattern.  In each byte,
415
//! the LSB is the right pixel of the pattern.
416
//!
417
//! This function will write a character pattern into the LCD for use as a
418
//! character to be displayed.  After writing the pattern, it can be used on
419
//! the LCD by writing the corresponding character index to the display.
420
//!
421
//! This function is contained in <tt>utils/pdc.c</tt>, with
422
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
423
//!
424
//! \return None.
425
//
426
//*****************************************************************************
427
void
428
PDCLCDCreateChar(unsigned char ucChar, unsigned char *pucData)
429
{
430
    //
431
    // Check the arguments.
432
    //
433
    ASSERT(ucChar < 8);
434
 
435
    //
436
    // Wait until the LCD has finished executing any previous command.
437
    //
438
    while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
439
    {
440
    }
441
 
442
    //
443
    // Write the character pattern memory address.
444
    //
445
    PDCWrite(PDC_LCD_CSR, LCD_CGADDR + (ucChar * 8));
446
 
447
    //
448
    // Write the pattern to chacter pattern memory.
449
    //
450
    for(ucChar = 0; ucChar < 8; ucChar++)
451
    {
452
        //
453
        // Wait until the LCD has finished executing any previous command.
454
        //
455
        while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
456
        {
457
        }
458
 
459
        //
460
        // Write this row of the pattern.
461
        //
462
        PDCWrite(PDC_LCD_RAM, *pucData++);
463
    }
464
}
465
 
466
//*****************************************************************************
467
//
468
//! Set the position of the cursor.
469
//!
470
//! \param ucX is the horizontal position.  Valid values are zero through
471
//! fifteen.
472
//! \param ucY is the vertical position.. Valid values are zero and one.
473
//!
474
//! This function will move the cursor to the specified position.  All
475
//! characters written to the LCD are placed at the current cursor position,
476
//! which is automatically advanced.
477
//!
478
//! This function is contained in <tt>utils/pdc.c</tt>, with
479
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
480
//!
481
//! \return None.
482
//
483
//*****************************************************************************
484
void
485
PDCLCDSetPos(unsigned char ucX, unsigned char ucY)
486
{
487
    //
488
    // Check the arguments.
489
    //
490
    ASSERT(ucX < 16);
491
    ASSERT(ucY < 2);
492
 
493
    //
494
    // Wait until the LCD has finished executing any previous command.
495
    //
496
    while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
497
    {
498
    }
499
 
500
    //
501
    // Set the cursor position.
502
    //
503
    PDCWrite(PDC_LCD_CSR, LCD_DDADDR | (0x40 * ucY) + ucX);
504
}
505
 
506
//*****************************************************************************
507
//
508
//! Writes a string to the LCD display.
509
//!
510
//! \param pcStr pointer to the string to be displayed.
511
//! \param ulCount is the number of characters to be displayed.
512
//!
513
//! This function will display a string on the LCD at the current cursor
514
//! position.  It is the caller's responsibility to position the cursor to the
515
//! place where the string should be displayed (either explicitly via
516
//! PDCLCDSetPos() or implicitly from where the cursor was left after a
517
//! previous call to PDCLCDWrite()), and to properly account for the LCD
518
//! boundary (line wrapping is not automatically performed).  Null characters
519
//! are not treated special and are written to the LCD, which interprets it as
520
//! a special programmable character glyph (see PDCLCDCreateChar()).
521
//!
522
//! This function is contained in <tt>utils/pdc.c</tt>, with
523
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
524
//!
525
//! \return None.
526
//
527
//*****************************************************************************
528
void
529
PDCLCDWrite(const char *pcStr, unsigned long ulCount)
530
{
531
    //
532
    // Write the string to the LCD.
533
    //
534
    while(ulCount--)
535
    {
536
        //
537
        // Wait until the LCD has finished executing any previous command.
538
        //
539
        while((PDCRead(PDC_LCD_CSR) & LCD_B_BUSY))
540
        {
541
        }
542
 
543
        //
544
        // Write this character to the LCD.
545
        //
546
        PDCWrite(PDC_LCD_RAM, *pcStr++);
547
    }
548
}
549
 
550
//*****************************************************************************
551
//
552
//! Reads a GPIO direction register.
553
//!
554
//! \param ucIdx is the index of the GPIO direction register to read; valid
555
//! values are 0, 1, and 2.
556
//!
557
//! This function reads one of the GPIO direction registers in the PDC.  The
558
//! direction bit is set for pins that are outputs and clear for pins that are
559
//! inputs.
560
//!
561
//! This function is contained in <tt>utils/pdc.c</tt>, with
562
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
563
//!
564
//! \return The contents of the direction register.
565
//
566
//*****************************************************************************
567
unsigned char
568
PDCGPIODirRead(unsigned char ucIdx)
569
{
570
    //
571
    // Check the argument.
572
    //
573
    ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
574
 
575
    //
576
    // Read the requested direction register.
577
    //
578
    if(ucIdx == 0)
579
    {
580
        return(PDCRead(PDC_GPXDIR));
581
    }
582
    else if(ucIdx == 1)
583
    {
584
        return(PDCRead(PDC_GPYDIR));
585
    }
586
    else
587
    {
588
        return(PDCRead(PDC_GPZDIR));
589
    }
590
}
591
 
592
//*****************************************************************************
593
//
594
//! Write a GPIO direction register.
595
//!
596
//! \param ucIdx is the index of the GPIO direction register to write; valid
597
//! values are 0, 1, and 2.
598
//! \param ucValue is the value to write to the GPIO direction register.
599
//!
600
//! This function writes ones of the GPIO direction registers in the PDC.  The
601
//! direction bit should be set for pins that are to be outputs and clear for
602
//! pins that are to be inputs.
603
//!
604
//! This function is contained in <tt>utils/pdc.c</tt>, with
605
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
606
//!
607
//! \return None.
608
//
609
//*****************************************************************************
610
void
611
PDCGPIODirWrite(unsigned char ucIdx, unsigned char ucValue)
612
{
613
    //
614
    // Check the arguments.
615
    //
616
    ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
617
 
618
    //
619
    // Write the requested direction register.
620
    //
621
    if(ucIdx == 0)
622
    {
623
        PDCWrite(PDC_GPXDIR, ucValue);
624
    }
625
    else if(ucIdx == 1)
626
    {
627
        PDCWrite(PDC_GPYDIR, ucValue);
628
    }
629
    else
630
    {
631
        PDCWrite(PDC_GPZDIR, ucValue);
632
    }
633
}
634
 
635
//*****************************************************************************
636
//
637
//! Reads a GPIO data register.
638
//!
639
//! \param ucIdx is the index of the GPIO direction register to read; valid
640
//! values are 0, 1, and 2.
641
//!
642
//! This function reads one of the GPIO data registers in the PDC.  The value
643
//! returned for a pin is the value being driven out for outputs or the value
644
//! being read for inputs.
645
//!
646
//! This function is contained in <tt>utils/pdc.c</tt>, with
647
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
648
//!
649
//! \return The contents of the data register.
650
//
651
//*****************************************************************************
652
unsigned char
653
PDCGPIORead(unsigned char ucIdx)
654
{
655
    //
656
    // Check the argument.
657
    //
658
    ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
659
 
660
    //
661
    // Read the requested data register.
662
    //
663
    if(ucIdx == 0)
664
    {
665
        return(PDCRead(PDC_GPXDAT));
666
    }
667
    else if(ucIdx == 1)
668
    {
669
        return(PDCRead(PDC_GPYDAT));
670
    }
671
    else
672
    {
673
        return(PDCRead(PDC_GPZDAT));
674
    }
675
}
676
 
677
//*****************************************************************************
678
//
679
//! Write a GPIO data register.
680
//!
681
//! \param ucIdx is the index of the GPIO data register to write; valid values
682
//! are 0, 1, and 2.
683
//! \param ucValue is the value to write to the GPIO data register.
684
//!
685
//! This function writes one of the GPIO direction registers in the PDC.  The
686
//! written to a pin is driven out for output pins and ignored for input pins.
687
//!
688
//! This function is contained in <tt>utils/pdc.c</tt>, with
689
//! <tt>utils/pdc.h</tt> containing the API definition for use by applications.
690
//!
691
//! \return None.
692
//
693
//*****************************************************************************
694
void
695
PDCGPIOWrite(unsigned char ucIdx, unsigned char ucValue)
696
{
697
    //
698
    // Check the arguments.
699
    //
700
    ASSERT((ucIdx == 0) || (ucIdx == 1) || (ucIdx == 2));
701
 
702
    //
703
    // Write the requested data register.
704
    //
705
    if(ucIdx == 0)
706
    {
707
        PDCWrite(PDC_GPXDAT, ucValue);
708
    }
709
    else if(ucIdx == 1)
710
    {
711
        PDCWrite(PDC_GPYDAT, ucValue);
712
    }
713
    else
714
    {
715
        PDCWrite(PDC_GPZDAT, ucValue);
716
    }
717
}
718
 
719
//*****************************************************************************
720
//
721
// Close the Doxygen group.
722
//! @}
723
//
724
//*****************************************************************************

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.