/*
 *  ======== Adaptor_Module_startup ========
 */
Int Adaptor_Module_startup(Int phase)
{
    Int i;
    Queue_Elem *elem;

    if (Queue_Module_startupDone() == FALSE) {
        return (Startup_NOTDONE);
    }

    /* If there are control messages, put the packets onto the free msg queue */
    if (ServiceMgr_supportControl == TRUE) {
        elem = (Queue_Elem *)Adaptor_msgBuf;
        for (i = 0; i < ServiceMgr_numIncomingCtrlPacketBufs +
             ServiceMgr_numOutgoingCtrlPacketBufs; i++) {
            Queue_put(Adaptor_module->freeMsgQ, elem);
            elem = (Queue_Elem *)((UInt)elem + ServiceMgr_maxCtrlPacketSize);
        }
    }

    /* Put the packets onto the free event queue */
    elem = (Queue_Elem *)Adaptor_eventBuf;
    for (i = 0; i < ServiceMgr_numEventPacketBufs; i++) {
        Queue_put(Adaptor_module->freeEventQ, elem);
        elem = (Queue_Elem *)((UInt)elem + ServiceMgr_maxEventPacketSize);
    }

    /* Call the transport init function */
    if (ServiceMgr_transportFxns.initFxn != NULL) {
        ServiceMgr_transportFxns.initFxn();
    }

    return (Startup_DONE);
}
/*
 *  ======== Clock_Instance_init ========
 */
Void Clock_Instance_init(Clock_Object *obj, Clock_FuncPtr func, UInt timeout,
    const Clock_Params *params)
{
    Queue_Handle clockQ;

    Assert_isTrue((BIOS_clockEnabled == TRUE), Clock_A_clockDisabled);

    Assert_isTrue(((BIOS_getThreadType() != BIOS_ThreadType_Hwi) &&
                   (BIOS_getThreadType() != BIOS_ThreadType_Swi)),
                        Clock_A_badThreadType);

    Assert_isTrue(!(params->startFlag && (timeout == 0)), (Assert_Id)NULL);

    obj->timeout = timeout;
    obj->period = params->period;
    obj->fxn = func;
    obj->arg = params->arg;
    obj->active = FALSE;

    /*
     * Clock object is always placed on Clock work Q
     */
    clockQ = Clock_Module_State_clockQ();
    Queue_put(clockQ, &obj->elem);

    if (params->startFlag) {
        Clock_start(obj);
    }
}
/*
 *  ======== Adaptor_sendPacket ========
 *  Function called by a service to send a packet.
 */
Bool Adaptor_sendPacket(UIAPacket_Hdr *packet)
{
    Bool status;
    Adaptor_Entry *entry;

    /* Set the src fields */
    UIAPacket_setSenderAdrs(packet, 0);

    /*
     *  If the call is being made in the context of the transferAgent,
     *  just call the Adaptor directly.
     */
    if ((Adaptor_module->transferAgentHandle == Task_self())) {
        status = Adaptor_sendToHost(packet);
    }
    else {

        /* Not in the transfer agent's context. Put it on the outgoing queue */
        entry = (Adaptor_Entry *)((UInt)packet - sizeof(Queue_Elem));

        Queue_put(Adaptor_module->outgoingQ, (Queue_Elem *)entry);
        Event_post(Adaptor_module->event, Event_Id_03);
        status = TRUE;
    }

    return (status);
}
Beispiel #4
0
/**
 * @brief  print char on uart1 non-blocking
 * @param  c char
 * @retval None
 */
void usart_putc_nb(char c) {
#ifdef USE_QUEUE
	Queue_put(&txbuf, c);
	USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
#else
	USART_SendData(USART1, c);
#endif
}
/*
 *  ======== Adaptor_freePacket ========
 *  Function called by a service to "free" a packet.
 */
Void Adaptor_freePacket(UIAPacket_Hdr *packet)
{
    Queue_Elem *elem;
    UIAPacket_HdrType type = UIAPacket_getHdrType(packet);

    elem = (Queue_Elem *)((UInt)packet - sizeof(Queue_Elem));

    /* Determine the type of header to place on the correct queue */
    if (type == UIAPacket_HdrType_EventPkt) {
        Queue_put(Adaptor_module->freeEventQ, elem);
        Semaphore_post(Adaptor_module->freeEventSem);
    }
    else {
        Queue_put(Adaptor_module->freeMsgQ, elem);
        Semaphore_post(Adaptor_module->freeMsgSem);
    }
}
/*
 *  ======== Task_exit ========
 */
Void Task_exit()
{
    UInt tskKey, hwiKey;
    Task_Object *tsk;
#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    Int i;
#endif

    tsk = Task_self();

#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    /*
     * Process Task_exit hooks.  Should be called outside the Task kernel.
     */
    for (i = 0; i < Task_hooks.length; i++) {
        if (Task_hooks.elem[i].exitFxn != NULL) {
            Task_hooks.elem[i].exitFxn(tsk);
        }
    }
#endif

    Log_write2(Task_LD_exit, (UArg)tsk, (UArg)tsk->fxn);

    tskKey = Task_disable();
    hwiKey = Hwi_disable();

    Task_blockI(tsk);

    tsk->mode = Task_Mode_TERMINATED;

    Task_processVitalTaskFlag(tsk);

    Hwi_restore(hwiKey);

    Queue_elemClear((Queue_Elem *)tsk);

    /* add to terminated task list if it was dynamically created */
    if (Task_deleteTerminatedTasks == TRUE) {
        Task_Handle dynTask;

        dynTask = Task_Object_first();

        while (dynTask) {
            if (tsk == dynTask) {
                tsk->readyQ = Task_Module_State_terminatedQ();
                Queue_put(tsk->readyQ, (Queue_Elem *)tsk);
                break;
            }
            else {
                dynTask = Task_Object_next(dynTask);
            }
        }
    }

    Task_restore(tskKey);
}
Beispiel #7
0
/**
 * @brief  print char on uart1
 * @param  c char
 * @retval None
 */
void usart_putc(char c) {
#ifdef USE_QUEUE
	while( Queue_put(&txbuf, c) == 0 )
		;
	USART_ITConfig(USART1, USART_IT_TXE, ENABLE);
#else
	USART_SendData(USART1, c);
	while (USART_GetFlagStatus(USART1, USART_FLAG_TXE) == RESET)
		;
#endif
}
/*
 *  ======== Adaptor_rxTaskFxn ========
 *  Task that receives incoming messages from the host.
 *  These messages are then sent to the transfer agent.
 */
Void Adaptor_rxTaskFxn(UArg arg, UArg unused)
{
    Int status;
    Adaptor_Entry *entry;
    UIAPacket_Hdr *packet;

    /* Make sure the transport is set to go */
    if (ServiceMgr_transportFxns.startFxn != NULL) {
        Adaptor_module->transportMsgHandle =
            ServiceMgr_transportFxns.startFxn(UIAPacket_HdrType_Msg);
    }

    /*
     *  Loop to receive msgs from the instrumentation host
     */
    while (TRUE) {

        /* Grab a free incomingMsg buffer */
        packet = Adaptor_getFreePacket(UIAPacket_HdrType_Msg,
                                       BIOS_WAIT_FOREVER);

        /* Receive the packet. */
        status = ServiceMgr_transportFxns.recvFxn(
                     Adaptor_module->transportMsgHandle, &packet,
                     ServiceMgr_maxCtrlPacketSize);

        /* Put onto router's message queue */
        if ((status > 0) &&
            (UIAPacket_getHdrType(packet) == UIAPacket_HdrType_Msg)) {

            /* The Queue elem is just above the packet */
            entry = (Adaptor_Entry *)((UInt)packet - sizeof(Queue_Elem));

            Queue_put(Adaptor_module->incomingQ, (Queue_Elem *)entry);
            Event_post(Adaptor_module->event, Event_Id_01);
        }
        else {
            /* Return the packet */
            Adaptor_freePacket(packet);

            /* Reset the transport with a stop/start */
            if (ServiceMgr_transportFxns.stopFxn != NULL) {
                ServiceMgr_transportFxns.stopFxn(
                    Adaptor_module->transportMsgHandle);
            }

            if (ServiceMgr_transportFxns.startFxn != NULL) {
                Adaptor_module->transportMsgHandle =
                    ServiceMgr_transportFxns.startFxn(UIAPacket_HdrType_Msg);
            }
        }
    }
}
/*
 *  ======== Task_postInit ========
 *  Function to be called during module startup to complete the
 *  initialization of any statically created or constructed task.
 *  Initialize stack.
 *  Build Initial stack image.
 *  Add task to corresponding ready Queue.
 *
 *  returns (0) and clean 'eb' on success
 *  returns (0) and 'eb' if Task_SupportProxy_start() fails.
 *  returns (n) and 'eb' for number of successful createFxn() calls iff
 *     one of the createFxn() calls fails
 */
Int Task_postInit(Task_Object *tsk, Error_Block *eb)
{
    UInt tskKey, hwiKey;
    Queue_Handle readyQ;
#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    Int i;
#endif

    tsk->context = Task_SupportProxy_start(tsk,
                (Task_SupportProxy_FuncPtr)Task_enter,
                (Task_SupportProxy_FuncPtr)Task_exit,
                eb);

    if (Error_check(eb)) {
        return (0);
    }

    tsk->mode = Task_Mode_READY;

    tsk->pendElem = NULL;

#ifndef ti_sysbios_knl_Task_DISABLE_ALL_HOOKS
    for (i = 0; i < Task_hooks.length; i++) {
        tsk->hookEnv[i] = (Ptr)0;
        if (Task_hooks.elem[i].createFxn != NULL) {
            Task_hooks.elem[i].createFxn(tsk, eb);

            if (Error_check(eb)) {
                return (i);
            }
        }
    }
#endif

    if (tsk->priority < 0) {
        tsk->mask = 0;
        tsk->readyQ = Task_Module_State_inactiveQ();
        Queue_put(tsk->readyQ, (Queue_Elem *)tsk);
    }
    else {
        tsk->mask = 1 << tsk->priority;
        readyQ = Queue_Object_get(Task_module->readyQ, tsk->priority);
        tsk->readyQ = readyQ;

        tskKey = Task_disable();
        hwiKey = Hwi_disable();
        Task_unblock(tsk);
        Hwi_restore(hwiKey);
        Task_restore(tskKey);
    }

    return (0);
}
Beispiel #10
0
/*
 *  ======== Power_registerConstraint ========
 *  Register an operational constraint with Power.
 *
 */
Power_Status Power_registerConstraint(Power_Constraint type, UArg value,
    Power_ConstraintHandle *handle)
{
    Power_Status status = Power_SOK;
    Power_ConstraintObj * pConstraint;
    Error_Block eb;

    /* check for NULL handle pointer */
    if (handle == NULL) {
        status = Power_EINVALIDPOINTER;
    }

    /* else, check for invalid constraint type */
    else if ((type < Power_DISALLOWED_CPU_SETPOINT_MASK) ||
             (type > Power_DISALLOWEDSLEEPSTATE_MASK)) {
        status = Power_EINVALIDVALUE;
    }

    /* else, allocate a constraint object */
    else {
        Error_init(&eb);
        pConstraint = Memory_calloc(Power_Object_heap(), 
            sizeof(Power_ConstraintObj), 0, &eb);
        if ((pConstraint == NULL) || Error_check(&eb)) {
            status = Power_EFAIL;
        }

        /* fill in and enqueue the constraint, update aggregate constraints */
        else {

            /* fill in constraint object elements */
            pConstraint->type = type;
            pConstraint->value = value;

            /* place constraint object on the constraints queue */
            Queue_put(Power_Module_State_constraintsQ(), 
                (Queue_Elem*) pConstraint);

            /* update aggregated constraints with the new constraint */
            Power_updateConstraints(type, value);

            /* set out parameters */
            *handle = (UArg *) pConstraint;
        }
    }

    return (status);
}
/*
 *  ======== Clock_addI ========
 */
Void Clock_addI(Clock_Object *obj, Clock_FuncPtr func, UInt32 timeout, UArg arg)
{
    Queue_Handle clockQ;

    obj->timeout = timeout;
    obj->period = 0;
    obj->fxn = func;
    obj->arg = arg;
    obj->active = FALSE;

    /*
     * Clock object is always placed on Clock work Q
     */
    clockQ = Clock_Module_State_clockQ();
    Queue_put(clockQ, &obj->elem);
}
Beispiel #12
0
/*
 *  ======== Power_registerNotify ========
 *  Register a function to be called on a specific power event.
 *
 */
Power_Status Power_registerNotify(Power_Event eventType, UInt eventMask,
    Fxn notifyFxn, UArg clientArg, Power_NotifyHandle * notifyHandle,
    Fxn *delayedCompletionFxn)
{
    Power_NotifyObj * pNotify;
    Queue_Handle notifyQ;
    Error_Block eb;

    /* check for out of range event type */
    if ((eventType < 0) || (eventType >= Power_INVALIDEVENT)) {
        return (Power_EINVALIDEVENT);
    }

    /* check for NULL pointers for notifyFxn and out params */
    if ((notifyFxn == NULL) || (notifyHandle == NULL) ||
       (delayedCompletionFxn == NULL)) {
        return (Power_EINVALIDPOINTER);
    }

    /* allocate a notification object */
    Error_init(&eb);
    pNotify = Memory_calloc(Power_Object_heap(), sizeof(Power_NotifyObj), 0, 
        &eb);
    if ((pNotify == NULL) || Error_check(&eb)) {
        return (Power_EFAIL);
    }

    /* fill in notify object elements */
    pNotify->eventType = eventType;
    pNotify->notifyFxn = notifyFxn;
    pNotify->clientArg = clientArg;
    pNotify->eventMask = eventMask;

    /* determine the appropriate notification queue */
    notifyQ = (Queue_Handle)((UInt8 *)(Power_module->notifyQ) +
                (UInt)(eventType * (2 * sizeof(Ptr))));

    /* place notify object on appropriate event queue */
    Queue_put(notifyQ, (Queue_Elem*) pNotify);

    /* set out parameters */
    *notifyHandle = pNotify;
    *delayedCompletionFxn = 
        (Fxn) ti_sysbios_family_c674_Power_delayCompletionFxns[eventType];

    return(Power_SOK);
}
Beispiel #13
0
/*********************************************************************
 * @fn      Util_enqueueMsg
 *
 * @brief   Creates a queue node and puts the node in RTOS queue.
 *
 * @param   msgQueue - queue handle.
 * @param   sem - thread's event processing semaphore that queue is
 *                associated with.
 * @param   pMsg - pointer to message to be queued
 *
 * @return  TRUE if message was queued, FALSE otherwise.
 */
uint8_t Util_enqueueMsg(Queue_Handle msgQueue, 
#ifdef ICALL_EVENTS
                        Event_Handle event,
#else //!ICALL_EVENTS
                        Semaphore_Handle sem,
#endif //ICALL_EVENTS
                        uint8_t *pMsg)
{
  queueRec_t *pRec;

  // Allocated space for queue node.
#ifdef USE_ICALL
  if ((pRec = ICall_malloc(sizeof(queueRec_t))))
#else
  if ((pRec = (queueRec_t *)malloc(sizeof(queueRec_t))))
#endif
  {
    pRec->pData = pMsg;

    // This is an atomic operation
    Queue_put(msgQueue, &pRec->_elem);

    // Wake up the application thread event handler.
#ifdef ICALL_EVENTS
    if (event)
    {
      Event_post(event, UTIL_QUEUE_EVENT_ID);
    }
#else //!ICALL_EVENTS
    if (sem)
    {
      Semaphore_post(sem);
    }
#endif //ICALL_EVENTS

    return TRUE;
  }

  // Free the message.
#ifdef USE_ICALL
  ICall_free(pMsg);
#else
  free(pMsg);
#endif

  return FALSE;
}
/*
 *  ======== Power_registerNotify ========
 *  Register a function to be called on a specific power event.
 *
 */
Power_Status Power_registerNotify(Power_NotifyObj * pNotifyObj,
    UInt32 eventTypes, Fxn notifyFxn, UArg clientArg, UArg arg)
{
    /* check for NULL pointers  */
    if ((pNotifyObj == NULL) || (notifyFxn == NULL)) {
        return (Power_EINVALIDPOINTER);
    }

    /* fill in notify object elements */
    pNotifyObj->eventTypes = eventTypes;
    pNotifyObj->notifyFxn = notifyFxn;
    pNotifyObj->clientArg = clientArg;

    /* place notify object on event notification queue */
    Queue_put(Power_Module_State_notifyQ(), (Queue_Elem*) pNotifyObj);

    return (Power_SOK);
}
Beispiel #15
0
/**
 * @brief  USART1's interrupt handler
 * @param  None
 * @retval None
 */
void USART1_IRQHandler() {
	if (USART_GetITStatus(USART1, USART_IT_RXNE)) {
		uint8_t data = USART_ReceiveData(USART1);
		USART_ClearITPendingBit(USART1, USART_IT_RXNE); // Clear interrupt flag
		Queue_put(&rxbuf, data);
		if( registered_rx_handler ) registered_rx_handler(data);
	}
	if (USART_GetITStatus(USART1, USART_IT_TXE)) {
		USART_ClearITPendingBit(USART1, USART_IT_TXE); // Clear interrupt flag
		uint16_t data = Queue_get(&txbuf);
		if (data) {
			USART_SendData(USART1, data & 0xFF);
		} else {
			USART_ITConfig(USART1, USART_IT_TXE, DISABLE);
			txrunning = 0;
		}
	}
}