/*HEADER********************************************************************** * * Copyright 2008 Freescale Semiconductor, Inc. * Copyright 1989-2008 ARC International * * This software is owned or controlled by Freescale Semiconductor. * Use of this software is governed by the Freescale MQX RTOS License * distributed with this Material. * See the MQX_RTOS_LICENSE file distributed for more details. * * Brief License Summary: * This software is provided in source form for you to use free of charge, * but it is not open source software. You are allowed to use this software * but you cannot redistribute it or derivative works of it in source form. * The software may be used only in connection with a product containing * a Freescale microprocessor, microcontroller, or digital signal processor. * See license agreement file for full license terms including other * restrictions. ***************************************************************************** * * Comments: * * This file contains the source for the hello example program. * * *END************************************************************************/ #include #include #include #include "timer.h" #include "MQX_Def.h" #include "Startup_Task.h" #include "Touch_Task.h" #include "Footswitch_Task.h" #include "USB_HostTask.h" #include "USB_DeviceTask.h" #include "fsl_gpio.h" #include "fsl_cache.h" #include "fsl_pwm.h" #include "pin_mux.h" #include "fsl_xbara.h" #include #include #include "peripherals.h" #include #if ! BSPCFG_ENABLE_IO_SUBSYSTEM #error This application requires BSPCFG_ENABLE_IO_SUBSYSTEM defined non-zero in user_config.h. Please recompile BSP with this option. #endif LWEVENT_STRUCT Sys_LWEVENT; /* If you assign priority zero to a task, the task runs with interrupts disabled. When you assign task priorities in the task template list, note that: • MQX RTOS creates one ready queue for each priority up to the lowest priority (highest number). • While an application is running, it cannot create a task that has a lower priority (a higher number) than the lowest-priority task in the task template list. You can assign any combination of the following attributes to a task: • Autostart - when MQX RTOS starts, it creates one instance of the task. • DSP - MQX RTOS saves the DSP co-processor registers as part of the task's context. • Floating point - MQX RTOS saves floating-point registers as part of the task's context. • Time slice - MQX RTOS uses round robin scheduling for the task (the default is FIFO scheduling). Task index begin at 1 Param est pris en compteur que si MQX_AUTO_START_TASK, sinon utilise param passer par _task_create */ #define TASK_W_TEST_CNT 6 void USB_TestUSBWrite_Task(uint32_t param); void USB_TestLCD_Task(uint32_t param); const TASK_TEMPLATE_STRUCT MQX_template_list[] = { /* Task Index, Function, Stack, Priority, Name, Attributes, Param, Time Slice */ { STARTUP_TASK_ID, Startup_task, 4500, STARTUP_TASK_PRIO, "Startup", MQX_AUTO_START_TASK, 0, 0 }, { TOUCH_TASK_ID, Touch_task, 2500, TOUCH_TASK_PRIO, "Touch", 0, 0, 0 }, { USB_HOST_TASK_ID, USB_Host_Task, USB_TASK_STACK_SIZE, USB_TASK_PRIO, "USB Host", 0, 0, 0 }, { USB_DEV_TASK_ID, USB_Device_Task, USB_TASK_STACK_SIZE, USB_TASK_PRIO, "USB Device", 0, 0, 0 }, { 0 } }; /*TASK*----------------------------------------------------- * * Task Name : hello_task * Comments : * This task prints " Hello World " * *END*-----------------------------------------------------*/ void Startup_task( uint32_t initial_data ) { _task_id Lcl_CreatedTaskId; _int_install_unexpected_isr(); // Task prio Stack _timer_create_component( 2, 2000); _lwevent_create(&Sys_LWEVENT,LWEVENT_AUTO_CLEAR); printf("MQX Startup Task :\n"); printf("\nLib info :\n"); printf("BSP %s v%s build date %s\n",_mqx_bsp_board,_mqx_bsp_revision,_mqx_bsp_BuildDate ); printf("MQX v%s\nPSP %s build date %s\n",_mqx_version,_mqx_psp_revision,_mqx_date ); printf("USB Device Stack v%s build date %s\n",_usbdevice_revision,_usbdevice_BuildDate); printf("USB Host Stack v%s build date %s\n",_usbhost_revision,_usbhost_BuildDate); printf("Start Touch Task\n"); if(_task_create(MQX_LOCAL_PROCESSOR,TOUCH_TASK_ID,NULL) == MQX_NULL_TASK_ID) { _task_block(); } printf("Start USB Device Task\n"); if(_task_create(MQX_LOCAL_PROCESSOR,USB_DEV_TASK_ID,NULL) == MQX_NULL_TASK_ID) { printf("Failed to create USB Device Task\n"); _task_block(); } printf("Start USB Host Task\n"); if(_task_create(MQX_LOCAL_PROCESSOR,USB_HOST_TASK_ID, BSP_DEFAULT_USB_CONTROLLER_ID) == MQX_NULL_TASK_ID) { printf("Failed to create USB Host Task\n"); _task_block(); } #if TASK_W_TEST_CNT > 0 TASK_TEMPLATE_STRUCT Test_USBFile_Task_Template = { .TASK_TEMPLATE_INDEX = 0, .TASK_ADDRESS = USB_TestUSBWrite_Task, .TASK_STACKSIZE = 5000, .TASK_PRIORITY = USB_APP_TASK_PRIO, .TASK_NAME = "Test MFS", .TASK_ATTRIBUTES = MQX_AUTO_START_TASK, .CREATION_PARAMETER = 0, .DEFAULT_TIME_SLICE = 0}; _task_id TidTest[TASK_W_TEST_CNT] = {MQX_NULL_TASK_ID}; for(uint8_t i = 0; i < TASK_W_TEST_CNT; i++) { TidTest[i] = _task_create(MQX_LOCAL_PROCESSOR, 0, (uint32_t)&Test_USBFile_Task_Template); assert(TidTest[i] != MQX_NULL_TASK_ID); } TASK_TEMPLATE_STRUCT Test_LCD_Task_Template = { .TASK_TEMPLATE_INDEX = 0, .TASK_ADDRESS = USB_TestLCD_Task, .TASK_STACKSIZE = 5000, .TASK_PRIORITY = USB_APP_TASK_PRIO, .TASK_NAME = "Test LCD", .TASK_ATTRIBUTES = MQX_AUTO_START_TASK, .CREATION_PARAMETER = 0, .DEFAULT_TIME_SLICE = 0}; _task_id LCDTid = _task_create(MQX_LOCAL_PROCESSOR, 0, (uint32_t)&Test_LCD_Task_Template); #endif while(1) { _time_delay(30*1000); _mem_pool_id *pool_error_ptr = NULL; _mqx_uint memtest = _mem_test_all(pool_error_ptr); if(memtest != MQX_OK) { printf("\n\n\n\t\t\t ###### MEM ERROR DETECTED #####\n"); } _mqx_print_ram_usage(); } } void USB_TestUSBWrite_Task(uint32_t param) { _task_id MyTId = _task_get_id(); printf("Start Test Task 0x%X\r",MyTId); char Txt[64]; char pathfile[64]; uint32_t Wcnt = 0; bool Even = MyTId % 2 ; MQX_FILE_PTR fd_ptr = NULL; sprintf(pathfile,"%s",Even ? "C:TestUSB1.txt" : "C:TestUSB2.txt"); while(1) { if(fd_ptr == NULL) { fd_ptr = fopen(pathfile, "a+"); } if(fd_ptr != NULL) { printf("Task %X Write to %s...",MyTId,pathfile); sprintf(Txt,"TID=0x%X %d\n",MyTId,Wcnt++); int32_t Werr = write(fd_ptr, Txt, strlen(Txt)); int32_t ferror_code = ferror(fd_ptr); int32_t fcloseRtn = fclose(fd_ptr); fd_ptr = NULL; printf("WriteReturn = %d,ferror_code = %X, fcloseRtn = %X\n",Werr,ferror_code,fcloseRtn); _time_delay(100); } else { printf("Test Task 0x%X => Null file pointer\r",MyTId); _time_delay(5000); } } } bool _LCD_RGB_Init(elcdif_rgb_mode_config_t* Config,uint16_t * LCD_FrameBuffer) { /* Set the PWM to drive LCD backlight */ XBARA_Init(XBARA1); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm4Fault0); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm4Fault1); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault2); XBARA_SetSignalsConnection(XBARA1, kXBARA1_InputLogicHigh, kXBARA1_OutputFlexpwm1234Fault3); Periphs_PWM_LCD_BACKLIGHT(); PWM_SetPwmLdok(PWM4, (kPWM_Control_Module_1), true); PWM_StartTimer(PWM4_PERIPHERAL, (kPWM_Control_Module_1)); Config->bufferAddr = (uint32_t) LCD_FrameBuffer; ELCDIF_RgbModeInit(LCDIF, Config); LCDIF->CTRL2 = LCDIF_CTRL2_OUTSTANDING_REQS(2); ELCDIF_RgbModeStart(LCDIF); return true; } void _RGB_TEST_FillScreen(uint16_t Color,uint16_t *LCD_FrameBuffer,size_t LCD_FrameBufferSize) { uint16_t *PixelRGB565_End = ( uint16_t *) ((uint32_t) LCD_FrameBuffer + LCD_FrameBufferSize); for(uint16_t *PixelRGB565 = &LCD_FrameBuffer[0]; PixelRGB565 < PixelRGB565_End; PixelRGB565++) { *PixelRGB565 = Color; } } void _RGB_TEST_FillScreenArea(elcdif_rgb_mode_config_t* Config,uint16_t Color,uint16_t *LCD_FrameBuffer,size_t LCD_FrameBufferSize,uint16_t X1,uint16_t Y1,uint16_t X2,uint16_t Y2) { for(uint16_t Line = 0 ; Line < Y2 - Y1 ; Line++) { uint16_t *PixelRGB565 = &LCD_FrameBuffer[0] + (Y1 + Line) * Config->panelWidth + X1; for(uint16_t Col = 0 ; Col < X2 - X1 ; Col++) { *PixelRGB565++ = Color; } } } void _LCD_SetBacklight(uint8_t Percent) { PWM_UpdatePwmDutycycle(PWM4_PERIPHERAL, kPWM_Module_1,kPWM_PwmA,kPWM_EdgeAligned,Percent); /* Set the load okay bit for all submodules to load registers from their buffer */ PWM_SetPwmLdok(PWM4_PERIPHERAL, kPWM_Control_Module_1, true); } SDK_ALIGN( uint8_t Framebuffer[1024*600*2],8); uint8_t Testbuffer[1000]; void USB_TestLCD_Task(uint32_t param) { elcdif_rgb_mode_config_t Confi_LCD_RGB = { .panelWidth = 1024,.panelHeight = 600, .hsw = 140,.hfp = 16, .hbp = 160, .vsw = 160,.vfp = 20, .vbp = 1, .polarityFlags = kELCDIF_DataEnableActiveHigh | kELCDIF_VsyncActiveLow | kELCDIF_HsyncActiveLow | kELCDIF_DriveDataOnRisingClkEdge, .pixelFormat = kELCDIF_PixelFormatRGB565,.dataBus = kELCDIF_DataBus16Bit, .bufferAddr = NULL, }; size_t LCD_FrameBufferSize = 2*Confi_LCD_RGB.panelWidth*Confi_LCD_RGB.panelHeight; uint16_t * LCD_FrameBufferArray = (uint16_t * )Framebuffer;//_mem_alloc_system_zero(LCD_FrameBufferSize); _LCD_RGB_Init(&Confi_LCD_RGB,LCD_FrameBufferArray); _RGB_TEST_FillScreen(LCD_RGB_GREEN,LCD_FrameBufferArray,LCD_FrameBufferSize); _LCD_SetBacklight(100); //If this task run, USB write task fail after some time with, fclose return Err A07 #if !defined(DBGKO) _task_block(); #endif uint16_t Color[3] = {LCD_RGB_RED,LCD_RGB_GREEN,LCD_RGB_BLUE}; uint8_t i = 0; while(1) { _RGB_TEST_FillScreenArea(&Confi_LCD_RGB,Color[i],LCD_FrameBufferArray,LCD_FrameBufferSize,200,100,240,140); _time_delay(100); _RGB_TEST_FillScreenArea(&Confi_LCD_RGB,Color[i],LCD_FrameBufferArray,LCD_FrameBufferSize,800,100,840,140); _time_delay(100); _RGB_TEST_FillScreenArea(&Confi_LCD_RGB,Color[i],LCD_FrameBufferArray,LCD_FrameBufferSize,200,500,240,540); _time_delay(100); _RGB_TEST_FillScreenArea(&Confi_LCD_RGB,Color[i],LCD_FrameBufferArray,LCD_FrameBufferSize,800,500,840,540); _time_delay(100); _RGB_TEST_FillScreen(Color[i],LCD_FrameBufferArray,LCD_FrameBufferSize); _time_delay(100); i = (i + 1) % 3; } }