_mqx_uint _bsp_io_pcb_shm_int_install ( /* [IN] the initialization record for this device */ IO_PCB_SHM_INIT_STRUCT_PTR init_ptr, /* [IN] the context record for this device */ IO_PCB_SHM_INFO_STRUCT_PTR info_ptr ) { if (!_int_install_isr(init_ptr->RX_VECTOR, _bsp_io_pcb_shm_rx_isr, info_ptr)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } /* Install the tx finished ISR */ if (!_int_install_isr(init_ptr->TX_VECTOR, _bsp_io_pcb_shm_tx_isr, info_ptr)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } _bsp_int_init(init_ptr->RX_VECTOR, BSPCFG_IO_PCB_SHM_RX_PRIO, 0, TRUE); _bsp_int_init(init_ptr->TX_VECTOR, BSPCFG_IO_PCB_SHM_TX_PRIO, 0 , TRUE); return MQX_OK; }
_mqx_uint _bsp_io_pcb_shm_int_install ( /* [IN] the initialization record for this device */ IO_PCB_SHM_INIT_STRUCT_PTR init_ptr, /* [IN] the context record for this device */ IO_PCB_SHM_INFO_STRUCT_PTR info_ptr ) { if (!_int_install_isr(init_ptr->RX_VECTOR, _bsp_io_pcb_shm_rx_isr, info_ptr)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } /* Install the tx finished ISR */ if (!_int_install_isr(init_ptr->TX_VECTOR, _bsp_io_pcb_shm_tx_isr, info_ptr)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } /* clear all inter-core interrupts */ MSCM_IRCP0IR = (1 << (info_ptr->INIT.RX_VECTOR - GIC_CPU_to_CPU_int0)); MSCM_IRCP0IR = (1 << (info_ptr->INIT.TX_VECTOR - GIC_CPU_to_CPU_int0)); MSCM_IRCP1IR = (1 << (info_ptr->INIT.REMOTE_RX_VECTOR - NVIC_CPU_to_CPU_int0)); MSCM_IRCP1IR = (1 << (info_ptr->INIT.REMOTE_TX_VECTOR - NVIC_CPU_to_CPU_int0)); _bsp_int_init(init_ptr->RX_VECTOR, BSPCFG_IO_PCB_SHM_RX_PRIO, 0, TRUE); _bsp_int_init(init_ptr->TX_VECTOR, BSPCFG_IO_PCB_SHM_TX_PRIO, 0 , TRUE); return MQX_OK; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_dev_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_dev_init(struct usb_dev_if_struct *usb_if) { _mqx_int result; if (usb_if == NULL) { return IO_ERROR; } result = _bsp_usb_dev_io_init(usb_if); if (result != MQX_OK) return result; if (usb_if->DEV_INIT_PARAM == &_khci0_dev_init_param) { /* Configure enable USB regulator for device */ SIM_SOPT1CFG_REG(SIM_BASE_PTR) |= SIM_SOPT1CFG_URWE_MASK; SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* Enable internal pull-up resistor */ USB_CONTROL_REG(USB0_BASE_PTR) = USB_CONTROL_DPPULLUPNONOTG_MASK; USB_USBTRC0_REG(USB0_BASE_PTR) |= 0x40; /* Software must set this bit to 1 */ /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); } else if (usb_if->DEV_INIT_PARAM == &_ehci0_dev_init_param) { USBHS_USBCMD |= USBHS_USBCMD_RST_MASK; while (USBHS_USBCMD & USBHS_USBCMD_RST_MASK) { /* delay while resetting USB controller */ } USBHS_USBMODE = USBHS_USBMODE_CM_DEVICE_MASK; USBHS_USBCMD &= ~( USBHS_USBCMD_ITC(0xFF)); // Set interrupt threshold control = 0 USBHS_USBMODE |= USBHS_USBMODE_SLOM_MASK; // Setup Lockouts Off /* setup interrupt */ _bsp_int_init(INT_USBHS, BSP_USB_INT_LEVEL, 0, TRUE); } else { /* unknown controller */ result = IO_ERROR; } return MQX_OK; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_host_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_host_init(struct usb_host_if_struct *usb_if) { _mqx_int result; if (usb_if == NULL) { return IO_ERROR; } result = _bsp_usb_host_io_init(usb_if); if (result != MQX_OK) return result; if (usb_if->HOST_INIT_PARAM == &_khci0_host_init_param) { /* Do not configure enable USB regulator for host */ // SIM_SOPT1CFG_REG(SIM_BASE_PTR) |= SIM_SOPT1CFG_URWE_MASK; // SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); } else if (usb_if->HOST_INIT_PARAM == &_ehci0_host_init_param) { USBHS_USBCMD |= USBHS_USBCMD_RST_MASK; while (USBHS_USBCMD & USBHS_USBCMD_RST_MASK) { /* delay while resetting USB controller */ } USBHS_USBMODE = USBHS_USBMODE_CM_HOST_MASK; USBHS_USBCMD = USBHS_USBCMD_ASP(3) | USBHS_USBCMD_ITC(0); /* setup interrupt */ _bsp_int_init(INT_USBHS, BSP_USB_INT_LEVEL, 0, TRUE); } else { /* unknown controller */ result = IO_ERROR; } return result; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_host_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_host_init(pointer param) { _mqx_uint dev_num = (_mqx_uint) param; _mqx_int result = _bsp_usb_io_init(dev_num); if (result != MQX_OK) return result; if (dev_num == USBCFG_CONTROLLER_KHCI) { /* Do not configure enable USB regulator for host */ // SIM_SOPT1CFG_REG(SIM_BASE_PTR) |= SIM_SOPT1CFG_URWE_MASK; // SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); } else if (dev_num == USBCFG_CONTROLLER_EHCI) { } else { /* unknown controller */ result = IO_ERROR; } return result; }
boolean MACNET_install_isr( ENET_CONTEXT_STRUCT_PTR enet_ptr, uint_32 int_num, uint_32 int_index, INT_ISR_FPTR isr, uint_32 level, uint_32 sublevel ) { uint_32 vector = MACNET_get_vector(enet_ptr->PARAM_PTR->ENET_IF->MAC_NUMBER, int_index); #if BSPCFG_ENET_RESTORE MACNET_CONTEXT_STRUCT_PTR macnet_context_ptr = (MACNET_CONTEXT_STRUCT_PTR) enet_ptr->MAC_CONTEXT_PTR; /* Save old ISR and data */ macnet_context_ptr->OLDISR_PTR[int_num] = _int_get_isr(vector); macnet_context_ptr->OLDISR_DATA[int_num] = _int_get_isr_data(vector); #endif if (_int_install_isr(vector, isr, (pointer)enet_ptr)==NULL) { return FALSE; } /* Initialize interrupt priority and level */ _bsp_int_init((PSP_INTERRUPT_TABLE_INDEX)vector, level, sublevel, TRUE); return TRUE; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_btnled_init * Returned Value : HMI_CLIENT_STRUCT_PTR for success, NULL for failure * Comments : * This function performs BSP-specific initialization related to HMI. * It installs interrupts for TSS and initializes btnled client with * default providers. *END*----------------------------------------------------------------------*/ HMI_CLIENT_STRUCT_PTR _bsp_btnled_init(void) { _int_install_isr(INT_TSI0, TSS_TSI0Isr, NULL); /* Install and then enable TSI0 Isr */ _bsp_int_init(INT_TSI0, BSP_TSI_INT_LEVEL, 0, TRUE); _bsp_int_enable(INT_TSI0); _bsp_tss_io_init(); /* TSI init */ hmi_tss_init(hmi_system_control_kinetis); /* TSS init */ /* BTNLED initialization */ hmi_btnled_handle_ptr = btnled_init(); if(hmi_btnled_handle_ptr == NULL) { return NULL; /* BTNLED not initialized */ } /* providers init - only providers available on board */ hmi_twrpi_provider_lwgpio_ptr = hmi_lwgpio_provider_init(hmi_init_table_lwgpio); /* LWGPIO */ hmi_twrpi_provider_keypad_ptr = hmi_tss_keypad_provider_init(hmi_init_table_tss_twrpi_void, 0); /* TSS Keypad - C0_TYPE */ /* add providers to the btnled table */ if (!hmi_add_provider(hmi_btnled_handle_ptr, hmi_twrpi_provider_keypad_ptr) || !hmi_add_provider(hmi_btnled_handle_ptr,hmi_twrpi_provider_lwgpio_ptr)) { return NULL; /* provider's addition to the client's table failed */ } return hmi_btnled_handle_ptr; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_dev_init(struct usb_dev_if_struct *usb_if) { _mqx_int result = _bsp_usb_io_init(); if (result != MQX_OK) return result; /* Configure enable USB regulator for device */ SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* Enable internal pull-up resistor */ USB_CONTROL_REG(USB0_BASE_PTR) = USB_CONTROL_DPPULLUPNONOTG_MASK; USB_USBTRC0_REG(USB0_BASE_PTR) |= 0x40; /* Software must set this bit to 1 */ /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); return MQX_OK; }
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; }
_mqx_int _mtim16_timer_install_kernel ( /* [IN] the timer to initialize */ uint8_t timer, /* [IN] ticks per second */ uint32_t tickfreq, /* [IN] input clock speed in Hz */ uint32_t clk, /* [IN] interrupt priority */ uint32_t priority, /* [IN] unmask the timer after installation */ bool unmask_timer ) { uint32_t result; uint32_t period; _mqx_uint vector = _bsp_get_mtim16_vector(timer); if (vector == 0) { return MQX_INVALID_DEVICE; } _bsp_int_disable(vector); /* Set up tick timer */ period = _mtim16_timer_init(timer, tickfreq, clk, FALSE); /* Install the timer interrupt handler */ if (_int_install_isr(vector, _mtim16_kernel_isr, NULL) == NULL) { return MQX_TIMER_ISR_INSTALL_FAIL; } /* Initialize the timer interrupt */ _time_set_timer_vector(_bsp_get_mtim16_vector(timer)); _time_set_hwtick_function(_mtim16_get_hwticks, (void *) timer); _time_set_hwticks_per_tick(period); _time_set_ticks_per_sec(tickfreq); _bsp_int_init(vector, priority, 0, TRUE); _bsp_int_enable(vector); if (unmask_timer) { _mtim16_unmask_int(timer); } return MQX_OK; }
/****************************************************************************** * @name audio_timer_init * * @brief This function initialize audio timer * * @return None * * @comment * *******************************************************************************/ void audio_timer_init(void) { if(_int_install_isr(AUDIO_INT, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR, NULL) == NULL) { return ; } /* Endif */ #if (defined BSP_TWR_K40X256) || (defined BSP_TWR_K60N512) ||\ (defined BSP_TWR_K53N512) || (defined BSP_KWIKSTIK_K40X256) ||\ (defined BSP_TWR_K70F120M) || (defined BSP_TWR_K60F120M) ||\ (defined BSP_TWR_K60D100M) _bsp_int_init(AUDIO_INT, 2, 0, TRUE); #endif }
/****************************************************************************** * @name audio_timer_init * * @brief This function init audio timer isr * * @return None * * @comment * *******************************************************************************/ void audio_timer_init(void) { #if (defined BSP_M52259DEMO)||(defined BSP_M52259EVB)||(defined BSP_TWRMCF52259)\ ||(defined BSP_M52277EVB)||(defined BSP_M52223EVB) if(_int_install_isr(BSP_PIT1_INT_VECTOR, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR, NULL) == NULL) { return ; } #endif #if(defined BSP_M5329EVB) _time_set_timer_vector(BSP_PIT3_INT_VECTOR); if (_int_install_isr(BSP_PIT3_INT_VECTOR, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR, NULL) == NULL) { return; } /* Endif */ #endif #if (defined BSP_TWRMCF51JE) _int_install_isr(MCF51JE_INT_Vcmt, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR,NULL); #endif #if (defined BSP_TWRMCF51MM) _int_install_isr(MCF51MM_INT_Vcmt, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR,NULL); #endif #if (defined BSP_MCF51JMEVB) _int_install_isr(MCF51JM_INT_Vcmt, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR,NULL); #endif #if (defined BSP_TWR_K40X256) || (defined BSP_TWR_K60N512) || (defined BSP_TWR_K53N512) || (defined BSP_KWIKSTIK_K40X256) if(_int_install_isr(INT_PIT1, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR, NULL) == NULL) { return ; } _bsp_int_init(INT_PIT1, 2, 0, TRUE); #endif #if (defined BSP_TWRMCF51JF) _int_install_isr(Vftm0fault_ovf, (void (_CODE_PTR_)(pointer))AUDIO_TIMER_ISR,NULL); #endif }
_mqx_int _mtim16_timer_install ( /* [IN] the timer to initialize */ uint8_t timer, /* [IN] ticks per second */ uint32_t tickfreq, /* [IN] input clock speed in Hz */ uint32_t clk, /* [IN] interrupt priority */ uint32_t priority, INT_ISR_FPTR isr_ptr, /* [IN] unmask the timer after installation */ bool unmask_timer ) { uint32_t result; _mqx_uint vector = _bsp_get_mtim16_vector(timer); if (vector == 0) { return MQX_INVALID_DEVICE; } _bsp_int_disable(vector); /* Set up tick timer */ _mtim16_timer_init(timer, tickfreq, clk, FALSE); /* Install the timer interrupt handler */ if (_int_install_isr(vector, isr_ptr, NULL) == NULL) { return MQX_TIMER_ISR_INSTALL_FAIL; } _bsp_int_init(vector, priority, 0, TRUE); _bsp_int_enable(vector); if (unmask_timer) { _mtim16_unmask_int(timer); } return MQX_OK; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_init(pointer param) { uint_32 status; _bsp_usb_io_init(); // setup interrupt status = _bsp_int_init(MCF5225_INT_USB, 3, 0, TRUE); if (status != MQX_OK) { return -1; } return MQX_OK; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_host_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_host_init(struct usb_host_if_struct *usb_if) { _mqx_int result = _bsp_usb_host_io_init(usb_if); if (result != MQX_OK) return result; /* Do not configure enable USB regulator for host */ /* SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; */ /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); return MQX_OK; }
/**************************************************************** * * Function Name : init_interrupt_btn * Comments : * Open the pin BSP_BTN1 for input, initialize interrupt and set * interrupt handler. * *****************************************************************/ void init_interrupt_btn(void * button) { LWGPIO_STRUCT_PTR btn_ptr = (LWGPIO_STRUCT_PTR) button; /* opening pins for input */ if (!lwgpio_init(btn_ptr, BSP_BUTTON1, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE)) { printf("Initializing button GPIO as input failed.\n"); _task_block(); } #ifdef BSP_BUTTON1_MUX_IRQ lwgpio_set_functionality(btn_ptr, BSP_BUTTON1_MUX_IRQ); #if defined(BSP_BUTTONS_ACTIVE_HIGH) lwgpio_set_attribute(btn_ptr, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE); #else lwgpio_set_attribute(btn_ptr, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* enable gpio functionality for given pin, react on falling edge */ if (! lwgpio_int_init(btn_ptr, LWGPIO_INT_MODE_FALLING)) { printf("Initializing button GPIO for interrupt failed.\n"); _task_block(); } /* Install the interrupt directly to the vector table in the processor. */ if(! _int_install_kernel_isr(lwgpio_int_get_vector(btn_ptr), btn_kernel_isr)) { printf("Install interrupt handler to hardware vector table failed.\n"); _task_block(); } /* set the interrupt level, and unmask the interrupt in interrupt controller */ if(MQX_OK != _bsp_int_init(lwgpio_int_get_vector(btn_ptr), 3, 0, TRUE)) { printf("Initialize interrupt failed.\n"); _task_block(); } /* enable interrupt on GPIO peripheral module */ lwgpio_int_enable(btn_ptr, TRUE); #else printf("This platform does not support pin mux interrupt function\n"); _task_block(); #endif /* BSP_BUTTON1_MUX_IRQ */ }
static void button_led_init ( void ) { static LWGPIO_STRUCT sw; /* Set the pin to input */ if (!lwgpio_init(&sw, BSP_SW2, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE)) { printf("\nSW initialization failed.\n"); _task_block(); } /* Set functionality to GPIO mode */ lwgpio_set_functionality(&sw, BSP_SW2_MUX_GPIO); /* Enable pull up */ lwgpio_set_attribute(&sw, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); /* Setup the pin interrupt mode */ if (!lwgpio_int_init(&sw, LWGPIO_INT_MODE_FALLING)) { printf("Initializing SW for interrupt failed.\n"); _task_block(); } /* Install gpio interrupt service routine */ _int_install_isr(lwgpio_int_get_vector(&sw), button_isr, (void *) &sw); /* Set interrupt priority and enable interrupt source in the interrupt controller */ _bsp_int_init(lwgpio_int_get_vector(&sw), 3, 0, TRUE); /* Enable interrupt for pin */ lwgpio_int_enable(&sw, TRUE); /* Initialize LED pin for output */ if (!lwgpio_init(&led1, BSP_LED1, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_HIGH)) { printf("\nLED1 initialization failed.\n"); _task_block(); } /* Set LED pin to GPIO functionality */ lwgpio_set_functionality(&led1, BSP_LED1_MUX_GPIO); }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_host_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_host_init(struct usb_host_if_struct *usb_if) { USB_MemMapPtr usb_ptr; USB_EHCI_HOST_INIT_STRUCT_PTR usb_init; _mqx_int result; if (usb_if == NULL) { return USBBSP_ERROR; } if (usb_if->HOST_INIT_PARAM == &_ehci0_host_init_param) { usb_ptr = USB0_BASE_PTR; } else if (usb_if->HOST_INIT_PARAM == &_ehci1_host_init_param) { usb_ptr = USB1_BASE_PTR; } else { return USBBSP_ERROR; /* unknown controller */ } result = _bsp_usb_host_io_init(usb_if); if (result != MQX_OK) return result; USB_USBCMD_REG(usb_ptr) &= ~USB_USBCMD_RS_MASK; while (USB_USBCMD_REG(usb_ptr) & USB_USBCMD_RS_MASK); { /* delay while resetting USB controller */ } USB_USBCMD_REG(usb_ptr) |= USB_USBCMD_RST_MASK; while (USB_USBCMD_REG(usb_ptr) & USB_USBCMD_RST_MASK) { /* delay while resetting USB controller */ } USB_USBMODE_REG(usb_ptr) = USB_USBMODE_CM_MASK; USB_USBCMD_REG(usb_ptr) = USB_USBCMD_ASP(3) | USB_USBCMD_ITC(0); /* setup interrupt */ usb_init = (USB_EHCI_HOST_INIT_STRUCT_PTR)usb_if->HOST_INIT_PARAM; result = _bsp_int_init(usb_init->VECTOR, BSP_USB_INT_LEVEL, 0, TRUE); return result; }
/*FUNCTION**************************************************************** * * Function Name : _rtc_int_enable * Returned Value : bitmask of new int enable state * Comments : * This function enables/disables RTC interrupts according to specified bitmask. * *END*********************************************************************/ uint_32 _rtc_int_enable ( /* [IN] whether to enable or disable interrupts */ boolean enable, /* [IN] bitmask of affected interrupts */ uint_32 bitmask ) { if( enable == TRUE ) { user_enables |= bitmask; } else { user_enables &= ~bitmask; } _bsp_int_init(INT_RTC, BSP_RTC_INT_LEVEL, 0, enable); return user_enables; }
static uint32_t init_IRQ_interrupt(LWGPIO_STRUCT_PTR irq_pin, INT_ISR_FPTR isr) { /* Configure GPIO for nRF24L01 module */ if (FALSE == lwgpio_init(irq_pin, nRF24L01_IRQ_PIN, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE)) { return MQX_ERROR; } /* swich pin functionality (MUX) to GPIO mode */ lwgpio_set_functionality(irq_pin, nRF24L01_IRQ_PIN_MUX); if(!lwgpio_int_init(irq_pin, LWGPIO_INT_MODE_FALLING)) { return MQX_ERROR; } _int_install_isr(lwgpio_int_get_vector(irq_pin), isr, irq_pin); lwgpio_int_enable(irq_pin, TRUE); return _bsp_int_init(lwgpio_int_get_vector(irq_pin), 4, 0, TRUE); }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_dev_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_dev_init(struct usb_dev_if_struct *usb_if) { _mqx_int result = _bsp_usb_dev_io_init(usb_if); if (result != MQX_OK) return result; /* Configure enable USB regulator for device */ SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* Enable internal pull-up resistor */ USB_CONTROL_REG(USB0_BASE_PTR) = USB_CONTROL_DPPULLUPNONOTG_MASK; /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); return MQX_OK; }
/*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 } }
static int sample_timer_init() { SIM_SCGC6 |= SIM_SCGC6_PIT_MASK; // Enable PIT Module Clock sample_qpit_ptr = (VQPIT_REG_STRUCT_PTR)PIT_BASE_PTR; sample_qpit_ptr->MCR = 0/* QPIT_MCR_FRZ*/; printf("PIT reg 0x%x\n",PIT_BASE_PTR); if(_int_install_isr(SAMPLE_INT, SAMPLE_TIMER_ISR, NULL) == NULL) { printf("install sample timer isr failed\n"); return -1; } /* Endif */ /* create lwevent group */ if (_lwevent_create(&sample_event, 0) != MQX_OK) { /* 0 - manual clear */ return -1; } _bsp_int_init(SAMPLE_INT, 2, 0, TRUE /*FALSE*/); return 0; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_host_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_host_init(struct usb_host_if_struct *usb_if) { _mqx_int result = _bsp_usb_io_init(); if (result != MQX_OK) return result; /* Do not configure enable USB regulator for host */ // SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); return MQX_OK; }
/*FUNCTION*------------------------------------------------------------------- * * Function Name : _bsp_usb_dev_init * Returned Value : 0 for success, -1 for failure * Comments : * This function performs BSP-specific initialization related to USB * *END*----------------------------------------------------------------------*/ _mqx_int _bsp_usb_dev_init(pointer param) { _mqx_uint dev_num = (_mqx_uint) param; _mqx_int result = _bsp_usb_io_init(dev_num); if (result != MQX_OK) return result; if (dev_num == USBCFG_CONTROLLER_KHCI) { /* Configure enable USB regulator for device */ SIM_SOPT1CFG_REG(SIM_BASE_PTR) |= SIM_SOPT1CFG_URWE_MASK; SIM_SOPT1_REG(SIM_BASE_PTR) |= SIM_SOPT1_USBREGEN_MASK; /* Reset USB peripheral */ USB_USBTRC0_REG(USB0_BASE_PTR) |= USB_USBTRC0_USBRESET_MASK; /* Wait while resetting */ while (USB_USBTRC0_REG(USB0_BASE_PTR) & USB_USBTRC0_USBRESET_MASK) {} /* reset USB CTRL register */ USB_USBCTRL_REG(USB0_BASE_PTR) = 0; /* Enable internal pull-up resistor */ USB_CONTROL_REG(USB0_BASE_PTR) = USB_CONTROL_DPPULLUPNONOTG_MASK; USB_USBTRC0_REG(USB0_BASE_PTR) |= 0x40; /* Software must set this bit to 1 */ /* setup interrupt */ _bsp_int_init(INT_USB0, BSP_USB_INT_LEVEL, 0, TRUE); } else if (dev_num == USBCFG_CONTROLLER_EHCI) { } else { /* unknown controller */ result = IO_ERROR; } return MQX_OK; }
/*TASK*----------------------------------------------------------------- * * Function Name : Sdcard_task * Returned Value : void * Comments : * *END------------------------------------------------------------------*/ void Sdcard_task ( uint_32 temp ) { boolean inserted = TRUE, last = FALSE; _mqx_int error_code; MQX_FILE_PTR com_handle; //#if defined BSP_SDCARD_GPIO_DETECT // LWGPIO_STRUCT sd_detect; //#endif #if defined BSP_SDCARD_GPIO_PROTECT LWGPIO_STRUCT sd_protect; #endif #ifdef BSP_SDCARD_GPIO_CS LWGPIO_STRUCT sd_cs; SPI_CS_CALLBACK_STRUCT callback; #endif _task_id player_task_id, sd_walker_id; _mqx_int sd_event_value; _mqx_uint wait_state; #ifdef USB_ACCESSORY_PLAY connect_msg_t msg; int delaySetp = 0; #endif if (MQX_OK !=_lwevent_create(&(sddetect_event), LWEVENT_AUTO_CLEAR)) { printf("\n_lwevent_create sddetect_event failed\n"); _task_block(); } /* Open low level communication device */ com_handle = fopen (SDCARD_COM_CHANNEL, NULL); if (NULL == com_handle) { printf("Error installing communication handle.\n"); _task_block(); } #ifdef BSP_SDCARD_GPIO_CS /* Open GPIO file for SPI CS signal emulation */ error_code = lwgpio_init(&sd_cs, BSP_SDCARD_GPIO_CS, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with associated pins failed.\n"); _task_block(); } lwgpio_set_functionality(&sd_cs,BSP_SDCARD_CS_MUX_GPIO); lwgpio_set_attribute(&sd_cs, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); /* Set CS callback */ callback.MASK = BSP_SDCARD_SPI_CS; callback.CALLBACK = set_CS; callback.USERDATA = &sd_cs; if (SPI_OK != ioctl (com_handle, IO_IOCTL_SPI_SET_CS_CALLBACK, &callback)) { printf ("Setting CS callback failed.\n"); _task_block(); } #endif #if defined BSP_SDCARD_GPIO_DETECT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_detect, BSP_SDCARD_GPIO_DETECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with sdcard detect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_detect,BSP_SDCARD_DETECT_MUX_GPIO); lwgpio_set_attribute(&sd_detect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #ifndef SD_DETECT_POLLING // init sd detcet pin interrupt lwgpio_int_init(&sd_detect,LWGPIO_INT_MODE_RISING | LWGPIO_INT_MODE_FALLING /* LWGPIO_INT_MODE_HIGH*/); /* falling,raising mode = 3 */ /* install gpio interrupt service routine */ _int_install_isr(lwgpio_int_get_vector(&sd_detect), EXT_SDDETECT_ISR, (void *) &sd_detect); _bsp_int_init(lwgpio_int_get_vector(&sd_detect), 5, 0, TRUE); lwgpio_int_enable(&sd_detect, TRUE); #endif #endif #if defined BSP_SDCARD_GPIO_PROTECT /* Init GPIO pins for other SD card signals */ error_code = lwgpio_init(&sd_protect, BSP_SDCARD_GPIO_PROTECT, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if (!error_code) { printf("Initializing GPIO with sdcard protect pin failed.\n"); _task_block(); } /*Set detect and protect pins as GPIO Function */ lwgpio_set_functionality(&sd_protect,BSP_SDCARD_PROTECT_MUX_GPIO); lwgpio_set_attribute(&sd_protect, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* Install SD card device */ error_code = _io_sdcard_install("sdcard:", (pointer)&_bsp_sdcard0_init, com_handle); if ( error_code != MQX_OK ) { printf("Error installing SD card device (0x%x)\n", error_code); _task_block(); } _lwevent_set(&sddetect_event,SD_ATTACHED_EVENT); // set attached event at mode manager _time_delay(1000); /* wait otg main task ready */ printf("start sd card task\n"); // use sd detect interrupt for (;;) { #ifdef SD_DETECT_POLLING wait_state = _lwevent_wait_ticks(&sddetect_event,SD_EVENT_MASK, FALSE, 4/* 0*/); #else wait_state = _lwevent_wait_ticks(&sddetect_event,SD_EVENT_MASK, FALSE, 0); #endif //if (wait_state == LWEVENT_WAIT_TIMEOUT/* MQX_OK*/) { if (wait_state != MQX_OK ) { #ifndef SD_DETECT_POLLING printf("waiting sddetect_event fail\n"); // _task_block(); // _lwevent_destroy(&sddetect_event); //-goto wait_timeout; continue; #else _lwevent_set(&sddetect_event,SD_ATTACHED_EVENT); #endif } //else sd_event_value = _lwevent_get_signalled(); if (sd_event_value == SD_ATTACHED_EVENT ) { _time_delay (200); inserted = !lwgpio_get_value(&sd_detect); if(!inserted) // mount sd fs ,must attached sd card ! continue; // printf("mount sd card...\n"); // mount_sdcard(); #ifndef USB_ACCESSORY_PLAY /* create player and sd_walker task*/ player_task_id = _task_create(0, PLAYER_TASK, 0); printf("Creating sd player task................"); if (player_task_id == MQX_NULL_TASK_ID) { printf("[FAIL]\n"); } else { printf("[OK]\n"); } sd_walker_id = _task_create(0, SD_WALKER_TASK, 0); printf("Creating sd walker task................"); if (sd_walker_id == MQX_NULL_TASK_ID) { printf("[FAIL]\n"); } else { printf("[OK]\n"); } #else msg.conct_source = mp_for_TF; msg.conct_action = mp_plugIn; /* post message, TFcard plug in*/ if (LWMSGQ_FULL == _lwmsgq_send(connect_taskq, (uint_32 *) &msg, 0)) { printf("Could not inform about TFCard device attached\n"); } //_time_delay (1); // give mode manager task some times to cancel play ,if sd task high than mode task #endif // _lwevent_set(&player_event, PLAYER_EVENT_MSK_SD_FS_MOUNTED); //auto play event last = inserted; } // SD_ATTACHED_EVENT else if (sd_event_value == SD_DETTACHED_EVENT ) { // _time_delay (100); //inserted = !lwgpio_get_value(&sd_detect); //if(inserted) // continue; #ifndef USB_ACCESSORY_PLAY _lwevent_set(&player_event, PLAYER_EVENT_MSK_SD_FS_UNMOUNTED); _lwevent_wait_ticks(&player_event, PLAYER_EVENT_MSK_PLAYER_TASK_KILLED, TRUE, 0); _lwevent_clear(&player_event, PLAYER_EVENT_MSK_PLAYER_TASK_KILLED); /* And the destroy play_task and sd_walker task */ _task_destroy(sd_walker_id); _task_destroy(player_task_id); #else /* post message, TFcard plug out*/ msg.conct_source = mp_for_TF; msg.conct_action = mp_plugOut; /* post message, TFcard plug out*/ if (LWMSGQ_FULL == _lwmsgq_send(connect_taskq, (uint_32 *) &msg, 0)) { printf("Could not inform about TFCard device de-attached\n"); } //_time_delay (1); // give mode manager task some times to cancel play ,if sd task high than mode task #endif // printf("unmount sd card...\n"); // unmount_sdcard(); // printf ("SD card uninstalled.\n"); } } }
uint32_t _kuart_mix_init ( /* [IN] the interrupt I/O initialization information */ IO_SERIAL_INT_DEVICE_STRUCT_PTR int_io_dev_ptr, /* [IN] the rest of the name of the device opened */ char * open_name_ptr ) { /* Body */ KUART_INFO_STRUCT_PTR sci_info_ptr; KUART_INIT_STRUCT_PTR sci_init_ptr; uint32_t result = MQX_OK; //Init basic uart setting sci_init_ptr = int_io_dev_ptr->DEV_INIT_DATA_PTR; result = _kuart_polled_init((void *)sci_init_ptr, &int_io_dev_ptr->DEV_INFO_PTR, open_name_ptr); if (result != MQX_OK) { return(result); }/* Endif */ sci_info_ptr = int_io_dev_ptr->DEV_INFO_PTR; sci_info_ptr->RX_KEEP = 1; /* Add a timer config to check the UART RX state */ sci_info_ptr->LW_TIMER_PTR = (LWTIMER_PERIOD_STRUCT_PTR)_mem_alloc_system_zero(sizeof(LWTIMER_PERIOD_STRUCT) + sizeof(LWTIMER_STRUCT)); if (!sci_info_ptr->LW_TIMER_PTR) { result = MQX_OUT_OF_MEMORY; goto error_free_timer; } sci_info_ptr->LW_TIMER = (LWTIMER_STRUCT_PTR)((uint8_t *)sci_info_ptr->LW_TIMER_PTR + sizeof(LWTIMER_PERIOD_STRUCT)); _time_init_ticks(&sci_info_ptr->ticks, 1); _lwtimer_create_periodic_queue(sci_info_ptr->LW_TIMER_PTR ,*(uint32_t *)(&sci_info_ptr->ticks), 0); _lwtimer_add_timer_to_queue( sci_info_ptr->LW_TIMER_PTR, sci_info_ptr->LW_TIMER, 0, _kuart_period_isr, (void *)int_io_dev_ptr); /* RX DMA setting */ sci_info_ptr->RX_BUF = _mem_alloc_system_zero_uncached(sci_init_ptr->IQUEUE_SIZE); sci_info_ptr->RX_ACTIVE = sci_info_ptr->RX_BUF; if (!sci_info_ptr->RX_BUF) { result = MQX_OUT_OF_MEMORY; goto error_free_buf; } sci_info_ptr->RX_DMA_CHAN = sci_init_ptr->RX_DMA_CHANNEL; sci_info_ptr->RX_DMA_HARDWARE_REQUEST = _bsp_get_serial_rx_dma_request(sci_init_ptr->DEVICE); #if PSP_MQX_CPU_IS_KINETIS sci_info_ptr->ERR_INT = _bsp_get_serial_error_int_num(sci_init_ptr->DEVICE); #endif sci_info_ptr->RX_DMA_SEQ = 0; result = dma_channel_claim(&sci_info_ptr->RX_DCH, sci_info_ptr->RX_DMA_CHAN); if (result != MQX_OK) { goto error_free_channel; } result = dma_callback_reg(sci_info_ptr->RX_DCH, _kuart_dma_rx_isr, int_io_dev_ptr); dma_channel_setup(sci_info_ptr->RX_DCH, 1, DMA_CHANNEL_FLAG_LOOP_MODE); dma_request_source(sci_info_ptr->RX_DCH, sci_info_ptr->RX_DMA_HARDWARE_REQUEST); if (result != MQX_OK) { goto error_free_channel; } /* Init RX/TX interrupt vector */ sci_info_ptr->OLD_ISR_TXRX_DATA = _int_get_isr_data(sci_init_ptr->RX_TX_VECTOR); sci_info_ptr->OLD_ISR_EXCEPTION_HANDLER = _int_get_exception_handler(sci_init_ptr->RX_TX_VECTOR); sci_info_ptr->OLD_ISR_TXRX = _int_install_isr(sci_init_ptr->RX_TX_VECTOR, _kuart_mix_int_tx_isr, int_io_dev_ptr); _bsp_int_init(sci_init_ptr->RX_TX_VECTOR, sci_init_ptr->RX_TX_PRIORITY, 0, TRUE); /* Init mix error vector */ sci_info_ptr->OLD_ISR_ERR = _int_install_isr(sci_info_ptr->ERR_INT, _kuart_mix_err_isr, int_io_dev_ptr); _bsp_int_init(sci_info_ptr->ERR_INT, sci_init_ptr->ERR_PRIORITY, 0, TRUE); /* config the UART RX channel first */ _kuart_prepare_rx_dma(int_io_dev_ptr); return(MQX_OK); error_free_timer: if (!sci_info_ptr->LW_TIMER_PTR) _mem_free(sci_info_ptr->LW_TIMER_PTR); error_free_channel: dma_channel_release(sci_info_ptr->RX_DCH); error_free_buf: if (sci_info_ptr->RX_BUF) _mem_free(sci_info_ptr->RX_BUF); return result; } /* Endbody */
/*! * \cond DOXYGEN_PRIVATE * * \brief This function initializes caller allocated structure according to given * numerical identifier of the timer. * * Called by hwtimer_init(). * Initializes the HWTIMER structure. * Sets interrupt priority and registers ISR. * * \param hwtimer[in] Returns initialized hwtimer structure handle. * \param pit_id[in] Determines PIT modul and pit channel. * \param isr_prior[in] Interrupt priority for PIT * * \return MQX_OK Success. * \return MQX_INVALID_PARAMETER When channel number does not exist in pit module. * \return MQX_INVALID_COMPONENT_HANDLE Doesnt have any interrupt vectors, or pit does not exist. * \return -1 When pit is used byt PE or when _int_install_isr faild. * * \see hwtimer_pit_deinit * \see hwtimer_pit_set_div * \see hwtimer_pit_start * \see hwtimer_pit_stop * \see hwtimer_pit_get_time * \see hwtimer_pit_isr * \see hwtimer_pit_isr_shared */ static _mqx_int hwtimer_pit_init(HWTIMER_PTR hwtimer, uint32_t pit_id, uint32_t isr_prior) { HWTIMER_PTR * pit_hwtimers_array = NULL; uint32_t pit_hwtimers_array_size; PSP_INTERRUPT_TABLE_INDEX vector; PIT_MemMapPtr pit_base; uint32_t pit_number; uint32_t pit_channel; uint32_t pit_channels_count; uint32_t pit_vectors_count; _mqx_uint i; const _mqx_uint *pit_vectors = NULL; PIT_MemMapPtr pit; /* Count of chanels is computed, because this information missing in generated iomap file */ pit_channels_count = sizeof(pit->CHANNEL) / sizeof(pit->CHANNEL[0]); #if MQX_CHECK_ERRORS if (pit_channels_count <= pit_id) { return MQX_INVALID_PARAMETER; } #endif /* We need to store pit_id of timer in context struct */ hwtimer->ll_context[0] = (uint32_t)PIT_BASE_PTR; hwtimer->ll_context[1] = pit_id; pit_base = (PIT_MemMapPtr) hwtimer->ll_context[0]; pit_channel = GET_PIT_CHANNEL_FROM_PITID(hwtimer->ll_context[1]); pit_number = GET_PIT_NUMBER_FROM_PITID(hwtimer->ll_context[1]); #if PE_LDD_VERSION if (PE_PeripheralUsed((uint32_t)pit_base)) { return -1; } #endif /* Enable PIT Module Clock */ pit_io_init(0); /* workaround, add delay to pit clk gating and pit module enabling */ for (i = 0; i <= 50; i++) { ; } /* Enable PIT module */ PIT_MCR_REG(pit_base) = 0; #if BSPCFG_HWTIMER_PIT_FREEZE /* Allows the timers to be stopped when the device enters the Debug mode. */ PIT_MCR_REG(pit_base) |= PIT_MCR_FRZ_MASK; #endif /* Disable timer and interrupt */ PIT_TCTRL_REG(pit_base, pit_channel) = 0; /* Clear any pending interrupt */ PIT_TFLG_REG(pit_base, pit_channel) = PIT_TFLG_TIF_MASK; /* Set isr for timer*/ pit_vectors_count = pit_get_vectors(pit_number, &pit_vectors); #if MQX_CHECK_ERRORS if ((NULL == pit_vectors) || (0 == pit_vectors_count)) { return MQX_INVALID_COMPONENT_HANDLE; //doesnt have any interrupt vectors, or pit does not exist } #endif if (pit_channels_count <= pit_vectors_count) { /* Every channel has own interrupt vector */ vector = (PSP_INTERRUPT_TABLE_INDEX) (pit_vectors[pit_channel]); if (NULL == _int_install_isr(vector, (INT_ISR_FPTR) hwtimer_pit_isr, (void *) hwtimer)) { return -1; } _bsp_int_init(vector, isr_prior, 0, TRUE); } else { pit_hwtimers_array_size = pit_get_hwtimers_array(&pit_hwtimers_array); #if MQX_CHECK_ERRORS if ((NULL == pit_hwtimers_array) || (0 == pit_hwtimers_array_size)) { return MQX_INVALID_COMPONENT_HANDLE; } #endif /* Pit has shared interrupt vectors */ pit_hwtimers_array[pit_channel] = hwtimer; for (i = 0; i < pit_vectors_count; i++) { vector = (PSP_INTERRUPT_TABLE_INDEX) (pit_vectors[i]); if (NULL == _int_install_isr(vector, (INT_ISR_FPTR) hwtimer_pit_isr_shared, NULL)) { return -1; } _bsp_int_init(vector, isr_prior, 0, TRUE); } } return MQX_OK; }
boolean SEC_InitializeIO(void) { /* Init Gpio for Leds as output to drive LEDs (LED10 - LED13) */ #ifdef LED_1 output_port = lwgpio_init(&led1, LED_1, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if(!output_port){ printf("Initializing LWGPIO for LED1 failed.\n"); } lwgpio_set_functionality(&led1, BSP_LED1_MUX_GPIO); /*Turn off Led */ lwgpio_set_value(&led1, LWGPIO_VALUE_LOW); #endif #ifdef LED_2 output_port = lwgpio_init(&led2, LED_2, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if(!output_port){ printf("Initializing LWGPIO for LED2 failed.\n"); } lwgpio_set_functionality(&led2, BSP_LED2_MUX_GPIO); /*Turn off Led */ lwgpio_set_value(&led2, LWGPIO_VALUE_LOW); #endif #ifdef LED_3 output_port = lwgpio_init(&led3, LED_3, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if(!output_port){ printf("Initializing LWGPIO for LED3 failed.\n"); } lwgpio_set_functionality(&led3, BSP_LED3_MUX_GPIO); /*Turn off Led */ lwgpio_set_value(&led3, LWGPIO_VALUE_LOW); #endif #ifdef LED_4 output_port = lwgpio_init(&led4, LED_4, LWGPIO_DIR_OUTPUT, LWGPIO_VALUE_NOCHANGE); if(!output_port){ printf("Initializing LWGPIO for LED3 failed.\n"); } lwgpio_set_functionality(&led4, BSP_LED4_MUX_GPIO); /*Turn off Led */ lwgpio_set_value(&led4, LWGPIO_VALUE_LOW); #endif #ifdef BSP_BUTTON1 /* Open and set port DD as input to read value from switches */ input_port = lwgpio_init(&button1, DOOR_STATE, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if(!input_port) { printf("Initializing LW GPIO for button1 as input failed.\n"); _task_block(); } #if (defined BSP_BUTTON1_MUX_IRQ && defined SECEMAIL_TWRMCF51CN_STOP_ENABLED) lwgpio_set_functionality(&button1 ,BSP_BUTTON1_MUX_IRQ); lwgpio_set_attribute(&button1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); if (!lwgpio_int_init(&button1, LWGPIO_INT_MODE_RISING)) { printf("Initializing button GPIO for interrupt failed.\n"); } #else lwgpio_set_functionality(&button1 ,BSP_BUTTON1_MUX_GPIO); lwgpio_set_attribute(&button1, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* install gpio interrupt service routine */ _int_install_isr(lwgpio_int_get_vector(&button1), kbi_callback, (void *) &button1); _bsp_int_init(lwgpio_int_get_vector(&button1), 3, 0, TRUE); lwgpio_int_enable(&button1, TRUE); #endif #ifdef BSP_BUTTON2 input_port = lwgpio_init(&button2, WINDOW_STATE, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); if(!input_port) { printf("Initializing LW GPIO for button2 as input failed.\n"); _task_block(); } #if (defined BSP_BUTTON2_MUX_IRQ && defined SECEMAIL_TWRMCF51CN_STOP_ENABLED) lwgpio_set_functionality(&button2 ,BSP_BUTTON2_MUX_IRQ); lwgpio_set_attribute(&button2, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); if (!lwgpio_int_init(&button2, LWGPIO_INT_MODE_FALLING)) { printf("Initializing button GPIO for interrupt failed.\n"); } #else lwgpio_set_functionality(&button2 ,BSP_BUTTON2_MUX_GPIO); lwgpio_set_attribute(&button2, LWGPIO_ATTR_PULL_UP, LWGPIO_AVAL_ENABLE); #endif /* install gpio interrupt service routine */ _int_install_isr(lwgpio_int_get_vector(&button2), kbi_callback, (void *) &button2); _bsp_int_init(lwgpio_int_get_vector(&button2), 3, 0, TRUE); lwgpio_int_enable(&button2, TRUE); #endif return (input_port!=0) && (output_port!=0); }
/*FUNCTION**************************************************************** * * Function Name : _io_spi_install * Returned Value : MQX error code * Comments : * Installs SPI device. * *END**********************************************************************/ _mqx_int _io_spi_install ( /* [IN] A string that identifies the device for fopen */ char *identifier, /* [IN] Pointer to driver initialization data */ SPI_INIT_STRUCT_CPTR init_data_ptr ) { SPI_DRIVER_DATA_STRUCT_PTR driver_data; _mqx_int error_code = MQX_OK; if ((init_data_ptr->DEVIF->SETPARAM == NULL) || (init_data_ptr->DEVIF->TX_RX == NULL)) { /* Missing mandatory low level driver function */ return IO_ERROR_DEVICE_INVALID; } driver_data = (SPI_DRIVER_DATA_STRUCT_PTR)_mem_alloc_system_zero((_mem_size)sizeof(SPI_DRIVER_DATA_STRUCT)); if (driver_data == NULL) { return MQX_OUT_OF_MEMORY; } _mem_set_type(driver_data, MEM_TYPE_IO_SPI_POLLED_DEVICE_STRUCT); driver_data->CS_CALLBACK = init_data_ptr->CS_CALLBACK; driver_data->CS_USERDATA= init_data_ptr->CS_USERDATA; driver_data->PARAMS = init_data_ptr->PARAMS; driver_data->DEVIF = init_data_ptr->DEVIF; /* initialize low level driver */ if (driver_data->DEVIF->INIT) error_code = driver_data->DEVIF->INIT(init_data_ptr->DEVIF_INIT, &(driver_data->DEVIF_DATA)); if (error_code != MQX_OK) { _mem_free(driver_data); return error_code; } _lwsem_create(&driver_data->BUS_LOCK, 1); /********************************************/ /*special for em9301 IRQ*/ _lwsem_create(&driver_data->IRQ_SEM, 0); lwgpio_init(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_PIN, LWGPIO_DIR_INPUT, LWGPIO_VALUE_NOCHANGE); lwgpio_set_functionality(&driver_data->SPI_IRQ_PIN, BSP_EM9301_IRQ_MUX_IRQ); lwgpio_set_attribute(&driver_data->SPI_IRQ_PIN, LWGPIO_ATTR_PULL_DOWN, LWGPIO_AVAL_ENABLE); lwgpio_int_init(&driver_data->SPI_IRQ_PIN, LWGPIO_INT_MODE_RISING); _int_install_isr(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), _dspi_em9301_isr, driver_data); _bsp_int_init(lwgpio_int_get_vector(&driver_data->SPI_IRQ_PIN), BSP_DSPI_INT_LEVEL, 0, TRUE); lwgpio_int_enable(&driver_data->SPI_IRQ_PIN, TRUE); /********************************************/ error_code = _io_dev_install_ext(identifier, _io_spi_open, _io_spi_close, _io_spi_read, _io_spi_write, _io_spi_ioctl, _io_spi_uninstall, (void *)driver_data); if (error_code) { /* deinitialize low level driver */ if (driver_data->DEVIF->DEINIT) driver_data->DEVIF->DEINIT(driver_data->DEVIF_DATA); _lwsem_destroy(&driver_data->BUS_LOCK); _mem_free(driver_data); return error_code; } return MQX_OK; }