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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [io/] [common/] [v2_0/] [doc/] [io.sgml] - Blame information for rev 249

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
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
I/O Package (Device Drivers)
34
 
35
36
 
37
38
Introduction
39
 
40
41
The I/O package is designed as a general purpose framework for
42
supporting device drivers. This includes all classes of
43
drivers from simple serial to networking stacks and beyond.
44
45
 
46
47
Components of the I/O package, such as device drivers, are
48
configured into the system just like all other components.
49
Additionally, end users may add their own drivers to this set.
50
51
 
52
53
While the set of drivers (and the devices they represent) may be
54
considered static, they must be accessed via an opaque
55
“handle”. Each device in the system has a unique name and
56
the cyg_io_lookup() function is used to map that
57
name onto the handle for the device. This “hiding” of the
58
device implementation allows for generic, named devices, as well as
59
more flexibility. Also, the cyg_io_lookup()
60
function provides drivers the opportunity to initialize the device
61
when usage actually starts.
62
63
 
64
65
All devices have a name. The standard provided devices use names such
66
as “/dev/console” and
67
“/dev/serial0”, where the
68
“/dev/” prefix indicates that this is
69
the name of a device.
70
71
 
72
The entire I/O package API, as well as the standard
73
set of provided drivers, is written in C. 
74
 
75
Basic functions are provided to send data to and receive data
76
from a device. The details of how this is done is left to the device [class] itself.
77
For example, writing data to a block device like a disk drive may
78
have different semantics than writing to a serial port. 
79
 
80
Additional functions are provided to manipulate the state
81
of the driver and/or the actual device. These functions
82
are, by design, quite specific to the actual driver. 
83
 
84
This driver model supports layering; in other words, a device
85
may actually be created “on top of” another device.
86
For example, the “tty” (terminal-like) devices are
87
built on top of simple serial devices. The upper layer then has
88
the flexibility to add features and functions not found at the lower
89
layers. In this case the “tty” device provides
90
for line buffering and editing not available from the simple serial
91
drivers.
92
93
 
94
Some drivers will support visibility of the layers they depend
95
upon. The “tty” driver allows information about
96
the actual serial device to be manipulated by passing get/set
97
config calls that use a serial driver “key” down
98
to the serial driver itself. 
99
 
100
101
 
102
103
104
 
105
106
<!-- <index></index> -->User API
107
 
108
109
All functions, except cyg_io_lookup()
110
require an I/O “handle”.
111
112
 
113
114
All functions return a value of the type Cyg_ErrNo. If an
115
error condition is detected, this value will be negative and the
116
absolute value indicates the actual error, as specified in
117
cyg/error/codes.h. The only other legal return
118
value will be ENOERR. All other function arguments
119
are pointers (references). This allows the drivers to pass information
120
efficiently, both into and out of the driver. The most striking
121
example of this is the “length” value passed to the read
122
and write functions. This parameter contains the desired length of
123
data on input to the function and the actual transferred length on
124
return.
125
126
 
127
128
// Lookup a device and return its handle
129
  Cyg_ErrNo cyg_io_lookup(
130
    const char *name,
131
    cyg_io_handle_t *handle )
132
133
 
134
135
This function maps a device name onto an appropriate handle. If the
136
named device is not in the system, then the error
137
-ENOENT is returned. If the device is found, then
138
the handle for the device is returned by way of the handle pointer
139
*handle.
140
141
 
142
143
// Write data to a device
144
Cyg_ErrNo cyg_io_write(
145
    cyg_io_handle_t handle,
146
    const void *buf,
147
    cyg_uint32 *len )
148
149
 
150
151
This function sends data to a device. The size of data to send is
152
contained in *len and the actual size sent will
153
be returned in the same place.
154
155
 
156
157
// Read data from a device
158
Cyg_ErrNo cyg_io_read(
159
    cyg_io_handle_t handle,
160
    void *buf,
161
    cyg_uint32 *len )
162
163
 
164
165
This function receives data from a device. The desired size of data to
166
receive is contained in *len and the actual
167
size obtained will be returned in the same place.
168
169
 
170
171
// Get the configuration of a device
172
Cyg_ErrNo cyg_io_get_config(
173
    cyg_io_handle_t handle,
174
    cyg_uint32 key,
175
    void *buf,
176
    cyg_uint32 *len )
177
178
 
179
180
This function is used to obtain run-time configuration about a
181
device. The type of information retrieved is specified by the
182
key. The data will be returned in the given
183
buffer. The value of *len should contain the
184
amount of data requested, which must be at least as large as the size
185
appropriate to the selected key. The actual size of data retrieved is
186
placed in  *len. The appropriate key values
187
differ for each driver and are all listed in the file
188
<cyg/io/config_keys.h>.
189
190
 
191
192
// Change the configuration of a device
193
Cyg_ErrNo cyg_io_set_config(
194
    cyg_io_handle_t handle,
195
    cyg_uint32 key,
196
    const void *buf,
197
    cyg_uint32 *len )
198
199
 
200
201
This function is used to manipulate or change the run-time
202
configuration of a device. The type of information is specified by the
203
key. The data will be obtained from the given
204
buffer. The value of *len should contain the
205
amount of data provided, which must match the size appropriate to the
206
selected key.  The appropriate key values differ for each driver and
207
are all listed in the file
208
<cyg/io/config_keys.h>.
209
210
 
211
212
 
213
214
215
 
216
217
Serial driver details
218
 
219
220
Two different classes of serial drivers are provided as a standard
221
part of the eCos system. These are described as “raw
222
serial” (serial) and “tty-like” (tty).
223
224
 
225
226
 
227
228
Raw Serial Driver
229
 
230
231
Use the include file <cyg/io/serialio.h> for
232
this driver.
233
234
 
235
236
The raw serial driver is capable of sending
237
and receiving blocks of raw data to a serial device. Controls are
238
provided to configure the actual hardware, but there is no manipulation
239
of the data by this driver.
240
241
 
242
243
There may be many instances of this driver in a given system,
244
one for each serial channel. Each channel corresponds to a physical
245
device and there will typically be a device module created for this
246
purpose. The device modules themselves are configurable, allowing
247
specification of the actual hardware details, as well as such details
248
as whether the channel should be buffered by the serial driver,
249
etc.
250
251
 
252
253
 
254
255
Runtime Configuration
256
 
257
258
Runtime configuration is achieved by exchanging data structures with
259
the driver via the cyg_io_set_config() and
260
cyg_io_get_config() functions.
261
262
 
263
264
typedef struct {
265
 cyg_serial_baud_rate_t baud;
266
 cyg_serial_stop_bits_t stop;
267
 cyg_serial_parity_t parity;
268
 cyg_serial_word_length_t word_length;
269
 cyg_uint32 flags;
270
} cyg_serial_info_t;
271
272
 
273
274
The field word_length contains the number of data bits per word
276
(character). This must be one of the values:
277
278
 
279
280
 CYGNUM_SERIAL_WORD_LENGTH_5
281
 CYGNUM_SERIAL_WORD_LENGTH_6
282
 CYGNUM_SERIAL_WORD_LENGTH_7
283
 CYGNUM_SERIAL_WORD_LENGTH_8
284
285
 
286
287
The field baud contains a baud rate selection.  This must be
289
one of the values:
290
291
 
292
293
 CYGNUM_SERIAL_BAUD_50
294
 CYGNUM_SERIAL_BAUD_75
295
 CYGNUM_SERIAL_BAUD_110
296
 CYGNUM_SERIAL_BAUD_134_5
297
 CYGNUM_SERIAL_BAUD_150
298
 CYGNUM_SERIAL_BAUD_200
299
 CYGNUM_SERIAL_BAUD_300
300
 CYGNUM_SERIAL_BAUD_600
301
 CYGNUM_SERIAL_BAUD_1200
302
 CYGNUM_SERIAL_BAUD_1800
303
 CYGNUM_SERIAL_BAUD_2400
304
 CYGNUM_SERIAL_BAUD_3600
305
 CYGNUM_SERIAL_BAUD_4800
306
 CYGNUM_SERIAL_BAUD_7200
307
 CYGNUM_SERIAL_BAUD_9600
308
 CYGNUM_SERIAL_BAUD_14400
309
 CYGNUM_SERIAL_BAUD_19200
310
 CYGNUM_SERIAL_BAUD_38400
311
 CYGNUM_SERIAL_BAUD_57600
312
 CYGNUM_SERIAL_BAUD_115200
313
 CYGNUM_SERIAL_BAUD_234000
314
315
 
316
The field stop contains the number of stop bits. This must be
318
one of the values:
319
 
320
321
 CYGNUM_SERIAL_STOP_1
322
 CYGNUM_SERIAL_STOP_1_5
323
 CYGNUM_SERIAL_STOP_2
324
325
 
326
327
Note
328
329
On most hardware, a selection of 1.5 stop bits is only valid
330
if the word (character) length is 5.
331
332
333
 
334
The field parity contains the parity mode.  This must be one of
336
the values: 
337
 
338
339
 CYGNUM_SERIAL_PARITY_NONE
340
 CYGNUM_SERIAL_PARITY_EVEN
341
 CYGNUM_SERIAL_PARITY_ODD
342
 CYGNUM_SERIAL_PARITY_MARK
343
 CYGNUM_SERIAL_PARITY_SPACE
344
345
 
346
The field flags is a bitmask which controls the behavior of the
348
serial device driver. It should be built from the values
349
CYG_SERIAL_FLAGS_xxx defined below:
350
351
 
352
353
#define CYG_SERIAL_FLAGS_RTSCTS 0x0001
354
355
 
356
If this bit is set then the port is placed in “hardware
357
handshake” mode. In this mode, the CTS and RTS pins control
358
when data is allowed to be sent/received at the port. This
359
bit is ignored if the hardware does not support this level of
360
handshake.
361
362
 
363
364
typedef struct {
365
  cyg_int32 rx_bufsize;
366
  cyg_int32 rx_count;
367
  cyg_int32 tx_bufsize;
368
  cyg_int32 tx_count;
369
} cyg_serial_buf_info_t;
370
371
 
372
The field rx_bufsize contains
373
the total size of the incoming data buffer. This is set to zero on
374
devices that do not support buffering (i.e. polled devices).
375
 
376
The field rx_count contains the
377
number of bytes currently occupied in the incoming data buffer.
378
This is set to zero on devices that do not support buffering (i.e. polled
379
devices).
380
 
381
The field tx_bufsize contains the
382
total size of the transmit data buffer. This is set to zero on devices
383
that do not support buffering (i.e. polled devices).
384
 
385
The field tx_count contains the
386
number of bytes currently occupied in the transmit data buffer.  This
387
is set to zero on devices that do not support buffering (i.e. polled
388
devices).
389
 
390
391
 
392
393
394
 
395
396
<!-- <index></index> -->API Details
397
 
398
399
 
400
401
cyg_io_write
402
 
403
404
cyg_io_write(handle, buf, len)
405
406
 
407
408
Send the data from buf to the device. The
409
driver maintains a buffer to hold the data. The size of the
410
intermediate buffer is configurable within the interface module. The
411
data is not modified at all while it is being buffered. On return,
412
*len contains the amount of characters actually
413
consumed .
414
 
415
416
It is possible to configure the write call to be blocking
417
(default) or non-blocking. Non-blocking mode requires both the configuration
418
option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
419
to be enabled, and the specific device to be set to non-blocking
420
mode for writes (see cyg_io_set_config()).
421
422
 
423
424
In blocking mode, the call will not return until there is space in the
425
buffer and the entire contents of buf have been
426
consumed.
427
428
 
429
430
In non-blocking mode, as much as possible gets consumed from
431
buf. If everything was consumed, the call
432
returns ENOERR. If only part of the
433
buf contents was consumed,
434
-EAGAIN is returned and the caller must try
435
again. On return, *len contains the number of characters actually
436
consumed .
437
 
438
439
The call can also return -EINTR if interrupted
440
via the cyg_io_get_config()/ABORT key.
441
442
 
443
444
 
445
446
447
 
448
449
cyg_io_read
450
 
451
452
cyg_io_read(handle, buf, len)
453
454
 
455
456
Receive data into the buffer, buf, from the
457
device. No manipulation of the data is performed before being
458
transferred.  An interrupt driven interface module will support data
459
arriving when no read is pending by buffering the data in the serial
460
driver.  Again, this buffering is completely configurable. On return,
461
*len contains the number of characters actually
462
received.
463
 
464
465
It is possible to configure the read call to be blocking (default)
466
or  non-blocking. Non-blocking mode requires both the configuration
467
option  CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
468
to be enabled, and the specific device to be set to non-blocking
469
mode for reads (see cyg_io_set_config()).
470
471
 
472
473
In blocking mode, the call will not return until the requested
474
amount of data has been read.
475
 
476
477
In non-blocking mode, data waiting in the device buffer is copied to
478
buf, and the call returns immediately. If there
479
was enough data in the buffer to fulfill the request,
480
ENOERR is returned.  If only part of the request
481
could be fulfilled, -EAGAIN is returned and the
482
caller must try again. On return, *len contains
483
the number of characters actually received.
484
 
485
486
The call can also return -EINTR if interrupted via
487
the cyg_io_get_config()/ABORT
488
key.
489
490
 
491
492
 
493
494
495
 
496
497
cyg_io_get_config
498
 
499
500
cyg_io_get_config(handle, key, buf, len)
501
502
 
503
This function returns current [runtime] information
504
about the device and/or driver. 
505
 
506
507
  
508
    CYG_IO_GET_CONFIG_SERIAL_INFO
509
    
510
      
511
        
512
          Buf type:
513
          
514
            cyg_serial_info_t
515
          
516
        
517
        
518
          Function:
519
          
520
            
521
              This function retrieves the current state of the driver
522
              and hardware. This information contains fields for
523
              hardware baud rate, number of stop bits, and parity
524
              mode. It also includes a set of flags that control the
525
              port, such as hardware flow control.
526
            
527
          
528
        
529
      
530
    
531
  
532
 
533
  
534
    CYG_IO_GET_CONFIG_SERIAL_BUFFER_INFO
535
    
536
       
537
         
538
           Buf type:
539
           
540
             cyg_serial_buf_info_t
541
           
542
         
543
         
544
           Function:
545
           
546
             
547
               This function retrieves the current state of the
548
               software buffers in the serial drivers. For both
549
               receive and transmit buffers it returns the total
550
               buffer size and the current number of bytes occupied in
551
               the buffer. It does not take into account any buffering
552
               such as FIFOs or holding registers that the serial
553
               device itself may have.
554
             
555
           
556
         
557
       
558
    
559
  
560
 
561
  
562
    CYG_IO_GET_CONFIG_SERIAL_OUTPUT_DRAIN
563
    
564
      
565
        
566
          Buf type:
567
          
568
            void *
569
          
570
        
571
        
572
          Function:
573
          
574
            
575
              This function waits for any buffered output to
576
              complete. This function only completes when there is no
577
              more data remaining to be sent to the device.
578
            
579
          
580
        
581
      
582
    
583
  
584
 
585
  
586
    CYG_IO_GET_CONFIG_SERIAL_OUTPUT_FLUSH
587
    
588
      
589
        
590
          Buf type:
591
          
592
            void *
593
          
594
        
595
        
596
          Function:
597
          
598
            
599
              This function discards any buffered output for the
600
              device.
601
            
602
          
603
        
604
      
605
    
606
  
607
 
608
  
609
    CYG_IO_GET_CONFIG_SERIAL_INPUT_DRAIN
610
    
611
      
612
        
613
          Buf type:
614
          
615
            void *
616
          
617
        
618
        
619
          Function:     
620
          
621
            This function discards any buffered input for the
622
            device.
623
          
624
        
625
      
626
    
627
  
628
 
629
  
630
    CYG_IO_GET_CONFIG_SERIAL_ABORT
631
    
632
      
633
        
634
          Buf type:
635
          
636
             void*
637
          
638
        
639
        
640
          Function:
641
          
642
            This function will cause any pending read or write calls on
643
            this device to return with -EABORT.
644
          
645
        
646
      
647
    
648
  
649
 
650
  
651
    CYG_IO_GET_CONFIG_SERIAL_READ_BLOCKING
652
    
653
      
654
        
655
          Buf type:
656
          
657
             cyg_uint32 (values 0 or 1)
658
          
659
        
660
        
661
          Function:
662
          
663
            This function will read back the blocking-mode
664
            setting for read calls on this device. This call is only
665
            available if the configuration option
666
            CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is
667
            enabled.
668
          
669
        
670
      
671
    
672
  
673
 
674
  
675
    CYG_IO_GET_CONFIG_SERIAL_WRITE_BLOCKING
676
    
677
      
678
        
679
          Buf type:
680
          
681
             cyg_uint32 (values 0 or 1)
682
          
683
        
684
        
685
          Function:
686
          
687
            
688
            This function will read back the blocking-mode
689
            setting for write calls on this device. This call is only
690
            available if the configuration option
691
            CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING is enabled.
692
          
693
        
694
      
695
    
696
  
697
698
 
699
700
 
701
702
703
 
704
705
cyg_io_set_config
706
 
707
708
cyg_io_set_config(handle, key, buf,len)
709
710
 
711
This function is used to update or change runtime configuration
712
of a port. 
713
 
714
715
  
716
    CYG_IO_SET_CONFIG_SERIAL_INFO
717
    
718
      
719
        
720
          Buf type:
721
          
722
            cyg_serial_info_t
723
          
724
        
725
        
726
          Function:
727
          
728
            This function updates the information for the driver
729
            and hardware.  The information contains fields for
730
            hardware baud rate, number of stop bits, and parity
731
            mode. It also includes a set of flags that control the
732
            port, such as hardware flow control.
733
            
734
          
735
        
736
      
737
    
738
  
739
 
740
  
741
    CYG_IO_SET_CONFIG_SERIAL_READ_BLOCKING
742
    
743
      
744
        
745
          Buf type:
746
          
747
             cyg_uint32 (values 0 or 1)
748
          
749
        
750
        
751
          Function:
752
          
753
            This function will set the blocking-mode for read
754
            calls on this device. This call is only available if the
755
            configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
756
            is enabled.
757
            
758
          
759
        
760
      
761
    
762
  
763
 
764
  
765
    CYG_IO_SET_CONFIG_SERIAL_WRITE_BLOCKING
766
    
767
      
768
        
769
          Buf type:
770
          
771
            cyg_uint32 (values 0 or 1)
772
          
773
        
774
        
775
          Function:
776
          
777
            This function will set the blocking-mode for write
778
            calls on this device. This call is only available if the
779
            configuration option CYGOPT_IO_SERIAL_SUPPORT_NONBLOCKING
780
            is enabled.
781
            
782
          
783
        
784
      
785
    
786
  
787
788
 
789
790
 
791
792
 
793
794
 
795
796
 
797
798
 
799
800
801
 
802
803
 TTY driver
804
 
805
806
Use the include file <cyg/io/ttyio.h> for
807
this driver.
808
809
 
810
811
This driver is built on top of the simple
812
serial driver and is typically used for a device that interfaces with
813
humans such as a terminal. It provides some minimal formatting of data
814
on output and allows for line-oriented editing on input.
815
816
 
817
818
 
819
820
Runtime configuration
821
 
822
823
Runtime configuration is achieved by exchanging data structures with
824
the driver via the cyg_io_set_config() and
825
cyg_io_get_config() functions.
826
827
 
828
 
829
830
typedef struct {
831
 cyg_uint32 tty_out_flags;
832
 cyg_uint32 tty_in_flags;
833
} cyg_tty_info_t;
834
835
 
836
The field tty_out_flags
837
is used to control what happens to data as it is send to the serial
838
port. It contains a bitmap comprised of the bits as defined by the
839
CYG_TTY_OUT_FLAGS_xxx values below. 
840
 
841
842
#define CYG_TTY_OUT_FLAGS_CRLF 0x0001 // Map '\n' => '\n\r' on output
843
844
 
845
If this bit is set in tty_out_flags,
846
any occurrence of the character "\n" will
847
be replaced by the sequence "\n\r" before
848
being sent to the device.
849
 
850
The field tty_in_flags
851
is used to control how data is handled as it comes from the serial
852
port. It contains a bitmap comprised of the bits as defined by the
853
CYG_TTY_IN_FLAGS_xxx values below. 
854
 
855
856
#define CYG_TTY_IN_FLAGS_CR 0x0001 // Map '\r' => '\n' on input
857
858
 
859
If this bit is set in tty_in_flags, the
860
character "\r" (“return” or “enter” on
861
most keyboards) will be mapped to "\n".
862
 
863
864
#define CYG_TTY_IN_FLAGS_CRLF 0x0002 // Map '\n\r' => '\n' on input
865
866
 
867
868
If this bit is set in tty_in_flags, the
869
character sequence "\n\r" (often sent by DOS/Windows
870
based terminals) will be mapped to "\n". 
871
 
872
873
#define CYG_TTY_IN_FLAGS_BINARY 0x0004 // No input processing
874
875
 
876
If this bit is set in tty_in_flags, the
877
input will not be manipulated in any way before being placed in
878
the user’s buffer. 
879
 
880
881
#define CYG_TTY_IN_FLAGS_ECHO 0x0008 // Echo characters as processed
882
883
 
884
885
If this bit is set in tty_in_flags, characters
886
will be echoed back to the serial port as they are processed. 
887
 
888
889
 
890
891
892
 
893
894
<!-- <index></index> -->API details
895
 
896
897
cyg_io_read(handle, buf, len)
898
899
 
900
This function is used to read data from the device. In the
901
default case, data is read until an end-of-line character ("\n"
902
or "\r") is read. Additionally, the characters are echoed
903
back to the [terminal] device. Minimal editing
904
of the input is also supported. 
905
 
906
907
When connecting to a remote target via GDB it is not possible
908
to provide console input while GDB is connected. The GDB remote
909
protocol does not support input. Users must disconnect from GDB
910
if this functionality is required.
911
912
 
913
914
cyg_io_write(handle, buf, len)
915
916
 
917
This function is used to send data to the device. In the default
918
case, the end-of-line character "\n" is replaced by the
919
sequence "\n\r". 
920
 
921
922
cyg_io_get_config(handle, key, buf, len)
923
924
 
925
This function is used to get information about the channel’s
926
configuration at runtime. 
927
 
928
929
  
930
    CYG_IO_GET_CONFIG_TTY_INFO
931
    
932
      
933
        
934
          Buf type:
935
          
936
            cyg_tty_info_t
937
          
938
        
939
        
940
          Function:
941
          
942
            This function retrieves the current state of the
943
            driver.
944
            
945
          
946
        
947
      
948
    
949
  
950
951
 
952
Serial driver keys (see above) may also be specified
953
in which case the call is passed directly to the serial
954
driver. 
955
 
956
957
cyg_io_set_config(handle, key, buf, len)
958
959
 
960
This function is used to modify the channel’s configuration
961
at runtime. 
962
 
963
 
964
965
  
966
    CYG_IO_SET_CONFIG_TTY_INFO
967
    
968
      
969
        
970
          Buf type:
971
          
972
            cyg_tty_info_t
973
          
974
        
975
        
976
          Function:     
977
          
978
            This function changes the current state of the
979
            driver.
980
          
981
        
982
      
983
    
984
  
985
986
 
987
Serial driver
988
keys (see above) may also be specified in which case the
989
call is passed directly to the serial driver. 
990
 
991
992
 
993
994
 
995
996
 
997
998
999
 
1000
 
1001
1002
 
1003
1004
 
1005
1006
1007
 
1008
1009
How to Write a Driver
1010
 
1011
1012
 
1013
1014
A device driver is nothing more than a
1015
named entity that supports the basic I/O functions - read, write, get
1016
config, and set config. Typically a device driver also uses and
1017
manages interrupts from the device. While the interface is generic and
1018
device driver independent, the actual driver implementation is
1019
completely up to the device driver designer. 
1020
 
1021
That said, the reason for using a device driver is to provide
1022
access to a device from application code in as general purpose a
1023
fashion as reasonable. Most driver writers are also concerned with
1024
making this access as simple as possible while being as efficient
1025
as possible. 
1026
 
1027
Most device drivers are concerned with the movement of information,
1028
for example data bytes along a serial interface, or packets in a
1029
network. In order to make the most efficient use of system resources,
1030
interrupts are used. This will allow other application processing
1031
to take place while the data transfers are under way, with interrupts
1032
used to indicate when various events have occurred. For example,
1033
a serial port typically generates an interrupt after a character
1034
has been sent “down the wire” and the interface
1035
is ready for another. It makes sense to allow further application
1036
processing while the data is being sent since this can take quite
1037
a long time. The interrupt can be used to allow the driver to send
1038
a character as soon as the current one is complete, without any
1039
active participation by the application code. 
1040
 
1041
The main building blocks for device drivers are found in the
1042
include file: <cyg/io/devtab.h>
1043
 
1044
All device drivers in eCos are described
1045
by a device table entry, using the cyg_devtab_entry_t type.
1046
The entry should be created using the DEVTAB_ENTRY() macro,
1047
like this:
1048
 
1049
1050
DEVTAB_ENTRY(l, name, dep_name, handlers, init, lookup, priv)
1051
1052
 
1053
1054
Arguments
1055
  
1056
    l
1057
    The "C" label for this device table entry.
1058
  
1059
  
1060
    name
1061
    The "C" string name for the device.
1062
  
1063
  
1064
    dep_name
1065
    For a layered device, the "C" string name of the
1066
    device this device is built upon.
1067
  
1068
  
1069
    handlers
1070
    A pointer to the I/O function "handlers" (see below).
1071
  
1072
  
1073
    init
1074
    A function called when eCos is initialized. This
1075
    function can query the device, setup hardware, etc.
1076
  
1077
  
1078
    lookup
1079
    A function called when cyg_io_lookup() is called
1080
    for this device. 
1081
  
1082
  
1083
    priv
1084
    A placeholder for any device specific data
1085
    required by the driver.
1086
  
1087
1088
 
1089
The interface to the driver is through the handlers field.  This is a pointer to
1091
a set of functions which implement the various cyg_io_XXX()
1092
routines. This table is defined by the macro:
1093
 
1094
 
1095
1096
DEVIO_TABLE(l, write, read, get_config, set_config)
1097
1098
 
1099
1100
Arguments
1101
  
1102
    l
1103
    The "C" label for this table of handlers.
1104
  
1105
  
1106
    write
1107
    The function called as a result of
1108
    cyg_io_write().
1109
  
1110
  
1111
    read
1112
    The function called as a result of
1113
    cyg_io_read(). 
1114
  
1115
  
1116
    get_config
1117
    The function called as a result of
1118
    cyg_io_get_config().
1119
  
1120
  
1121
    set_config
1122
    The function called as a result of
1123
    cyg_io_set_config(). 
1124
  
1125
1126
 
1127
1128
When eCos is initialized (sometimes called
1129
“boot” time), the init() function is called
1130
for all devices in the system. The init() function is
1131
allowed to return an error in which case the device will be placed
1132
“off line” and all I/O requests to that device will be
1133
considered in error.
1134
1135
 
1136
1137
The lookup() function is called whenever
1138
the cyg_io_lookup() function
1139
is called with this device name. The lookup function may cause the device
1140
to come “on line” which would then allow I/O
1141
operations to proceed. Future versions of the I/O system
1142
will allow for other states, including power saving modes,
1143
etc.
1144
1145
 
1146
1147
1148
 
1149
1150
How to Write a Serial Hardware Interface Driver
1151
 
1152
 
1153
The standard serial driver supplied with
1154
eCos is structured as a hardware independent
1155
portion and a hardware dependent interface module. To add support for
1156
a new serial port, the user should be able to use the existing
1157
hardware independent portion and just add their own interface driver which handles the details of the
1159
actual device. The user should have no need to change the hardware
1160
independent portion. 
1161
 
1162
The interfaces used by the serial driver and serial implementation
1163
modules are contained in the file <cyg/io/serial.h>
1164
1165
 
1166
1167
In the sections below we use the notation <<xx>> to
1168
mean a module specific value, referred to as “xx” below.
1169
1170
 
1171
1172
 
1173
1174
DevTab Entry
1175
 
1176
The interface module contains the devtab entry (or entries
1177
if a single module supports more than one interface). This entry
1178
should have the form: 
1179
 
1180
1181
DEVTAB_ENTRY(<<module_name>>,
1182
             <<device_name>>,
1183
             0,
1184
             &serial_devio,
1185
             <<module_init>>,
1186
             <<module_lookup>>,
1187
             &<<serial_channel>>
1188
            );
1189
1190
 
1191
1192
Arguments
1193
  
1194
    module_name
1195
    The "C" label for this devtab entry
1196
  
1197
  
1198
    device_name
1199
    The "C" string for the
1200
    device. E.g. /dev/serial0.
1201
  
1202
  
1203
    serial_devio
1204
    The table of I/O functions. This set is defined in
1205
    the hardware independent serial driver and should be used.
1206
    
1207
  
1208
  
1209
    module_init
1210
    The module initialization function.
1211
  
1212
  
1213
    module_lookup
1214
    The device lookup function. This function
1215
    typically sets up the device for actual use, turning on
1216
    interrupts, configuring the port, etc.
1217
  
1218
  
1219
    serial_channel
1220
    This table (defined below) contains the interface
1221
    between the interface module and the serial driver proper.
1222
  
1223
1224
 
1225
1226
 
1227
1228
1229
 
1230
1231
Serial Channel Structure
1232
 
1233
Each serial device must have a “serial channel”.
1234
This is a set of data which describes all operations on the device.
1235
It also contains buffers, etc., if the device is to be buffered.
1236
The serial channel is created by the macro: 
1237
 
1238
1239
SERIAL_CHANNEL_USING_INTERRUPTS(l, funs, dev_priv, baud,stop, parity, word_length,
1240
                                flags, out_buf, out_buflen, in_buf, in_buflen)
1241
1242
 
1243
1244
  Arguments
1245
  
1246
    l
1247
    The "C" label for this structure.
1248
  
1249
  
1250
    funs
1251
    The set of interface functions (see below).
1252
  
1253
  
1254
    dev_priv
1255
    A placeholder for any device specific data for
1256
    this channel.
1257
  
1258
  
1259
    baud
1260
    The initial baud rate value
1261
    (cyg_serial_baud_t).
1262
  
1263
  
1264
    stop
1265
    The initial stop bits value
1266
    (cyg_serial_stop_bits_t).
1267
  
1268
  
1269
    parity
1270
    The initial parity mode value
1271
    (cyg_serial_parity_t).
1272
  
1273
  
1274
    word_length
1275
    The initial word length value
1276
    (cyg_serial_word_length_t).
1277
  
1278
  
1279
    flags
1280
    The initial driver flags value.
1281
  
1282
  
1283
    out_buf
1284
    Pointer to the output
1285
    buffer. NULL if none required.
1286
  
1287
  
1288
    out_buflen
1289
    The length of the output buffer.
1290
  
1291
  
1292
    in_buf
1293
    pointer to the input
1294
    buffer. NULL if none required.
1295
  
1296
  
1297
    in_buflen
1298
    The length of the input buffer. 
1299
  
1300
1301
 
1302
1303
If either buffer length is zero, no buffering will take place
1304
in that direction and only polled mode functions will be used.
1305
1306
 
1307
1308
The interface from the hardware independent driver into the
1309
hardware interface module is contained in the funs table.
1310
This is defined by the macro:
1311
1312
 
1313
1314
 
1315
1316
1317
 
1318
1319
Serial Functions Structure
1320
 
1321
1322
SERIAL_FUNS(l, putc, getc, set_config, start_xmit, stop_xmit)
1323
1324
 
1325
 
1326
1327
  Arguments
1328
  
1329
    l
1330
    The "C" label for this structure.
1331
  
1332
  
1333
    putc
1334
    
1335
      bool (*putc)(serial_channel *priv, unsigned char
1336
      c)
1337
      
1338
      This function sends one character to the interface. It should
1339
      return true if the character is actually consumed. It should
1340
      return false if there is no space in the interface
1341
      
1342
    
1343
  
1344
  
1345
    getc
1346
    
1347
      unsigned char (*getc)(serial_channel *priv)
1348
      
1349
      This function fetches one character from the interface. It will
1350
      be only called in a non-interrupt driven mode, thus it should
1351
      wait for a character by polling the device until ready.
1352
      
1353
    
1354
  
1355
  
1356
    set_config
1357
    
1358
      bool (*set_config)(serial_channel
1359
      *priv,cyg_serial_info_t *config)
1360
      
1361
        This function is used to configure the port. It should return
1362
        true if the hardware is updated to match the desired
1363
        configuration. It should return false if the port cannot
1364
        support some parameter specified by the given
1365
        configuration. E.g. selecting 1.5 stop bits and 8 data bits is
1366
        invalid for most serial devices and should not be allowed.
1367
      
1368
    
1369
  
1370
  
1371
    start_xmit
1372
    void (*start_xmit)(serial_channel *priv)
1373
      
1374
        In interrupt mode, turn on the transmitter and allow for
1375
        transmit interrupts.
1376
      
1377
    
1378
  
1379
  
1380
    stop_xmit
1381
    
1382
      void (*stop_xmit)(serial_channel *priv)
1383
      In interrupt mode, turn off the transmitter.
1384
    
1385
  
1386
1387
 
1388
1389
 
1390
1391
1392
 
1393
1394
Callbacks
1395
 
1396
1397
The device interface module can execute functions in the
1398
hardware independent driver via chan->callbacks.
1399
These functions are available:
1400
1401
 
1402
1403
void (*serial_init)( serial_channel *chan )
1404
1405
 
1406
This function is used to initialize the serial channel. It
1407
is only required if the channel is being used in interrupt
1408
mode.
1409
 
1410
1411
void (*xmt_char)( serial_channel *chan )
1412
1413
 
1414
1415
This function would be called from an interrupt handler after a
1416
transmit interrupt indicating that additional characters may be
1417
sent. The upper driver will call the putc
1418
function as appropriate to send more data to the device.
1419
 
1420
1421
void (*rcv_char)( serial_channel *chan, unsigned char c )
1422
1423
 
1424
 
1425
1426
This function is used to tell the driver that a character has arrived
1427
at the interface. This function is typically called from the interrupt
1428
handler. 
1429
 
1430
1431
Furthermore, if the device has a FIFO it should require the hardware
1432
independent driver to provide block transfer functionality (driver CDL
1433
should include "implements
1434
CYGINT_IO_SERIAL_BLOCK_TRANSFER").  In that case, the following
1435
functions are available as well:
1436
 
1437
1438
bool (*data_xmt_req)(serial_channel *chan,
1439
                     int space,
1440
                     int* chars_avail,
1441
                     unsigned char** chars)
1442
void (*data_xmt_done)(serial_channel *chan)
1443
1444
 
1445
1446
Instead of calling xmt_char() to get a single
1447
character for transmission at a time, the driver should call
1448
data_xmt_req() in a loop, requesting character
1449
blocks for transfer. Call with a space argument of how much space
1450
there is available in the FIFO.
1451
 
1452
If the call returns true, the driver can read
1453
chars_avail characters from
1454
chars and copy them into the FIFO.
1455
 
1456
If the call returns false, there are
1457
no more buffered characters and the driver should continue without
1458
filling up the FIFO.
1459
 
1460
When all data has been unloaded, the
1461
driver must call data_xmt_done().
1462
 
1463
 
1464
1465
bool (*data_rcv_req)(serial_channel *chan,
1466
                     int avail,
1467
                     int* space_avail,
1468
                     unsigned char** space)
1469
void (*data_rcv_done)(serial_channel *chan)
1470
1471
 
1472
Instead of calling rcv_char() with a single
1473
character at a time, the driver should call
1474
data_rcv_req() in a loop, requesting space to
1475
unload the FIFO to. avail is the number of
1476
characters the driver wishes to unload.
1477
 
1478
 
1479
If the call returns true, the driver can copy
1480
space_avail characters to
1481
space. 
1482
 
1483
 
1484
If the call returns false, the input buffer is
1485
full. It is up to the driver to decide what to do in that case
1486
(callback functions for registering overflow are being planned for
1487
later versions of the serial driver).
1488
1489
 
1490
When all data has been unloaded, the driver must call
1491
data_rcv_done().
1492
 
1493
1494
 
1495
1496
 
1497
1498
 
1499
1500
1501
 
1502
1503
Serial testing with ser_filter
1504
 
1505
1506
 
1507
1508
Rationale
1509
 
1510
1511
Since some targets only have one serial connection, a serial testing harness
1512
needs to be able to share the connection with GDB
1513
(however, the test and GDB can also run on separate
1514
lines).
1515
1516
 
1517
1518
The serial filter (ser_filter)
1519
sits between the serial port and GDB and monitors
1520
the exchange of data between GDB and the target.
1521
Normally, no changes are made to the data.
1522
1523
 
1524
1525
When a test request packet is sent from the test on the target, it is
1526
intercepted by the filter.
1527
1528
 
1529
1530
The filter and target then enter a loop, exchanging protocol data between
1531
them which GDB never sees.
1532
1533
 
1534
1535
In the event of a timeout, or a crash on the target, the filter falls
1536
back into its pass-through mode. If this happens due to a crash it should be
1537
possible to start regular debugging with GDB. The
1538
filter will stay in the pass-though mode until GDB
1539
disconnects.
1540
1541
1542
 
1543
1544
1545
 
1546
1547
The Protocol
1548
 
1549
The protocol commands are prefixed with an "@"
1550
character which the serial filter is looking for. The protocol
1551
commands include:
1552
1553
 
1554
1555
  
1556
    PING
1557
    
1558
      Allows the test on the target to probe for the filter. The
1559
      filter responds with OK, while
1560
      GDB would just ignore the
1561
      command. This allows the tests to do nothing if they require the
1562
      filter and it is not present.
1563
    
1564
  
1565
  
1566
    CONFIG
1567
    
1568
      Requests a change of serial line configuration. Arguments
1569
      to the command specify baud rate, data bits, stop bits, and
1570
      parity. [This command is not fully implemented yet - there is no
1571
      attempt made to recover if the new configuration turns out to
1572
      cause loss of data.]
1573
    
1574
  
1575
  
1576
    BINARY
1577
    
1578
      Requests data to be sent from the filter to the
1579
      target. The data is checksummed, allowing errors in the transfer
1580
      to be detected.  Sub-options of this command control how the
1581
      data transfer is made:
1582
      
1583
        
1584
          NO_ECHO
1585
          
1586
            (serial driver receive test) Just send data from the
1587
            filter to the target. The test verifies the checksum and
1588
            PASS/FAIL depending on the result. 
1589
          
1590
        
1591
        
1592
          EOP_ECHO
1593
          
1594
            (serial driver half-duplex receive and send test) As
1595
            NO_ECHO but the test echoes back the
1596
            data to the filter.  The filter does a checksum on the
1597
            received data and sends the result to the target. The test
1598
            PASS/FAIL depending on the result of both checksum
1599
            verifications.
1600
          
1601
        
1602
        
1603
          DUPLEX_ECHO
1604
          
1605
            (serial driver duplex receive and send test) Smaller
1606
            packets of data are sent back and forth in a pattern that
1607
            ensures that the serial driver will be both sending and
1608
            receiving at the same time. Again, checksums are computed
1609
            and verified resulting in PASS/FAIL.
1610
            
1611
          
1612
        
1613
      
1614
    
1615
  
1616
  
1617
    TEXT
1618
    
1619
       This is a test of the text translations in the TTY layer.
1620
      Requests a transfer of text data from the target to the filter
1621
      and possibly back again. The filter treats this as a binary
1622
      transfer, while the target ma be doing translations on the
1623
      data. The target provides the filter with checksums for what it
1624
      should expect to see. This test is not implemented yet.
1625
      
1626
    
1627
  
1628
1629
 
1630
The above commands may be extended, and new commands added, as
1631
required to test (new) parts of the serial drivers in
1632
eCos.
1633
1634
 
1635
1636
 
1637
1638
1639
 
1640
1641
The Serial Tests
1642
 
1643
1644
The serial tests are built as any other eCos test. After running the
1645
make tests command, the tests can be found in
1646
install/tests/io_serial/
1647
 
1648
1649
  
1650
    serial1
1651
    A simple API test.
1652
  
1653
  
1654
    serial2
1655
    
1656
      A simple serial send test. It writes out two strings, one
1657
      raw and one encoded as a GDB
1658
      O-packet
1659
    
1660
  
1661
  
1662
    serial3 [ requires the serial filter ]
1663
    
1664
      This tests the half-duplex send and receive capabilities
1665
      of the serial driver. 
1666
    
1667
  
1668
  
1669
    serial4 [ requires the serial filter ]
1670
    
1671
      This test attempts to use a few different serial
1672
      configurations, testing the driver's configuration/setup
1673
      functionality. 
1674
    
1675
  
1676
  
1677
    serial5 [ requires the serial filter ]
1678
    
1679
      This tests the duplex send and receive capabilities of the
1680
      serial driver. 
1681
    
1682
  
1683
1684
 
1685
All tests should complete in less than 30 seconds.
1686
 
1687
1688
 
1689
1690
1691
 
1692
1693
Serial Filter Usage
1694
 
1695
Running the ser_filter program with no (or wrong) arguments results in
1696
the following output:
1697
1698
 
1699
1700
Usage: ser_filter [-t -S] TcpIPport SerialPort BaudRate
1701
or: ser_filter -n [-t -S] SerialPort BaudRate
1702
-t: Enable tracing.
1703
-S: Output data read from serial line.
1704
-c: Output data on console instead of via GDB.
1705
-n: No GDB.
1706
1707
 
1708
The normal way to use it with GDB is to start the filter:
1709
 
1710
1711
$ ser_filter -t 9000 com1 38400
1712
1713
 
1714
1715
In this case, the filter will be listening on port 9000 and connect to the
1716
target via the serial port COM1 at 38400 baud. On a UNIX
1717
host, replace "COM1" with a device such as
1718
"/dev/ttyS0".
1719
1720
 
1721
1722
The  option enables tracing which will cause the
1723
filter to describe its actions on the console.
1724
1725
 
1726
Now start GDB with one of the tests as an
1727
argument:
1728
1729
 
1730
1731
$ mips-tx39-elf-gdb -nw install/tests/io_serial/serial3
1732
1733
 
1734
Then connect to the filter:
1735
 
1736
1737
(gdb) target remote localhost:9000
1738
1739
 
1740
1741
This should result in a connection in exactly the same way as if you
1742
had connected directly to the target on the serial line.
1743
1744
 
1745
1746
(gdb) c
1747
1748
 
1749
1750
Which should result in output similar to the below:
1751
1752
 
1753
1754
Continuing.
1755
INFO: <BINARY:16:1!>
1756
PASS: <Binary test completed>
1757
INFO: <BINARY:128:1!>
1758
PASS: <Binary test completed>
1759
INFO: <BINARY:256:1!>
1760
PASS: <Binary test completed>
1761
INFO: <BINARY:1024:1!>
1762
PASS: <Binary test completed>
1763
INFO: <BINARY:512:0!>
1764
PASS: <Binary test completed>
1765
...
1766
PASS: <Binary test completed>
1767
INFO: <BINARY:16384:0!>
1768
PASS: <Binary test completed>
1769
PASS: <serial13 test OK>
1770
EXIT: <done>
1771
1772
 
1773
1774
If any of the individual tests fail the testing will terminate with a
1775
FAIL.
1776
1777
 
1778
1779
With tracing enabled, you would also see the filter's status output:
1780
1781
 
1782
1783
The PING command sent from the target to determine the
1784
presence of the filter:
1785
1786
 
1787
1788
[400 11:35:16] Dispatching command PING
1789
[400 11:35:16] Responding with status OK
1790
1791
 
1792
Each of the binary commands result in output similar to:
1793
 
1794
1795
[400 11:35:16] Dispatching command BINARY
1796
[400 11:35:16] Binary data (Size:16, Flags:1).
1797
[400 11:35:16] Sending CRC: '170231!', len: 7.
1798
[400 11:35:16] Reading 16 bytes from target.
1799
[400 11:35:16] Done. in_crc 170231, out_crc 170231.
1800
[400 11:35:16] Responding with status OK
1801
[400 11:35:16] Received DONE from target.
1802
1803
 
1804
1805
This tracing output is normally sent as O-packets to GDB
1806
 which will display the tracing text. By using the
1807
 option, the tracing text can be redirected to the
1808
console from which ser_filter was started.
1809
1810
 
1811
1812
 
1813
1814
1815
 
1816
1817
A Note on Failures
1818
 
1819
1820
A serial connection (especially when driven at a high baud rate) can garble the
1821
transmitted data because of noise from the environment. It is not the job of
1822
the serial driver to ensure data integrity - that is the job of protocols
1823
layering on top of the serial driver. 
1824
 
1825
In the current implementation the serial tests and the serial filter are
1826
not resilient to such data errors. This means that the test may crash or hang
1827
(possibly without reporting a FAIL). It also
1828
means that you should be aware of random errors - a FAIL
1829
 is not necessarily caused by a bug in the serial driver.
1830
1831
 
1832
Ideally, the serial testing infrastructure should be able to distinguish
1833
random errors from consistent errors - the former are most likely due to noise
1834
in the transfer medium, while the latter are more likely to be caused by faulty
1835
drivers. The current implementation of the infrastructure does not have this
1836
capability.
1837
 
1838
1839
 
1840
1841
1842
 
1843
1844
Debugging
1845
 
1846
If a test fails, the serial filter's output may provide some hints about
1847
what the problem is. If the option  is used when starting
1848
the filter, data received from the target is printed out:
1849
1850
 
1851
1852
[400 11:35:16] 0000 50 41 53 53 3a 3c 42 69 'PASS:<Bi'
1853
[400 11:35:16] 0008 6e 61 72 79 20 74 65 73 'nary.tes'
1854
[400 11:35:16] 0010 74 20 63 6f 6d 70 6c 65 't.comple'
1855
[400 11:35:16] 0018 74 65 64 3e 0d 0a 49 4e 'ted>..IN'
1856
[400 11:35:16] 0020 46 4f 3a 3c 42 49 4e 41 'FO:<BINA'
1857
[400 11:35:16] 0028 52 59 3a 31 32 38 3a 31 'RY:128:1'
1858
[400 11:35:16] 0030 21 3e 0d 0a 40 42 49 4e '!..@BIN'
1859
[400 11:35:16] 0038 41 52 59 3a 31 32 38 3a 'ARY:128:'
1860
[400 11:35:16] 0040 31 21 .. .. .. .. .. .. '1!'
1861
1862
 
1863
In the case of an error during a testing command the data received by the
1864
filter will be printed out, as will the data that was expected. This allows
1865
the two data sets to be compared which may give some idea of what the problem
1866
is.
1867
 
1868
1869
 
1870
1871
 
1872
1873
 
1874
1875
 
1876
1877
 
1878
1879
1880
 
1881
1882
Device Driver Interface to the Kernel
1883
 
1884
1885
This chapter describes the API that device drivers may use
1886
to interact with the kernel and HAL. It is primarily concerned with
1887
the control and management of interrupts and the synchronization of
1888
ISRs, DSRs and threads.
1889
1890
 
1891
1892
The same API will be present in configurations where the kernel
1893
is not present. In this case the functions will be supplied by code
1894
acting directly on the HAL.
1895
1896
 
1897
 
1898
1899
 
1900
1901
Interrupt Model
1902
 
1903
1904
eCos presents a three level interrupt model to
1905
device drivers. This consists of Interrupt Service Routines (ISRs) that are invoked
1907
in response to a hardware interrupt; Deferred
1908
Service Routines (DSRs) that are invoked in response to a request by
1909
an ISR; and threads that are the clients of the driver. 
1910
 
1911
1912
Hardware interrupts are delivered with minimal intervention to an
1913
ISR. The HAL decodes the hardware source of the interrupt and calls
1914
the ISR of the attached interrupt object. This ISR may manipulate the
1915
hardware but is only allowed to make a restricted set of calls on the
1916
driver API. When it returns, an ISR may request that its DSR should be
1917
scheduled to run.
1918
1919
 
1920
1921
A DSR will be run when it is safe to do so without interfering with
1922
the scheduler. Most of the time the DSR will run immediately after the
1923
ISR, but if the current thread is in the scheduler, it will be delayed
1924
until the thread is finished. A DSR is allowed to make a larger set of
1925
driver API calls, including, in particular, being able to call
1926
cyg_drv_cond_signal() to wake up waiting
1927
threads.
1928
1929
 
1930
1931
Finally, threads are able to make all API calls and in particular are
1932
allowed to wait on mutexes and condition variables. 
1933
 
1934
 
1935
1936
For a device driver to receive interrupts it must first define ISR and
1937
DSR routines as shown below, and then call
1938
cyg_drv_interrupt_create().  Using the handle
1939
returned, the driver must then call
1940
cyg_drv_interrupt_attach() to actually attach the
1941
interrupt to the hardware vector.
1942
1943
 
1944
 
1945
1946
 
1947
1948
1949
 
1950
1951
<!-- <index></index> -->Synchronization
1952
 
1953
There are three levels of synchronization supported:
1954
 
1955
1956
  
1957
    
1958
    Synchronization with ISRs. This normally means disabling
1959
    interrupts to prevent the ISR running during a critical
1960
    section. In an SMP environment, this will also require the use of
1961
    a spinlock to synchronize with ISRs, DSRs or threads running on
1962
    other CPUs.  This is implemented by the
1963
    cyg_drv_isr_lock() and
1964
    cyg_drv_isr_unlock() functions. This
1965
    mechanism should be used sparingly and for short periods only.
1966
    For finer grained synchronization, individual spinlocks are also
1967
    supplied.
1968
    
1969
  
1970
 
1971
  
1972
    
1973
    Synchronization with DSRs. This will be implemented in the kernel
1974
    by taking the scheduler lock to prevent DSRs running during
1975
    critical sections. In non-kernel configurations it will be
1976
    implemented by non-kernel code. This is implemented by the
1977
    cyg_drv_dsr_lock() and
1978
    cyg_drv_dsr_unlock() functions. As with ISR
1979
    synchronization, this mechanism should be used sparingly. Only
1980
    DSRs and threads may use this synchronization mechanism, ISRs are
1981
    not allowed to do this.
1982
    
1983
  
1984
  
1985
    
1986
    Synchronization with threads. This is implemented with mutexes
1987
    and condition variables. Only threads may lock the mutexes and
1988
    wait on the condition variables, although DSRs may signal
1989
    condition variables.
1990
    
1991
  
1992
1993
 
1994
1995
Any data that is accessed from more than one level must be protected
1996
against concurrent access. Data that is accessed by ISRs must be
1997
protected with the ISR lock, or a spinlock at all times,
1998
even in ISRs. Data that is shared between DSRs
1999
and threads should be protected with the DSR lock. Data that is only
2000
accessed by threads must be protected with mutexes.
2001
2002
 
2003
2004
 
2005
2006
2007
 
2008
2009
<!-- <index></index> -->SMP Support
2010
 
2011
2012
Some eCos targets contain support for Symmetric Multi-Processing (SMP)
2013
configurations, where more than one CPU may be present. This option
2014
has a number of ramifications for the way in which device drivers must
2015
be written if they are to be SMP-compatible.
2016
2017
 
2018
2019
Since it is possible for the ISR, DSR and thread components of a
2020
device driver to execute on different CPUs, it is important that
2021
SMP-compatible device drivers use the driver API routines correctly.
2022
2023
 
2024
2025
Synchronization between threads and DSRs continues to require that the
2026
thread-side code use cyg_drv_dsr_lock() and
2027
cyg_drv_dsr_unlock() to protect access to shared
2028
data. While it is not strictly necessary for DSR code to claim the DSR
2029
lock, since DSRs are run with it claimed already, it is good practice
2030
to do so.
2031
2032
 
2033
2034
Synchronization between ISRs and DSRs or threads requires that access
2035
to sensitive data be protected, in all places, by calls to
2036
cyg_drv_isr_lock() and
2037
cyg_drv_isr_unlock(). Disabling or masking
2038
interrupts is not adequate, since the thread or DSR may be running on
2039
a different CPU and interrupt enable/disable only work on the current
2040
CPU.
2041
2042
 
2043
2044
The ISR lock, for SMP systems, not only disables local interrupts, but
2045
also acquires a spinlock to protect against concurrent access from
2046
other CPUs. This is necessary because ISRs are not run with the
2047
scheduler lock claimed. Hence they can run in parallel with the other
2048
components of the device driver.
2049
2050
 
2051
2052
The ISR lock provided by the driver API is just a shared spinlock that
2053
is available for use by all drivers. If a driver needs to implement a
2054
finer grain of locking, it can use private spinlocks, accessed via the
2055
cyg_drv_spinlock_*() functions.
2056
2057
 
2058
2059
 
2060
2061
2062
 
2063
2064
Device Driver Models
2065
 
2066
2067
There are several ways in which device drivers
2068
may be built. The exact model chosen will depend on the properties of
2069
the device and the behavior desired. There are three basic models that
2070
may be adopted.
2071
2072
 
2073
2074
The first model is to do all device processing in the ISR.  When it is
2075
invoked the ISR programs the device hardware directly and accesses
2076
data to be transferred directly in memory. The ISR should also call
2077
cyg_drv_interrupt_acknowledge().  When it is
2078
finished it may optionally request that its DSR be invoked.  The DSR
2079
does nothing but call cyg_drv_cond_signal() to
2080
cause a thread to be woken up. Thread level code must call
2081
cyg_drv_isr_lock(), or
2082
cyg_drv_interrupt_mask() to prevent ISRs running
2083
while it manipulates shared memory.
2084
2085
 
2086
2087
The second model is to defer device processing to the DSR.  The ISR
2088
simply prevents further delivery of interrupts by either programming
2089
the device, or by calling
2090
cyg_drv_interrupt_mask().  It must then call
2091
cyg_drv_interrupt_acknowledge() to allow other
2092
interrupts to be delivered and then request that its DSR be
2093
called. When the DSR runs it does the majority of the device handling,
2094
optionally signals a condition variable to wake a thread, and finishes
2095
by calling cyg_drv_interrupt_unmask() to re-allow
2096
device interrupts. Thread level code uses
2097
cyg_drv_dsr_lock() to prevent DSRs running while
2098
it manipulates shared memory.  The eCos serial device drivers use this
2099
approach.
2100
2101
 
2102
2103
The third model is to defer device processing even further to a
2104
thread. The ISR behaves exactly as in the previous model and simply
2105
blocks and acknowledges the interrupt before request that the DSR
2106
run. The DSR itself only calls
2107
cyg_drv_cond_signal() to wake the thread. When
2108
the thread awakens it performs all device processing, and has full
2109
access to all kernel facilities while it does so. It should finish by
2110
calling cyg_drv_interrupt_unmask() to re-allow
2111
device interrupts.  The eCos ethernet device drivers are written to
2112
this model.
2113
2114
 
2115
2116
The first model is good for devices that need immediate processing and
2117
interact infrequently with thread level. The second model trades a
2118
little latency in dealing with the device for a less intrusive
2119
synchronization mechanism. The last model allows device processing to
2120
be scheduled with other threads and permits more complex device
2121
handling.
2122
2123
 
2124
2125
 
2126
2127
2128
 
2129
2130
Synchronization Levels
2131
 
2132
2133
Since it would be dangerous for an ISR or DSR to make a call
2134
that might reschedule the current thread (by trying to lock a mutex
2135
for example) all functions in this API have an associated synchronization
2136
level. These levels are:
2137
2138
 
2139
2140
  
2141
    Thread
2142
    
2143
      
2144
      This function may only be called from within threads. This is
2145
      usually the client code that makes calls into the device driver.
2146
      In a non-kernel configuration, this will be code running at the
2147
      default non-interrupt level.
2148
      
2149
    
2150
  
2151
 
2152
  
2153
    DSR
2154
    
2155
      
2156
      This function may be called by either DSR or thread code.
2157
      
2158
    
2159
  
2160
 
2161
  
2162
    ISR
2163
    
2164
      
2165
      This function may be called from ISR, DSR or thread code.
2166
      
2167
    
2168
  
2169
2170
 
2171
2172
The following table shows, for each API function, the levels
2173
at which is may be called:
2174
2175
 
2176
2177
                                  Callable from:
2178
Function                       ISR     DSR    Thread
2179
-------------------------------------------------------------------------
2180
 
2181
cyg_drv_isr_lock                X       X       X
2182
cyg_drv_isr_unlock              X       X       X
2183
cyg_drv_spinlock_init                           X
2184
cyg_drv_spinlock_destroy                        X
2185
cyg_drv_spinlock_spin           X       X       X
2186
cyg_drv_spinlock_clear          X       X       X
2187
cyg_drv_spinlock_try            X       X       X
2188
cyg_drv_spinlock_test           X       X       X
2189
cyg_drv_spinlock_spin_intsave   X       X       X
2190
cyg_drv_spinlock_clear_intsave  X       X       X
2191
cyg_drv_dsr_lock                        X       X
2192
cyg_drv_dsr_unlock                      X       X
2193
cyg_drv_mutex_init                              X
2194
cyg_drv_mutex_destroy                           X
2195
cyg_drv_mutex_lock                              X
2196
cyg_drv_mutex_trylock                           X
2197
cyg_drv_mutex_unlock                            X
2198
cyg_drv_mutex_release                           X
2199
cyg_drv_cond_init                               X
2200
cyg_drv_cond_destroy                            X
2201
cyg_drv_cond_wait                               X
2202
cyg_drv_cond_signal                     X       X
2203
cyg_drv_cond_broadcast                  X       X
2204
cyg_drv_interrupt_create                        X
2205
cyg_drv_interrupt_delete                        X
2206
cyg_drv_interrupt_attach        X       X       X
2207
cyg_drv_interrupt_detach        X       X       X
2208
cyg_drv_interrupt_mask          X       X       X
2209
cyg_drv_interrupt_unmask        X       X       X
2210
cyg_drv_interrupt_acknowledge   X       X       X
2211
cyg_drv_interrupt_configure     X       X       X
2212
cyg_drv_interrupt_level         X       X       X
2213
cyg_drv_interrupt_set_cpu       X       X       X
2214
cyg_drv_interrupt_get_cpu       X       X       X
2215
 
2216
2217
2218
 
2219
2220
2221
 
2222
2223
The API
2224
 
2225
2226
This section details the Driver Kernel
2227
Interface. Note that most of these functions are identical to Kernel C
2228
API calls, and will in most configurations be wrappers for them. In
2229
non-kernel configurations they will be supported directly by the HAL,
2230
or by code to emulate the required behavior.
2231
2232
 
2233
This API is defined in the header file
2234
<cyg/hal/drv_api.h>.
2235
2236
 
2237
2238
 
2239
2240
<!-- <index></index> -->cyg_drv_isr_lock
2241
 
2242
2243
  
2244
    Function:
2245
    
2246
      void cyg_drv_isr_lock()
2247
    
2248
  
2249
  
2250
    Arguments:
2251
    
2252
      None
2253
    
2254
  
2255
  
2256
    Result:
2257
    
2258
      None 
2259
    
2260
  
2261
  
2262
    Level:
2263
    
2264
      ISR
2265
    
2266
  
2267
  
2268
    Description:
2269
    
2270
      
2271
      Disables delivery of interrupts, preventing all ISRs running.  This
2272
      function maintains a counter of the number of times it is
2273
      called.
2274
      
2275
    
2276
  
2277
2278
2279
 
2280
2281
2282
 
2283
2284
<!-- <index></index> -->cyg_drv_isr_unlock
2285
 
2286
2287
  
2288
    Function:   
2289
    
2290
      void cyg_drv_isr_unlock()
2291
    
2292
  
2293
  
2294
    Arguments:
2295
    
2296
      None
2297
    
2298
  
2299
  
2300
    Result:     
2301
    
2302
      None 
2303
    
2304
  
2305
  
2306
    Level:      
2307
    
2308
      ISR
2309
    
2310
  
2311
  
2312
    Description:        
2313
    
2314
      Re-enables delivery of interrupts, allowing ISRs to
2315
      run. This function decrements the counter maintained by
2316
      cyg_drv_isr_lock(), and only re-allows
2317
      interrupts when it goes to zero. 
2318
    
2319
  
2320
2321
 
2322
2323
 
2324
2325
2326
 
2327
2328
<!-- <index></index> -->cyg_drv_spinlock_init
2329
 
2330
2331
  
2332
    Function:
2333
    
2334
2335
void cyg_drv_spinlock_init(cyg_spinlock_t *lock, cyg_bool_t locked )
2336
2337
    
2338
  
2339
  
2340
    Arguments:
2341
    
2342
      lock - pointer to spinlock to initialize
2343
      locked - initial state of lock
2344
    
2345
  
2346
  
2347
    Result:
2348
    
2349
      None
2350
    
2351
  
2352
  
2353
    Level:
2354
    
2355
      Thread
2356
    
2357
  
2358
  
2359
    Description:
2360
    
2361
      
2362
      Initialize a spinlock. The locked
2363
      argument indicates how the spinlock should be initialized:
2364
      TRUE for locked or FALSE
2365
      for unlocked state.
2366
      
2367
    
2368
  
2369
2370
 
2371
2372
 
2373
2374
2375
 
2376
2377
<!-- <index></index> -->cyg_drv_spinlock_destroy
2378
 
2379
2380
  
2381
    Function:
2382
    
2383
      void cyg_drv_spinlock_destroy(cyg_spinlock_t *lock )
2384
    
2385
  
2386
  
2387
    Arguments:
2388
    
2389
      lock - pointer to spinlock destroy
2390
    
2391
  
2392
  
2393
    Result:
2394
    
2395
      None
2396
    
2397
  
2398
  
2399
    Level:
2400
    
2401
      Thread
2402
    
2403
  
2404
  
2405
    Description:
2406
    
2407
      
2408
      Destroy a spinlock that is no longer of use. There should be no
2409
      CPUs attempting to claim the lock at the time this function is
2410
      called, otherwise the behavior is undefined.
2411
      
2412
    
2413
  
2414
2415
 
2416
2417
 
2418
2419
2420
 
2421
2422
<!-- <index></index> -->cyg_drv_spinlock_spin
2423
 
2424
2425
  
2426
    Function:
2427
    
2428
      void cyg_drv_spinlock_spin(cyg_spinlock_t *lock )
2429
    
2430
  
2431
  
2432
    Arguments:
2433
    
2434
      lock - pointer to spinlock to claim
2435
    
2436
  
2437
  
2438
    Result:
2439
    
2440
      None
2441
    
2442
  
2443
  
2444
    Level:
2445
    
2446
      ISR
2447
    
2448
  
2449
  
2450
    Description:
2451
    
2452
      
2453
      Claim a spinlock, waiting in a busy loop until it is
2454
      available. Wherever this is called from, this operation
2455
      effectively pauses the CPU until it succeeds. This operations
2456
      should therefore be used sparingly, and in situations where
2457
      deadlocks/livelocks cannot occur. Also see
2458
      cyg_drv_spinlock_spin_intsave().
2459
      
2460
    
2461
  
2462
2463
 
2464
2465
 
2466
2467
2468
 
2469
2470
<!-- <index></index> -->cyg_drv_spinlock_clear
2471
 
2472
2473
  
2474
    Function:
2475
    
2476
      void cyg_drv_spinlock_clear(cyg_spinlock_t *lock )
2477
    
2478
  
2479
  
2480
    Arguments:
2481
    
2482
      lock - pointer to spinlock to clear 
2483
    
2484
  
2485
  
2486
    Result:
2487
    
2488
      None
2489
    
2490
  
2491
  
2492
    Level:
2493
    
2494
      ISR
2495
    
2496
  
2497
  
2498
    Description:
2499
    
2500
      
2501
      Clear a spinlock. This clears the spinlock and allows another
2502
      CPU to claim it. If there is more than one CPU waiting in
2503
      cyg_drv_spinlock_spin() then just one of
2504
      them will be allowed to proceed.
2505
      
2506
    
2507
  
2508
2509
 
2510
2511
 
2512
2513
2514
 
2515
2516
<!-- <index></index> -->cyg_drv_spinlock_try
2517
 
2518
2519
  
2520
    Function:
2521
    
2522
      cyg_bool_t cyg_drv_spinlock_try(cyg_spinlock_t *lock )
2523
    
2524
  
2525
  
2526
    Arguments:
2527
    
2528
      lock - pointer to spinlock to try
2529
    
2530
  
2531
  
2532
    Result:
2533
    
2534
      TRUE if the spinlock was claimed,
2535
      FALSE otherwise.
2536
    
2537
  
2538
  
2539
    Level:
2540
    
2541
      ISR
2542
    
2543
  
2544
  
2545
    Description:
2546
    
2547
      
2548
      Try to claim the spinlock without waiting. If the spinlock could
2549
      be claimed immediately then TRUE is
2550
      returned. If the spinlock is already claimed then the result is
2551
      FALSE.
2552
      
2553
    
2554
  
2555
2556
 
2557
2558
 
2559
2560
2561
 
2562
2563
<!-- <index></index> -->cyg_drv_spinlock_test
2564
 
2565
2566
  
2567
    Function:
2568
    
2569
      cyg_bool_t cyg_drv_spinlock_test(cyg_spinlock_t *lock )
2570
    
2571
  
2572
  
2573
    Arguments:
2574
    
2575
      lock - pointer to spinlock to test
2576
    
2577
  
2578
  
2579
    Result:
2580
    
2581
      TRUE if the spinlock is available,
2582
      FALSE otherwise.
2583
    
2584
  
2585
  
2586
    Level:
2587
    
2588
      ISR
2589
    
2590
  
2591
  
2592
    Description:
2593
    
2594
      
2595
      Inspect the state of the spinlock. If the spinlock is not locked
2596
      then the result is TRUE. If it is locked then
2597
      the result will be FALSE.
2598
      
2599
    
2600
  
2601
2602
 
2603
2604
 
2605
2606
2607
 
2608
2609
<!-- <index></index> -->cyg_drv_spinlock_spin_intsave
2610
 
2611
2612
  
2613
    Function:
2614
    
2615
2616
void cyg_drv_spinlock_spin_intsave(cyg_spinlock_t *lock,
2617
                                   cyg_addrword_t *istate )
2618
2619
    
2620
  
2621
  
2622
    Arguments:
2623
    
2624
      lock - pointer to spinlock to claim
2625
      istate - pointer to interrupt state save location
2626
    
2627
  
2628
  
2629
    Result:
2630
    
2631
      None
2632
    
2633
  
2634
  
2635
    Level:
2636
    
2637
      ISR
2638
    
2639
  
2640
  
2641
    Description:
2642
    
2643
      
2644
      This function behaves exactly like
2645
      cyg_drv_spinlock_spin() except that it also
2646
      disables interrupts before attempting to claim the lock. The
2647
      current interrupt enable state is saved in
2648
      *istate. Interrupts remain disabled once
2649
      the spinlock had been claimed and must be restored by calling
2650
      cyg_drv_spinlock_clear_intsave().
2651
      
2652
      
2653
      In general, device drivers should use this function to claim and
2654
      release spinlocks rather than the
2655
      non-_intsave() variants, to ensure proper
2656
      exclusion with code running on both other CPUs and this CPU.
2657
      
2658
    
2659
  
2660
2661
 
2662
2663
 
2664
2665
2666
 
2667
2668
<!-- <index></index> -->cyg_drv_spinlock_clear_intsave
2669
 
2670
2671
  
2672
    Function:
2673
    
2674
2675
void cyg_drv_spinlock_clear_intsave( cyg_spinlock_t *lock,
2676
                                     cyg_addrword_t istate )
2677
2678
    
2679
  
2680
  
2681
    Arguments:
2682
    
2683
      lock - pointer to spinlock to clear 
2684
      istate - interrupt state to restore 
2685
    
2686
  
2687
  
2688
    Result:
2689
    
2690
      None
2691
    
2692
  
2693
  
2694
    Level:
2695
    
2696
      ISR
2697
    
2698
  
2699
  
2700
    Description:
2701
    
2702
      
2703
      This function behaves exactly like
2704
      cyg_drv_spinlock_clear() except that it
2705
      also restores an interrupt state saved by
2706
      cyg_drv_spinlock_spin_intsave(). The
2707
      istate argument must have been
2708
      initialized by a previous call to
2709
      cyg_drv_spinlock_spin_intsave().
2710
      
2711
    
2712
  
2713
2714
 
2715
2716
 
2717
2718
2719
 
2720
2721
<!-- <index></index> -->cyg_drv_dsr_lock
2722
 
2723
2724
  
2725
    Function:
2726
    
2727
      void cyg_drv_dsr_lock()
2728
    
2729
  
2730
  
2731
    Arguments:
2732
    
2733
      None
2734
    
2735
  
2736
  
2737
    Result:     
2738
    
2739
      None 
2740
    
2741
  
2742
  
2743
    Level:      
2744
    
2745
      DSR
2746
    
2747
  
2748
  
2749
    Description:        
2750
    
2751
      Disables scheduling of DSRs. This function maintains a
2752
      counter of the number of times it has been called. 
2753
    
2754
  
2755
2756
2757
 
2758
2759
2760
 
2761
2762
<!-- <index></index> -->cyg_drv_dsr_unlock
2763
 
2764
2765
  
2766
    Function:   
2767
    
2768
      void cyg_drv_dsr_unlock()
2769
    
2770
  
2771
  
2772
    Arguments:
2773
    
2774
      None
2775
    
2776
  
2777
  
2778
    Result:
2779
    
2780
                
2781
      None 
2782
    
2783
  
2784
  
2785
    Level:
2786
    
2787
      DSR
2788
    
2789
  
2790
  
2791
    Description:        
2792
    
2793
      Re-enables scheduling of DSRs. This function decrements
2794
      the counter incremented by
2795
      cyg_drv_dsr_lock().  DSRs are only allowed
2796
      to be delivered when the counter goes to zero. 
2797
    
2798
  
2799
2800
2801
 
2802
2803
2804
 
2805
2806
<!-- <index></index> -->cyg_drv_mutex_init
2807
 
2808
2809
  
2810
    Function:   
2811
    
2812
      void cyg_drv_mutex_init(cyg_drv_mutex *mutex)
2813
    
2814
  
2815
  
2816
    Arguments:
2817
    
2818
      mutex - pointer to mutex to initialize
2819
    
2820
  
2821
  
2822
    Result:     
2823
    
2824
      None 
2825
    
2826
  
2827
  
2828
    Level:      
2829
    
2830
      Thread
2831
    
2832
  
2833
  
2834
    Description:        
2835
    
2836
      Initialize the mutex pointed to by the
2837
      mutex argument. 
2838
    
2839
  
2840
2841
 
2842
2843
 
2844
2845
2846
 
2847
2848
<!-- <index></index> -->cyg_drv_mutex_destroy
2849
 
2850
2851
  
2852
    Function:   
2853
    
2854
      void cyg_drv_mutex_destroy( cyg_drv_mutex *mutex )
2855
    
2856
  
2857
  
2858
    Arguments:
2859
    
2860
      mutex - pointer to mutex to destroy
2861
    
2862
  
2863
  
2864
    Result:     
2865
    
2866
      None 
2867
    
2868
  
2869
  
2870
    Level:      
2871
    
2872
      Thread
2873
    
2874
  
2875
  
2876
    Description:        
2877
    
2878
      Destroy the mutex pointed to by the
2879
      mutex argument. The mutex should be unlocked
2880
      and there should be no threads waiting to lock it when this call
2881
      in made.
2882
    
2883
  
2884
2885
 
2886
2887
 
2888
2889
2890
 
2891
2892
<!-- <index></index> -->cyg_drv_mutex_lock
2893
 
2894
2895
  
2896
    Function:   
2897
    
2898
      cyg_bool cyg_drv_mutex_lock( cyg_drv_mutex *mutex )
2899
    
2900
  
2901
  
2902
    Arguments:
2903
    
2904
      mutex - pointer to mutex to lock
2905
    
2906
  
2907
  
2908
    Result:
2909
    
2910
      TRUE it the thread has claimed the
2911
      lock, FALSE otherwise.
2912
    
2913
  
2914
  
2915
    Level:
2916
    
2917
      Thread
2918
    
2919
  
2920
  
2921
    Description:        
2922
    
2923
      Attempt to lock the mutex pointed to by the
2924
      mutex argument.  If the mutex is already
2925
      locked by another thread then this thread will wait until that
2926
      thread is finished. If the result from this function is
2927
      FALSE then the thread was broken out of its
2928
      wait by some other thread. In this case the mutex will not have
2929
      been locked. 
2930
    
2931
  
2932
2933
 
2934
2935
 
2936
2937
2938
 
2939
2940
<!-- <index></index> -->cyg_drv_mutex_trylock
2941
 
2942
2943
  
2944
    Function:
2945
    
2946
      cyg_bool cyg_drv_mutex_trylock( cyg_drv_mutex *mutex )
2947
    
2948
  
2949
  
2950
    Arguments:
2951
    
2952
      mutex - pointer to mutex to lock
2953
    
2954
  
2955
  
2956
    Result:
2957
    
2958
      TRUE if the mutex has been locked,
2959
      FALSE otherwise. 
2960
    
2961
  
2962
  
2963
    Level:
2964
    
2965
      Thread
2966
    
2967
  
2968
  
2969
    Description:
2970
    
2971
      Attempt to lock the mutex pointed to by the
2972
      mutex argument without waiting. If the
2973
      mutex is already locked by some other thread then this function
2974
      returns FALSE. If the function can lock the
2975
      mutex without waiting, then TRUE is
2976
      returned. 
2977
    
2978
  
2979
2980
 
2981
2982
 
2983
2984
2985
 
2986
2987
<!-- <index></index> -->cyg_drv_mutex_unlock
2988
 
2989
2990
  
2991
    Function:   
2992
    
2993
      void cyg_drv_mutex_unlock( cyg_drv_mutex *mutex )
2994
    
2995
  
2996
  
2997
    Arguments:
2998
    
2999
      mutex - pointer to mutex to unlock
3000
    
3001
  
3002
  
3003
    Result:     
3004
    
3005
    None 
3006
    
3007
  
3008
  
3009
    Level:      
3010
    
3011
      Thread
3012
    
3013
  
3014
  
3015
    Description:        
3016
    
3017
      Unlock the mutex pointed to by the
3018
      mutex argument. If there are any threads
3019
      waiting to claim the lock, one of them is woken up to try and
3020
      claim it. 
3021
    
3022
  
3023
3024
 
3025
3026
 
3027
3028
3029
 
3030
3031
<!-- <index></index> -->cyg_drv_mutex_release
3032
 
3033
3034
  
3035
    Function:   
3036
    
3037
      void cyg_drv_mutex_release( cyg_drv_mutex *mutex )
3038
    
3039
  
3040
  
3041
    Arguments:
3042
    
3043
      mutex - pointer to mutex to release
3044
    
3045
  
3046
  
3047
    Result:     
3048
    
3049
      None 
3050
    
3051
  
3052
  
3053
    Level:      
3054
    
3055
      Thread
3056
    
3057
  
3058
  
3059
    Description:        
3060
    
3061
      Release all threads waiting on the mutex pointed to by the
3062
      mutex argument. These threads will return
3063
      from cyg_drv_mutex_lock() with a
3064
      FALSE result and will not have claimed the
3065
      mutex. This function has no effect on any thread that may have
3066
      the mutex claimed. 
3067
    
3068
  
3069
3070
 
3071
3072
 
3073
3074
3075
 
3076
3077
<!-- <index></index> -->cyg_drv_cond_init
3078
 
3079
3080
  
3081
    Function:   
3082
    
3083
       void cyg_drv_cond_init( cyg_drv_cond *cond, cyg_drv_mutex *mutex )
3084
              
3085
    
3086
  
3087
  
3088
    Arguments:
3089
    
3090
      cond - condition variable to initialize
3091
      mutex - mutex to associate with this condition variable
3092
    
3093
  
3094
  
3095
    Result:     
3096
    
3097
      None
3098
    
3099
  
3100
  
3101
    Level:      
3102
    
3103
      Thread 
3104
    
3105
  
3106
  
3107
    Description:        
3108
    
3109
      Initialize the condition variable pointed to by the
3110
      cond argument.  The
3111
      mutex argument must point to a mutex with
3112
      which this condition variable is associated. A thread may only
3113
      wait on this condition variable when it has already locked the
3114
      associated mutex. Waiting will cause the mutex to be unlocked,
3115
      and when the thread is reawakened, it will automatically claim
3116
      the mutex before continuing. 
3117
    
3118
  
3119
3120
 
3121
3122
 
3123
3124
3125
 
3126
3127
<!-- <index></index> -->cyg_drv_cond_destroy
3128
 
3129
3130
  
3131
    Function:   
3132
    
3133
       void cyg_drv_cond_destroy( cyg_drv_cond *cond )
3134
    
3135
  
3136
  
3137
    Arguments:
3138
    
3139
      cond - condition variable to destroy
3140
    
3141
  
3142
  
3143
    Result:     
3144
    
3145
      None 
3146
    
3147
  
3148
  
3149
    Level:      
3150
    
3151
      Thread
3152
    
3153
  
3154
  
3155
    Description:        
3156
    
3157
      Destroy the condition variable pointed to by the
3158
      cond argument. 
3159
    
3160
  
3161
3162
 
3163
3164
 
3165
3166
3167
 
3168
3169
<!-- <index></index> -->cyg_drv_cond_wait
3170
 
3171
3172
  
3173
    Function:   
3174
    
3175
      void cyg_drv_cond_wait( cyg_drv_cond *cond )
3176
    
3177
  
3178
  
3179
    Arguments:
3180
    
3181
      cond - condition variable to wait on
3182
    
3183
  
3184
  
3185
    Result:     
3186
    
3187
      None 
3188
    
3189
  
3190
  
3191
    Level:      
3192
    
3193
      Thread
3194
    
3195
  
3196
  
3197
    Description:        
3198
    
3199
      Wait for a signal on the condition variable pointed to by
3200
      the cond argument. The thread must have
3201
      locked the associated mutex, supplied in
3202
      cyg_drv_cond_init(), before waiting on this
3203
      condition variable. While the thread waits, the mutex will be
3204
      unlocked, and will be re-locked before this function returns. It
3205
      is possible for threads waiting on a condition variable to
3206
      occasionally wake up spuriously. For this reason it is necessary
3207
      to use this function in a loop that re-tests the condition each
3208
      time it returns. Note that this function performs an implicit
3209
      scheduler unlock/relock sequence, so that it may be used within
3210
      an explicit
3211
      cyg_drv_dsr_lock()...cyg_drv_dsr_unlock()
3212
      structure.
3213
    
3214
  
3215
3216
 
3217
3218
 
3219
3220
3221
 
3222
3223
<!-- <index></index> -->cyg_drv_cond_signal
3224
 
3225
3226
  
3227
    Function:   
3228
    
3229
      void cyg_drv_cond_signal( cyg_drv_cond *cond )
3230
    
3231
  
3232
  
3233
    Arguments:
3234
    
3235
      cond - condition variable to signal
3236
    
3237
  
3238
  
3239
    Result:     
3240
    
3241
      None 
3242
    
3243
  
3244
  
3245
    Level:      
3246
    
3247
      DSR
3248
    
3249
  
3250
  
3251
    Description:        
3252
    
3253
      Signal the condition variable pointed to by the cond
3254
      argument.  If there are any threads waiting on this variable at
3255
      least one of them will be awakened. Note that in some
3256
      configurations there may not be any difference between this
3257
      function and cyg_drv_cond_broadcast().
3258
      
3259
    
3260
  
3261
3262
 
3263
3264
 
3265
3266
3267
 
3268
3269
<!-- <index></index> -->cyg_drv_cond_broadcast
3270
 
3271
3272
  
3273
    Function:   
3274
    
3275
      void cyg_drv_cond_broadcast( cyg_drv_cond *cond )
3276
    
3277
  
3278
  
3279
    Arguments:
3280
    
3281
      cond - condition variable to broadcast to
3282
    
3283
  
3284
  
3285
    Result:     
3286
    
3287
      None 
3288
    
3289
  
3290
  
3291
    Level:      
3292
    
3293
      DSR
3294
    
3295
  
3296
  
3297
    Description:        
3298
    
3299
      Signal the condition variable pointed to by the
3300
      cond argument.  If there are any threads
3301
      waiting on this variable they will all be awakened. 
3302
    
3303
  
3304
3305
 
3306
3307
 
3308
3309
3310
 
3311
3312
<!-- <index></index> -->cyg_drv_interrupt_create
3313
 
3314
3315
  
3316
    Function:   
3317
    
3318
3319
void cyg_drv_interrupt_create( cyg_vector_t vector,
3320
                               cyg_priority_t priority,
3321
                               cyg_addrword_t data,
3322
                               cyg_ISR_t *isr,
3323
                               cyg_DSR_t *dsr,
3324
                               cyg_handle_t *handle,
3325
                               cyg_interrupt *intr
3326
                             )
3327
3328
    
3329
  
3330
  
3331
    Arguments:
3332
    
3333
      vector - vector to attach to
3334
      priority - queuing priority
3335
      data - data pointer
3336
      isr - interrupt service routine
3337
      dsr - deferred service routine
3338
      handle - returned handle
3339
      intr - put interrupt object here
3340
    
3341
  
3342
  
3343
    Result:     
3344
    
3345
      None
3346
    
3347
  
3348
  
3349
    Level:      
3350
    
3351
      Thread
3352
    
3353
  
3354
  
3355
    Description:        
3356
    
3357
      Create an interrupt object and returns a handle to it. The
3358
      object contains information about which interrupt vector to use
3359
      and the ISR and DSR that will be called after the interrupt
3360
      object is attached to the vector. The interrupt object will be
3361
      allocated in the memory passed in the
3362
      intr parameter. The interrupt object is
3363
      not immediately attached; it must be attached with the
3364
      cyg_interrupt_attach() call. 
3365
    
3366
  
3367
3368
3369
 
3370
3371
3372
 
3373
3374
<!-- <index></index> -->cyg_drv_interrupt_delete
3375
 
3376
3377
  
3378
    Function:   
3379
    
3380
       void cyg_drv_interrupt_delete( cyg_handle_t interrupt )
3381
    
3382
  
3383
  
3384
    Arguments:
3385
    
3386
      interrupt - interrupt to delete
3387
    
3388
  
3389
  
3390
    Result:     
3391
    
3392
      None 
3393
    
3394
  
3395
  
3396
    Level:      
3397
    
3398
      Thread
3399
    
3400
  
3401
  
3402
    Description:        
3403
    
3404
      Detach the interrupt from the vector and free the memory
3405
      passed in the intr argument to
3406
      cyg_drv_interrupt_create() for
3407
      reuse. 
3408
    
3409
  
3410
3411
 
3412
3413
 
3414
3415
3416
 
3417
3418
<!-- <index></index> -->cyg_drv_interrupt_attach
3419
 
3420
3421
  
3422
    Function:   
3423
    
3424
      void cyg_drv_interrupt_attach( cyg_handle_t interrupt )
3425
    
3426
  
3427
  
3428
    Arguments:
3429
    
3430
      interrupt - interrupt to attach
3431
    
3432
  
3433
  
3434
    Result:     
3435
    
3436
      None 
3437
    
3438
  
3439
  
3440
    Level:      
3441
    
3442
      ISR
3443
    
3444
  
3445
  
3446
    Description:        
3447
    
3448
      Attach the interrupt to the vector so that interrupts will
3449
      be delivered to the ISR when the interrupt occurs. 
3450
    
3451
  
3452
3453
3454
 
3455
3456
3457
 
3458
3459
<!-- <index></index> -->cyg_drv_interrupt_detach
3460
 
3461
3462
  
3463
    Function:   
3464
    
3465
      void cyg_drv_interrupt_detach( cyg_handle_t interrupt )
3466
    
3467
  
3468
  
3469
    Arguments:
3470
    
3471
      interrupt - interrupt to detach
3472
    
3473
  
3474
  
3475
    Result:     
3476
    
3477
      None 
3478
    
3479
  
3480
  
3481
    Level:      
3482
    
3483
      ISR
3484
    
3485
  
3486
  
3487
    Description:        
3488
    
3489
      Detach the interrupt from the vector so that interrupts
3490
      will no longer be delivered to the ISR. 
3491
    
3492
  
3493
3494
 
3495
3496
 
3497
3498
3499
 
3500
3501
<!-- <index></index> -->cyg_drv_interrupt_mask
3502
 
3503
3504
  
3505
    Function:   
3506
    
3507
      void cyg_drv_interrupt_mask(cyg_vector_t vector )
3508
    
3509
  
3510
  
3511
    Arguments:
3512
    
3513
      vector - vector to mask
3514
    
3515
  
3516
  
3517
    Result:     
3518
    
3519
      None 
3520
    
3521
  
3522
  
3523
    Level:      
3524
    
3525
      ISR
3526
    
3527
  
3528
  
3529
    Description:        
3530
    
3531
      Program the interrupt controller to stop delivery of
3532
      interrupts on the given vector. On architectures which implement
3533
      interrupt priority levels this may also disable all lower
3534
      priority interrupts. 
3535
    
3536
  
3537
3538
3539
 
3540
3541
3542
 
3543
3544
<!-- <index></index> -->cyg_drv_interrupt_mask_intunsafe
3545
 
3546
3547
  
3548
    Function:   
3549
    
3550
      void cyg_drv_interrupt_mask_intunsafe(cyg_vector_t vector )
3551
    
3552
  
3553
  
3554
    Arguments:
3555
    
3556
      vector - vector to mask
3557
    
3558
  
3559
  
3560
    Result:     
3561
    
3562
      None 
3563
    
3564
  
3565
  
3566
    Level:      
3567
    
3568
      ISR
3569
    
3570
  
3571
  
3572
    Description:        
3573
    
3574
      Program the interrupt controller to stop delivery of
3575
      interrupts on the given vector. On architectures which implement
3576
      interrupt priority levels this may also disable all lower
3577
      priority interrupts. This version differs from
3578
      cyg_drv_interrupt_mask() in not being
3579
      interrupt safe. So in situations where, for example, interrupts
3580
      are already known to be disabled, this may be called to avoid
3581
      the extra overhead.
3582
    
3583
  
3584
3585
3586
 
3587
3588
3589
 
3590
3591
<!-- <index></index> -->cyg_drv_interrupt_unmask
3592
 
3593
3594
  
3595
    Function:   
3596
    
3597
      void cyg_drv_interrupt_unmask(cyg_vector_t vector )
3598
    
3599
  
3600
  
3601
    Arguments:
3602
    
3603
      vector - vector to unmask
3604
    
3605
  
3606
  
3607
    Result:     
3608
    
3609
      None 
3610
    
3611
  
3612
  
3613
    Level:      
3614
    
3615
      ISR
3616
    
3617
  
3618
  
3619
    Description:        
3620
    
3621
      Program the interrupt controller to re-allow delivery of
3622
      interrupts on the given vector. 
3623
    
3624
  
3625
3626
3627
 
3628
3629
3630
 
3631
3632
<!-- <index></index> -->cyg_drv_interrupt_unmask_intunsafe
3633
 
3634
3635
  
3636
    Function:   
3637
    
3638
      void cyg_drv_interrupt_unmask_intunsafe(cyg_vector_t vector )
3639
    
3640
  
3641
  
3642
    Arguments:
3643
    
3644
      vector - vector to unmask
3645
    
3646
  
3647
  
3648
    Result:     
3649
    
3650
      None 
3651
    
3652
  
3653
  
3654
    Level:      
3655
    
3656
      ISR
3657
    
3658
  
3659
  
3660
    Description:        
3661
    
3662
      Program the interrupt controller to re-allow delivery of
3663
      interrupts on the given vector. This
3664
      version differs from
3665
      cyg_drv_interrupt_unmask() in not being
3666
      interrupt safe.
3667
    
3668
  
3669
3670
3671
 
3672
3673
3674
 
3675
3676
<!-- <index></index> -->cyg_drv_interrupt_acknowledge
3677
 
3678
3679
  
3680
    Function:   
3681
    
3682
      void cyg_drv_interrupt_acknowledge( cyg_vector_t vector )
3683
    
3684
  
3685
  
3686
    Arguments:
3687
    
3688
      vector - vector to acknowledge
3689
    
3690
  
3691
  
3692
    Result:     
3693
    
3694
      None 
3695
    
3696
  
3697
  
3698
    Level:      
3699
    
3700
      ISR
3701
    
3702
  
3703
  
3704
    Description:        
3705
    
3706
      Perform any processing required at the interrupt
3707
      controller and in the CPU to cancel the current interrupt
3708
      request on the vector. An ISR may also
3709
      need to program the hardware of the device to prevent an
3710
      immediate re-triggering of the interrupt. 
3711
    
3712
  
3713
3714
3715
 
3716
3717
3718
 
3719
3720
<!-- <index></index> -->cyg_drv_interrupt_configure
3721
 
3722
3723
  
3724
    Function:   
3725
    
3726
      
3727
void cyg_drv_interrupt_configure( cyg_vector_t vector,
3728
                                  cyg_bool_t level,
3729
                                  cyg_bool_t up
3730
                                )
3731
3732
    
3733
  
3734
  
3735
    Arguments:
3736
    
3737
      vector - vector to configure
3738
      level - level or edge triggered
3739
      up - rising/falling edge, high/low level
3740
    
3741
  
3742
  
3743
    Result:     
3744
    
3745
      None
3746
    
3747
  
3748
  
3749
    Level:      
3750
    
3751
      ISR
3752
    
3753
  
3754
  
3755
    Description:        
3756
    
3757
      Program the interrupt controller with the characteristics
3758
      of the interrupt source. The level
3759
      argument chooses between level- or edge-triggered
3760
      interrupts. The up argument chooses
3761
      between high and low level for level triggered interrupts or
3762
      rising and falling edges for edge triggered interrupts. This
3763
      function only works with interrupt controllers that can control
3764
      these parameters. 
3765
    
3766
  
3767
3768
 
3769
3770
 
3771
3772
3773
 
3774
3775
<!-- <index></index> -->cyg_drv_interrupt_level
3776
 
3777
3778
  
3779
    Function:   
3780
    
3781
3782
void cyg_drv_interrupt_level( cyg_vector_t vector,
3783
                              cyg_priority_t level
3784
                            )
3785
3786
    
3787
  
3788
  
3789
    Arguments:
3790
    
3791
      vector - vector to configure
3792
      level - level to set
3793
    
3794
  
3795
  
3796
    Result:     
3797
    
3798
      None 
3799
    
3800
  
3801
  
3802
    Level:      
3803
    
3804
      ISR
3805
    
3806
  
3807
  
3808
    Description:        
3809
    
3810
      Program the interrupt controller to deliver the given
3811
       interrupt at the supplied priority level. This function only
3812
       works with interrupt controllers that can control this
3813
       parameter.
3814
    
3815
  
3816
3817
 
3818
3819
 
3820
3821
3822
 
3823
3824
<!-- <index></index> -->cyg_drv_interrupt_set_cpu
3825
 
3826
3827
  
3828
    Function:
3829
    
3830
3831
void cyg_drv_interrupt_set_cpu( cyg_vector_t vector,
3832
                                cyg_cpu_t cpu
3833
                              )
3834
3835
    
3836
  
3837
  
3838
    Arguments:
3839
    
3840
      vector - interrupt vector to route
3841
      cpu - destination CPU
3842
    
3843
  
3844
  
3845
    Result:
3846
    
3847
      None
3848
    
3849
  
3850
  
3851
    Level:
3852
    
3853
      ISR
3854
    
3855
  
3856
  
3857
    Description:        
3858
    
3859
      
3860
      This function causes all interrupts on the given vector to be
3861
      routed to the specified CPU. Subsequently, all such interrupts
3862
      will be handled by that CPU. This only works if the underlying
3863
      hardware is capable of performing this kind of routing. This
3864
      function does nothing on a single CPU system.
3865
      
3866
    
3867
  
3868
3869
 
3870
3871
 
3872
3873
3874
 
3875
3876
<!-- <index></index> -->cyg_drv_interrupt_get_cpu
3877
 
3878
3879
  
3880
    Function:
3881
    
3882
3883
cyg_cpu_t cyg_drv_interrupt_set_cpu( cyg_vector_t vector )
3884
3885
    
3886
  
3887
  
3888
    Arguments:
3889
    
3890
      vector - interrupt vector to query
3891
    
3892
  
3893
  
3894
    Result:
3895
    
3896
      The CPU to which this vector is routed
3897
    
3898
  
3899
  
3900
    Level:
3901
    
3902
      ISR
3903
    
3904
  
3905
  
3906
    Description:        
3907
    
3908
      
3909
      In multi-processor systems this function returns the id of the
3910
      CPU to which interrupts on the given vector are current being
3911
      delivered. In single CPU systems this function returns zero.
3912
      
3913
    
3914
  
3915
3916
 
3917
3918
 
3919
3920
3921
 
3922
3923
<!-- <index></index> -->cyg_ISR_t
3924
 
3925
3926
  
3927
    Type:       
3928
    
3929
3930
typedef cyg_uint32 cyg_ISR_t( cyg_vector_t vector,
3931
                              cyg_addrword_t data
3932
                            )
3933
3934
    
3935
  
3936
  
3937
    Fields:
3938
    
3939
      vector - vector being delivered
3940
      data - data value supplied by client
3941
    
3942
  
3943
  
3944
    Result:     
3945
    
3946
      Bit mask indicating whether interrupt was handled and
3947
      whether the DSR should be called. 
3948
    
3949
  
3950
  
3951
    Description:        
3952
    
3953
      Interrupt Service Routine definition. A pointer to a
3954
      function with this prototype is passed to
3955
      cyg_interrupt_create() when an interrupt
3956
      object is created. When an interrupt is delivered the function
3957
      will be called with the vector number and the data value that
3958
      was passed to cyg_interrupt_create().
3959
      
3960
      The return value is a bit mask containing one or both of the
3961
      following bits: 
3962
      
3963
        
3964
          CYG_ISR_HANDLED       
3965
          
3966
            indicates that the interrupt was handled by this
3967
            ISR. It is a configuration option whether this will
3968
            prevent further ISR being run. 
3969
          
3970
        
3971
        
3972
          CYG_ISR_CALL_DSR      
3973
          
3974
            causes the DSR that was passed to
3975
            cyg_interrupt_create() to be
3976
            scheduled to be called.
3977
          
3978
        
3979
      
3980
    
3981
  
3982
3983
 
3984
3985
 
3986
3987
3988
 
3989
3990
<!-- <index></index> -->cyg_DSR_t
3991
 
3992
3993
  
3994
    Type:       
3995
    
3996
3997
typedef void cyg_DSR_t( cyg_vector_t vector,
3998
                        cyg_ucount32 count,
3999
                        cyg_addrword_t data
4000
                      )
4001
4002
    
4003
  
4004
  
4005
    Fields:
4006
    
4007
      vector - vector being delivered
4008
      count - number of times DSR has been scheduled
4009
      data - data value supplied by client
4010
    
4011
  
4012
  
4013
    Result:     
4014
    
4015
      None
4016
    
4017
  
4018
  
4019
    Description:        
4020
    
4021
      Deferred Service Routine prototype. A pointer to a
4022
      function with this prototype is passed to
4023
      cyg_interrupt_create() when an interrupt
4024
      object is created. When the ISR requests the scheduling of its
4025
      DSR, this function will be called at some later point. In
4026
      addition to the vector and
4027
      data arguments, which will be the same as
4028
      those passed to the ISR, this routine is also passed a
4029
      count of the number of times the ISR has
4030
      requested that this DSR be scheduled.  This counter is zeroed
4031
      each time the DSR actually runs, so it indicates how many
4032
      interrupts have occurred since it last ran.
4033
    
4034
  
4035
4036
 
4037
4038
 
4039
4040
 
4041
4042
 
4043
4044
 
4045
4046
 
4047
4048
 
4049
 
4050

powered by: WebSVN 2.1.0

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