コード例 #1
0
ファイル: lpc_rit.c プロジェクト: kammce/SJSU-DEV-Linux
void rit_enable(void_func_t function, uint32_t time_ms)
{
    if (0 == function) {
        return;
    }
    // Divide by zero guard
    if(0 == time_ms) {
        time_ms = 1;
    }

    // Power up first otherwise writing to RIT will give us Hard Fault
    lpc_pconp(pconp_rit, true);

    // Enable CLK/1 to simplify RICOMPVAL calculation below
    lpc_pclk(pclk_rit, clkdiv_1);

    LPC_RIT->RICTRL = 0;
    LPC_RIT->RICOUNTER = 0;
    LPC_RIT->RIMASK = 0;
    LPC_RIT->RICOMPVAL = sys_get_cpu_clock() / (1000 / time_ms);

    // Clear timer upon match, and enable timer
    const uint32_t isr_clear_bitmask = (1 << 0);
    const uint32_t timer_clear_bitmask = (1 << 1);
    const uint32_t timer_enable_bitmask = (1 << 3);
    LPC_RIT->RICTRL = isr_clear_bitmask | timer_clear_bitmask | timer_enable_bitmask;

    // Enable System Interrupt and connect the callback
    g_rit_callback = function;
    vTraceSetISRProperties(RIT_IRQn, "RIT", IP_RIT);
    NVIC_EnableIRQ(RIT_IRQn);
}
コード例 #2
0
ファイル: Application.c プロジェクト: SISommer/mcuoneclipse
void APP_Init(void) {
  //DbgConsole_Printf("hello world.\r\n");
#if PL_CONFIG_HAS_SHELL_QUEUE
  SQUEUE_Init();
#endif
  semSW2 = xSemaphoreCreateBinary();
  if (semSW2==NULL) { /* semaphore creation failed */
    for(;;){} /* error */
  }
  vQueueAddToRegistry(semSW2, "Sem_SW2");

  semSW3 = xSemaphoreCreateBinary();
  if (semSW3==NULL) { /* semaphore creation failed */
    for(;;){} /* error */
  }
  vQueueAddToRegistry(semSW3, "Sem_SW3");

  semLED = xSemaphoreCreateBinary();
  if (semLED==NULL) { /* semaphore creation failed */
    for(;;){} /* error */
  }
  vQueueAddToRegistry(semLED, "Sem_LED");

  semMouse = xSemaphoreCreateBinary();
  if (semMouse==NULL) { /* semaphore creation failed */
    for(;;){} /* error */
  }
  vQueueAddToRegistry(semMouse, "Sem_Mouse");

  semKbd = xSemaphoreCreateBinary();
  if (semKbd==NULL) { /* semaphore creation failed */
    for(;;){} /* error */
  }
  vQueueAddToRegistry(semKbd, "Sem_Kbd");
#if 0  /*! \todo 1 Increase stack size by 50 */
  if (xTaskCreate(ButtonTask, "Buttons", configMINIMAL_STACK_SIZE+50, NULL, tskIDLE_PRIORITY+2, NULL) != pdPASS) { /*! \todo 1 Increase stack size by 50 */
#else
    if (xTaskCreate(ButtonTask, "Buttons", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+2, NULL) != pdPASS) {
#endif
    for(;;){} /* error */
  }
  if (xTaskCreate(AppTask, "App", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL) != pdPASS) {
    for(;;){} /* error */
  }
#if configUSE_TRACE_HOOKS
  vTraceSetISRProperties("ISR_USB", TRACE_PRIO_ISR_USB);
#endif
}
コード例 #3
0
ファイル: eint.c プロジェクト: kammce/SJSU-DEV-Linux
/**
 * Enables a port pin interrupt by inserting entry to the linked list, and writing to the
 * enable register to enable the interrupt.
 *
 * @param [in] pin_number     0-31
 * @param [in] type           The type of the interrupt (rising or falling)
 * @param [in] func           The callback function.
 * @param [in] list_head_ptr  The pointer of the linked list to add the interrupt configuration to.
 * @param [in] int_en_reg_ptr The pointer of CPU register to enable the interrupt
 */
static void eint3_enable(uint8_t pin_num, eint_intr_t type, void_func_t func,
                         eint3_entry_t **list_head_ptr, volatile uint32_t *int_en_reg_ptr)
{
    const uint32_t pin_mask = (UINT32_C(1) << pin_num);
    eint3_entry_t *e = NULL;

    if (0 != pin_mask && NULL != func && NULL != (e = malloc(sizeof(*e))) )
    {
        /* Insert new entry at the head of the list */
        e->callback = func;
        e->pin_mask = pin_mask;
        e->next = *list_head_ptr;
        *list_head_ptr = e;

        /* Enable the interrupt */
        *int_en_reg_ptr |= e->pin_mask;

        /* EINT3 shares pin interrupts with Port0 and Port2 */
        vTraceSetISRProperties(EINT3_IRQn, "EINT3", IP_eint);
        NVIC_EnableIRQ(EINT3_IRQn);
    }
}
コード例 #4
0
ファイル: can.c プロジェクト: kammce/SJSU-DEV-Linux
bool CAN_init(can_t can, uint32_t baudrate_kbps, uint16_t rxq_size, uint16_t txq_size,
              can_void_func_t bus_off_cb, can_void_func_t data_ovr_cb)
{
    if (!CAN_VALID(can)){
        return false;
    }

    can_struct_t *pStruct = CAN_STRUCT_PTR(can);
    LPC_CAN_TypeDef *pCAN = pStruct->pCanRegs;
    bool failed = true;

    /* Enable CAN Power, and select the PINS
     * CAN1 is at P0.0, P0.1 and P0.21, P0.22
     * CAN2 is at P0.4, P0.5 and P2.7,  P2.8
     * On SJ-One board, we have P0.0, P0.1, and P2.7, P2.8
     */
    if (can1 == can) {
        LPC_SC->PCONP |= can1_pconp_mask;
        LPC_PINCON->PINSEL0 &= ~(0xF << 0);
        LPC_PINCON->PINSEL0 |=  (0x5 << 0);
    }
    else if (can2 == can){
        LPC_SC->PCONP |= can2_pconp_mask;
        LPC_PINCON->PINSEL4 &= ~(0xF << 14);
        LPC_PINCON->PINSEL4 |=  (0x5 << 14);
    }

    /* Create the queues with minimum size of 1 to avoid NULL pointer reference */
    if (!pStruct->rxQ) {
        pStruct->rxQ = xQueueCreate(rxq_size ? rxq_size : 1, sizeof(can_msg_t));
    }
    if (!pStruct->txQ) {
        pStruct->txQ = xQueueCreate(txq_size ? txq_size : 1, sizeof(can_msg_t));
    }

    /* The CAN dividers must all be the same for both CANs
     * Set the dividers of CAN1, CAN2, ACF to CLK / 1
     */
    lpc_pclk(pclk_can1, clkdiv_1);
    lpc_pclk(pclk_can2, clkdiv_1);
    lpc_pclk(pclk_can_flt, clkdiv_1);

    pCAN->MOD = can_mod_reset;
    pCAN->IER = 0x0; // Disable All CAN Interrupts
    pCAN->GSR = 0x0; // Clear error counters
    pCAN->CMR = 0xE; // Abort Tx, release Rx, clear data over-run

    /**
     * About the AFMR register :
     *                      B0              B1
     * Filter Mode |    AccOff bit  |   AccBP bit   |   CAN Rx interrupt
     * Off Mode             1               0           No messages accepted
     * Bypass Mode          X               1           All messages accepted
     * FullCAN              0               0           HW acceptance filtering
     */
    LPC_CANAF->AFMR = afmr_disabled;

    // Clear pending interrupts and the CAN Filter RAM
    LPC_CANAF_RAM->mask[0] = pCAN->ICR;
    memset((void*)&(LPC_CANAF_RAM->mask[0]), 0, sizeof(LPC_CANAF_RAM->mask));

    /* Zero out the filtering registers */
    LPC_CANAF->SFF_sa     = 0;
    LPC_CANAF->SFF_GRP_sa = 0;
    LPC_CANAF->EFF_sa     = 0;
    LPC_CANAF->EFF_GRP_sa = 0;
    LPC_CANAF->ENDofTable = 0;

    /* Do not accept any messages until CAN filtering is enabled */
    LPC_CANAF->AFMR = afmr_disabled;

    /* Set the baud-rate. You can verify the settings by visiting:
     * http://www.kvaser.com/en/support/bit-timing-calculator.html
     */
    do {
        const uint32_t baudDiv = sys_get_cpu_clock() / (1000 * baudrate_kbps);
        const uint32_t SJW = 3;
        const uint32_t SAM = 0;
        uint32_t BRP = 0, TSEG1 = 0, TSEG2 = 0, NT = 0;

        /* Calculate suitable nominal time value
         * NT (nominal time) = (TSEG1 + TSEG2 + 3)
         * NT <= 24
         * TSEG1 >= 2*TSEG2
         */
        failed = true;
        for(NT=24; NT > 0; NT-=2) {
            if ((baudDiv % NT)==0) {
                BRP = baudDiv / NT - 1;
                NT--;
                TSEG2 = (NT/3) - 1;
                TSEG1 = NT -(NT/3) - 1;
                failed = false;
                break;
            }
        }

        if (!failed) {
            pCAN->BTR  = (SAM << 23) | (TSEG2<<20) | (TSEG1<<16) | (SJW<<14) | BRP;
            // CANx->BTR = 0x002B001D; // 48Mhz 100Khz
        }
    } while (0);

    /* If everything okay so far, enable the CAN interrupts */
    if (!failed) {
        /* At minimum, we need Rx/Tx interrupts */
        pCAN->IER = (intr_rx | intr_all_tx);

        /* Enable BUS-off interrupt and callback if given */
        if (bus_off_cb) {
            pStruct->bus_error = bus_off_cb;
            pCAN->IER |= g_can_bus_err_intr;
        }
        /* Enable data-overrun interrupt and callback if given */
        if (data_ovr_cb) {
            pStruct->data_overrun = data_ovr_cb;
            pCAN->IER |= intr_ovrn;
        }

        /* Finally, enable the actual CPU core interrupt */
        vTraceSetISRProperties(CAN_IRQn, "CAN", IP_can);
        NVIC_EnableIRQ(CAN_IRQn);
    }

    /* return true if all is well */
    return (false == failed);
}
コード例 #5
0
ファイル: main.c プロジェクト: notwendig/FreeRTOS-eZ80F91
int main( void )
{
	BaseType_t	res = pdPASS;
	rtc_t	rtc;
	TickType_t xTimeNow;
	/* Seed the random number generator. */
	xTimeNow = 0;//xTaskGetTickCount();
	prvSRand( 0);

#if configUSE_TRACE_FACILITY == 1
	vTraceInitTraceData();
	vTraceSetISRProperties(TIID_EthRx, "i_EthRx", IPRI_EthRx);
	vTraceSetISRProperties(TIID_EthTx, "i_EthTx", IPRI_EthTx);
	vTraceSetISRProperties(TIID_EthSys, "i_EthSys", IPRI_EthSys);
	vTraceSetISRProperties(TIID_Tmr0, "i_Tmr0", IPRI_Tmr0);
	vTraceSetISRProperties(TIID_Tmr1, "i_Tmr1", IPRI_Tmr1);
	vTraceSetISRProperties(TIID_Tmr2, "i_Tmr2", IPRI_Tmr2);
	vTraceSetISRProperties(TIID_rtc, "i_rtc", IPRI_rtc);
	vTraceSetISRProperties(TIID_uart0, "i_uart0", IPRI_uart0);
	vTraceSetISRProperties(TIID_uart1, "i_uart1", IPRI_uart1);
	vTraceSetISRProperties(TIID_button0, "i_swb0", IPRI_button0);
	vTraceSetISRProperties(TIID_button1, "i_swb1", IPRI_button1);
	vTraceSetISRProperties(TIID_button2, "i_swb2", IPRI_button2);
	// uiTraceStart(); 
	// vTraceStop()
#endif
		
#if INCLUDE_CONSOLE == 1 || INCLUDE_MODEM == 1  		// Include serial port 0 or serial port 1
	initSerial();
#endif

#if INCLUDE_RTC	== 1		// Include Realtime Clock
	initRTC();
#endif

#if INCLUDE_BUTTONS == 1
	initButtons();
#endif

#if INCLUDE_NETWORK
	/* Initialise the RTOS's TCP/IP stack.  The tasks that use the network
    are created in the vApplicationIPNetworkEventHook() hook function
    below.  The hook function is called when the network connects. */
	res = FreeRTOS_IPInit( ucIPAddress, ucNetMask, ucGatewayAddress, ucDNSServerAddress, ucMACAddress );
    //vRegisterSampleCLICommands();
	vRegisterTCPCLICommands();
	vRegisterMonitorCLICommands();
	
	// Commandline interface (Telnet port 5010)
	vStartTCPCommandInterpreterTask( 2048, 5010, tskIDLE_PRIORITY + 1);
#endif 

#ifdef INCLUDE_MONITOR
	// Demo Sysinfo 
	// Connect putty 115200,8,1,n (ansi terminal) to get the status informations
	res = xTaskCreate( sysinfo, "SysInfo", configMINIMAL_STACK_SIZE*2, (void *)portMAX_DELAY, PRIO_SYSINFO, NULL);
#endif


#if INCLUDE_LED5x7	== 1
	initLED5x7();
	res = xTaskCreate( TaskLED, "TaskLED", configMINIMAL_STACK_SIZE, (void *)portMAX_DELAY, PRIO_LED, NULL);
#endif

#ifdef CPM22 
	memset(cpmmem,0,sizeof(cpmmem));
	res = xTaskCreate( prvTCPCpmIOTask, "CPMIO", configMINIMAL_STACK_SIZE*2, (void*)cpmmem, PRIO_CPMIO, NULL);
#endif

	vTaskStartScheduler();

    return res;
}