/******************************************************************************* * @fn bspSpiOpen * * @brief Open the RTOS SPI driver * * @param none * * @return none */ void bspSpiOpen(void) { if (hSpiPin != NULL) { // Remove IO configuration of SPI lines PIN_close(hSpiPin); hSpiPin = NULL; } if (spiHandle == NULL) { /* Configure SPI as master, 1 mHz bit rate*/ SPI_Params_init(&spiParams); spiParams.bitRate = 1000000; spiParams.mode = SPI_MASTER; spiParams.transferMode = SPI_MODE_BLOCKING; /* Attempt to open SPI. */ spiHandle = SPI_open(Board_SPI0, &spiParams); if (spiHandle == NULL) { Task_exit(); } } nUsers++; }
/******************************************************************************* * @fn bspI2cInit * * @brief Initialize the RTOS I2C driver (must be called only once) * * @param none * * @return none */ void bspI2cInit(void) { Semaphore_Params semParamsMutex; // Create protection semaphore Semaphore_Params_init(&semParamsMutex); semParamsMutex.mode = Semaphore_Mode_BINARY; Semaphore_construct(&mutex, 1, &semParamsMutex); // Reset the I2C controller HapiResetPeripheral(PRCM_PERIPH_I2C0); I2C_init(); I2C_Params_init(&i2cParams); i2cParams.bitRate = I2C_400kHz; i2cHandle = I2C_open(Board_I2C, &i2cParams); // Initialize local variables slaveAddr = 0xFF; interface = BSP_I2C_INTERFACE_0; if (i2cHandle == NULL) { Task_exit(); } }
/* * ======== pthread_exit ======== */ void pthread_exit(void *retval) { pthread_Obj *thread = (pthread_Obj *)pthread_self(); /* * This function terminates the calling thread and returns * a value via retval that (if the thread is joinable) is available to * another thread that calls pthread_join(). * * Any clean-up handlers that have not yet been popped, are popped * (in the reverse of the order in which they were pushed) and executed. */ thread->ret = retval; /* * Don't bother disabling the Task scheduler while the thread * is exiting. It will be up to the application to not make * such calls as pthread_cancel() or pthread_detach() while the * thread is exiting. */ /* Pop and execute the cleanup handlers */ while (thread->cleanupList != NULL) { _pthread_cleanup_pop(thread->cleanupList, 1); } /* Cleanup any pthread specific data */ _pthread_removeThreadKeys((pthread_t)thread); if (!thread->detached) { Semaphore_post(Semaphore_handle(&(thread->joinSem))); /* Set this task's priority to -1 to stop it from running. */ Task_setPri(thread->task, -1); } else { /* Free memory */ #if ti_sysbios_posix_Settings_supportsMutexPriority__D Queue_destruct(&(thread->mutexList)); #endif Semaphore_destruct(&(thread->joinSem)); Memory_free(Task_Object_heap(), thread, sizeof(pthread_Obj)); /* * Don't call Task_delete on the calling thread. Task_exit() * will put the task on the terminated queue, and if * Task_deleteTerminatedTasks is TRUE, the task will be cleaned * up automatically. */ Task_exit(); } }
/* * ======== tsk0_func ======== * This function is executed only on CORE0. * It sends an event to the next processor then pends on a semaphore. * The semaphore is posted by the callback function. */ Void tsk0_func(UArg arg0, UArg arg1) { Int status; /* Send an event to the next processor */ if (MultiProc_self() == 0) { rawtimestamps[seq++] = Timestamp_get32(); status = Notify_sendEvent(dstProc, INTERRUPT_LINE, EVENTID, NULL, TRUE); if (status < 0) { System_abort("Notify_sendEvent failed\n"); } } Task_exit(); }
TIMM_OSAL_ERRORTYPE TIMM_OSAL_ExitTask (TIMM_OSAL_PTR pTask, void *value_ptr) { TIMM_OSAL_ERRORTYPE bReturnStatus = TIMM_OSAL_ERR_NONE; TIMM_OSAL_TASK *pHandle = (TIMM_OSAL_TASK *)pTask; if (TIMM_OSAL_NULL == pHandle) { bReturnStatus = TIMM_OSAL_ERR_PARAMETER; goto EXIT; } if (pHandle->isCreated != TIMM_OSAL_TRUE) { bReturnStatus = TIMM_OSAL_ERR_UNKNOWN; goto EXIT; } Task_exit (/*&(pHandle->task)*/); EXIT: return bReturnStatus; }
void maintenanceTask() { System_printf("Main Task started\n"); System_flush(); #if 1 /* Enable radio SPI */ spicom_init(); #endif #if 1 /* Enable Trace */ trace_init(); #endif #if 1 /* Digital io */ dio_init(); #endif #ifdef RN_ACTIVE rn_sysbios_init(); rn_module_init(); ap_sim_module_init(); //rn_sysbios_start(); rn_module_start(1); ap_sim_module_start(1); rn_module_start(2); ap_sim_module_start(2); #endif maintenanceMainTask(); /* Should never return but in case*/ Task_exit(); }
Void roveCmdCntrl(UArg arg0, UArg arg1) { //const FOREVER hack to kill the 'unreachable statement' compiler warning extern const uint8_t FOREVER; //initialized in main extern PWM_Handle motor_0; extern PWM_Handle motor_1; extern PWM_Handle motor_2; extern PWM_Handle motor_3; extern PWM_Handle motor_4; extern PWM_Handle motor_5; base_station_msg_struct fromBaseMsg; char commandBuffer[MAX_COMMAND_SIZE + 4]; int messageSize; int deviceJack; int motor_speed = 0; int16_t arm_speed = 0; int i = 0; System_printf("roveCmdCntrlr init! \n\n"); System_flush(); while (FOREVER) { // System_printf("CmdCntrl Is PENDING FOR MAIL!\n\n"); // System_flush(); Mailbox_pend(fromBaseStationMailbox, &fromBaseMsg, BIOS_WAIT_FOREVER); switch (fromBaseMsg.id) { // case 0 hack to make a happy switch case 0: break; case motor_right_id: //the left motors must be the negative of the right motors. Their phase is backwards motor_speed = -(((struct motor_control_struct*) (&fromBaseMsg))->speed); DriveMotor(motor_0, motor_speed); DriveMotor(motor_1, motor_speed); DriveMotor(motor_2, -motor_speed); break; // end drive motor_right_id case motor_left_id: motor_speed = (((struct motor_control_struct*) (&fromBaseMsg))->speed); DriveMotor(motor_3, -motor_speed); DriveMotor(motor_4, motor_speed); DriveMotor(motor_5, -motor_speed); break; //end drive motor_left_id case bms_emergency_command_id: if((((struct bms_emergency_command*) (&fromBaseMsg)) -> command) == 1) { digitalWrite(SOFT_RESET_GPIO_PIN, HIGH); } break; default: deviceJack = getDeviceJack(fromBaseMsg.id); // flag for invalid struct size if (getStructSize(fromBaseMsg.id) != -1) { messageSize = buildSerialStructMessage((void *) &fromBaseMsg, commandBuffer); deviceWrite(deviceJack, commandBuffer, messageSize); } break; } //endswitch //debugging only: // i = 0; // // System_printf("Cmd Cntrl Just Sent!: "); // // while (i < (messageSize)) { // // System_printf("%d, ", commandBuffer[i]); // i++; // // } //end while } System_flush(); System_printf("Rove Cmd Cntrl Task Error: Forced Exit\n"); System_flush(); Task_exit(); } //endfnct: roveCmdCntrl() Task Thread
/* * ======== consoleTaskFxn ======== * Console task * * This task listens to the key pressed in the keyboard through USBCDC. * The string ended with return character '\n' will trigger the task * to send this string to the mailbox. * For example, when the user enter "ls\n", this task will scan all the * files in the root of SD card and send the file list to the mailbox to * inform the drawing task to display on the screen. * The up/down arrow can be used to scroll up/down to display more files * in the SD card. */ Void consoleTaskFxn (UArg arg0, UArg arg1) { unsigned int count; unsigned int cpuLoad; char input[128]; UInt key; DrawMessage drawMsg; count = 1; /* printf goes to the UART com port */ printf("\f======== Welcome to the Console ========\n"); printf("Enter a command followed by return.\n" "Type help for a list of commands.\n\n"); printf("%d %% ", count++); fflush(stdout); /* Loop forever receiving commands */ while(true) { /* Get the user's input */ scanf("%s", input); /* Flush the remaining characters from stdin since they are not used. */ fflush(stdin); if (!strcmp(input, "a")) { /* Print the CPU load */ cpuLoad = Load_getCPULoad(); printf("CPU Load: %d\n", cpuLoad); drawMsg.drawCommand = KeyBoadCOMMAND; up_remove_blank(4); up(4); // copy the data to message key = Gate_enterSystem(); copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048); Gate_leaveSystem(key); Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER); } else if (!strcmp(input, "d")) { /* Print the CPU load */ cpuLoad = Load_getCPULoad(); printf("CPU Load: %d\n", cpuLoad); drawMsg.drawCommand = KeyBoadCOMMAND; down_remove_blank(4); down(4); // copy the data to message key = Gate_enterSystem(); copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048); Gate_leaveSystem(key); Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER); } else if (!strcmp(input, "w")) { /* Print the CPU load */ cpuLoad = Load_getCPULoad(); printf("CPU Load: %d\n", cpuLoad); drawMsg.drawCommand = KeyBoadCOMMAND; left_remove_blank(4); left(4); // copy the data to message key = Gate_enterSystem(); copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048); Gate_leaveSystem(key); Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER); } else if (!strcmp(input, "s")) { /* Print the CPU load */ cpuLoad = Load_getCPULoad(); printf("CPU Load: %d\n", cpuLoad); drawMsg.drawCommand = KeyBoadCOMMAND; right_remove_blank(4); right(4); // copy the data to message key = Gate_enterSystem(); copyFrom2048ArrayToDrawMessage(4,drawMsg.draw2048 , Array2048); Gate_leaveSystem(key); Mailbox_post(mailboxHandle, &drawMsg, BIOS_WAIT_FOREVER); } else if (!strcmp(input, "exit")) { /* Exit the console task */ printf("Are you sure you want to exit the console? Y/N: "); fflush(stdout); scanf("%s", input); fflush(stdin); if ((input[0] == 'y' || input[0] == 'Y') && input[1] == 0x00) { printf("Exiting console, goodbye.\n"); Task_exit(); } } else { /* Print a list of valid commands. */ printf("Valid commands:\n" "- w: move up.\n" "- a: move left.\n" "- s: move down.\n" "- a: move right.\n" "- exit: Exit the console task.\n"); } fillBox(4); // printf("%d %% ", count++); fflush(stdout); } }