/* * ======== USBKBD_init ======== */ void USBKBD_init(void) { Hwi_Handle hwi; Error_Block eb; Semaphore_Params semParams; Error_init(&eb); /* Install interrupt handler */ hwi = Hwi_create(INT_USB0, USBKBD_hwiHandler, NULL, &eb); if (hwi == NULL) { System_abort("Can't create USB Hwi"); } /* RTOS primitives */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; semKeyboard = Semaphore_create(0, &semParams, &eb); if (semKeyboard == NULL) { System_abort("Can't create keyboard semaphore"); } semUSBConnected = Semaphore_create(0, &semParams, &eb); if (semUSBConnected == NULL) { System_abort("Can't create USB semaphore"); } gateKeyboard = GateMutex_create(NULL, &eb); if (gateKeyboard == NULL) { System_abort("Can't create keyboard gate"); } gateUSBWait = GateMutex_create(NULL, &eb); if (gateUSBWait == NULL) { System_abort("Could not create USB Wait gate"); } /* State specific variables */ state = USBKBD_STATE_UNCONFIGURED; kbLEDs = 0x00; /* Set the USB stack mode to Device mode with VBUS monitoring */ USBStackModeSet(0, eUSBModeForceDevice, 0); /* * Pass our device information to the USB HID device class driver, * initialize the USB controller and connect the device to the bus. */ if (!USBDHIDKeyboardInit(0, &keyboardDevice)) { System_abort("Error initializing the keyboard"); } }
/** * \brief creates a mutex for inter-thread mutual exclusion for resource protection * * * * \param[in] p_handle Handle to a mutex control block * \param[in] p_name Name of mutex * * \return e_SUCCESS on success, e_FAILURE on error * * \sa OS_mutex_delete, OS_mutex_lock, OS_mutex_unlock * \note * * \warning */ e_ret_status OS_mutex_create(handle p_handle, const void *const p_name) { GateMutex_Params gateParams; GateMutex_Handle mtx_handle = {0}; Error_Block eb; GateMutex_Params_init(&gateParams); Error_init(&eb); gateParams.instance->name = "Default_Name"; mtx_handle = GateMutex_create(&gateParams, &eb); if (NULL == mtx_handle) { return e_FAILURE; } *(GateMutex_Handle *)p_handle = mtx_handle; return e_SUCCESS; }
Void ListTest(Void) { List_Params listParams; List_Handle listHandle; List_Elem *elem; ListNode *node; UInt32 i, value; Bool failed = FALSE; IGateProvider_Handle gateHandle; List_Params_init(&listParams); gateHandle = (IGateProvider_Handle) GateMutex_create(); if(gateHandle == NULL) { Osal_printf("ListTest: GateMutex_create failed.\n"); goto exit; } listParams.gateHandle = gateHandle; listHandle = List_create(&listParams); if(listHandle == NULL) { Osal_printf("ListTest: List_create failed.\n"); goto gateExit; } node = Memory_alloc(NULL, LIST_SIZE * sizeof(ListNode), 0); if(node == NULL) { Osal_printf("ListTest: Memory_alloc failed.\n"); goto listExit; } // Put some nodes into the list for(i = 0; i < LIST_SIZE; i++) { node[i].value = i; List_put(listHandle, (List_Elem *)&node[i]); } // Traverse the list for(i = 0, elem = List_next(listHandle, NULL); elem != NULL && !failed; i++, elem = List_next(listHandle, elem)) { value = ((ListNode *)elem)->value; // Check against expected value if(value != i) { Osal_printf("ListTest: data mismatch, expected " "0x%x, actual 0x%x\n", i, i, value); failed = TRUE; } } // Remove nodes for(i = 0; i < LIST_SIZE && !List_empty(listHandle); i++) { // Get first element and put it back to test List_get and List_putHead elem = List_get(listHandle); List_putHead(listHandle, elem); // Now remove it permanently to test List_remove if(elem != NULL) { List_remove(listHandle, elem); } } // Did we remove the expected number of nodes? if(i != LIST_SIZE) { Osal_printf("ListTest: removed %d node(s), expected %d\n", i, LIST_SIZE); failed = TRUE; } if(!List_empty(listHandle)) { Osal_printf("ListTest: list not empty!\n"); failed = TRUE; } if(failed) Osal_printf("ListTest: FAILED!\n"); else Osal_printf("ListTest: PASSED!\n"); listExit: List_delete(&listHandle); gateExit: GateMutex_delete((GateMutex_Handle *)&gateHandle); exit: return; }
/*! * @brief Function to setup the DM8168DUCATIPWR module. * * This function sets up the DM8168DUCATIPWR module. This function must * be called before any other instance-level APIs can be invoked. * Module-level configuration needs to be provided to this * function. If the user wishes to change some specific config * parameters, then DM8168DUCATIPWR_getConfig can be called to get the * configuration filled with the default values. After this, only * the required configuration values can be changed. If the user * does not wish to make any change in the default parameters, the * application can simply call DM8168DUCATIPWR_setup with NULL * parameters. The default parameters would get automatically used. * * @param cfg Optional DM8168DUCATIPWR module configuration. If provided as * NULL, default configuration is used. * * @sa DM8168DUCATIPWR_destroy * GateMutex_create */ Int DM8168DUCATIPWR_setup (DM8168DUCATIPWR_Config * cfg) { Int status = PWRMGR_SUCCESS; DM8168DUCATIPWR_Config tmpCfg; IArg key; Error_Block eb; #if defined(SYSLINK_BUILD_RTOS) Error_init(&eb); #endif /* #if defined(SYSLINK_BUILD_RTOS) */ #if defined(SYSLINK_BUILD_HLOS) eb = 0; #endif /* #if defined(SYSLINK_BUILD_HLOS) */ GT_1trace (curTrace, GT_ENTER, "DM8168DUCATIPWR_setup", cfg); if (cfg == NULL) { DM8168DUCATIPWR_getConfig (&tmpCfg); cfg = &tmpCfg; } /* This sets the refCount variable is not initialized, upper 16 bits is * written with module Id to ensure correctness of refCount variable. */ key = Gate_enterSystem(); DM8168DUCATIPWR_state.refCount++; if (DM8168DUCATIPWR_state.refCount > 1) { status = DM8168DUCATIPWR_S_ALREADYSETUP; Gate_leaveSystem(key); } else { Gate_leaveSystem(key); /* Create a default gate handle for local module protection. */ DM8168DUCATIPWR_state.gateHandle = (IGateProvider_Handle) GateMutex_create ((GateMutex_Params*)NULL, &eb); if (DM8168DUCATIPWR_state.gateHandle == NULL) { key = Gate_enterSystem(); DM8168DUCATIPWR_state.refCount = 0; Gate_leaveSystem(key); /*! @retval PWRMGR_E_FAIL Failed to create GateMutex! */ status = PWRMGR_E_FAIL; GT_setFailureReason (curTrace, GT_4CLASS, "DM8168DUCATIPWR_setup", status, "Failed to create GateMutex!"); } else { /* Copy the user provided values into the state object. */ memcpy (&DM8168DUCATIPWR_state.cfg, cfg, sizeof (DM8168DUCATIPWR_Config)); /* Initialize the name to handles mapping array. */ memset (&DM8168DUCATIPWR_state.pwrHandles, 0, (sizeof (DM8168DUCATIPWR_Handle) * MultiProc_MAXPROCESSORS)); DM8168DUCATIPWR_state.isSetup = TRUE; } } GT_1trace (curTrace, GT_LEAVE, "DM8168DUCATIPWR_setup", status); /*! @retval PWRMGR_SUCCESS Operation successful */ return (status); }
/* * ======== USBCDCMOUSE_init ======== */ void USBCDCMOUSE_init(void) { Error_Block eb; Semaphore_Params semParams; GateMutex_Params gateParams; Error_init(&eb); /* RTOS primitives */ Semaphore_Params_init(&semParams); semParams.mode = Semaphore_Mode_BINARY; semParams.__iprms.name = "semTxSerial"; semTxSerial = Semaphore_create(0, &semParams, &eb); if (semTxSerial == NULL) { System_abort("Can't create TX semaphore"); } semParams.__iprms.name = "semRxSerial"; semRxSerial = Semaphore_create(0, &semParams, &eb); if (semRxSerial == NULL) { System_abort("Can't create RX semaphore"); } semParams.__iprms.name = "semMouse"; semMouse = Semaphore_create(0, &semParams, &eb); if (semMouse == NULL) { System_abort("Can't create USB semaphore"); } semParams.__iprms.name = "semUSBConnected"; semUSBConnected = Semaphore_create(0, &semParams, &eb); if (semUSBConnected == NULL) { System_abort("Can't create USB semaphore"); } GateMutex_Params_init(&gateParams); gateParams.__iprms.name = "gateTxSerial"; gateTxSerial = GateMutex_create(NULL, &eb); if (gateTxSerial == NULL) { System_abort("Can't create gate"); } gateParams.__iprms.name = "gateRxSerial"; gateRxSerial = GateMutex_create(NULL, &eb); if (gateRxSerial == NULL) { System_abort("Can't create gate"); } gateParams.__iprms.name = "gateMouse"; gateMouse = GateMutex_create(NULL, &eb); if (gateMouse == NULL) { System_abort("Can't create mouse gate"); } gateParams.__iprms.name = "gateUSBWait"; gateUSBWait = GateMutex_create(NULL, &eb); if (gateUSBWait == NULL) { System_abort("Could not create USB Wait gate"); } /* Initialize the USB module, enable events and connect if UBUS is present */ USB_setup(true, true); }