_mem_size _lwmem_get_free_internal ( /* [IN] which pool to get free size from */ _lwmem_pool_id pool_id ) { /* Body */ LWMEM_BLOCK_STRUCT_PTR block_ptr; _mem_size total_size; LWMEM_POOL_STRUCT_PTR mem_pool_ptr = (LWMEM_POOL_STRUCT_PTR)pool_id; #if MQX_CHECK_VALIDITY if (mem_pool_ptr->VALID != LWMEM_POOL_VALID) { _task_set_error(MQX_LWMEM_POOL_INVALID); return(0); } /* Endif */ #endif _int_disable(); block_ptr = mem_pool_ptr->POOL_FREE_LIST_PTR; while ( block_ptr != NULL ) { /* Provide window for higher priority tasks */ mem_pool_ptr->POOL_ALLOC_PTR = block_ptr; _int_enable(); _int_disable(); block_ptr = mem_pool_ptr->POOL_ALLOC_PTR; if (block_ptr == mem_pool_ptr->POOL_FREE_LIST_PTR) { total_size = 0; /* some task with higher priority did reset our loop pointer */ } /* Endif */ total_size += block_ptr->BLOCKSIZE; block_ptr = block_ptr->U.NEXTBLOCK; } /* Endwhile */ _int_enable(); return(total_size); } /* Endbody */
boolean _29glxxxN_chip_erase ( /* [IN] the flash information structure */ IO_FLASHX_STRUCT_PTR flashx_ptr ) { /* Body */ volatile uint_16 _PTR_ sect16_ptr; volatile uchar _PTR_ sect8_ptr; uint_32 result; if (flashx_ptr->WRITE_PROTECT) { (*flashx_ptr->WRITE_PROTECT)(flashx_ptr, FALSE); }/* Endif */ if (flashx_ptr->WIDTH == 16) { sect16_ptr = (volatile uint_16 _PTR_)flashx_ptr->BASE_ADDR; _int_disable(); sect16_ptr[0xAAA] = 0xAAAA; sect16_ptr[0x555] = 0x5555; sect16_ptr[0xAAA] = 0x8080; sect16_ptr[0xAAA] = 0xAAAA; sect16_ptr[0x555] = 0x5555; sect16_ptr[0xAAA] = 0x1010; /* chip erase */ _int_enable(); while ((result = _29glxxxN_status(flashx_ptr, (pointer)sect16_ptr)) == FLASH_BUSY) { }/* Endwhile */ sect16_ptr[0] = 0xF0F0; } else if (flashx_ptr->WIDTH == 8) { sect8_ptr = (volatile uchar _PTR_)flashx_ptr->BASE_ADDR; _int_disable(); sect8_ptr[0xAAA] = 0xAA; sect8_ptr[0x555] = 0x55; sect8_ptr[0xAAA] = 0x80; sect8_ptr[0xAAA] = 0xAA; sect8_ptr[0x555] = 0x55; sect8_ptr[0xAAA] = 0x10; /* chip erase */ _int_enable(); while ((result = _29glxxxN_status(flashx_ptr, (pointer)sect8_ptr)) == FLASH_BUSY) { }/* Endwhile */ sect8_ptr[0] = 0xF0; }/* Endif */ if (flashx_ptr->WRITE_PROTECT) { (*flashx_ptr->WRITE_PROTECT)(flashx_ptr, TRUE); }/* Endif */ return result == FLASH_READY; } /* Endbody */
int32_t RTCS_msgqueue_trysend ( _rtcs_msgqueue *msgq, void *msg ) { /* Body */ /* Check for an empty slot in the queue */ _int_disable(); if (msgq->EMPTY.VALUE <= 0) { _int_enable(); return RTCS_ERROR; } else { --msgq->EMPTY.VALUE; } /* Endif */ /* Dequeue the message */ msgq->QUEUE[msgq->TAIL++] = msg; if (msgq->TAIL == RTCSMQ_SIZE) { msgq->TAIL = 0; } /* Endif */ /* Unblock the receiver */ _int_enable(); _lwsem_post(&msgq->FULL); return RTCS_OK; } /* Endbody */
_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_sai_int_close ( /* [IN] the file handle for the device being closed */ MQX_FILE_PTR fd_ptr ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SAI_DEVICE_STRUCT_PTR io_sai_dev_ptr; _mqx_int result = MQX_OK; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; io_sai_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; _int_disable(); if (io_sai_dev_ptr->READ_COUNT > 0) { io_sai_dev_ptr->READ_COUNT--; } if (io_sai_dev_ptr->WRITE_COUNT > 0) { io_sai_dev_ptr->WRITE_COUNT--; } if ((io_sai_dev_ptr->READ_COUNT == 0) && (io_sai_dev_ptr->WRITE_COUNT == 0)) { if (io_sai_dev_ptr->DEV_DEINIT) { result = (*io_sai_dev_ptr->DEV_DEINIT)(io_sai_dev_ptr, io_sai_dev_ptr->DEV_INFO_PTR); } } _int_enable(); return result; } /* Endbody */
/*! * \cond DOXYGEN_PRIVATE * * \brief Atomically captures current time into HWTIMER_TIME_STRUCT structure * * Corrects/normalizes the values if necessary (interrupt pending, etc.) * * \param hwtimer[in] Pointer to hwtimer structure. * \param time[out] Pointer to time structure. This value is filled with current value of the timer. * * \return MQX_OK Success. * * \see hwtimer_pit_init * \see hwtimer_pit_deinit * \see hwtimer_pit_set_div * \see hwtimer_pit_start * \see hwtimer_pit_stop * \see hwtimer_pit_isr * \see hwtimer_pit_isr_shared */ static _mqx_int hwtimer_pit_get_time(HWTIMER_PTR hwtimer, HWTIMER_TIME_PTR time) { PIT_MemMapPtr pit_base = (PIT_MemMapPtr) hwtimer->ll_context[0]; uint32_t pit_channel = GET_PIT_CHANNEL_FROM_PITID(hwtimer->ll_context[1]); uint32_t temp_cval; /* Disable interrupt from timer*/ _int_disable(); time->TICKS = hwtimer->ticks; temp_cval = PIT_CVAL_REG(pit_base, pit_channel); /* Check pending interrupt flag */ if(PIT_TFLG_REG(pit_base, pit_channel) & PIT_TFLG_TIF_MASK) { _int_enable(); time->SUBTICKS = hwtimer->modulo - 1; } else { _int_enable(); time->SUBTICKS = PIT_LDVAL_REG(pit_base, pit_channel) - temp_cval; } 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); }
_mqx_uint _mmu_create_vcontext ( /* [IN] the task to which a virtual context is to be added */ _task_id task_id ) { /* Body */ TD_STRUCT_PTR td_ptr; PSP_VIRTUAL_CONTEXT_STRUCT_PTR context_ptr; td_ptr = _task_get_td(task_id); if (td_ptr == NULL) { return(MQX_INVALID_TASK_ID); }/* Endif */ context_ptr = _mem_alloc_system_zero(sizeof(PSP_VIRTUAL_CONTEXT_STRUCT)); if (context_ptr == NULL) { return(MQX_OUT_OF_MEMORY); }/* Endif */ _queue_init(&context_ptr->PAGE_INFO,0); _int_disable(); if (td_ptr->FLAGS & TASK_MMU_CONTEXT_EXISTS) { _int_enable(); _mem_free(context_ptr); return(MQX_MMU_CONTEXT_EXISTS); } /* Endif */ td_ptr->MMU_VIRTUAL_CONTEXT_PTR = context_ptr; td_ptr->FLAGS |= TASK_MMU_CONTEXT_EXISTS; _int_enable(); return(MQX_OK); } /* Endbody */
_mqx_int _io_i2c_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_I2C_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_int result = MQX_OK; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; int_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; _int_disable(); if (int_io_dev_ptr->COUNT == 0) { /* Device is already closed */ _int_enable (); return MQX_IO_OPERATION_NOT_AVAILABLE; } if (--int_io_dev_ptr->COUNT == 0) { if (int_io_dev_ptr->DEV_DEINIT) { result = (*int_io_dev_ptr->DEV_DEINIT)(int_io_dev_ptr, int_io_dev_ptr->DEV_INFO_PTR); } } _int_enable(); return result; } /* Endbody */
/*! * \brief Creates the periodic timer queue. * * \param[in] period_ptr The location of the data structure to be initialized. * \param[in] period The cycle length of this timer in ticks. * \param[in] wait_ticks The number of ticks to wait before starting this queue. * * \return MQX_OK * * \see _lwtimer_add_timer_to_queue * \see _lwtimer_cancel_period * \see _lwtimer_cancel_timer * \see _lwtimer_create_periodic_queue * \see LWTIMER_PERIOD_STRUCT */ _mqx_uint _lwtimer_create_periodic_queue ( LWTIMER_PERIOD_STRUCT_PTR period_ptr, _mqx_uint period, _mqx_uint wait_ticks ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); _KLOGE4(KLOG_lwtimer_create_periodic_queue, period_ptr, period, wait_ticks); period_ptr->PERIOD = period; period_ptr->EXPIRY = 0; period_ptr->WAIT = wait_ticks; _QUEUE_INIT(&period_ptr->TIMERS,0); period_ptr->TIMER_PTR = (void *) &period_ptr->TIMERS; _int_disable(); if (kernel_data->LWTIMERS.NEXT == NULL) { /* Initialize the light weight timer queue */ _QUEUE_INIT(&kernel_data->LWTIMERS, 0); kernel_data->LWTIMER_ISR = _lwtimer_isr_internal; } /* Endif */ period_ptr->VALID = LWTIMER_VALID; _QUEUE_ENQUEUE(&kernel_data->LWTIMERS, &period_ptr->LINK); _int_enable(); _KLOGX2(KLOG_lwtimer_create_periodic_queue, MQX_OK); return (MQX_OK); } /* Endbody */
/*! * \brief Cancels all the lightweight timers in the periodic queue. * * \param[in] period_ptr Pointer to the periodic queue to cancel. * * \return MQX_OK * \return MQX_LWTIMER_INVALID (Period_ptr points to an invalid periodic queue.) * * \see _lwtimer_add_timer_to_queue * \see _lwtimer_cancel_timer * \see _lwtimer_create_periodic_queue * \see LWTIMER_PERIOD_STRUCT */ _mqx_uint _lwtimer_cancel_period ( LWTIMER_PERIOD_STRUCT_PTR period_ptr ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_lwtimer_cancel_period, period_ptr); #if MQX_CHECK_VALIDITY if (period_ptr->VALID != LWTIMER_VALID) { _KLOGX2(KLOG_lwtimer_cancel_period, MQX_LWTIMER_INVALID); return MQX_LWTIMER_INVALID; } /* Endif */ #endif _int_disable(); period_ptr->VALID = 0; _QUEUE_REMOVE(&kernel_data->LWTIMERS, period_ptr); _int_enable(); _KLOGX2(KLOG_lwtimer_cancel_period, MQX_OK); return (MQX_OK); } /* Endbody */
void _int_default_isr ( /* [IN] the parameter passed to the ISR by the kernel */ pointer vector_number ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TD_STRUCT_PTR td_ptr; _GET_KERNEL_DATA(kernel_data); td_ptr = kernel_data->ACTIVE_PTR; _KLOGE5(KLOG_int_default_isr, td_ptr, vector_number, &vector_number, vector_number); _int_disable(); if (td_ptr->STATE != UNHANDLED_INT_BLOCKED) { td_ptr->STATE = UNHANDLED_INT_BLOCKED; td_ptr->INFO = (_mqx_uint)vector_number; _task_set_error_td_internal(td_ptr, MQX_UNHANDLED_INTERRUPT); _QUEUE_UNLINK(td_ptr); } /* Endif */ _int_enable(); } /* Endbody */
static _mqx_int _io_serial_mix_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_DEINIT) { result = (*int_io_dev_ptr->DEV_DEINIT)(int_io_dev_ptr->DEV_INIT_DATA_PTR, int_io_dev_ptr->DEV_INFO_PTR); } /* Endif */ _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 */
_mqx_int _io_sai_dma_close ( /* [IN] the file handle for the device being closed */ MQX_FILE_PTR fd_ptr ) { /* Body */ IO_DEVICE_STRUCT_PTR io_dev_ptr; IO_SAI_DEVICE_STRUCT_PTR io_sai_dev_ptr; _mqx_int result = MQX_OK; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; io_sai_dev_ptr = (void *)io_dev_ptr->DRIVER_INIT_PTR; _int_disable(); if (io_sai_dev_ptr->READ_COUNT > 0) { io_sai_dev_ptr->READ_COUNT = 0; if (io_sai_dev_ptr->DEV_DEINIT) { result = (*io_sai_dev_ptr->DEV_DEINIT)(io_sai_dev_ptr, I2S_IO_READ); } } if (io_sai_dev_ptr->WRITE_COUNT > 0) { io_sai_dev_ptr->WRITE_COUNT = 0; if (io_sai_dev_ptr->DEV_DEINIT) { result = (*io_sai_dev_ptr->DEV_DEINIT)(io_sai_dev_ptr, I2S_IO_WRITE); } } _int_enable(); return result; } /* Endbody */
_mqx_int _io_usb_dcd_polled_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_USB_DCD_POLLED_DEVICE_STRUCT_PTR pol_io_dev_ptr; _mqx_int result = MQX_OK; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; pol_io_dev_ptr = (pointer)io_dev_ptr->DRIVER_INIT_PTR; _int_disable (); if (--pol_io_dev_ptr->COUNT == 0) { if (pol_io_dev_ptr->DEV_DEINIT) { result = (*pol_io_dev_ptr->DEV_DEINIT)(pol_io_dev_ptr,pol_io_dev_ptr->DEV_INFO_PTR); } } _int_enable (); return result; } /* Endbody */
_mqx_int _io_usb_dcd_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_USB_DCD_INT_DEVICE_STRUCT_PTR int_io_dev_ptr; _mqx_int result = MQX_OK; io_dev_ptr = (IO_DEVICE_STRUCT_PTR)fd_ptr->DEV_PTR; int_io_dev_ptr = (void *)io_dev_ptr->DRIVER_INIT_PTR; _int_disable(); if (--int_io_dev_ptr->COUNT == 0) { if (int_io_dev_ptr->DEV_DEINIT) { result = (*int_io_dev_ptr->DEV_DEINIT)(int_io_dev_ptr, int_io_dev_ptr->DEV_INFO_PTR); } } _int_enable(); return result; } /* Endbody */
/*! * \brief Resets the lightweight log to its initial state (remove all entries). * * \param[in] log_number Log number of a previously created lightweight log (if * log_number is 0, kernel log is reseted). * * \return MQX_OK * \return LOG_INVALID (Log_number is out of range.) * \return LOG_DOES_NOT_EXIST (Log_number was not created.) * \return MQX_COMPONENT_DOES_NOT_EXIST (Log component is not created.) * \return MQX_INVALID_COMPONENT_HANDLE (Log component data is not valid.) * * \see _lwlog_disable * \see _lwlog_enable */ _mqx_uint _lwlog_reset ( _mqx_uint log_number ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; LWLOG_COMPONENT_STRUCT_PTR log_component_ptr; LWLOG_HEADER_STRUCT_PTR log_header_ptr; LWLOG_ENTRY_STRUCT_PTR entry_ptr; _GET_KERNEL_DATA(kernel_data); #if MQX_CHECK_ERRORS if (log_number >= LOG_MAXIMUM_NUMBER) { return (LOG_INVALID); } /* Endif */ #endif log_component_ptr = (LWLOG_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_LWLOG]; if (log_component_ptr == NULL) { return (MQX_COMPONENT_DOES_NOT_EXIST); } /* Endif */ _int_disable(); #if MQX_CHECK_VALIDITY if (log_component_ptr->VALID != LWLOG_VALID) { return (MQX_INVALID_COMPONENT_HANDLE); } /* Endif */ #endif log_header_ptr = log_component_ptr->LOGS[log_number]; #if MQX_CHECK_ERRORS if (log_header_ptr == NULL) { _int_enable(); return (LOG_DOES_NOT_EXIST); } /* Endif */ #endif log_header_ptr->READS = 0; log_header_ptr->CURRENT_ENTRIES = 0; log_header_ptr->NUMBER = 1; entry_ptr = &log_header_ptr->FIRST_ENTRY; log_header_ptr->WRITE_PTR = entry_ptr + (log_header_ptr->MAX_ENTRIES - 1); log_header_ptr->READ_PTR = entry_ptr; log_header_ptr->OLDEST_PTR = entry_ptr; _int_enable(); return (MQX_OK); } /* Endbody */
pointer _lwmem_get_next_block_internal ( /* [IN] the td whose blocks are being looked for */ TD_STRUCT_PTR td_ptr, /* [IN] the block last obtained */ pointer in_block_ptr ) { KERNEL_DATA_STRUCT_PTR kernel_data; LWMEM_POOL_STRUCT_PTR lwmem_pool_ptr; LWMEM_BLOCK_STRUCT_PTR block_ptr = in_block_ptr; LWMEM_BLOCK_STRUCT_PTR free_ptr; _GET_KERNEL_DATA(kernel_data); if (block_ptr == NULL) { // first item, start on first item in first pool lwmem_pool_ptr = kernel_data->KERNEL_LWMEM_POOL; block_ptr = lwmem_pool_ptr->POOL_ALLOC_START_PTR; } else { // continued, get lwmem pool from provided in_block_ptr block_ptr = GET_LWMEMBLOCK_PTR(in_block_ptr); lwmem_pool_ptr = block_ptr->POOL; block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE); } _int_disable(); do { free_ptr = lwmem_pool_ptr->POOL_FREE_LIST_PTR; while ((uchar_ptr)block_ptr < (uchar_ptr)lwmem_pool_ptr->POOL_ALLOC_END_PTR){ if (block_ptr->U.S.TASK_NUMBER == TASK_NUMBER_FROM_TASKID(td_ptr->TASK_ID)) { /* check for block is not free block */ while (free_ptr && free_ptr < block_ptr) { free_ptr = free_ptr->U.NEXTBLOCK; } if (free_ptr != block_ptr) { /* This block is owned by the target task and it's not free block*/ _int_enable(); return((pointer)((uchar_ptr)block_ptr + sizeof(LWMEM_BLOCK_STRUCT))); } } block_ptr = (LWMEM_BLOCK_STRUCT_PTR)((uchar_ptr)block_ptr + block_ptr->BLOCKSIZE); } // continue in next lwmem pool lwmem_pool_ptr = (LWMEM_POOL_STRUCT_PTR)(lwmem_pool_ptr->LINK.NEXT); block_ptr = lwmem_pool_ptr->POOL_ALLOC_START_PTR; } while (lwmem_pool_ptr != kernel_data->KERNEL_LWMEM_POOL); // repeat until processed lwmem pool is not first pool (pool list is circular list) _int_enable(); return(NULL); }
uint_32 _core_mutex_create_internal(CORE_MUTEX_PTR mutex_ptr, uint_32 core_num, uint_32 mutex_num, uint_32 policy, boolean allocated ) { CORE_MUTEX_COMPONENT_PTR component_ptr = _core_mutext_get_component_ptr(); #if MQX_CHECK_ERRORS if (component_ptr == NULL) { return MQX_COMPONENT_DOES_NOT_EXIST; } // range check mutex_id if (mutex_num>=SEMA4_NUM_GATES) { return (MQX_INVALID_PARAMETER); } if (core_num>=PSP_NUM_CORES) { return (MQX_INVALID_PARAMETER); } if (mutex_ptr==NULL) { return MQX_INVALID_PARAMETER; } #endif mutex_ptr->VALID = CORE_MUTEX_VALID; mutex_ptr->GATE_NUM = mutex_num; mutex_ptr->GATE_PTR = &(component_ptr->DEVICE[core_num].SEMA4_PTR->GATE[mutex_ptr->GATE_NUM]); mutex_ptr->WAIT_Q = _taskq_create(policy); #if MQX_CHECK_ERRORS if (mutex_ptr->WAIT_Q==NULL) { return MQX_TASKQ_CREATE_FAILED; } #endif _int_disable(); #if MQX_CHECK_ERRORS if (component_ptr->DEVICE[core_num].MUTEX_PTR[mutex_num] !=NULL) { _int_enable(); _taskq_destroy(mutex_ptr->WAIT_Q); return MQX_COMPONENT_EXISTS; } #endif component_ptr->DEVICE[core_num].MUTEX_PTR[mutex_num]=mutex_ptr; // Need to remember if we allocated this mutex, or user did if (allocated) { component_ptr->DEVICE[core_num].ALLOCED |= (1<<mutex_num); } // Enable 'unlocked' interrupt for this core if (_psp_core_num()==0) { component_ptr->DEVICE[core_num].SEMA4_PTR->CP0INE |= 1 << (SEMA4_NUM_GATES - 1 - idx[mutex_num]); //1 << (SEMA4_NUM_GATES-1-mutex_num); } else { component_ptr->DEVICE[core_num].SEMA4_PTR->CP1INE |= 1 << (SEMA4_NUM_GATES - 1 - idx[mutex_num]); //1 << (SEMA4_NUM_GATES-1-mutex_num); } _int_enable(); return COREMUTEX_OK; }
/*! * \brief Destroys an existing lightweight log. * * \param[in] log_number Log number of a previously created lightweight log (if * log_number is 0, kernel log is destroyed). * * \return MQX_OK * \return LOG_DOES_NOT_EXIST (Log_number was not previously created.) * \return LOG_INVALID (Log_number is out of range.) * \return MQX_COMPONENT_DOES_NOT_EXIST (Lightweight log component is not created.) * \return MQX_INVALID_COMPONENT_HANDLE (Lightweight log component data is not valid.) * * \see _lwlog_create * \see _lwlog_create_at * \see _lwlog_create_component */ _mqx_uint _lwlog_destroy ( _mqx_uint log_number ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; LWLOG_COMPONENT_STRUCT_PTR log_component_ptr; LWLOG_HEADER_STRUCT_PTR log_header_ptr; _GET_KERNEL_DATA(kernel_data); #if MQX_CHECK_ERRORS if (log_number >= LOG_MAXIMUM_NUMBER) { return (LOG_INVALID); } /* Endif */ #endif log_component_ptr = (LWLOG_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_LWLOG]; #if MQX_CHECK_ERRORS if (log_component_ptr == NULL) { return (MQX_COMPONENT_DOES_NOT_EXIST); } /* Endif */ #endif #if MQX_CHECK_VALIDITY if (log_component_ptr->VALID != LWLOG_VALID) { return (MQX_INVALID_COMPONENT_HANDLE); } /* Endif */ #endif _int_disable(); log_header_ptr = log_component_ptr->LOGS[log_number]; #if MQX_CHECK_ERRORS if (log_header_ptr == NULL) { _int_enable(); return (LOG_DOES_NOT_EXIST); } /* Endif */ #endif log_component_ptr->LOGS[log_number] = NULL; _int_enable(); #if !MQX_LITE_VERSION_NUMBER if (log_header_ptr->TYPE == LWLOG_DYNAMIC) { _mem_free(log_header_ptr); } /* Endif */ #endif return (MQX_OK); } /* Endbody */
_mqx_uint _name_create_component ( /* [IN] the initial number of names that can be stored */ _mqx_uint initial_number, /* [IN] the number of names to be added when table full */ _mqx_uint grow_number, /* [IN] the maximum number of names that can be stored */ _mqx_uint maximum_number ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; _mqx_uint result; pointer handle; NAME_COMPONENT_STRUCT_PTR component_ptr; _GET_KERNEL_DATA(kernel_data); _KLOGE4(KLOG_name_create_component, initial_number, grow_number, maximum_number); component_ptr = (NAME_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT]; if (component_ptr != NULL){ if (maximum_number > component_ptr->MAX_NUMBER) { component_ptr->MAX_NUMBER = maximum_number; } /* Endif */ _KLOGX2(KLOG_name_create_component, MQX_OK); return(MQX_OK); } /* Endif */ result = _name_create_handle_internal(&handle, initial_number, grow_number, maximum_number, initial_number); /* We must exclude all ISRs at this point */ if (result == MQX_OK) { _int_disable(); if (kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT] != NULL){ _int_enable(); _name_destroy_handle_internal(handle); component_ptr = (NAME_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT]; if (maximum_number > component_ptr->MAX_NUMBER) { component_ptr->MAX_NUMBER = maximum_number; } /* Endif */ _KLOGX2(KLOG_name_create_component, MQX_OK); return(MQX_OK); } /* Endif */ kernel_data->KERNEL_COMPONENTS[KERNEL_NAME_MANAGEMENT] = handle; _int_enable(); } /* Endif */ _KLOGX2(KLOG_name_create_component, result); return(result); } /* Endbody */
uint_32 _core_mutex_install( const CORE_MUTEX_INIT_STRUCT *init_ptr ) { CORE_MUTEX_COMPONENT_PTR component_ptr = _core_mutext_get_component_ptr(); PSP_INTERRUPT_TABLE_INDEX vector; uint_32 i; #if MQX_CHECK_ERRORS if (component_ptr!=NULL) { return MQX_COMPONENT_EXISTS; } #endif component_ptr = _mem_alloc_system_zero(sizeof(*component_ptr)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (component_ptr==NULL) { return MQX_OUT_OF_MEMORY; } #endif for (i=0;i<SEMA4_NUM_DEVICES;i++) { vector = _bsp_get_sema4_vector(i); component_ptr->DEVICE[i].SEMA4_PTR = _bsp_get_sema4_base_address(i); if (_psp_core_num()==0) { component_ptr->DEVICE[i].CPNTF_PTR = &(component_ptr->DEVICE[i].SEMA4_PTR->CP0NTF); } else { component_ptr->DEVICE[i].CPNTF_PTR = &(component_ptr->DEVICE[i].SEMA4_PTR->CP1NTF); } #if MQX_CHECK_ERRORS if ((component_ptr->DEVICE[i].SEMA4_PTR == NULL) || (vector==0)) { _mem_free(component_ptr); return MQX_INVALID_DEVICE; } #endif } _int_disable(); #if MQX_CHECK_ERRORS if (_core_mutext_get_component_ptr()) { _int_enable(); _mem_free(component_ptr); return MQX_COMPONENT_EXISTS; } #endif _core_mutext_set_component_ptr(component_ptr); _int_enable(); for (i=0;i<SEMA4_NUM_DEVICES;i++) { vector = _bsp_get_sema4_vector(i); _int_install_isr(vector, _sema4_isr, &component_ptr->DEVICE[i]); _bsp_int_init(vector, init_ptr->INT_PRIORITY, 0, TRUE); } return COREMUTEX_OK; }
pointer _taskq_create ( /* [IN] the policy of this task queue (fifo or priority queueing) */ _mqx_uint policy ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; TASK_QUEUE_STRUCT_PTR task_queue_ptr; _GET_KERNEL_DATA(kernel_data); _KLOGE2(KLOG_taskq_create, policy); #if MQX_CHECK_ERRORS if (! ((policy == MQX_TASK_QUEUE_FIFO) || (policy == MQX_TASK_QUEUE_BY_PRIORITY))) { _task_set_error(MQX_INVALID_PARAMETER); _KLOGX2(KLOG_taskq_create, NULL); return (NULL); } /* Endif */ if (kernel_data->IN_ISR) { _task_set_error(MQX_CANNOT_CALL_FUNCTION_FROM_ISR); _KLOGX2(KLOG_taskq_create, NULL); return(NULL); }/* Endif */ #endif task_queue_ptr = (TASK_QUEUE_STRUCT_PTR)_mem_alloc_system((_mem_size) sizeof(TASK_QUEUE_STRUCT)); #if MQX_CHECK_MEMORY_ALLOCATION_ERRORS if (task_queue_ptr == NULL) { _KLOGX2(KLOG_taskq_create, NULL); return(NULL); } /* Endif */ #endif _mem_set_type(task_queue_ptr, MEM_TYPE_TASK_Q); task_queue_ptr->POLICY = policy; _QUEUE_INIT(&task_queue_ptr->TD_QUEUE, 0); task_queue_ptr->VALID = TASK_QUEUE_VALID; _int_disable(); if (kernel_data->KERNEL_TASK_QUEUES.NEXT == NULL) { /* Initialize the task queue */ _QUEUE_INIT(&kernel_data->KERNEL_TASK_QUEUES,0); } /* Endif */ _QUEUE_ENQUEUE(&kernel_data->KERNEL_TASK_QUEUES, task_queue_ptr); _int_enable(); _KLOGX2(KLOG_taskq_create, task_queue_ptr); return(task_queue_ptr); } /* Endbody */
/*FUNCTION*---------------------------------------------------------------- * * Function Name : main (Main_Task if using MQX) * Returned Value : none * Comments : * Execution starts here * *END*--------------------------------------------------------------------*/ void Main_Task ( uint32_t param ) { /* Body */ USB_STATUS status = USB_OK; /* _usb_otg_init needs to be done with interrupts disabled */ _int_disable(); _int_install_unexpected_isr(); _usb_host_driver_install(USBCFG_DEFAULT_HOST_CONTROLLER); /* ** It means that we are going to act like host, so we initialize the ** host stack. This call will allow USB system to allocate memory for ** data structures, it uses later (e.g pipes etc.). */ status = _usb_host_init ( USBCFG_DEFAULT_HOST_CONTROLLER, /* Use value in header file */ &host_handle); /* Returned pointer */ if (status != USB_OK) { printf("\nUSB Host Initialization failed. STATUS: %x", status); fflush(stdout); } /* ** Since we are going to act as the host driver, register the driver ** information for wanted class/subclass/protocols */ status = _usb_host_driver_info_register ( host_handle, DriverInfoTable ); if (status != USB_OK) { printf("\nDriver Registration failed. STATUS: %x", status); fflush(stdout); } _int_enable(); printf("\n MQX USB Audio Speaker Host Demo\n"); fflush(stdout); /* Creat lwevents*/ if (MQX_OK !=_lwevent_create(&USB_Keyboard_Event, LWEVENT_AUTO_CLEAR)){ printf("\n_lwevent_create USB_Keyboard_Event failed.\n"); } if (MQX_OK !=_lwevent_create(&USB_Audio_FU_Request, LWEVENT_AUTO_CLEAR)){ printf("\n_lwevent_create USB_Audio_FU_Request failed.\n"); } if (MQX_OK !=_lwevent_create(&SD_Card_Event, LWEVENT_AUTO_CLEAR)){ printf("\n_lwevent_create SD_Card_Event failed.\n"); } _task_create(0, AUDIO_TASK, (uint32_t) host_handle); _task_create(0, HID_KEYB_TASK, (uint32_t) host_handle); _task_create(0, SDCARD_TASK, (uint32_t) host_handle); _task_create(0, SHELL_TASK, (uint32_t) host_handle); /* The main task has done its job, so exit */ } /* Endbody */
/*! * \brief Adds the lightweight timer to the periodic queue. * * The function inserts the timer in the queue in order of increasing offset * from the queue's start time. * * \param[in] period_ptr Pointer to the periodic queue. * \param[in] timer_ptr Pointer to the lightweight timer to add to the queue, * must be smaller than queue. * \param[in] ticks Tick offset from the timers period to expire at. * \param[in] func Function to call when the timer expires. * \param[in] parameter Parameter to pass to the function. * * \return MQX_OK * \return MQX_LWTIMER_INVALID (Period_ptr points to an invalid periodic queue.) * \return MQX_INVALID_PARAMETER (Ticks is greater than or equal to the * periodic queue's period.) * * \warning Disables and enables interrupts. * * \see _lwtimer_cancel_period * \see _lwtimer_cancel_timer * \see _lwtimer_create_periodic_queue * \see LWTIMER_PERIOD_STRUCT * \see LWTIMER_STRUCT */ _mqx_uint _lwtimer_add_timer_to_queue ( LWTIMER_PERIOD_STRUCT_PTR period_ptr, LWTIMER_STRUCT_PTR timer_ptr, _mqx_uint ticks, LWTIMER_ISR_FPTR func, pointer parameter ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; LWTIMER_STRUCT_PTR qe_ptr; _mqx_uint i; _GET_KERNEL_DATA(kernel_data); _KLOGE4(KLOG_lwtimer_add_timer_to_queue, period_ptr, timer_ptr, ticks); #if MQX_CHECK_ERRORS if (period_ptr->VALID != LWTIMER_VALID) { _KLOGX2(KLOG_lwtimer_add_timer_to_queue, MQX_LWTIMER_INVALID); return (MQX_LWTIMER_INVALID); } /* Endif */ if (ticks >= period_ptr->PERIOD) { _KLOGX2(KLOG_lwtimer_add_timer_to_queue, MQX_INVALID_PARAMETER); return (MQX_INVALID_PARAMETER); } /* Endif */ #endif timer_ptr->TIMER_FUNCTION = func; timer_ptr->PARAMETER = parameter; timer_ptr->PERIOD_PTR = period_ptr; timer_ptr->RELATIVE_TICKS = ticks; _int_disable(); /* Insert into queue in order of increasing offset from start time */ qe_ptr = (pointer) &period_ptr->TIMERS.NEXT; i = _QUEUE_GET_SIZE(&period_ptr->TIMERS) + 1; while (--i) { qe_ptr = (pointer) qe_ptr->LINK.NEXT; if (qe_ptr->RELATIVE_TICKS >= ticks) { qe_ptr = (pointer) qe_ptr->LINK.PREV; break; } /* Endif */ } /* Endwhile */ timer_ptr->VALID = LWTIMER_VALID; _QUEUE_INSERT(&period_ptr->TIMERS, qe_ptr, &timer_ptr->LINK); _int_enable(); _KLOGX2(KLOG_lwtimer_add_timer_to_queue, MQX_OK); return (MQX_OK); } /* Endbody */
boolean _29wsxxxN_erase ( /* [IN] the flash information structure */ IO_FLASHX_STRUCT_PTR dev_ptr, /* [IN] the sector to erase */ char _PTR_ input_sect_ptr, /* [IN] the sector size */ _mem_size sector_size ) { /* Body */ volatile uint_16 _PTR_ sect16_ptr; uint_32 result = FLASH_READY; uint_32 tmp1; uint_32 time0; /* test for flash write protect */ if (_29wsxxxN_test_lock_bits(dev_ptr) == LOCKED) { return FLASH_WRITE_PROTECT; }/* Endif */ if (dev_ptr->WIDTH == 16) { sect16_ptr = (volatile uint_16 _PTR_)input_sect_ptr; _int_disable(); /* unlock flash */ *( sect16_ptr + 0x555 ) = 0x00AA; *( sect16_ptr + 0x2AA ) = 0x0055; /* setup command */ *( sect16_ptr + 0x555 ) = 0x0080; /* unlock */ *( sect16_ptr + 0x555 ) = 0x00AA; *( sect16_ptr +0x2AA ) = 0x0055; /* Sector erase */ *( sect16_ptr ) = 0x0030; _int_enable(); /* erase check */ tmp1 = *sect16_ptr; /* wait, until DQ3 = 0 or tSEA=50us */ time0 = _time_get_microseconds(); while(!(tmp1 & DQ3) && (_time_get_microseconds()-time0)<50) { tmp1 = *sect16_ptr; } _io_flashx_wait_us(4); result = _29wsxxxN_test_erase_cmd(input_sect_ptr, (uint_16)0xFFFF); } else { result = FLASH_UNSUPPORTED_BUS_SIZE; } return result == FLASH_READY; } /* Endbody */
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _mpc5125_ipic_set_group_prios * Returned Value : none * Comments : * Dynamically Sets relative priorities in a group and updates mask table * *END*------------------------------------------------------------------------*/ void _mpc5125_ipic_set_group_prios ( /* [IN] pointer to Interrupt group parameter structure */ pointer param ) { _int_disable(); _mpc5125_ipic_set_group_prios_internal(param); _mpc5125_update_int_mask_table(); _int_enable(); }
void _io_pcb_shm_tx_isr ( /* [IN] the info structure */ pointer handle ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; IO_PCB_SHM_BUFFER_STRUCT_PTR bd_ptr; IO_PCB_FRAGMENT_STRUCT_PTR frag_ptr; uint_16 num_frags; uint_32 cntrl; info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)handle; _int_disable(); while (info_ptr->TXENTRIES < info_ptr->TX_LENGTH) { /* Get the address of the Tx descriptor */ bd_ptr = &info_ptr->TX_RING_PTR[info_ptr->TXLAST]; _DCACHE_INVALIDATE_LINE(bd_ptr); pcb_ptr = (IO_PCB_STRUCT_PTR) _bsp_ptov(bd_ptr->PACKET_PTR); cntrl = bd_ptr->CONTROL; /* Make sure the buffer is released by remote CPU */ if (cntrl != IO_PCB_SHM_BUFFER_ALOCATED) { break; } // Have to restore virtual addresses to free fragments num_frags = pcb_ptr->NUMBER_OF_FRAGMENTS; for(frag_ptr = (IO_PCB_FRAGMENT_STRUCT_PTR) &(pcb_ptr->FRAGMENTS[0]); num_frags; num_frags--, frag_ptr++) { frag_ptr->FRAGMENT = _bsp_ptov(frag_ptr->FRAGMENT); } /* Free PCB */ _io_pcb_free(pcb_ptr); /* Update info */ info_ptr->TX_PACKETS++; info_ptr->TXLAST = NEXT_INDEX(info_ptr->TXLAST, info_ptr->TX_LENGTH); info_ptr->TXENTRIES++; } /* Check if there is more to send */ _io_pcb_shm_tx(handle); /* Enable Interrupts */ _int_enable(); }
int __diab_atomic_enter ( void ) { /* Body */ _int_disable(); /* Unused return value */ return 0; } /* Endbody */
/*! * \brief Resets the log to its initial state (remove all entries). * * \param[in] log_number Log number of a previously created log. * * \return MQX_OK * \return LOG_INVALID (Log_number is out of range.) * \return LOG_DOES_NOT_EXIST (Log_number was not created.) * \return MQX_COMPONENT_DOES_NOT_EXIST (Log component is not created.) * \return MQX_INVALID_COMPONENT_HANDLE (Log component data is not valid.) * * \see _log_disable * \see _log_enable */ _mqx_uint _log_reset ( _mqx_uint log_number ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; LOG_COMPONENT_STRUCT_PTR log_component_ptr; LOG_HEADER_STRUCT_PTR log_header_ptr; _GET_KERNEL_DATA(kernel_data); #if MQX_CHECK_ERRORS if (log_number >= LOG_MAXIMUM_NUMBER) { return(LOG_INVALID); } /* Endif */ if (kernel_data->KERNEL_COMPONENTS[KERNEL_LOG] == NULL) { return(MQX_COMPONENT_DOES_NOT_EXIST); } /* Endif */ #endif log_component_ptr = (LOG_COMPONENT_STRUCT_PTR) kernel_data->KERNEL_COMPONENTS[KERNEL_LOG]; #if MQX_CHECK_VALIDITY if (log_component_ptr->VALID != LOG_VALID) { return(MQX_INVALID_COMPONENT_HANDLE); } /* Endif */ #endif _int_disable(); log_header_ptr = log_component_ptr->LOGS[log_number]; #if MQX_CHECK_ERRORS if (log_header_ptr == NULL) { _int_enable(); return(LOG_DOES_NOT_EXIST); } /* Endif */ #endif log_header_ptr->SIZE = 0; log_header_ptr->NUMBER = 1; log_header_ptr->LOG_WRITE = &log_header_ptr->DATA[0]; log_header_ptr->LOG_READ = log_header_ptr->LOG_WRITE; log_header_ptr->LAST_LOG = log_header_ptr->LOG_WRITE; _int_enable(); return(MQX_OK); } /* Endbody */