void Main_task(uint32_t initial_data) { int ret = 0; func_args args; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_open(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card installed to %s\n", filesystem_name); benchmark_test(&args); ret = sdcard_close(&sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_close(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card uninstalled.\n"); _mqx_exit(0); }
void Main_task(uint32_t initial_data) { int ret = 0; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; printf("Starting client example... \n"); ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_open(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card installed to %s\n", filesystem_name); setup_ethernet(); setup_clock(); client_test(); ret = sdcard_close(&sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_close(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card uninstalled.\n"); _mqx_exit(0); }
void server_task ( uint_32 param ) { SERVER_MESSAGE_PTR msg_ptr; _mqx_uint i; _queue_id server_qid; boolean result; _task_id task_id; /* open a message queue */ server_qid = _msgq_open(SERVER_QUEUE, 0); if (server_qid == 0) { printf("\nCould not open the server message queue\n"); _mqx_exit(0); } /* create a message pool */ message_pool = _msgpool_create(sizeof(SERVER_MESSAGE), NUM_CLIENTS, 0, 0); if (message_pool == MSGPOOL_NULL_POOL_ID) { printf("\nCount not create a message pool\n"); _mqx_exit(0); } /* create the client tasks */ for (i = 0; i < NUM_CLIENTS; i++) { task_id = _task_create(0, CLIENT_TASK, (uint_32)i); if (task_id == 0) { printf("\nCould not create a client task\n"); _mqx_exit(0); } } while (TRUE) { msg_ptr = _msgq_receive(server_qid, 0); if (msg_ptr == NULL) { printf("\nCould not receive a message\n"); _mqx_exit(0); } printf(" %c \n", msg_ptr->DATA[0]); /* return the message */ msg_ptr->HEADER.TARGET_QID = msg_ptr->HEADER.SOURCE_QID; msg_ptr->HEADER.SOURCE_QID = server_qid; result = _msgq_send(msg_ptr); if (result != TRUE) { printf("\nCould not send a message\n"); _mqx_exit(0); } } }
int_32 Shell_bootloader_go_image(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { _autoboot_cmd = AUTOBOOT_DISABLE; _image_index = _io_atoi(argv[1]); if(_bootloader_check_image(FALSE,_image_index)) { printf("\nStarting application at image:%d\n",_image_index); _mqx_exit(0); } else { printf("\nError no image found !\n"); } } if (print_usage) { if (shorthelp) { printf("%s [<index>] \n", argv[0]); } else { printf("Usage: %s [<index>] \n", argv[0]); printf(" <index> = image index in memory table \n"); } } }
void world_task ( uint_32 initial_data ) { _task_id hello_task_id; hello_task_id = _task_create(0, HELLO_TASK, 0); if (hello_task_id == MQX_NULL_TASK_ID) { printf ("\n Could not create hello_task\n"); } else { printf(" World \n"); } /* Start CR 1764 */ /* ** This example uses polled serial I/O by default. Should it be modified ** to use interrupt driven serial drivers, you will need to uncomment the ** following delay code to insure serial communication completes before ** _mqx_exit() disables all interrupts. */ // _time_delay(200); /* End CR 1764 */ _mqx_exit(0); }
void write_task ( uint_32 initial_data ) { pointer write_sem; pointer read_sem; pointer index_sem; /* open connections to all the semaphores */ if (_sem_open("sem.write", &write_sem) != MQX_OK) { printf("\nOpening write semaphore failed."); _mqx_exit(0); } if (_sem_open("sem.index", &index_sem) != MQX_OK) { printf("\nOpening index semaphore failed."); _mqx_exit(0); } if (_sem_open("sem.read", &read_sem) != MQX_OK) { printf("\nOpening read semaphore failed."); _mqx_exit(0); } while (TRUE) { /* wait for the semphores */ if (_sem_wait(write_sem, 0) != MQX_OK) { printf("\nWwaiting for Write semaphore failed"); _mqx_exit(0); } if (_sem_wait(index_sem, 0) != MQX_OK) { printf("\nWaiting for index semaphore failed"); _mqx_exit(0); } fifo.DATA[fifo.WRITE_INDEX++] = _task_get_id(); if (fifo.WRITE_INDEX >= ARRAY_SIZE) { fifo.WRITE_INDEX = 0; } /* Post the semaphores */ _sem_post(index_sem); _sem_post(read_sem); } }
void Shell_task ( uint_32 temp ) { /* Run the shell on the serial port */ printf("Audio driver demo application\n"); Shell(Shell_commands, NULL); _mqx_exit(0); }
void Main_task(uint_32 initial_data) { int ret = 0; _mqx_int error_code, bytes; _mqx_uint param; _mqx_uint sz; MQX_FILE_PTR com_handle, sdcard_handle, filesystem_handle, partman_handle; MQX_FILE_PTR cert_file = NULL; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; const char* fileName = "a:\certs\\client-key.der"; printf("Starting client example... \n"); ret = sdcard_open(&com_handle, &sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_open(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card installed to %s\n", filesystem_name); setup_ethernet(); client_test(); ret = sdcard_close(&sdcard_handle, &partman_handle, &filesystem_handle, partman_name, filesystem_name); if (ret != 0) { printf("error: sdcard_close(), ret = %d\n", ret); _mqx_exit(1); } printf("SD card uninstalled.\n"); _mqx_exit(0); }
void main_task ( uint_32 initial_data ) { _mqx_uint result; _mqx_uint i; /* Create the kernel log */ result = _klog_create(2*1024, 0); if (result != MQX_OK) { printf("Main task: _klog_create failed %08x", result); _mqx_exit(0); } /* Enable kernel logging */ _klog_control(KLOG_ENABLED | KLOG_CONTEXT_ENABLED | KLOG_INTERRUPTS_ENABLED| KLOG_SYSTEM_CLOCK_INT_ENABLED | KLOG_FUNCTIONS_ENABLED | KLOG_TIME_FUNCTIONS | KLOG_INTERRUPT_FUNCTIONS, TRUE); /* Write data into kernel log */ for (i = 0; i < 10; i++) { _time_delay_ticks(5 * i); } /* Disable kernel logging */ _klog_control(0xFFFFFFFF, FALSE); /* Read data from the kernel log */ printf("\nKernel log contains:\n"); while (_klog_display()){ } _mqx_exit(0); }
/*FUNCTION*------------------------------------------------ * * Function Name: Auto_boot_startup * Comments : * * *END*-----------------------------------------------------*/ void Auto_boot_startup(MQX_FILE_PTR flash_hdl) { uint_32 timeout; boolean autoboot; uint_32 image_index = 0; if (BOOTLOADER_OK != _bootloader_get_autoboot(flash_hdl,&timeout,&image_index)){ printf("\nError can't get kernel image!"); printf("\nPlease setup your network to take image from TFTP server"); printf("\n"); return; } if (image_index) { printf("\nBooting from image %d...",image_index); printf("\nHit any key to stop autoboot:"); while(1) { printf("%2d",timeout); if(status()) { autoboot = FALSE; fflush(stdin); break; } _time_delay(1000); autoboot = TRUE; timeout--; if(0 == timeout) break; } if(autoboot) { if(MQX_OK == _bootloader_load(flash_hdl, image_index)){ printf("\n"); /* Exit bootloader app and execute the new image */ _mqx_exit(0); } else { printf("\nError"); } } } return; }
int_32 Shell_bootloader_reset(int_32 argc, char_ptr argv[] ) { /* Body */ boolean print_usage, shorthelp = FALSE; int_32 return_code = SHELL_EXIT_SUCCESS; char_ptr read_buffer; MQX_FILE_PTR nandflash_hdl; IMAGE_INFO_PTR image; print_usage = Shell_check_help_request(argc, argv, &shorthelp ); if (!print_usage) { if (argc !=1) { printf("Error, invalid number of parameters\n"); return_code = SHELL_EXIT_ERROR; print_usage=TRUE; } else { _autoboot_cmd = AUTOBOOT_RESET; _mqx_exit(0); return MQX_OK; } } if (print_usage) { if (shorthelp) { printf("%s \n", argv[0]); } else { printf("Usage: %s ", argv[0]); printf(" <%s> booloader reset \n",argv[0]); } } }
/*! * \brief Initializes and starts MQX on the processor. * * The function does the following: * \li Initializes the default memory pool and memory components. * \li Initializes kernel data. * \li Performs BSP-specific initialization, which includes installing the * periodic timer. * \li Performs PSP-specific initialization. * \li Creates the interrupt stack. * \li Creates the ready queues. * \li Starts MQX tasks. * \li Starts autostart application tasks. * * \param[in] mqx_init Pointer to the MQX initialization structure for the * processor. * * \return Does not return (Success.) * \return If application called _mqx_exit(), error code that it passed to * _mqx_exit() (Success.) * \return Errors from _int_install_isr() (MQX cannot install the interrupt * subsystem.) * \return Errors from _io_init() (MQX cannot install the I/O subsystem.) * \return Errors from _mem_alloc_system() (There is not enough memory to * allocate either the interrupt stack or the interrupt table.) * \return Errors from _mem_alloc_zero() (There is not enough memory to allocate * the ready queues.) * \return MQX_KERNEL_MEMORY_TOO_SMALL (Init_struct_ptr does not specify enough * kernel memory.) * \return MQX_OUT_OF_MEMORY (There is not enough memory to allocate either the * ready queues, the interrupt stack, or the interrupt table.) * \return MQX_TIMER_ISR_INSTALL_FAIL (MQX cannot install the periodic timer ISR.) * * \warning Must be called exactly once per processor. * * \see _mqx_exit * \see _int_install_isr * \see _mem_alloc() * \see _mem_alloc_from() * \see _mem_alloc_system() * \see _mem_alloc_system_from() * \see _mem_alloc_system_zero() * \see _mem_alloc_system_zero_from() * \see _mem_alloc_zero() * \see _mem_alloc_zero_from() * \see _mem_alloc_align() * \see _mem_alloc_align_from() * \see _mem_alloc_at() * \see MQX_INITIALIZATION_STRUCT * \see TASK_TEMPLATE_STRUCT */ _mqx_uint _mqx ( register MQX_INITIALIZATION_STRUCT_PTR mqx_init ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TASK_TEMPLATE_STRUCT_PTR template_ptr; TD_STRUCT_PTR td_ptr; _mqx_uint result; pointer stack_ptr; pointer sys_td_stack_ptr; uchar_ptr sys_stack_base_ptr; #if MQX_EXIT_ENABLED || MQX_CRIPPLED_EVALUATION /* Setup a longjmp buffer using setjmp, so that if an error occurs * in mqx initialization, we can perform a longjmp to this location. * * Also _mqx_exit will use this jumpbuffer to longjmp to here in order * to cleanly exit MQX. */ if ( MQX_SETJMP( _mqx_exit_jump_buffer_internal ) ) { _GET_KERNEL_DATA(kernel_data); _int_set_vector_table(kernel_data->USERS_VBR); return kernel_data->USERS_ERROR; } /* Endif */ #endif /* * The kernel data structure starts at the start of kernel memory, * as specified in the initialization structure. Make sure address * specified is aligned */ kernel_data = (KERNEL_DATA_STRUCT_PTR) _ALIGN_ADDR_TO_HIGHER_MEM(mqx_init->START_OF_KERNEL_MEMORY); /* Set the global pointer to the kernel data structure */ _SET_KERNEL_DATA(kernel_data); /* The following assignments are done to force the linker to include * the symbols, which are required by TAD. * Note that we should use address of the variable so it is not optimized * as direct constant assignment when optimization level is high. * Note that counter will be immediately reset to zero on the subsequent * _mem_zero call. */ *(volatile pointer*) kernel_data = (pointer) & _mqx_version_number; *(volatile pointer*) kernel_data = (pointer) & _mqx_vendor; /* Initialize the kernel data to zero. */ _mem_zero((pointer) kernel_data, (_mem_size) sizeof(KERNEL_DATA_STRUCT)); #if MQX_CHECK_ERRORS && MQX_VERIFY_KERNEL_DATA /* Verify that kernel data can be read and written correcly without * errors. This is necessary during BSP development to validate the * DRAM controller is initialized properly. */ #ifndef PSP_KERNEL_DATA_VERIFY_ENABLE #define PSP_KERNEL_DATA_VERIFY_ENABLE 0 #endif /* PSP_KERNEL_DATA_VERIFY_ENABLE */ if (PSP_KERNEL_DATA_VERIFY_ENABLE) { /* This memory check is dangerous, because can destroy boot stack * stack which is used !!! -> MQX will failed ! * Set PSP_KERNEL_DATA_VERIFY_ENABLE to 1 * only if your boot stack is out of MQX memory heap */ result = _mem_verify((uchar_ptr)kernel_data + sizeof(KERNEL_DATA_STRUCT), mqx_init->END_OF_KERNEL_MEMORY); if ( result != MQX_OK ) { _mqx_exit(result); /* RETURN TO USER */ } } #endif /* MQX_CHECK_ERRORS && MQX_VERIFY_KERNEL_DATA */ /* Copy the MQX initialization structure into kernel data. */ kernel_data->INIT = *mqx_init; kernel_data->INIT.START_OF_KERNEL_MEMORY = (pointer) kernel_data; kernel_data->INIT.END_OF_KERNEL_MEMORY = (pointer) _ALIGN_ADDR_TO_LOWER_MEM(kernel_data->INIT.END_OF_KERNEL_MEMORY); /* init kernel data structures */ _mqx_init_kernel_data_internal(); /* Initialize the memory resource manager for the kernel */ result = _mem_init_internal(); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { _mqx_exit(result); /* RETURN TO USER */ } /* Endif */ #endif #if MQX_USE_INTERRUPTS /* Now obtain the interrupt stack */ if (kernel_data->INIT.INTERRUPT_STACK_LOCATION) { stack_ptr = kernel_data->INIT.INTERRUPT_STACK_LOCATION; result = kernel_data->INIT.INTERRUPT_STACK_SIZE; } else { if ( kernel_data->INIT.INTERRUPT_STACK_SIZE < PSP_MINSTACKSIZE ) { kernel_data->INIT.INTERRUPT_STACK_SIZE = PSP_MINSTACKSIZE; } /* Endif */ #if PSP_STACK_ALIGNMENT result = kernel_data->INIT.INTERRUPT_STACK_SIZE + PSP_STACK_ALIGNMENT + 1; #else result = kernel_data->INIT.INTERRUPT_STACK_SIZE; #endif stack_ptr = _mem_alloc_system((_mem_size)result); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (stack_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); /* RETURN TO USER */ } /* Endif */ #endif _mem_set_type(stack_ptr, MEM_TYPE_INTERRUPT_STACK); } /* Endif */ #if MQX_MONITOR_STACK _task_fill_stack_internal((_mqx_uint_ptr)stack_ptr, result); #endif kernel_data->INTERRUPT_STACK_PTR = _GET_STACK_BASE(stack_ptr, result); #endif /* * Set the stack for the system TD, in case the idle task gets blocked * by an exception or if idle task is not used. */ result = PSP_MINSTACKSIZE; sys_td_stack_ptr = _mem_alloc_system((_mem_size) result); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (sys_td_stack_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); /* RETURN TO USER */ } /* Endif */ #endif _mem_set_type(sys_td_stack_ptr, MEM_TYPE_SYSTEM_STACK); sys_stack_base_ptr = (uchar_ptr) _GET_STACK_BASE(sys_td_stack_ptr, result); td_ptr = SYSTEM_TD_PTR(kernel_data); td_ptr->STACK_PTR = (pointer)(sys_stack_base_ptr - sizeof(PSP_STACK_START_STRUCT)); td_ptr->STACK_BASE = sys_stack_base_ptr; #if MQX_TD_HAS_STACK_LIMIT td_ptr->STACK_LIMIT = _GET_STACK_LIMIT(sys_td_stack_ptr, result); #endif _mqx_system_stack = td_ptr->STACK_PTR; /* Build the MQX ready to run queues */ result = _psp_init_readyqs(); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if ( result != MQX_OK ) { _mqx_exit(result); /* RETURN TO USER */ } /* Endif */ #endif #if MQX_USE_COMPONENTS /* Create a light wait semaphore for component creation */ _lwsem_create((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM, 1); #endif /* Create a light wait semaphore for task creation/destruction creation */ _lwsem_create((LWSEM_STRUCT_PTR) & kernel_data->TASK_CREATE_LWSEM, 1); /* Call bsp to enable timers and other devices */ result = _bsp_enable_card(); #if MQX_CHECK_ERRORS if ( result != MQX_OK ) { _mqx_exit(result); /* RETURN TO USER */ } /* Endif */ #endif #if MQX_HAS_TIME_SLICE /* Set the kernel default time slice value */ PSP_ADD_TICKS_TO_TICK_STRUCT(&kernel_data->SCHED_TIME_SLICE, MQX_DEFAULT_TIME_SLICE, &kernel_data->SCHED_TIME_SLICE); #endif /* Create the idle task */ #if MQX_USE_IDLE_TASK td_ptr = _task_init_internal( (TASK_TEMPLATE_STRUCT_PTR)&kernel_data->IDLE_TASK_TEMPLATE, kernel_data->ACTIVE_PTR->TASK_ID, MQX_IDLE_TASK_PARAMETER, TRUE, NULL, 0); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (td_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _task_ready_internal(td_ptr); #endif /* Check here for auto-create tasks, and create them here */ template_ptr = kernel_data->INIT.TASK_TEMPLATE_LIST; while (template_ptr->TASK_TEMPLATE_INDEX) { if (template_ptr->TASK_ATTRIBUTES & MQX_AUTO_START_TASK) { td_ptr = _task_init_internal(template_ptr, kernel_data->ACTIVE_PTR->TASK_ID, template_ptr->CREATION_PARAMETER, FALSE, NULL, 0); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (td_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _task_ready_internal(td_ptr); } /* Endif */ ++template_ptr; } /* Endwhile */ _sched_start_internal(); /* WILL NEVER RETURN FROM HERE */ return MQX_OK; /* To satisfy lint */ } /* Endbody */
void Main_task(uint_32 initial_data) { printf("\n Hello World \n"); _mqx_exit(0); }
void _mqx_init_kernel_data_internal ( void ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TASK_TEMPLATE_STRUCT_PTR task_template_ptr; TD_STRUCT_PTR td_ptr; _mqx_uint priority_levels; _mqx_uint i; _GET_KERNEL_DATA(kernel_data); /* Store the configuration used when the kernel was compiled */ kernel_data->CONFIG1 = MQX_CNFG1; kernel_data->CONFIG2 = MQX_CNFG2; /* Store the addressability of the processor. How many bits in a byte. */ kernel_data->ADDRESSING_CAPABILITY = PSP_MEMORY_ADDRESSING_CAPABILITY; /* Indicate the endianess of the target */ kernel_data->ENDIANESS = PSP_ENDIAN; /* Store PSP memory alignment information */ #if PSP_MEM_STOREBLOCK_ALIGNMENT != 0 kernel_data->PSP_CFG_MEM_STOREBLOCK_ALIGNMENT = PSP_MEM_STOREBLOCK_ALIGNMENT; #endif kernel_data->PSP_CFG_MEMORY_ALIGNMENT = PSP_MEMORY_ALIGNMENT; kernel_data->PSP_CFG_STACK_ALIGNMENT = PSP_STACK_ALIGNMENT; /* ** Fill in fields of the kernel data structure from the initialization ** structure. */ //kernel_data->PROCESSOR_NUMBER = kernel_data->INIT.PROCESSOR_NUMBER; /* Set IPC id for compatibility */ #if MQX_USE_IPC kernel_data->MY_IPC_ID = BUILD_TASKID(kernel_data->INIT.PROCESSOR_NUMBER, 1); #endif /* Store location of current interrupt vector table */ #if MQX_EXIT_ENABLED kernel_data->USERS_VBR = (_mqx_max_type)_int_get_vector_table(); #endif #if MQX_CHECK_ERRORS if (kernel_data->INIT.TASK_TEMPLATE_LIST == NULL) { _mqx_exit(MQX_INVALID_POINTER); } /* Endif */ #endif #if MQX_HAS_TIME_SLICE /* Set the default scheduling policy for created tasks */ kernel_data->SCHED_POLICY = MQX_SCHED_FIFO; #endif #if MQX_KD_HAS_COUNTER /* Initialize the kernel counter. */ kernel_data->COUNTER = 1U; #endif /* Set up the disable and enable priority levels */ _psp_set_kernel_disable_level(); /* ** Initialize the system task so that functions which update the ** task error code can be called. ** The system task never runs, but it's TD is used for error codes ** during initialization, and for storage of memory blocks assigned ** to the system. */ td_ptr = (TD_STRUCT_PTR)&kernel_data->SYSTEM_TD; kernel_data->ACTIVE_PTR = td_ptr; kernel_data->ACTIVE_SR = kernel_data->DISABLE_SR; td_ptr->TASK_SR = kernel_data->DISABLE_SR; td_ptr->TASK_ID = BUILD_TASKID(kernel_data->INIT.PROCESSOR_NUMBER, SYSTEM_TASK_NUMBER); td_ptr->STATE = BLOCKED; /* Initialize the light weight semaphores queue */ _QUEUE_INIT(&kernel_data->LWSEM, 0); #if MQX_ENABLE_USER_MODE _QUEUE_INIT(&kernel_data->USR_LWSEM, 0); #endif #if MQX_HAS_TICK /* Set up the timeout queue */ _QUEUE_INIT(&kernel_data->TIMEOUT_QUEUE, 0); #endif /* ** Compute the number of MQX priority levels needed. This is done ** by determining the task that has the lowest priority (highest number) */ priority_levels = 0; task_template_ptr = kernel_data->INIT.TASK_TEMPLATE_LIST; for (i = 0; task_template_ptr->TASK_TEMPLATE_INDEX && (i < MQX_MAXIMUM_NUMBER_OF_TASK_TEMPLATES); ++i, ++task_template_ptr) { if (priority_levels < task_template_ptr->TASK_PRIORITY) { priority_levels = task_template_ptr->TASK_PRIORITY; } /* Endif */ } /* Endfor */ kernel_data->LOWEST_TASK_PRIORITY = priority_levels; #if MQX_USE_IDLE_TASK /* ** Initialize the task template for the IDLE Task. ** NOTE that the idle task runs at 1 level lower than any user task. */ task_template_ptr = (TASK_TEMPLATE_STRUCT_PTR) &kernel_data->IDLE_TASK_TEMPLATE; task_template_ptr->TASK_TEMPLATE_INDEX = IDLE_TASK; task_template_ptr->TASK_STACKSIZE = PSP_IDLE_STACK_SIZE; task_template_ptr->TASK_NAME = MQX_IDLE_TASK_NAME; task_template_ptr->TASK_ADDRESS = _mqx_idle_task; task_template_ptr->TASK_PRIORITY = priority_levels + 1; #endif /* ** Initialize the linked list of all TDs in the system. ** Initially zero. Not including system TD */ _QUEUE_INIT(&kernel_data->TD_LIST, 0); /* Set the TD counter */ /* Start SPR P171-0014-02 */ /* kernel_data->TD_COUNTER = 1; */ kernel_data->TASK_NUMBER = 1; /* End SPR P171-0014-02 */ } /* Endbody */
void lcd_task(uint32_t initial_data) { // MQX_FILE_PTR adc_file; TCHRES_INSTALL_PARAM_STRUCT install_params; printf("Hello from LCD demo\n\r"); #if (defined BSP_TCHRES_ADC_XPLUS_DEVICE) && (defined BSP_TCHRES_ADC_YPLUS_DEVICE) printf("Opening ADC device for XPLUS electrode ... " BSP_TCHRES_ADC_XPLUS_DEVICE " "); if (fopen(BSP_TCHRES_ADC_XPLUS_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_XPLUS_DEVICE = BSP_TCHRES_ADC_XPLUS_DEVICE; printf("done\n"); } printf("Opening ADC device for YPLUS electrode ... " BSP_TCHRES_ADC_YPLUS_DEVICE " "); if (fopen(BSP_TCHRES_ADC_YPLUS_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_YPLUS_DEVICE = BSP_TCHRES_ADC_YPLUS_DEVICE; printf("done\n"); } #elif (defined BSP_TCHRES_ADC_DEVICE) printf("Opening ADC device for XPLUS and YPLUS electrodes ... " BSP_TCHRES_ADC_DEVICE " "); if (fopen(BSP_TCHRES_ADC_DEVICE, (const char*)&adc_init) == NULL) { printf("failed\n"); _task_block(); } else { install_params.ADC_XPLUS_DEVICE = install_params.ADC_YPLUS_DEVICE = BSP_TCHRES_ADC_DEVICE; printf("done\n"); } #else printf("This demo application requires ADC devices for TCHRES to be defined!\n"); _task_block(); #endif #if ADC_IOCTL_CALIBRATE // ioctl( adc_file, ADC_IOCTL_CALIBRATE, NULL ); #endif _io_tchres_install("tchscr:", &_bsp_tchscr_resisitve_init, &install_params ); // Create the lwtimer component _lwtimer_create_periodic_queue(&lwt_ps, 25 / 5, 40); _lwtimer_add_timer_to_queue(&lwt_ps, &lwt_st25, 0, Time_event25ms, 0); if(!D4D_Init(&screen_entry)) { // D4D initialization failed printf("eGUI/D4D initialization failed\n\r"); _mqx_exit(0); } D4D_SetOrientation(D4D_ORIENT_LANDSCAPE); D4D_CheckTouchScreen(); for(;;) { D4D_Poll(); _time_delay(10); } }
/*! * \brief Starts MQXLite on the processor. * * The function does the following: * \n - Starts system timer. * \n - Starts MQX tasks. * \n - Starts autostart application tasks. * * \return Does not return (Success.) * \return If application calls _mqx_exit(), error code that it passed to _mqx_exit(). * * \warning Must be called exactly once per processor. * * \see _mqxlite_init * \see _mqx_exit */ _mqx_uint _mqxlite(void) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TD_STRUCT_PTR td_ptr; #if MQX_EXIT_ENABLED || MQX_CRIPPLED_EVALUATION /* Setup a longjmp buffer using setjmp, so that if an error occurs * in mqx initialization, we can perform a longjmp to this location. * * Also _mqx_exit will use this jumpbuffer to longjmp to here in order * to cleanly exit MQX. */ if ( MQX_SETJMP( _mqx_exit_jump_buffer_internal ) ) { _GET_KERNEL_DATA(kernel_data); _int_set_vector_table(kernel_data->USERS_VBR); return kernel_data->USERS_ERROR; } /* Endif */ #endif _GET_KERNEL_DATA(kernel_data); /* Create the idle task */ #if MQX_USE_IDLE_TASK td_ptr = _task_init_internal((TASK_TEMPLATE_STRUCT_PTR)&kernel_data->IDLE_TASK_TEMPLATE, kernel_data->ACTIVE_PTR->TASK_ID, #if MQX_ENABLE_LOW_POWER (uint_32)1, #else (uint_32)0, #endif FALSE, kernel_data->INIT.IDLE_TASK_STACK_LOCATION, kernel_data->IDLE_TASK_TEMPLATE.TASK_STACKSIZE); #if MQX_CHECK_ERRORS if (td_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _task_ready_internal(td_ptr); #endif /* MQX_USE_IDLE_TASK */ /* Check here for auto-create tasks, and create them here */ { TASK_TEMPLATE_STRUCT_PTR template_ptr; int task_index = 0; template_ptr = kernel_data->INIT.TASK_TEMPLATE_LIST; while (template_ptr->TASK_TEMPLATE_INDEX) { if (template_ptr->TASK_ATTRIBUTES & MQX_AUTO_START_TASK) { td_ptr = _task_init_internal(template_ptr, kernel_data->ACTIVE_PTR->TASK_ID, template_ptr->CREATION_PARAMETER, FALSE, (pointer)mqx_task_stack_pointers[task_index], (_mem_size)template_ptr->TASK_STACKSIZE); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (td_ptr == NULL) { _mqx_exit(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _task_ready_internal(td_ptr); } /* Endif */ ++template_ptr; ++task_index; } /* Endwhile */ } /* System timer start */ system_timer_start(NULL); _sched_start_internal(); /* WILL NEVER RETURN FROM HERE */ return MQX_OK; /* To satisfy lint */ } /* Endbody */
void SEC_InitializeNetworking(uint_32 pcbs, uint_32 msgs, uint_32 sockets, boolean dhcp) { int_32 error; IPCFG_IP_ADDRESS_DATA ip_data; _enet_address enet_address; #if PSP_MQX_CPU_IS_MCF51CN _enet_handle ehandle; _rtcs_if_handle ihandle; #endif /* runtime RTCS configuration */ _RTCSPCB_init = pcbs; _RTCS_msgpool_init = msgs; _RTCS_socket_part_init = sockets; error = RTCS_create(); if (error == RTCS_OK) { ip_data.ip = ENET_IPADDR; ip_data.mask = ENET_IPMASK; ip_data.gateway = ENET_IPGATEWAY; #if RTCSCFG_ENABLE_LWDNS LWDNS_server_ipaddr = ENET_IPDNS; #endif ENET_get_mac_address(BSP_DEFAULT_ENET_DEVICE, ENET_IPADDR, enet_address); #if PSP_MQX_CPU_IS_MCF51CN ENET_initialize_ex(&ENET_param, BSP_DEFAULT_ENET_DEVICE, &ehandle); if (RTCS_if_add(ehandle, RTCS_IF_ENET, &ihandle) == 0) { if (ipcfg_init_interface(-1, ihandle) != 0) { RTCS_if_remove(ihandle); ENET_shutdown(ehandle); _mqx_exit(1); } } else { ENET_shutdown(ehandle); } #else ipcfg_init_device(BSP_DEFAULT_ENET_DEVICE, enet_address); #endif ipcfg_add_dns_ip(BSP_DEFAULT_ENET_DEVICE,LWDNS_server_ipaddr); // check link status printf("\nWaiting for ethernet cable plug in ... "); while(!ipcfg_get_link_active(BSP_DEFAULT_ENET_DEVICE)) {}; printf("Cable connected\n"); /* If DHCP Enabled, get IP address from DHCP server */ if (dhcp) { printf("\nDHCP bind ... "); error = ipcfg_bind_dhcp_wait(BSP_DEFAULT_ENET_DEVICE, 1, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n", error); } else { printf("Successful!\n"); } } else { /* Else bind with static IP */ printf ("\nStatic IP bind ... "); error = ipcfg_bind_staticip(BSP_DEFAULT_ENET_DEVICE, &ip_data); if (error != IPCFG_ERROR_OK) { printf("Error %08x!\n",error); } else { printf("Successful!\n"); } } if (error == IPCFG_ERROR_OK) { ipcfg_get_ip(BSP_DEFAULT_ENET_DEVICE, &ip_data); printf("\nIP Address : %d.%d.%d.%d\n",IPBYTES(ip_data.ip)); printf("\nSubnet Address : %d.%d.%d.%d\n",IPBYTES(ip_data.mask)); printf("\nGateway Address : %d.%d.%d.%d\n",IPBYTES(ip_data.gateway)); printf("\nDNS Address : %d.%d.%d.%d\n",IPBYTES(ipcfg_get_dns_ip(BSP_DEFAULT_ENET_DEVICE,0))); } } else { printf("\nRTCS_Create failed !\n"); _task_block(); } SEC_GetTime(); }