Exemplo n.º 1
0
void vApplicationTickHook( void )
{
    /* This function will be called by each tick interrupt if
    configUSE_TICK_HOOK is set to 1 in FreeRTOSConfig.h.  User code can be
    added here, but the tick hook is called from an interrupt context, so
    code must not attempt to block, and only the interrupt safe FreeRTOS API
    functions can be used (those that end in FromISR()).  The code in this
    tick hook implementation is for demonstration only - it has no real
    purpose.  It just gives a semaphore every 50ms.  The semaphore unblocks a
    task that then toggles an LED.  Additionally, the call to
    vQueueSetAccessQueueSetFromISR() is part of the "standard demo tasks"
    functionality. */

    /* The semaphore and associated task are not created when the simple blinky
    demo is used. */
#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0
    {
        static unsigned long ulLastGiveTime = 0UL;
        const unsigned long ulRate = 50UL / portTICK_PERIOD_MS;
        extern SemaphoreHandle_t xLEDSemaphore;

        configASSERT( xLEDSemaphore );

        if( ( xTaskGetTickCountFromISR() - ulLastGiveTime ) > ulRate ) {
            /* The second parameter is normally used to determine if a context
            switch should be performed or not.  In this case the function is
            being performed from the tick hook, so the scheduler will make that
            assessment before returning to a task anyway - so the parameter is
            not needed and is just set to NULL. */
            xSemaphoreGiveFromISR( xLEDSemaphore, NULL );
            ulLastGiveTime += ulRate;
        }

        /* Write to a queue that is in use as part of the queue set demo to
        demonstrate using queue sets from an ISR. */
        vQueueSetAccessQueueSetFromISR();
    }
#endif /* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY */
}
Exemplo n.º 2
0
// generic interrupt handler called for all interrupt
void gpio_interrupt_handler() {
    uint32 status_reg = GPIO.STATUS;
    GPIO.STATUS_CLEAR = status_reg;
    uint8_t pin;
    while ((pin = __builtin_ffs(status_reg))) {
        pin--;
        status_reg &= ~BIT(pin);
        if (FIELD2VAL(GPIO_CONF_INTTYPE, GPIO.CONF[pin])) {
            uint32 ms = xTaskGetTickCountFromISR() * portTICK_RATE_MS;
            // debounce check (from button.c example code)
            //printf(" [interrupt %d] ", pin); fflush(stdout);
            if (button_last[pin] < ms - 200) {
                //printf(" [button %d pressed at %dms\r\n", pin, ms);
                button_last[pin] = ms;
                button_clicked[pin]++;
                button_count[pin]++;
            } else {
                //printf(" [BOUNCE! %d at %dms]\r\n", pin, ms);
            }
        }
    }
}
Exemplo n.º 3
0
/*************************************************************************
*                               uart releated  fuantions                          *
*************************************************************************/
static void uart_irq(uint32_t id, SerialIrq event)
{
	uart_socket_t *u = (uart_socket_t *)id;

	if(event == RxIrq) {
		if( u->rx_start == 0 ){
			RtlUpSemaFromISR(&u->action_sema);	//up action semaphore 
			u->rx_start = 1; // set this flag in uart_irq to indicate data recved
		}
		u->recv_buf[u->prxwrite++] = serial_getc(&u->sobj);
		if(u->prxwrite > (UART_RECV_BUFFER_LEN -1)){	//restart from  head if  reach tail
			u->prxwrite = 0;
			u->rxoverlap = 1;							//set overlap indicated that overlaped 
		}
		if(u->rxoverlap && (u->prxwrite + 1) > u->prxread ){
			u->prxread = u->prxwrite;		//if pwrite overhead pread ,pread is always flow rwrite 
		}
		u->last_update =  xTaskGetTickCountFromISR();	// update tick everytime recved data
	}

	if(event == TxIrq){
	}
}
Exemplo n.º 4
0
static void uartadapter_uart_irq(uint32_t id, SerialIrq event)
{
	portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;

	if(event == RxIrq) {		
		ua_rcv_ch = serial_getc(&ua_sobj);
		ua_uart_recv_buf[ua_pwrite] = ua_rcv_ch;
		ua_pwrite++;	//point to uart data recved
		xSemaphoreGiveFromISR( ua_uart_action_sema, &xHigherPriorityTaskWoken );	//up action semaphore 					
		
		if(ua_pwrite > (UA_UART_RECV_BUFFER_LEN -1)){	//restart from  head if  reach tail
			ua_pwrite = 0;
			ua_overlap = 1;		
		}
		
		if(ua_overlap && (ua_pwrite - 1) >= ua_pread ){
 		       //ua_printf(UA_ERROR, "IRQ missing data %d byte!", ua_pread - ua_pwrite + 1);
 		       irq_miss_cnt ++;
			ua_pread = ua_pwrite;		//if pwrite overhead pread ,pread is always flow rwrite 					
		}
		ua_tick_last_update =  xTaskGetTickCountFromISR();	// update tick everytime recved data
		irq_rx_cnt ++;
	}
}
Exemplo n.º 5
0
void EXTI15_10_IRQHandler(void) {
  // TODO(rqou): How to share this vector (or if it is even necessary)

  portTickType time_now = xTaskGetTickCountFromISR();

  if (EXTI->PR & (1 << GPIO_PIN(PINDEF_BUTTON0))) {
    // Clear pending
    EXTI->PR = (1 << GPIO_PIN(PINDEF_BUTTON0));
    // Invert is necessary because pin idles at 1
    int newState =
      !(GPIO_BANK(PINDEF_BUTTON0)->IDR & (1 << GPIO_PIN(PINDEF_BUTTON0)));

    if (time_now - button0_last_toggle >= DEBOUNCE_DELAY) {
      button0_state = newState;
    }

    button0_last_toggle = time_now;
    button0_actual_state = newState;
  }

  if (EXTI->PR & (1 << GPIO_PIN(PINDEF_BUTTON1))) {
    // Clear pending
    EXTI->PR = (1 << GPIO_PIN(PINDEF_BUTTON1));
    // Invert is necessary because pin idles at 1
    int newState =
      !(GPIO_BANK(PINDEF_BUTTON1)->IDR & (1 << GPIO_PIN(PINDEF_BUTTON1)));

    if (time_now - button1_last_toggle >= DEBOUNCE_DELAY) {
      // Invert is necessary because pin idles at 1
      button1_state = newState;
    }

    button1_last_toggle = time_now;
    button1_actual_state = newState;
  }
}
Exemplo n.º 6
0
void odp_canraw_recvdata(data_packet * p, UBaseType_t callFromISR)
{
    extern print_cbf printdata_CAN;
    extern printChar_cbf printChar;
    extern protocolConfigPtr actProtConfigPtr;
    struct CanRawConfig *protocolConfig;
    short ByteCnt;

    if (callFromISR)
	xTickNew = (uint16_t) xTaskGetTickCountFromISR();
    else
	xTickNew = (uint16_t) xTaskGetTickCount();

    if (xTickNew < xTickOld)	// check for xTick overflow
	xTickOld = 0;

    if (xTickCurrent >= 59999)	// limit timestamp to 0-59999 tick (ms)
	xTickCurrent = 0;

    xTickCurrent = xTickCurrent + (xTickNew - xTickOld);
    xTickOld = xTickNew;	// set latest value to xTickOld for next duration
    p->timestamp = xTickCurrent;

    protocolConfig = actProtConfigPtr;
    if (protocolConfig != NULL) {
	if (protocolConfig->showBusTransfer == 1) {	//normal output
	    MsgData *msg;
	    extern QueueHandle_t protocolQueue;
	    if (NULL != (msg = createDataMsg(p))) {
		UBaseType_t res = 0;
		if (callFromISR) {
		    res = sendMsgFromISR(MSG_BUS_RECV, protocolQueue, msg);
		} else {
		    res = sendMsg(MSG_BUS_RECV, protocolQueue, msg);
		}
		if (res != pdPASS) {
		    disposeMsg(msg);
		    DEBUGPRINT("FATAL ERROR: protocol queue is full!\n",
			       'a');
		}
	    } else {
		DEBUGPRINT("FATAL ERROR: Out of Heap space!l\n", 'a');
	    }
	}
	if (protocolConfig->showBusTransfer == 2) {	//normal output, but straight from the ISR
	    printdata_CAN(MSG_BUS_RECV, p, printChar);
	}
	if (protocolConfig->showBusTransfer == 3) {
	    // Lawicel format: Estimated out of http://lxr.free-electrons.com/source/drivers/net/can/slcan.c line 110 cc.
	    if (p->recv & 0x80000000) {	// Bit 32 set, so it's an extended CAN ID
		printser_string("T");
		printser_uint32ToHex(p->recv & 0x1FFFFFFF);
	    } else {
		printser_string("t");
		printser_int((p->recv & 0x700) >> 8, 10);
		printser_uint8ToHex(p->recv & 0x00FF);
	    }
	    printser_int(p->len, 10);
	    ByteCnt = 0;
	    while (ByteCnt != p->len) {
		printser_uint8ToHex(p->data[ByteCnt]);
		ByteCnt++;
	    }
	    if (p->err == 0x01)
		printser_string("FFFF");	// if error occurs set timestamp to 0xFFFF
	    else
		printser_uint16ToHex(p->timestamp * portTICK_PERIOD_MS & 0xFFFF);	//reduce down to 16 bit = 65536 ms = ~ 1 min
	    printLF();
	}
	if (protocolConfig->showBusTransfer == 4) {
	    printser_uint8ToRaw(255);	//startbyte
	    printser_uint8ToRaw((p->len & 0xF) |	// bit 0-3: DLC
				((p->err & 3) << 4) |	//bit 4-5 : Error flag
				(((p->recv & 0x80000000) ? 1 : 0) << 5)	//bit 6: Extended CAN ID
		);		//Status flag
	    printser_uint16ToRawCoded(p->timestamp * portTICK_PERIOD_MS & 0xFFFF);	//reduce down to 16 bit = 65536 ms = ~ 1 min
	    if ((p->recv & 0x80000000)) {	// Bit 32 set, so it's an exended CAN ID
		printser_uint32ToRawCoded(p->recv & 0x1FFFFFFF);
	    } else {
		printser_uint16ToRawCoded(p->recv & 0x1FFFFFFF);
	    }
	    int i;

	    for (i = 0; i < p->len; i++) {
		printser_uint8ToRawCoded(p->data[i]);
	    }
	}
    }
}
Exemplo n.º 7
0
void UartDev::handleInterrupt()
{
    /**
     * Bit Masks of IIR register Bits 3:1 that contain interrupt reason.
     * Bits are shifted left because reasonForInterrupt contains Bits 3:0
     */
    const uint16_t transmitterEmpty = (1 << 1);
    const uint16_t dataAvailable    = (2 << 1);
    const uint16_t dataTimeout      = (6 << 1);

    long higherPriorityTaskWoken = 0;
    long switchRequired = 0;
    char c = 0;
    unsigned charsSent = 0;

    uint16_t reasonForInterrupt = (mpUARTRegBase->IIR & 0xE);
    {
        /**
         * If multiple sources of interrupt arise, let this interrupt exit, and re-enter
         * for the new source of interrupt.
         */
        switch (reasonForInterrupt)
        {
            case transmitterEmpty:
            {
                if(uxQueueMessagesWaitingFromISR(mTxQueue) > mTxQWatermark) {
                    mTxQWatermark = uxQueueMessagesWaitingFromISR(mTxQueue);
                }

                /**
                 * When THRE (Transmit Holding Register Empty) interrupt occurs,
                 * we can send as many bytes as the hardware FIFO supports (16)
                 */
                const unsigned char hwTxFifoSize = 16;
                for(charsSent=0;
                        charsSent < hwTxFifoSize && xQueueReceiveFromISR(mTxQueue, &c, &higherPriorityTaskWoken);
                        charsSent++)
                {
                    mpUARTRegBase->THR = c;
                    if(higherPriorityTaskWoken) {
                        switchRequired = 1;
                    }
                }
            }
            break;

            case dataAvailable:
            case dataTimeout:
            {
                mLastActivityTime = xTaskGetTickCountFromISR();
                /**
                 * While receive Hardware FIFO not empty, keep queuing the data.
                 * Even if xQueueSendFromISR() Fails (Queue is full), we still need to
                 * read RBR register otherwise interrupt will not clear
                 */
                while (0 != (mpUARTRegBase->LSR & (1 << 0)))
                {
                    c = mpUARTRegBase->RBR;
                    xQueueSendFromISR(mRxQueue, &c, &higherPriorityTaskWoken);
                    if(higherPriorityTaskWoken) {
                        switchRequired = 1;
                    }
                }

                if(uxQueueMessagesWaitingFromISR(mRxQueue) > mRxQWatermark) {
                    mRxQWatermark = uxQueueMessagesWaitingFromISR(mRxQueue);
                }
            }
            break;

            default:
                /* Read LSR register to clear Line Status Interrupt */
                reasonForInterrupt = mpUARTRegBase->LSR;
                break;
        }
    }

    portEND_SWITCHING_ISR(switchRequired);
}
Exemplo n.º 8
0
void Usart0RxIsr(u8 data){
  xUsartRxTime = xTaskGetTickCountFromISR();

  if ((rfRxBufWP==0) && (data != 0x7E)){
    rfRxBufWP=0;
  }
  if ((rfRxBufWP==1) && (data != 0x45)){
    rfRxBufWP=0;
  }
  
  if(rfRxBufWP==0) {       //header1
    rfRxBuf[0] = data;
    rfRxBufWP++;
  }
  else if(rfRxBufWP==1) {  //header2
    rfRxBuf[rfRxBufWP] = data;
    rfRxBufWP++;
  }
  else if(rfRxBufWP==2) {  //command
    rfRxBuf[rfRxBufWP] = data;
    rfRxBufWP++;
  }
  else if(rfRxBufWP==3) {  //payload Len
    rfRxBuf[rfRxBufWP] = data;
    rfRxBufWP++;
    if (data>RF_REC_BUF_SIZE-4) {
      rfRxBufWP = 0;
    }
  }
  else if((rfRxBufWP>=4)&&(rfRxBufWP<(rfRxBuf[3]+4))) {  //payload 
    rfRxBuf[rfRxBufWP] = data;
    rfRxBufWP++;
  }
  else if (rfRxBufWP==(rfRxBuf[3]+4)) {  //sum
    rfRxBuf[rfRxBufWP] = data;
    u8 i,sum=0;
    float dis=0;
    for (i=0;i<rfRxBufWP;i++) {
      sum+=rfRxBuf[i];
    } 	
    if (sum==rfRxBuf[rfRxBufWP]) {                   //sum is right!	     
      if (rfRxBuf[2]==RF_DIST_2_BEACON1) {           //dis to B1
        memcpy(&dis, &rfRxBuf[4],4);
        SetDistanse2B1(dis);
      }
      else if (rfRxBuf[2]==RF_DIST_2_BEACON2) {      //dis to B2
        memcpy(&dis, &rfRxBuf[4],4);
        SetDistanse2B2(dis);
		halSetLedStatus(LED_RED, LED_TOGGLE);        //D1 and D2
      }
     else if (rfRxBuf[2]==RF_BROADCAST_INFO) {       //BCAST INFO
        //user add code to decode bcast info
        static rbNode* bInfo;
        bInfo = (rbNode*)(rfRxBuf+4);
        memcpy((u8*)(&bCastInfo[(bInfo->nodeID)-1]), rfRxBuf+4, sizeof(rbNode));
        halSetLedStatus(LED_YELLOW, LED_TOGGLE);  //D3 and D4
        asm ("NOP");
        //user end
      }
    }
    rfRxBufWP =  0;
  }
}
Exemplo n.º 9
0
OS_Tick OS_ISR_TickCountGet(void)
{
    return xTaskGetTickCountFromISR();
}
Exemplo n.º 10
0
unsigned int ulMainGetRunTimeCounterValue(void) {
  return xTaskGetTickCountFromISR();
}
Exemplo n.º 11
0
void GPIO_HANDLER(void)
{
    uint32_t now = xTaskGetTickCountFromISR();
    xQueueSendToBackFromISR(tsqueue, &now, NULL);
}
Exemplo n.º 12
0
	uint32_t FUNC_FLASHMEM millisISR()
	{
		return xTaskGetTickCountFromISR() * portTICK_RATE_MS;
	}