home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / documentation / documents / a252buf < prev    next >
Text File  |  1999-04-27  |  13KB  |  425 lines

  1. Buffer Manager
  2. ==============
  3.  
  4. The buffer manager provides a global buffer managing system, it provides a
  5. set of calls for setting up a buffer, inserting and removing data from a
  6. buffer and finally removing a buffer.  It is also possible to setup an area
  7. of memory to be used as a buffer.
  8.  
  9. The buffer manager extends the INSV, REMV and CNPV to provide access to
  10. these buffers and also allow block transfers.
  11.  
  12. The buffer manager is used by DeviceFS to provide buffers for the various
  13. devices that can be accessed.  A device may be linked to a buffer supply
  14. routines to be called when data enters the buffer and also a routine to be
  15. called when a buffer is removed (or a new device is attached).
  16.  
  17. When registering or creating a buffer it is possible to force a specific
  18. buffer handle, if this feature is not used then the manager will asign a
  19. unique handle to it.  It should be noted that buffer handles are no longer
  20. stored as eight bit quanities.
  21.  
  22. Block transfers are signalled by setting bit 31 of the buffer handle,
  23. anything which can be performed on a byte by byte basis can also be
  24. performed on a block, eg. examine the buffer contents.
  25.  
  26.  
  27. SWI interface
  28. =============
  29.  
  30. Buffer_Create
  31. -------------
  32.  
  33.   in:   r0  = flags for the buffer
  34.                 bit  0 =0 => buffer is dormant and should be woken up when
  35.                               data enters it
  36.                 bit  1 =1 => buffer generates "output buffer empty" events
  37.                 bit  2 =1 => buffer generates "input buffer full" events
  38.                 bit  3 =1 => buffer generates upcalls when free space
  39.                               threshold crossed (from above or below)
  40.                 bits 4-31    reserved for future expansion, should be set
  41.                               to zero on creation
  42.  
  43.         r1  = size of buffer to be created
  44.         r2  = buffer handle to assign to buffer, -1 for does not matter
  45.  
  46.   out:  V =0 => r0  = buffer handle
  47.         V =1 => r0 -> error block
  48.  
  49. This routine claims an area of memory from the RMA and links it into the
  50. buffer list, if r2 =-1 then the buffer manager will attempt to find a unique
  51. handle, if r2 <>-1 then the buffer manager will check that the handle
  52. specified is unique and then if it is assign it to that buffer.
  53.  
  54. The flags word is used to indicate what should happen when data is being
  55. inserted and removed from the buffer.
  56.  
  57. Bit 0 is used to indicate if the device attached to the buffer has
  58. been woken up, when =0 then the device is dormant and needs to be woken.
  59. When a device is attached and data is put into the buffer this bit is
  60. checked, if it is =0 then the wake up code for the device will be called
  61. allowing any device to wake up any hardware it may be driving and to start
  62. processing data within the buffer.
  63.  
  64. Bit 1 is used to indicate if "output buffer empty" events should be issued
  65. for this buffer.
  66.  
  67. Bit 2 is used to indicate if "input buffer full" events should be issued for
  68. this buffer.
  69.  
  70. Bit 3 is used to indicate if buffer threshold UpCalls should be issued for
  71. this buffer.
  72.  
  73. On exit r0 contains the buffer handle being used or a pointer to an error
  74. block.
  75.  
  76.  
  77. Buffer_Remove
  78. -------------
  79.  
  80.   in:   r0  = handle of buffer to be removed
  81.  
  82.   out:  V =1 => r0 -> error block, else preserved
  83.  
  84. This call should only be made on buffers created using Buffer_Create.
  85.  
  86. It attempts to de-register the buffer from the active list and assuming that
  87. worked ok it will attempt to free the memory relating to that buffer.
  88.  
  89.  
  90. Buffer_Register
  91. ---------------
  92.  
  93.   in:   r0  = flags for buffer (see above)
  94.         r1 -> start of memory for buffer
  95.         r2 -> end of buffer (+1)
  96.         r3  = handle to be assigned to buffer (-1 if to be generated)
  97.  
  98.   out:  V =0 => r0  = handle for buffer
  99.         V =1 => r0 -> error block
  100.  
  101. This call registers an area of memory as a buffer, the routine accepts
  102. similar parameters to the Buffer_Create SWI, but instead of the call
  103. claiming tha area of memory for you, you must actually specify the buffer's
  104. start and end addresses.
  105.  
  106. It is not advisable to put buffers in application workspace, this
  107. area of memory can be switched out when someone else tries to access it.  It
  108. is however possible for your task if it is going to be the only one using
  109. this buffer, and it will only be accessed whilst the task is currently paged
  110. in to register a buffer within its workspace.
  111.  
  112. For further details about the flags word and the specified buffer handle
  113. see the Buffer_Create call.
  114.  
  115.  
  116. Buffer_Deregister
  117. -----------------
  118.  
  119.   in:   r0  = handle of buffer to be deregistered.
  120.  
  121.   out:  V =0 => all preserved.
  122.         V =1 => r0 -> error block.
  123.  
  124. This call will simply unlink a buffer from the active list, the data within
  125. the buffer will be purged and any access to this buffer via INSV, REMV and
  126. CNPV will be ignored.
  127.  
  128. Do not use this call if you have created the buffer using Buffer_Create,
  129. instead use Buffer_Remove which releases any memory that may have been
  130. claimed.
  131.  
  132.  
  133. Buffer_ModifyFlags
  134. ------------------
  135.  
  136.   in:   r0  = handle of buffer to be modified
  137.         r1  = EOR mask
  138.         r2  = AND mask
  139.  
  140.   out:  r1  = old value
  141.         r2  = new value
  142.  
  143. This call allows you to modify the flags word stored with each buffer, the
  144. SWI allows two registers to be ANDed and then EORed with the current flags
  145. word, on exit the old and new values of this word are returned to the
  146. caller.
  147.  
  148. r1, r2 are applied as follows:
  149.  
  150.         new = (old AND r2) EOR r1
  151.  
  152. The caller should not modify reserved flag bits when issuing this call, ie
  153. bits 4 to 31 should be set in r2 and clear in r1.
  154.  
  155.  
  156. Buffer_LinkDevice
  157. -----------------
  158.  
  159.   in:   r0  = buffer handle,
  160.         r1 -> code to wake up device when needed      (0 => none)
  161.         r2 -> code to call when device to be detached (0 => cannot be
  162. detached)
  163.         r3  = private word to be passed in
  164.         r4 -> workspace for above routines
  165.  
  166.   out:  V =1 => r0 -> error block, else all preserved.
  167.  
  168. This call links a set of routines to the specified device, the caller
  169. supplies two routines, one to be called when data enters the buffer and
  170. another to be called when someone else attempts to link to the buffer.
  171.  
  172. r1 this contains a pointer to the routine to be called when data enters the
  173. buffer and it is currently marked dormant, the routine can be entered in any
  174. mode and with FIQs or IRQs enabled / disabled, the mode should be preserved
  175. as should the interrupt state.
  176.  
  177. The registers to the wake up code are setup as follows:
  178.  
  179.   in:   r0   = buffer handle
  180.         r8   = private word          (specified in r3 in SWI
  181. Buffer_LinkDevice)
  182.         r12 -> workspace for routine (specified in r4 in SWI
  183. Buffer_LinkDevice)
  184.  
  185.   out:  all should be preserved, including PSR.
  186.  
  187. The buffer manager automatically marks the buffer as active (non-dormant)
  188. before calling the wake up code.
  189.  
  190. If the caller to Buffer_LinkDevice specifies a routine pointer equal to zero
  191. then no wake up call is made.
  192.  
  193. The second routine supplied is a routine to be called whenever the owner of
  194. the buffer is about to change; if this value is zero then the device is
  195. indicating that the owner can never be changed and changing it will result
  196. in an error.
  197.  
  198. The routine if supplied gets called as follows:
  199.  
  200.   in:   r0   = buffer handle
  201.         r8   = private word
  202.         r12 -> workspace for the calls
  203.  
  204.   out:  V =1 => r0 -> error block
  205.         V =0 => all preserved
  206.  
  207. On return from this routine the routine can return an error, any errors
  208. returned halt the detach process.  The detach routines are called when
  209. someone attempts to kill the buffer manager module, this results in an error
  210. and the buffer manager refuses to die.
  211.  
  212. When attaching to a buffer it is possible that the SWI will fail, this is
  213. likely to be because the current owner is refusing to detach itself.
  214.  
  215.  
  216. Buffer_UnlinkDevice
  217. -------------------
  218.  
  219.   in:   r0  = buffer handle
  220.  
  221.   out:  V =0 => all preserved and device detached.
  222.         V =1 => r0 -> error block.
  223.  
  224. This routine will unlink a device from a buffer, no warning if given of the
  225. detach and the data that is currently stored within the buffer is purged.
  226.  
  227. This call should only be used by the actual device that called
  228. Buffer_LinkDevice, anyone else calling this SWI could confuse the system.
  229.  
  230.  
  231. Buffer_GetInfo
  232. --------------
  233.  
  234.   in:   r0  = buffer handle
  235.  
  236.   out:  V =1 => r0 -> error block
  237.         V =0 => r0  = flags relating to buffer
  238.                 r1 -> start of buffer in memory
  239.                 r2 -> end of buffer in memory (+1)
  240.                 r3  = insert index for buffer
  241.                 r4  = remove index for buffer
  242.                 r5  = remaining free space in buffer
  243.                 r6  = number of characters in buffer
  244.  
  245. This call returns data about the buffer, its position in memory, flags,
  246. insert and remove offsets and the amount of free space.
  247.  
  248.  
  249.  
  250. Buffer_Threshold
  251. ----------------
  252.  
  253.   in:   r0  = buffer handle
  254.         r1  = threshold / 0 none / -1 to read
  255.  
  256.   out:  r1  = previous value
  257.  
  258. This call is used to set/read the warning threshold of the buffer.  This is
  259. used to trigger UpCalls if bit 3 of the buffer flags is set.
  260.  
  261. The UpCalls are issued when the amount of free space in the buffer
  262. crosses the threshold value (see the UpCalls section below)
  263.  
  264.  
  265.  
  266. Vector calls
  267. ============
  268.  
  269. The SWIs for the buffer manager module allow you to modify and tinker with
  270. the actual buffer itself, they do not however supply a way of inserting and
  271. removing data from these buffers.
  272.  
  273. Extensions have been made to the three vectors; InsV, RemV and CnpV to
  274. handle the inserting and removing of data from the buffers, these calls have
  275. also been extended to allow block inserts.
  276.  
  277. For compatibility marking a block operation is done by setting bit 31 of the
  278. buffer handle.  This changes the specification for calling these vectors as
  279. follows:
  280.  
  281. InsV
  282. ----
  283.  
  284.   in:   r0  = byte to be inserted
  285.         r1  = buffer handle (bit 31 is clear)
  286.  
  287.   out:  r0, r1 preserved
  288.         r2 corrupt
  289.  
  290. or:-
  291.  
  292.   in:   r1  = buffer handle (bit 31 is set)
  293.         r2 -> first byte of data to be inserted
  294.         r3  = number of bytes to insert
  295.  
  296.   out:  r0, r1 preserved
  297.         r2 -> remaining data to be inserted
  298.         r3  = number of bytes still to be inserted
  299.  
  300. On both calls C is used to indicate if the insertion failed, if C=1 then it
  301. was not possible to insert all the specified data, or the specified byte.
  302.  
  303.  
  304. RemV
  305. ----
  306.  
  307.   in:   r1  = buffer handle (bit 31 clear)
  308.  
  309.   out:  r0  = next byte to be removed (for examine only)
  310.         r1  = preserved
  311.         r2  = byte removed (for remove only)
  312.  
  313. or:-
  314.  
  315.   in:   r1  = buffer handle (bit 31 set)
  316.         r2 -> buffer to be filled
  317.         r3  = number of bytes to place into buffer
  318.  
  319.   out:  r0, r1 preserved
  320.         r2 -> updated buffer position
  321.         r3  = number of bytes still to be removed
  322.  
  323. On both of the above calls V =1 on entry indicates that the data should be
  324. copied out (examine) and V =0 indicates that the data should actually be
  325. removed.
  326.  
  327. On exit C is used to indicate if the calls actually worked and if a byte or
  328. the requested block of data could be obtained.
  329.  
  330.  
  331. CnpV
  332. ----
  333.  
  334. Unchanged, except it copes with buffer manager buffers.
  335.  
  336.  
  337. Events
  338. ======
  339.  
  340. With the changes required to InsV, RemV and CnpV calls to cope with the new
  341. buffers and block transfers some of the events have been extended to cope
  342. with indicating that a block transfer occurred.
  343.  
  344. For further details of the events and when they are generated consult the
  345. PRM, as this remains unchanged.
  346.  
  347.  
  348. Event_OutputEmpty
  349. -----------------
  350.  
  351.   in:   r0  = Event_OutputEmpty (0)
  352.         r1  = buffer handle
  353.  
  354.   out:  all preserved.
  355.  
  356. This is issued when the last character is removed from a buffer which has
  357. output empty events enabled (see description of buffer flags).
  358.  
  359.  
  360. Event_InputFull
  361. ---------------
  362.  
  363.   in:   r0  = Event_InputFull (1)
  364.         r1  = buffer handle (bit 31 clear)
  365.         r2  = character not inserted
  366.  
  367. or:-
  368.         r0  = Event_InputFull (1)
  369.         r1  = buffer handle (bit 31 set)
  370.         r2 -> data not inserted
  371.         r3  = number of bytes not inserted
  372.  
  373.   out:  all preserved.
  374.  
  375. This event is generated when a character or block is inserted into a buffer
  376. which has input full events enabled (see description of buffer flags), and
  377. the insertion failed.
  378.  
  379.  
  380. Service calls
  381. =============
  382.  
  383. Service_BufferStarting (&6F)
  384. ----------------------------
  385.  
  386.   in:   r1  = Service_BufferStarting (&6F)
  387.  
  388.   out:  all preserved.
  389.  
  390. This call is passed around after the module has been initialised or reset.
  391. It allows module which wish to register buffers with the buffer manager to
  392. do so.
  393.  
  394. When the service is received all SWIs are valid.
  395.  
  396.  
  397.  
  398. UpCalls
  399. =======
  400.  
  401. UpCall_BufferFilling (8)
  402. ------------------------
  403.  
  404. in:     r0  = 8
  405.         r1  = Buffer handle
  406.         r2  = 0
  407.  
  408. out:    -
  409.  
  410. This is issued when data is inserted into the buffer and the free space
  411. becomes less than the specified threshold.
  412.  
  413.  
  414. UpCall_BufferEmptying (9)
  415. -------------------------
  416.  
  417. in:     r0  = 9
  418.         r1  = Buffer handle
  419.         r2  = -1
  420.  
  421. out:    -
  422.  
  423. This is issued when data is removed from the buffer and the free space
  424. becomes greater than or equal to the current threshold.
  425.