]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/performance-audio-sr.git/blobdiff - pasdk/test_dsp/io/ioBuff.c
Implemented event-based ASIT FSM execpt the initial state.
[processor-sdk/performance-audio-sr.git] / pasdk / test_dsp / io / ioBuff.c
index 6fc6581555bed00974f7121d0f5fcd48fb7956a8..0ade8152bc66ba5d16264d820a9ae8e03b092c80 100644 (file)
@@ -81,7 +81,7 @@ int ioBuffInit (ioBuffHandle_t handle, const ioBuffParams_t *params)
   inst->sync  = params->sync;           // synchronous read or synchronous write
   inst->nom_delay = params->nominalDelay;   // nominal delay for synchronous read/write
 
-  inst->rw_wrap_around = 0;
+  //inst->rw_wrap_around = 0;
   inst->status = BUFF_STATUS_NORMAL;
   inst->read_ptr  = inst->read_complete_ptr  = inst->base;
   inst->write_ptr = inst->write_complete_ptr = (void *)((uint_least32_t)inst->base + inst->nom_delay);
@@ -104,11 +104,11 @@ int ioBuffGetReadPtrs(ioBuffHandle_t handle, size_t mem_size,
 
   if(inst->status != BUFF_STATUS_OVERFLOW) {
     /* check if buffer underflows */
-    if(  (  (!inst->rw_wrap_around) 
+    if(  (  ((uint_least32_t)inst->write_complete_ptr >= (uint_least32_t)inst->read_ptr)
           &&(((uint_least32_t)inst->write_complete_ptr - 
               (uint_least32_t)inst->read_ptr) < mem_size)
          )
-       ||(  (inst->rw_wrap_around)
+       ||(  ((uint_least32_t)inst->write_complete_ptr < (uint_least32_t)inst->read_ptr)
           &&(((uint_least32_t)inst->write_complete_ptr + inst->size - 
               (uint_least32_t)inst->read_ptr) < mem_size)
          )
@@ -128,7 +128,7 @@ int ioBuffGetReadPtrs(ioBuffHandle_t handle, size_t mem_size,
                                                   delay_adjust);
         if(inst->read_ptr < inst->base) {
           inst->read_ptr = (void *)((uint_least32_t)inst->read_ptr + inst->size);
-          inst->rw_wrap_around = 1;   // set wrap around flag
+          //inst->rw_wrap_around = 1;   // set wrap around flag
         }
          
         ret_val = IOBUFF_ERR_UNDERFLOW;
@@ -210,11 +210,11 @@ int ioBuffGetWritePtrs(ioBuffHandle_t handle, size_t mem_size,
 
   /* check if buffer overflows or not */
   if(inst->status != BUFF_STATUS_UNDERFLOW) {   // this condition may need to be removed!!!
-    if(  (  (!inst->rw_wrap_around) 
+    if(  (  ((uint_least32_t)inst->read_complete_ptr < (uint_least32_t)inst->write_ptr)
           &&(((uint_least32_t)inst->read_complete_ptr + inst->size - 
               (uint_least32_t)inst->write_ptr) < mem_size)
          )
-       ||(  (inst->rw_wrap_around) 
+       ||(  ((uint_least32_t)inst->read_complete_ptr >= (uint_least32_t)inst->write_ptr)
           &&(((uint_least32_t)inst->read_complete_ptr - 
               (uint_least32_t)inst->write_ptr) < mem_size)
          )
@@ -242,7 +242,8 @@ int ioBuffGetWritePtrs(ioBuffHandle_t handle, size_t mem_size,
   else {
     /* already in underflow and remain in underflow untill write pointer is 
        ahead of read pointer */
-    ret_val = IOBUFF_ERR_UNDERFLOW;
+    //ret_val = IOBUFF_ERR_UNDERFLOW;
+    ret_val = IOBUFF_NOERR;  // underflow is not an error when getting write pointers
   }
 
   /* return 1 or 2 pointers depending buffer wraps around or not */
@@ -285,7 +286,7 @@ int ioBuffReadComplete(ioBuffHandle_t handle, void *read_begin, size_t read_size
   if(inst->read_complete_ptr >= inst->end) {
     inst->read_complete_ptr = (void *) ((uint_least32_t)inst->read_complete_ptr 
                                         - inst->size);
-    inst->rw_wrap_around ^= 1;   // toggle wrap around flag
+    //inst->rw_wrap_around ^= 1;   // toggle wrap around flag
   }
 
   return (IOBUFF_NOERR);
@@ -302,7 +303,7 @@ int ioBuffWriteComplete(ioBuffHandle_t handle, void *write_begin, size_t write_s
   if(inst->write_complete_ptr >= inst->end) {
     inst->write_complete_ptr = (void *)((uint_least32_t)inst->write_complete_ptr 
                                         - inst->size);
-    inst->rw_wrap_around ^= 1;   // toggle wrap around flag
+    //inst->rw_wrap_around ^= 1;   // toggle wrap around flag
   }
 
   return (IOBUFF_NOERR);
@@ -359,12 +360,12 @@ int ioBuffAdjustDelay(ioBuffHandle_t handle, size_t delay)
 
     if( (size_t)inst->write_complete_ptr >= ((size_t)inst->base+delay) ) {
         inst->read_ptr = inst->read_complete_ptr = (void *)((size_t)inst->write_complete_ptr - delay);
-        inst->rw_wrap_around = 0;
+        //inst->rw_wrap_around = 0;
     }
     else {
         temp = delay - ((size_t)inst->write_complete_ptr - (size_t)inst->base);
         inst->read_ptr = inst->read_complete_ptr = (void *)((size_t)inst->end - temp);
-        inst->rw_wrap_around = 1;
+        //inst->rw_wrap_around = 1;
     }
 
     inst->nom_delay = delay;