_mqx_int _io_usb_mfs_open ( /* [IN] the file handle for the device being opened */ MQX_FILE_PTR fd_ptr, /* [IN] the remaining portion of the name of the device */ char_ptr open_name_ptr, /* [IN] USB mass storage class handle */ char_ptr flags ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; CLASS_CALL_STRUCT_PTR ccs_ptr = (CLASS_CALL_STRUCT_PTR)flags; _mqx_int io_error; IO_USB_MFS_STRUCT_PTR info_ptr; info_ptr = (IO_USB_MFS_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; /* Save the mass storage class handle. */ info_ptr->MSC_STREAM = (pointer) ccs_ptr; /* Send the call now */ _lwsem_wait(&info_ptr->LWSEM); io_error = _io_usb_mfs_open_internal(info_ptr, ccs_ptr); _lwsem_post(&info_ptr->LWSEM); return io_error; } /* Endbody */
_mqx_int _io_sai_int_write ( /* [IN] the handle returned from _fopen */ MQX_FILE_PTR fd_ptr, /* [IN] where the data are to be stored */ char_ptr data_ptr, /* [IN] the number of bytes to read */ _mqx_int n ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SAI_DEVICE_STRUCT_PTR io_sai_dev_ptr; uint_32 result; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; io_sai_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; _lwsem_wait(&io_sai_dev_ptr->LWSEM); result = (*io_sai_dev_ptr->DEV_WRITE)(io_sai_dev_ptr, data_ptr, n); _lwsem_post(&io_sai_dev_ptr->LWSEM); return result; } /* Endbody */
/* ** =================================================================== ** Event : Task3_task (module mqx_tasks) ** ** Component : Task3 [MQXLite_task] ** Description : ** MQX task routine. The routine is generated into mqx_tasks.c ** file. ** Parameters : ** NAME - DESCRIPTION ** task_init_data - ** Returns : Nothing ** =================================================================== */ void Task3_task(uint32_t task_init_data) { for(;;){ volatile int16 xr,yr,zr; uint16 br; static char * st1 ="\n\rAccelerometer x value: " ; static char * st2 ="\n\rAccelerometer y value: " ; static char * st3 ="\n\rAccelerometer z value: " ; static char * st4 ="\n\rLight Sensor value: " ; _lwsem_wait(&i2csem); xr=xw, yr=yw, zr=zw, br=bw; _lwsem_post(&i2csem); Term1_Cls(); Term1_MoveTo(1,1); Term1_SendStr(st1); Term1_SendNum(xr); Term1_SendStr(st2); Term1_SendNum(yr); Term1_SendStr(st3); Term1_SendNum(zr); Term1_SendStr(st4); Term1_SendNum(br); Term1_SendStr(" "); _time_delay_ticks(50); } //Term1_SendStr("\r \n"); }
_mqx_int _io_dun_read ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr, /* [IN] where the characters are to be stored */ char_ptr data_ptr, /* [IN] the number of characters to input */ _mqx_int num ) { /* Body */ IODUN_STRUCT_PTR ras_ptr = fd_ptr->DEV_DATA_PTR; _mqx_int numchar = num; _lwsem_wait(&ras_ptr->LWSEM); while (numchar--) { *data_ptr++ = _io_dun_read_char(fd_ptr); } /* Endwhile */ _lwsem_post(&ras_ptr->LWSEM); return(num); } /* Endbody */
/* ** =================================================================== ** Event : Task2_task (module mqx_tasks) ** ** Component : Task2 [MQXLite_task] ** Description : ** MQX task routine. The routine is generated into mqx_tasks.c ** file. ** Parameters : ** NAME - DESCRIPTION ** task_init_data - ** Returns : Nothing ** =================================================================== */ void Task2_task(uint32_t task_init_data) { int i; int counter; const char comma = ','; for(;;){ counter++; float p_result[3]; _lwsem_wait(&uartsem); for(i=0; i<3; i++){ p_result[i]=result[i]; } _lwsem_post(&uartsem); for(i=0; i<3; i++){ Term1_SendFloatNum(p_result[i]); Term1_SendChar(comma); } Term1_CRLF(); //_time_delay_ticks(50); } //Term1_SendStr("\r \n"); }
_mqx_int _io_pcb_shm_read ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to read data */ char *data_ptr, /* [IN] the number of characters to input */ _mqx_int num ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr = fd_ptr->DEV_DATA_PTR; IO_PCB_STRUCT_PTR *pcb_ptr = (IO_PCB_STRUCT_PTR*)data_ptr; _int_disable(); if (fd_ptr->FLAGS & IO_O_NONBLOCK) { if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); return(MQX_OK); } } _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((void *)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); return(MQX_OK); }
_mqx_int _io_pcb_shm_read ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR _PTR_ pcb_ptr ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; _int_disable(); if (fd_ptr->FLAGS & IO_O_NONBLOCK) { if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); return(MQX_OK); } } _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); return(MQX_OK); }
/*FUNCTION*------------------------------------------------ * * Function Name: PPP_start * Comments : * * *END*-----------------------------------------------------*/ void PPP_start(void) { uint_32 error; _rtcs_if_handle ihandle; MQX_FILE_PTR pfile; _iopcb_handle pio; _ppp_handle phandle; IPCP_DATA_STRUCT ipcp_data; _PPP_PAP_RSECRETS = rsecrets; /* Require authentication, allow PAP */ _PPP_PAP_LSECRET = &lsecret; /* Allow peer to request PAP */ _PPP_CHAP_LNAME = localname; /* Needed by CHAP */ _PPP_CHAP_RSECRETS = rsecrets; /* Require authentication, allow CHAP */ _PPP_CHAP_LSECRETS = lsecrets; /* Allow peer to request CHAP */ /* Install a route for a default gateway */ RTCS_gate_add(GATE_ADDR, INADDR_ANY, INADDR_ANY); pfile = fopen(PPP_DEVICE, NULL); #ifdef PPP_DEVICE_DUN _io_dun_install("dun:"); pfile = fopen("dun:", (char_ptr)pfile); #endif pio = _iopcb_ppphdlc_init(pfile); _PPP_ACCM = 0; error = PPP_initialize(pio, &phandle); if (error) { printf("\nPPP initialize: %lx", error); _task_block(); } /* Endif */ _iopcb_open(pio, PPP_lowerup, PPP_lowerdown, phandle); error = RTCS_if_add(phandle, RTCS_IF_PPP, &ihandle); if (error) { printf("\nIF add failed, error = %lx", error); _task_block(); } /* Endif */ _lwsem_create(&ppp_sem, 0); _mem_zero(&ipcp_data, sizeof(ipcp_data)); ipcp_data.IP_UP = PPP_linkup; ipcp_data.IP_DOWN = NULL; ipcp_data.IP_PARAM = &ppp_sem; ipcp_data.ACCEPT_LOCAL_ADDR = FALSE; ipcp_data.ACCEPT_REMOTE_ADDR = FALSE; ipcp_data.LOCAL_ADDR = PPP_LOCADDR; ipcp_data.REMOTE_ADDR = PPP_PEERADDR; ipcp_data.DEFAULT_NETMASK = TRUE; ipcp_data.DEFAULT_ROUTE = TRUE; error = RTCS_if_bind_IPCP(ihandle, &ipcp_data); if (error) { printf("\nIF bind failed, error = %lx", error); _task_block(); } /* Endif */ printf("\nPlease initiate PPP connection. Waiting..."); _lwsem_wait(&ppp_sem); printf("\nPPP device %s bound to %d.%d.%d.%d", PPP_DEVICE, IPBYTES(ipcp_data.LOCAL_ADDR)); }
int unmount_sdcard() { _mqx_uint param; _mqx_int error_code; boolean readonly = FALSE; char filesystem_name[] = "a:"; char partman_name[] = "pm:"; printf("unmounte sd card +\n"); _lwsem_wait(&SD_MFS_IO_SEM); if( ! sd_mounted) { _lwsem_post(&SD_MFS_IO_SEM); return 0; } /* Close the filesystem */ if (MQX_OK != fclose (filesystem_handle)) { printf("Error closing filesystem.\n"); _task_block(); } filesystem_handle = NULL; /* Uninstall MFS */ error_code = _io_dev_uninstall(filesystem_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling filesystem.\n"); _task_block(); } /* Close partition manager */ if (MQX_OK != fclose (partman_handle)) { printf("Unable to close partition manager.\n"); _task_block(); } partman_handle = NULL; /* Uninstall partition manager */ error_code = _io_dev_uninstall(partman_name); if (error_code != MFS_NO_ERROR) { printf("Error uninstalling partition manager.\n"); _task_block(); } /* Close the SD card device */ if (MQX_OK != fclose (sdcard_handle)) { printf("Unable to close SD card device.\n"); _task_block(); } sdcard_handle = NULL; sd_mounted = 0; printf("unmounted sd card -\n"); _lwsem_post(&SD_MFS_IO_SEM); return 0; }
_mqx_uint _partition_create_component ( void ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; PARTITION_COMPONENT_STRUCT_PTR part_component_ptr; _GET_KERNEL_DATA(kernel_data); _KLOGE1(KLOG_partition_create_component); #if MQX_CHECK_ERRORS if (kernel_data->IN_ISR) { _KLOGX2(KLOG_partition_create_component, MQX_CANNOT_CALL_FUNCTION_FROM_ISR); return(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); } /* Endif */ #endif _lwsem_wait((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); #if MQX_CHECK_ERRORS if (kernel_data->KERNEL_COMPONENTS[KERNEL_PARTITIONS] != NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OK); return(MQX_OK); } /* Endif */ #endif part_component_ptr = _mem_alloc_system_zero( (_mem_size)sizeof(PARTITION_COMPONENT_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (part_component_ptr == NULL) { _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OUT_OF_MEMORY); return(MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(part_component_ptr, MEM_TYPE_PARTITION_COMPONENT); kernel_data->KERNEL_COMPONENTS[KERNEL_PARTITIONS] = part_component_ptr; /* START CR 308 */ part_component_ptr->VALID = PARTITION_VALID; /* END CR 308 */ _QUEUE_INIT(&part_component_ptr->PARTITIONS, 0); #if MQX_COMPONENT_DESTRUCTION kernel_data->COMPONENT_CLEANUP[KERNEL_PARTITIONS] = _partition_cleanup; #endif _lwsem_post((LWSEM_STRUCT_PTR)&kernel_data->COMPONENT_CREATE_LWSEM); _KLOGX2(KLOG_partition_create_component, MQX_OK); return(MQX_OK); } /* Endbody */
/*! * \brief Obtains the MFS drive lock. Cannot be called from an ISR. * * \param drive_ptr * * \return _mfs_error */ _mfs_error MFS_lock( MFS_DRIVE_STRUCT_PTR drive_ptr) { #if MFSCFG_USE_MUTEX return _mutex_lock(&drive_ptr->MUTEX); #else return _lwsem_wait(&drive_ptr->LWSEM); #endif }
/* ** =================================================================== ** Event : write_task (module mqx_tasks) ** ** Component : Task1 [MQXLite_task] ** Description : ** MQX task routine. The routine is generated into mqx_tasks.c ** file. ** Parameters : ** NAME - DESCRIPTION ** task_init_data - ** Returns : Nothing ** =================================================================== */ void write_task(uint32_t task_init_data) { printf("\nWrite task created: 0x%lX", task_init_data); while (TRUE) { if (_lwsem_wait(&fifo.WRITE_SEM) != MQX_OK) { printf("\n_lwsem_wait failed"); _task_block(); } fifo.DATA = (unsigned char)task_init_data; _lwsem_post(&fifo.READ_SEM); } }
/* ** =================================================================== ** Event : Task1_task (module mqx_tasks) ** ** Component : Task1 [MQXLite_task] ** Description : ** MQX task routine. The routine is generated into mqx_tasks.c ** file. ** Parameters : ** NAME - DESCRIPTION ** task_init_data - ** Returns : Nothing ** =================================================================== */ void Task1_task(uint32_t task_init_data) { Light_Sense_Calibrate(TRUE); for(;;){ Light_Sense_Measure(TRUE); _lwsem_wait(&adcsem); Light_Sense_GetValue16(&bw); _lwsem_post(&adcsem); _time_delay_ticks(2); } }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : btnled_remove_clb * Returned Value : TRUE if removed, FALSE otherwise. * Comments : * This function is for callback unregistration. * *END*--------------------------------------------------------------------*/ boolean btnled_remove_clb(HMI_CLIENT_STRUCT_PTR handle, BTNLED_CLBREG_STRUCT_PTR comp_clbreg) { BTNLED_CONTEXT_STRUCT_PTR context; BTNLED_CLBREG_STRUCT_PTR step_clbreg; BTNLED_CLBREG_STRUCT_PTR tmp_clbreg; if((handle == NULL) || (comp_clbreg == NULL)) { return FALSE; } context = (BTNLED_CONTEXT_STRUCT_PTR)handle->CONTEXT_PTR; /* wait semaphore */ _lwsem_wait(&context->LOCK_BTNLED_SEM); step_clbreg = context->CLBREG; if(step_clbreg == NULL) { /* post semaphore */ _lwsem_post(&context->LOCK_BTNLED_SEM); return FALSE; } /* only one clbreg_struct is in a queue */ if(step_clbreg == comp_clbreg) { context->CLBREG = step_clbreg->NEXT_CALLBACK; if(_mem_free(step_clbreg) != MQX_OK) { _lwsem_post(&context->LOCK_BTNLED_SEM); return FALSE; } _lwsem_post(&context->LOCK_BTNLED_SEM); return TRUE; } /* more than one clbreg_struct is in a queue */ while(step_clbreg->NEXT_CALLBACK!=NULL) { if(step_clbreg->NEXT_CALLBACK == comp_clbreg) { tmp_clbreg = step_clbreg->NEXT_CALLBACK; step_clbreg->NEXT_CALLBACK = step_clbreg->NEXT_CALLBACK->NEXT_CALLBACK; if(_mem_free(tmp_clbreg)!=MQX_OK) { _lwsem_post(&context->LOCK_BTNLED_SEM); return FALSE; } _lwsem_post(&context->LOCK_BTNLED_SEM); return TRUE; } step_clbreg = step_clbreg->NEXT_CALLBACK; } _lwsem_post(&context->LOCK_BTNLED_SEM); return FALSE; }
_mqx_int _io_serial_int_close ( /* [IN] the file handle for the device being closed */ FILE_DEVICE_STRUCT_PTR fd_ptr ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_int result = MQX_OK; _mqx_int ioctl_val; /* other task cannot break 'close' function */ _int_disable(); io_dev_ptr = fd_ptr->DEV_PTR; int_io_dev_ptr = (void *)io_dev_ptr->DRIVER_INIT_PTR; /* flush the output buffer before closing */ (*io_dev_ptr->IO_IOCTL)(fd_ptr, IO_IOCTL_FLUSH_OUTPUT, NULL); if (--int_io_dev_ptr->COUNT == 0) { if (int_io_dev_ptr->DEV_IOCTL != NULL) { if (fd_ptr->FLAGS & IO_SERIAL_HW_FLOW_CONTROL) { ioctl_val = IO_SERIAL_RTS; (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_CLEAR_HW_SIGNAL, &ioctl_val); } } if (int_io_dev_ptr->DEV_DEINIT) { #if MQX_ENABLE_LOW_POWER _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif result = (*int_io_dev_ptr->DEV_DEINIT)(int_io_dev_ptr->DEV_INIT_DATA_PTR, int_io_dev_ptr->DEV_INFO_PTR); #if MQX_ENABLE_LOW_POWER _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif } /* Endif */ _mem_free(int_io_dev_ptr->IN_QUEUE); int_io_dev_ptr->IN_QUEUE = NULL; _mem_free(int_io_dev_ptr->OUT_QUEUE); int_io_dev_ptr->OUT_QUEUE = NULL; _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS); _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS); } /* Endif */ _int_enable(); return(result); } /* Endbody */
void Task1_task2(uint32_t task_init_data) { LWSEM_STRUCT lwsem; LDD_TDeviceData* btn1_ptr, *led_ptr; uint32_t button_press_count = 0; button_state_t button_state, button_last_state; _lwsem_create(&lwsem, 0); btn1_ptr = GPIO1_Init(&lwsem); /* TODO: Enable pull up because board does not have external pull up resistor */ PORTC_PCR3 |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK; led_ptr = LED_Init(NULL); printf("\n====================== GPIO Example ======================\n"); printf("The (SW1) button is configured to trigger GPIO interrupt.\n"); printf("Press the (SW1) button 3x to continue.\n\n"); button_press_count = 1; while(button_press_count < 4){ /* wait for button press, lwsem is set in button isr */ _lwsem_wait(&lwsem); printf("Button pressed %dx\r", button_press_count++); } printf("The (SW1) button state is now polled.\n"); printf("Press the (SW1) button to switch LED on or off\n\n"); while (1) { if (0 == GPIO1_GetFieldValue(btn1_ptr, BUTTON1)) { button_state = BUTTON_PRESSED; } else { button_state = BUTTON_RELEASED; } if (button_state != button_last_state) { printf("Button %s\r", button_state == BUTTON_PRESSED ? "pressed " : "released"); button_last_state = button_state; /* Set LED on or off arcodingly */ LED_PutVal(led_ptr, button_state == BUTTON_PRESSED ? FALSE : TRUE); } /* Check button state every 20 ticks*/ _time_delay_ticks(20); } }
_mqx_int _io_serial_int_write ( /* [IN] the handle returned from _fopen */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] where the characters to print out are */ char _PTR_ data_ptr, /* [IN] the number of characters to output */ _mqx_int num ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_uint flags; _mqx_int i = num; io_dev_ptr = fd_ptr->DEV_PTR; int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; flags = fd_ptr->FLAGS; #if MQX_ENABLE_LOW_POWER _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif while ( i != 0 ) { if (flags & IO_SERIAL_TRANSLATION) { if (*data_ptr == '\n') { (void)_io_serial_int_putc_internal(int_io_dev_ptr, '\r', 0); } /* Endif */ } /* Endif */ if (_io_serial_int_putc_internal(int_io_dev_ptr, *data_ptr, flags)){ data_ptr++; i--; } else { num -= i; break; } /* Endif */ } /* Endwhile */ #if MQX_ENABLE_LOW_POWER _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif return num; } /* Endbody */
/*! * \brief This function creates a kernel component providing a lightweight log * service for all user tasks. * * The lightweight log component provides a maximum of 16 logs, all with the same * size of entries. Log number 0 is reserved for kernel log. * \n An application subsequently creates lightweight logs with _lwlog_create() or * _lwlog_create_at(). * * \return MQX_OK * \return MQX_OUT_OF_MEMORY (MQX is out of memory.) * \return MQX_CANNOT_CALL_FUNCTION_FROM_ISR (Function cannot be called from an ISR.) * * \warning Cannot be called from an ISR. * * \see _lwlog_create * \see _lwlog_create_at * \see _klog_create * \see _klog_create_at */ _mqx_uint _lwlog_create_component(void) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; LWLOG_COMPONENT_STRUCT_PTR log_component_ptr; _GET_KERNEL_DATA(kernel_data); #if MQX_CHECK_ERRORS if (kernel_data->IN_ISR) { _task_set_error(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); return MQX_CANNOT_CALL_FUNCTION_FROM_ISR; } /* Endif */ #endif _lwsem_wait((LWSEM_STRUCT_PTR) &kernel_data->COMPONENT_CREATE_LWSEM); #if MQX_CHECK_ERRORS if (kernel_data->KERNEL_COMPONENTS[KERNEL_LWLOG] != NULL) { _lwsem_post((LWSEM_STRUCT_PTR) &kernel_data->COMPONENT_CREATE_LWSEM); return (MQX_OK); } /* Endif */ #endif #if MQX_LITE_VERSION_NUMBER log_component_ptr = &lwlog_struct; #else log_component_ptr = _mem_alloc_system_zero((_mem_size) sizeof(LWLOG_COMPONENT_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (log_component_ptr == NULL) { _lwsem_post((LWSEM_STRUCT_PTR) &kernel_data->COMPONENT_CREATE_LWSEM); return (MQX_OUT_OF_MEMORY); } /* Endif */ #endif _mem_set_type(log_component_ptr, MEM_TYPE_LWLOG_COMPONENT); #endif /* MQX_LITE_VERSION_NUMBER */ kernel_data->KERNEL_COMPONENTS[KERNEL_LWLOG] = log_component_ptr; log_component_ptr->VALID = LWLOG_VALID; _lwsem_post((LWSEM_STRUCT_PTR) &kernel_data->COMPONENT_CREATE_LWSEM); return (MQX_OK); } /* Endbody */
_mqx_int _io_pcb_mqxa_read ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR _PTR_ pcb_ptr ) { /* Body */ IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; if (info_ptr->FD) { _int_disable(); /* ** Start CR 383 ** if (info_ptr->FD->FLAGS & IO_O_NONBLOCK) { */ if (fd_ptr->FLAGS & IO_O_NONBLOCK) { /* End CR 383 */ if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); /* ** Start CR 384 ** return(0); */ return MQX_OK; /* End CR 384 */ } /* Endif */ } /* Endif */ _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); /* ** Start CR 384 ** return(0); */ return MQX_OK; /* End CR 384 */ }/* Endif */ return(IO_ERROR); } /* Endbody */
/* ** =================================================================== ** Event : Task2_task (module mqx_tasks) ** ** Component : Task2 [MQXLite_task] ** Description : ** MQX task routine. The routine is generated into mqx_tasks.c ** file. ** Parameters : ** NAME - DESCRIPTION ** task_init_data - ** Returns : Nothing ** =================================================================== */ void Task2_task(uint32_t task_init_data) { for(;;){ byte c; Accel_SendChar(0x00); Accel_RecvChar(&c); Accel_SendStop(); if (c&&0x01){ Accel_SendChar(0x01); Accel_RecvBlock(vec, 6, &snt); Accel_SendStop(); _lwsem_wait(&i2csem); xw=vec[0]; yw=vec[1]; zw=vec[2]; _lwsem_post(&i2csem); } _time_delay_ticks(2); } }
void main_task ( uint_32 initial_data ) { _task_id test_task; _lwsem_create(&shutdown_sem, 0); test_task = _task_create(0, TEST_TASK,0); _lwsem_wait(&shutdown_sem); _task_destroy(test_task); printf("\nWatchdog expired"); _task_block(); }
/*FUNCTION*---------------------------------------------------------------- * * Function Name : btnled_add_clb * Returned Value : BTNLED_CLBREG_STRUCT_PTR * Comments : * This function is for callback registration. * *END*--------------------------------------------------------------------*/ BTNLED_CLBREG_STRUCT_PTR btnled_add_clb(HMI_CLIENT_STRUCT_PTR handle, uint_32 uid, uint_32 state, void (_CODE_PTR_ function)(pointer), pointer callback_parameter) { BTNLED_CONTEXT_STRUCT_PTR context; BTNLED_CLBREG_STRUCT_PTR clbreg_struct; BTNLED_CLBREG_STRUCT_PTR new_clbreg_struct; if(handle == NULL) { return NULL; } /* allocate btnled_clb_structure */ new_clbreg_struct = _mem_alloc_system_zero(sizeof(BTNLED_CLBREG_STRUCT)); if(new_clbreg_struct == NULL) { return NULL; } /* fill new new_clbreg_structure */ new_clbreg_struct->STATE = state; new_clbreg_struct->UID = uid; new_clbreg_struct->CALLBACK_PARAMETER = callback_parameter; new_clbreg_struct->CLBFUNCTION = function; new_clbreg_struct->NEXT_CALLBACK = NULL; /* find last callback */ context = (BTNLED_CONTEXT_STRUCT_PTR) handle->CONTEXT_PTR; /* wait semaphore */ _lwsem_wait(&context->LOCK_BTNLED_SEM); clbreg_struct = context->CLBREG; if(clbreg_struct == NULL) { context->CLBREG = new_clbreg_struct; } else { while(clbreg_struct->NEXT_CALLBACK!=NULL) { clbreg_struct = clbreg_struct->NEXT_CALLBACK; } clbreg_struct->NEXT_CALLBACK = new_clbreg_struct; } /* post semaphore */ _lwsem_post(&context->LOCK_BTNLED_SEM); return new_clbreg_struct; }
/*FUNCTION**************************************************************** * * Function Name : _io_spi_read * Returned Value : Number of bytes read * Comments : * POSIX wrapper to perform SPI transfer storing received data into the buffer. * Returns number of bytes received. * *END*********************************************************************/ static _mqx_int _io_spi_read ( /* [IN] The handle returned from _fopen */ MQX_FILE_PTR fd_ptr, /* [OUT] Where the characters are to be stored */ char *data_ptr, /* [IN] The number of bytes to read */ _mqx_int n ) { #if 0 //SPI_DEV_DATA_STRUCT_PTR dev_data; SPI_DRIVER_DATA_STRUCT_PTR driver_data; _mqx_int num = n; //dev_data = (SPI_DEV_DATA_STRUCT_PTR)(fd_ptr->DEV_DATA_PTR); char tmp; driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)(fd_ptr->DEV_PTR->DRIVER_INIT_PTR); _lwsem_wait(&driver_data->IRQ_SEM); /*add callback function here before real read*/ SPI_CS_CALLBACK_STRUCT callback; callback.CALLBACK = read_cs_callback; callback.USERDATA = fd_ptr; _io_spi_ioctl(fd_ptr, IO_IOCTL_SPI_SET_CS_CALLBACK, &callback); while(lwgpio_get_value(&driver_data->SPI_IRQ_PIN) && num) { if(IO_ERROR !=_io_spi_read_write(fd_ptr, NULL, &tmp, 1)) { *data_ptr++ = tmp; num--; } else return IO_ERROR; } //return _io_spi_read_write(fd_ptr, NULL, data_ptr, n); _io_spi_flush(fd_ptr, 0); return (n-num); #endif return _io_spi_read_write(fd_ptr, NULL, data_ptr, n); }
_mqx_uint _mmu_destroy_vcontext ( /* [IN] the task for which a virtual context is to be removed */ _task_id task_id ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TD_STRUCT_PTR td_ptr; PSP_VIRTUAL_CONTEXT_STRUCT_PTR context_ptr; PSP_PAGE_INFO_STRUCT_PTR mem_ptr; PSP_SUPPORT_STRUCT_PTR psp_support_ptr; _GET_KERNEL_DATA(kernel_data); psp_support_ptr = kernel_data->PSP_SUPPORT_PTR; td_ptr = _task_get_td(task_id); if (td_ptr == NULL) { return(MQX_INVALID_TASK_ID); }/* Endif */ _int_disable(); if ((td_ptr->FLAGS & TASK_MMU_CONTEXT_EXISTS) == 0) { _int_enable(); return(MQX_MMU_CONTEXT_DOES_NOT_EXIST); } /* Endif */ if (td_ptr == kernel_data->ACTIVE_PTR) { /* Remove task MMU pages from the MMU table */ _mmu_reset_vcontext_internal(); }/* Endif */ td_ptr->FLAGS &= ~TASK_MMU_CONTEXT_EXISTS; context_ptr = td_ptr->MMU_VIRTUAL_CONTEXT_PTR; td_ptr->MMU_VIRTUAL_CONTEXT_PTR = NULL; _lwsem_wait(&psp_support_ptr->VPAGE_FREELIST_LWSEM); _int_enable(); while (_QUEUE_GET_SIZE(&context_ptr->PAGE_INFO)) { _QUEUE_DEQUEUE(&context_ptr->PAGE_INFO, mem_ptr); _QUEUE_ENQUEUE(&psp_support_ptr->VPAGE_FREELIST, &mem_ptr->ELEMENT); } /* Endwhile */ _lwsem_post(&psp_support_ptr->VPAGE_FREELIST_LWSEM); _mem_free(context_ptr); return(MQX_OK); } /* Endbody */
_mqx_int _io_serial_int_close ( /* [IN] the file handle for the device being closed */ FILE_DEVICE_STRUCT_PTR fd_ptr ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_int result = MQX_OK; _mqx_int ioctl_val; io_dev_ptr = fd_ptr->DEV_PTR; int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; if (--int_io_dev_ptr->COUNT == 0) { if (int_io_dev_ptr->DEV_IOCTL != NULL) { if (fd_ptr->FLAGS & IO_SERIAL_HW_FLOW_CONTROL) { ioctl_val = IO_SERIAL_RTS; (*int_io_dev_ptr->DEV_IOCTL)(int_io_dev_ptr->DEV_INFO_PTR, IO_IOCTL_SERIAL_CLEAR_HW_SIGNAL, &ioctl_val); } } if (int_io_dev_ptr->DEV_DEINIT) { #if MQX_ENABLE_LOW_POWER _lwsem_wait (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif result = (*int_io_dev_ptr->DEV_DEINIT)(int_io_dev_ptr->DEV_INIT_DATA_PTR, int_io_dev_ptr->DEV_INFO_PTR); #if MQX_ENABLE_LOW_POWER _lwsem_post (&(int_io_dev_ptr->LPM_INFO.LOCK)); #endif } /* Endif */ _mem_free(int_io_dev_ptr->IN_QUEUE); _mem_free(int_io_dev_ptr->OUT_QUEUE); _taskq_destroy(int_io_dev_ptr->IN_WAITING_TASKS); _taskq_destroy(int_io_dev_ptr->OUT_WAITING_TASKS); } /* Endif */ return(result); } /* Endbody */
_mqx_int _io_usb_mfs_read ( /* [IN] the file handle for the device */ MQX_FILE_PTR fd_ptr, /* [IN] where the outgoing data is store */ char_ptr data_ptr, /* [IN] the number of bytes to output */ int_32 num ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr = fd_ptr->DEV_PTR; IO_USB_MFS_STRUCT_PTR info_ptr = (IO_USB_MFS_STRUCT_PTR)io_dev_ptr->DRIVER_INIT_PTR; _mqx_int io_result; _lwsem_wait(&info_ptr->LWSEM); io_result = _io_usb_mfs_read_write_sectors_internal(fd_ptr, info_ptr, data_ptr, (uint_32)num, FALSE); _lwsem_post(&info_ptr->LWSEM); return io_result; } /* Endbody */
/*TASK*------------------------------------------------------------------- * * Task Name : spi_read_task func * Comments : * *END*----------------------------------------------------------------------*/ static void taskRead(uint32_t para) { MQX_FILE_PTR dev_file = (MQX_FILE_PTR)para; SPI_CS_CALLBACK_STRUCT callback; uint8_t tmp, *buf; _lwsem_create(&IRQ_SEM, 0); lwgpio_init(&SPI_IRQ_PIN, BSP_EM9301_IRQ_PIN, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); lwgpio_set_functionality(&SPI_IRQ_PIN, BSP_EM9301_IRQ_MUX_IRQ); lwgpio_set_attribute(&SPI_IRQ_PIN, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE); lwgpio_int_init(&SPI_IRQ_PIN, LWGPIO_INT_MODE_RISING); _int_install_isr(lwgpio_int_get_vector(&SPI_IRQ_PIN), em9301_isr, &SPI_IRQ_PIN); _bsp_int_init(lwgpio_int_get_vector(&SPI_IRQ_PIN), BSP_DSPI_INT_LEVEL, 0, TRUE); lwgpio_int_enable(&SPI_IRQ_PIN, TRUE); for(;;) { _lwsem_wait(&IRQ_SEM); callback.CALLBACK = read_cs_callback; callback.USERDATA = dev_file; ioctl(dev_file, IO_IOCTL_SPI_SET_CS_CALLBACK, &callback); buf = hciBuffer; while(lwgpio_get_value(&SPI_IRQ_PIN)) { if(IO_ERROR != fread(&tmp, 1, 1,dev_file)) *buf++ = tmp; } fflush(dev_file); #if 1 uint8_t *start = hciBuffer; SYSTEM_Log("--Rx:"); while(start < buf) { SYSTEM_Log(" %02X", *start++); } SYSTEM_Log("\n"); #endif } }
/*! * \cond DOXYGEN_PRIVATE * \private * * \brief This function completely removes the specified name table. * * \param[in] name_handle The name data structure pointer. * * \return MQX_OK * \return MQX_COMPONENT_DOES_NOT_EXIST (Name component is not created.) * \return MQX_INVALID_COMPONENT_BASE (Name component data is not valid.) */ _mqx_uint _name_destroy_handle_internal ( void *name_handle ) { /* Body */ register NAME_COMPONENT_STRUCT_PTR name_manager_ptr; register NAME_COMPONENT_STRUCT_PTR next_ptr; name_manager_ptr = (NAME_COMPONENT_STRUCT_PTR) name_handle; #if MQX_CHECK_ERRORS if (name_manager_ptr == NULL) { return (MQX_COMPONENT_DOES_NOT_EXIST); } /* Endif */ #endif /* MQX_CHECK_ERRORS */ _int_disable(); #if MQX_CHECK_VALIDITY if (name_manager_ptr->VALID != NAME_VALID) { _int_enable(); return (MQX_INVALID_COMPONENT_BASE); } /* Endif */ #endif /* MQX_CHECK_VALIDITY */ _lwsem_wait((LWSEM_STRUCT_PTR) (&name_manager_ptr->SEM)); name_manager_ptr->VALID = 0; _int_enable(); _lwsem_destroy((LWSEM_STRUCT_PTR) (&name_manager_ptr->SEM)); while (name_manager_ptr) { next_ptr = name_manager_ptr->NEXT_TABLE; name_manager_ptr->VALID = 0; _mem_free(name_manager_ptr); name_manager_ptr = next_ptr; } /* Endwhile */ return (MQX_OK); } /* Endbody */
void main_task ( uint32_t initial_data ) { MY_ISR_STRUCT_PTR isr_ptr; uint32_t result; /* Create the lightweight semaphore */ result = _lwsem_create(&lwsem, 0); if (result != MQX_OK) { printf("\nCreating sem failed: 0x%X", result); _task_block(); } isr_ptr = _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT)); isr_ptr->TICK_COUNT = 0; isr_ptr->OLD_ISR_DATA = _int_get_isr_data(BSP_TIMER_INTERRUPT_VECTOR); isr_ptr->OLD_ISR = _int_get_isr(BSP_TIMER_INTERRUPT_VECTOR); /* Native MQX interrupt handling method, ISR is installed into the interrupt vector table in kernel */ if(! _int_install_isr(BSP_TIMER_INTERRUPT_VECTOR, new_tick_isr, isr_ptr)) { printf("Install interrupt handler to interrupt vector table of MQX kernel failed.\n"); _task_block(); } #ifndef DEMO_ENABLE_KERNEL_ISR _time_delay_ticks(200); printf("\nTick count = %d\n", isr_ptr->TICK_COUNT); _task_block(); #else printf("\n====================== ISR Example =======================\n"); printf("Press the SW1 to blink LED1, press it again to turn it off\n"); while(1) { _lwsem_wait(&lwsem); num_tick = isr_ptr->TICK_COUNT; } #endif /* DEMO_ENABLE_KERNEL_ISR */ }
void read_task ( uint32_t initial_data ) { _task_id task_id; _mqx_uint result; _mqx_uint i; /* Create the lightweight semaphores */ result = _lwsem_create(&fifo.READ_SEM, 0); if (result != MQX_OK) { printf("\nCreating read_sem failed: 0x%X", result); _task_block(); } result = _lwsem_create(&fifo.WRITE_SEM, 1); if (result != MQX_OK) { printf("\nCreating write_sem failed: 0x%X", result); _task_block(); } /* Create the write tasks */ for (i = 0; i < NUM_WRITERS; i++) { task_id = _task_create(0, WRITE_TASK, (uint32_t)('A' + i)); printf("\nwrite_task created, id 0x%lX", task_id); } while(TRUE) { result = _lwsem_wait(&fifo.READ_SEM); if (result != MQX_OK) { printf("\n_lwsem_wait failed: 0x%X", result); _task_block(); } putchar('\n'); putchar(fifo.DATA); _lwsem_post(&fifo.WRITE_SEM); } }