Example #1
0
void task1(void *arg)
{
    os_printf("task1 start....\n");
    for (;;) {
#if msg_queue_test
        msg_put(&my_queue, &msg1, FIFO);
        msg_put(&my_queue, &msg2, FIFO);
        msg_put(&my_queue, &msg3, FIFO);
        msg_put(&my_queue1, &msg4, FIFO);
        msg_put(&my_queue1, &msg5, FIFO);
        msg_put(&my_queue1, &msg6, FIFO);
        msg_put(&my_queue2, &msg7, FIFO);
        msg_put(&my_queue2, &msg8, FIFO);
        msg_put(&my_queue2, &msg9, FIFO);
#endif

#if sem_test
        sem_put(&sem);
        os_printf("task1 sem.count = %d\n", sem.count );
#endif

#if mutex_test
        mutex_get(&mutex);
        os_printf("task1 priority: %d\n", new_task->prio );
        schedule();
        os_printf("task1 running\n");
        mutex_put(&mutex);
#endif
        os_delay(300);
    }
}
Example #2
0
/***************************************************************************
 GfxSetFGColor
***************************************************************************/
void GfxSetFGColor(u_int32 Color)
{
   sem_get(GXA_Sem_Id, KAL_WAIT_FOREVER);

   mCheckFifo(1)
   mLoadReg(GXA_FG_COLOR_REG, Color)

   sem_put(GXA_Sem_Id);

}
Example #3
0
/**
 * Music player callback to get the current song path.
 */
static const char *get_current_song_path(void *arg_p)
{
    struct song_t *song_p;

    sem_get(&sem, NULL);
    song_p = hash_map_get(&song_map, current_song);
    sem_put(&sem, 1);

    return (song_p->name);
}
Example #4
0
CNXT_SMC_STATUS cnxt_smc_close ( CNXT_SMC_HANDLE Handle )
{
   CNXT_SMC_INST *pInst = (CNXT_SMC_INST*)Handle;
   CNXT_SMC_UNIT_INST *pUnitInst;

   IS_DRIVER_INITED(SMC,pDriverInst->bInit);
   IS_VALID_HANDLE(SMC, pInst, &(pDriverInst->pUnitInst[pInst->uUnitNumber].pFirstInst));

   if (sem_get(pDriverInst->DriverSem, KAL_WAIT_FOREVER) != RC_OK)
   {
      return CNXT_SMC_INTERNAL_ERROR;
   }

   /*
    * Put Driver Specific code here.
    */

   pUnitInst = &(pDriverInst->pUnitInst[pInst->uUnitNumber]);

   /* release the resource of the instance */
   if (REMOVE_HANDLE(&(pUnitInst->pFirstInst), pInst) == FALSE)
   {
      sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
      return CNXT_SMC_INTERNAL_ERROR;
   }

   DESTROY_HANDLE(&(pDriverInst->pInstList), pInst);

   /* set the unit to be shared if no instance opened for the unit */
   if ( pUnitInst->pFirstInst == NULL )
   {
      pUnitInst->bExclusive = FALSE;
   }

   sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
   return CNXT_SMC_OK;
} /* end cnxt_smc_close() */
Example #5
0
CNXT_SMC_STATUS cnxt_smc_reset ( CNXT_SMC_CONFIG *pCfg )
{
   u_int32 i;

   IS_DRIVER_INITED(SMC, pDriverInst->bInit);

   if (sem_get(pDriverInst->DriverSem, KAL_WAIT_FOREVER) != RC_OK)
   {
      return CNXT_SMC_INTERNAL_ERROR;
   }

   /* Mark the driver as not initialized */
   pDriverInst->bInit = FALSE;

   /* notify all clients of reset of the driver */
   for ( i = 0 ; i < CNXT_SMC_NUM_UNITS ; i ++ )
   {
      cnxt_smc_notify_unit_clients(CNXT_SMC_EVENT_RESET, i);
   }


   /* initialize internal data */
   if ( cnxt_smc_internal_data_init() == FALSE )
   {
      sem_put(pDriverInst->DriverSem);
      return CNXT_SMC_RESOURCE_ERROR;
   }
   
   /*
    * Put Driver Specific code here.
    */

   pDriverInst->bInit = TRUE; 
   sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
   return CNXT_SMC_OK;
} /* end cnxt_smc_reset() */
Example #6
0
static int next()
{
    music_player_song_stop(&music_player);

    /* Increment current song. */
    sem_get(&sem, NULL);
    current_song++;

    if (hash_map_get(&song_map, current_song) == NULL) {
        current_song = FIRST_SONG_NUMBER;
    }

    sem_put(&sem, 1);

    return (music_player_song_play(&music_player));
}
Example #7
0
static int prev()
{
    music_player_song_stop(&music_player);

    /* Increment current song. */
    sem_get(&sem, NULL);

    if (current_song == FIRST_SONG_NUMBER) {
        current_song = last_song_number;
    } else {
        current_song--;
    }

    sem_put(&sem, 1);

    return (music_player_song_play(&music_player));
}
Example #8
0
/**
 * Music player callback to get the next song path.
 */
static const char *get_next_song_path(void *arg_p)
{
    struct song_t *song_p;

    sem_get(&sem, NULL);

    /* Increment current song. */
    if (repeat == 0) {
        current_song++;
    }

    song_p = hash_map_get(&song_map, current_song);
    sem_put(&sem, 1);

    if (song_p != NULL) {
        return (song_p->name);
    } else {
        current_song = FIRST_SONG_NUMBER;
        return (NULL);
    }
}
Example #9
0
int cmd_play(int argc,
             const char *argv[],
             void *out_p,
             void *in_p)
{
    long song_number;
    struct song_t *song_p;

    if (argc > 2) {
        std_fprintf(out_p, FSTR("Usage: %s [<song number>]\r\n"), argv[0]);

        return (-EINVAL);
    }

    if (argc == 2) {
        if (std_strtol(argv[1], &song_number) != 0) {
            return (-EINVAL);
        }

        /* Find the song in the hash map. */
        song_p = hash_map_get(&song_map, song_number);

        if (song_p == NULL) {
            return (-EINVAL);
        }

        /* Stop the current song and set the new current song. */
        music_player_song_stop(&music_player);
        sem_get(&sem, NULL);
        current_song = song_number;
        sem_put(&sem, 1);
    }

    /* Play the song or resume it if it's paused. */
    return (music_player_song_play(&music_player));
}
Example #10
0
CNXT_SMC_STATUS cnxt_smc_open ( CNXT_SMC_HANDLE    *pHandle,
                                CNXT_SMC_CAPS      *pCaps,
                                CNXT_SMC_PFNNOTIFY pNotifyFn,
                                void               *pUserData )
{
   CNXT_SMC_INST *pInst;
   CNXT_SMC_UNIT_INST *pUnitInst;
   u_int32 uUnit;

   IS_DRIVER_INITED(SMC,pDriverInst->bInit);
   IS_NOT_NULL_POINTER(SMC, pHandle);
   IS_NOT_NULL_POINTER(SMC, pCaps);

   if (sem_get(pDriverInst->DriverSem, KAL_WAIT_FOREVER) != RC_OK)
   {
      return CNXT_SMC_INTERNAL_ERROR;
   }

   /* figure out unit number based on info in pCaps */
   uUnit = cnxt_smc_unit_num(pCaps);

   if (uUnit >= CNXT_SMC_NUM_UNITS)
   {
      return CNXT_SMC_BAD_UNIT;
   }

   /* check bExclusive */
   pUnitInst = &(pDriverInst->pUnitInst[uUnit]);
   if ((pUnitInst->pFirstInst != NULL) && 
       (pUnitInst->bExclusive || pCaps->bExclusive))
   {
      sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
      return CNXT_SMC_NOT_AVAILABLE;
   }
   /* 
    * There is a possibility that the pCaps needs to be checked further.
    * Add that here.
    */


   /* create an instance */
   if ( !CREATE_HANDLE(&(pDriverInst->pInstList), &pInst) )
   {
      *pHandle = NULL;
      sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
      return CNXT_SMC_RESOURCE_ERROR;
   }

   /* add the instance into the list */
   pInst->uUnitNumber = uUnit;
   if (ADD_HANDLE (&(pUnitInst->pFirstInst), pInst) == FALSE)
   {
      DESTROY_HANDLE(&(pDriverInst->pInstList), pInst);
      sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
      return CNXT_SMC_INTERNAL_ERROR;
   }

   pInst->Preface.pSelf = (CNXT_HANDLE_PREFACE*)pInst;
   pInst->pNotifyFn = pNotifyFn;    /* Use this fcn to notify appl of events */
   pInst->pUserData = pUserData;    /* Store data the inst needs */

   /*
    * Put Driver Specific code here.
    */

   /* set driver bExclusive field */
   pUnitInst->bExclusive = pCaps->bExclusive;

   *pHandle = (CNXT_SMC_HANDLE)pInst;

   sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
   return CNXT_SMC_OK;
} /* end cnxt_smc_open() */
Example #11
0
CNXT_SMC_STATUS cnxt_smc_init ( CNXT_SMC_CONFIG *pCfg )
{
   static bool ReEntry = FALSE;
   bool bKs;
   u_int32 i;

   /*
    * Need to ensure that this routine only called once, so
    * start crit section, test the semaphore for existence.
    * If not exist, then create.
    * get out of the critical section, and see if the semaphore
    * exists. If it doesn't, then return an error.
    * Now get the semaphore. If this fails then
    * someone else grapped the semaphore, or there is a bigger
    * system resource problem
    */
   while (1)
   {
      bKs = critical_section_begin();
      if ( ReEntry == FALSE )
      {
         ReEntry = TRUE;
         critical_section_end(bKs);
         break;
      }
      critical_section_end(bKs);
      task_time_sleep(5);
   }

   if (pDriverInst->DriverSem == 0)
   {
      pDriverInst->DriverSem = sem_create(1, NULL);
   }

   if (pDriverInst->DriverSem == 0)
   {
      ReEntry = FALSE;
      return CNXT_SMC_RESOURCE_ERROR;
   }

   if (sem_get(pDriverInst->DriverSem, KAL_WAIT_FOREVER) != RC_OK)
   {
      ReEntry = FALSE;
      return CNXT_SMC_INTERNAL_ERROR;
   }

   if (pDriverInst->bInit == TRUE)
   {
      sem_put(pDriverInst->DriverSem);
      ReEntry = FALSE;
      return CNXT_SMC_ALREADY_INIT;
   }

   /* initialize internal data */
   if ( cnxt_smc_internal_data_init() == FALSE )
   {
      sem_put(pDriverInst->DriverSem);
      ReEntry = FALSE;
      return CNXT_SMC_RESOURCE_ERROR;
   }

   /* connect internal data to the driver instance structure */
   pDriverInst->pInstList = InstArray;
   pDriverInst->pUnitInst  = UnitInst;

   /*
    * Put Driver Specific code here.
    */


   /* enable smart card access */
   smc_access_enable ();

   for ( i = 0 ; i < CNXT_SMC_NUM_UNITS ; i ++ )
   {
      /* create semaphore for synchronous implementations of asynchronous op */
      if ( Card[i].ResetJob.SyncSem == 0 )
      {
         Card[i].ResetJob.SyncSem = sem_create ( 0, NULL );
         if ( Card[i].ResetJob.SyncSem == 0 )
         {
            sem_put(pDriverInst->DriverSem);
            ReEntry = FALSE;
            return CNXT_SMC_RESOURCE_ERROR;
         }
      }

      if ( Card[i].PowerdownJob.SyncSem == 0 )
      {
         Card[i].PowerdownJob.SyncSem = sem_create ( 0, NULL );
         if ( Card[i].PowerdownJob.SyncSem == 0 )
         {
            sem_put(pDriverInst->DriverSem);
            ReEntry = FALSE;
            return CNXT_SMC_RESOURCE_ERROR;
         }
      }

      /* intialize card HW */
      smc_hw_init ( (pDriverInst->pUnitInst[i]).pCard, i );

      /* Hook Interrupts */
      if ( int_register_isr ( ( ( i == 0 ) ? INT_VENDOR_SLOT_0 : INT_VENDOR_SLOT_1 ),
                              (PFNISR)cnxt_smc_isr, FALSE, FALSE, 
                              &previous_isr[i] ) != RC_OK )
      {
         return CNXT_SMC_INTERNAL_ERROR;
      }

      /* enable interrupts */
      if ( int_enable ( ( i == 0 ) ? INT_VENDOR_SLOT_0 : INT_VENDOR_SLOT_1 ) != RC_OK )
      {
         return CNXT_SMC_INTERNAL_ERROR;
      }
   }

   pDriverInst->bInit = TRUE; 
   sem_put(pDriverInst->DriverSem); /* must be last line of routine! */
   ReEntry = FALSE;
   return CNXT_SMC_OK;
} /* end cnxt_smc_init() */