Esempio n. 1
0
int main(int argc, char** argv) {
    PT_setup();
    
	// Enable multivector interrupts
    INTEnableSystemMultiVectoredInt();
	// Initialize threads
    PT_INIT(&pt_cap);
    
    
    PT_INIT(&pt_blink);
    PT_INIT(&pt_cap_read)
    
    //init the display
    tft_init_hw();
    tft_begin();
    tft_fillScreen(ILI9340_BLACK);
    
	// Set orientation of the display
    tft_setRotation(1);
	
	// Set up pins
    PerPinSetup();
    while(1){
        PT_SCHEDULE(protothread_blink(&pt_blink));
        PT_SCHEDULE(protothread_cap(&pt_cap));
        PT_SCHEDULE(protothread_cap_read(&pt_cap_read));
    }
  
}
Esempio n. 2
0
File: basic.c Progetto: nnayo/scalp
void BSC_run(void)
{
	// incoming frames handling
	(void)PT_SCHEDULE(BSC_in(&BSC.in_pt));

	// reponse frames handling
	(void)PT_SCHEDULE(BSC_out(&BSC.out_pt));

	// if all frames are handled
	if ( !BSC.is_running && ( FIFO_full(&BSC.out_fifo) == 0 ) && ( FIFO_full(&BSC.in_fifo) == 0 ) ) {
		// unlock the dispatcher
		DPT_unlock(&BSC.interf);
	}
}
Esempio n. 3
0
void schedule(){
	int i, running;
	struct task *t;

#ifdef TRACE  
	feed_wdt();
#endif
		
	for (i=0; i<num_tasks;){

#ifdef TRACE
		cur_task = 99;
#endif  
	
		handle_events();

#ifdef TRACE
		cur_task = i;
#endif
		
		t=&(task_list[i]);
		/* Run the next thread with its own thread structure as argument */
		if (t->state == RUN) {
			running = PT_SCHEDULE( t->thread(&(t->thread_pt)) );
			i++;
		} else {
			task_del(i);
			// do not increment i, we probably have a new task at this index
		}
  	};
};
Esempio n. 4
0
/*---------------------------------------------------------------------------*/
static int
input_pt(struct http_socket *s,
         const uint8_t *inputptr, int inputdatalen)
{
  int i;
  PT_BEGIN(&s->pt);

  /* Parse the header */
  s->header_received = 0;
  do {
    for(i = 0; i < inputdatalen; i++) {
      if(!PT_SCHEDULE(parse_header_byte(s, inputptr[i]))) {
        s->header_received = 1;
        break;
      }
    }
    inputdatalen -= i;
    inputptr += i;

    if(s->header_received == 0) {
      /* If we have not yet received the full header, we wait for the
         next packet to arrive. */
      PT_YIELD(&s->pt);
    }
  } while(s->header_received == 0);

  do {
    /* Receive the data */
    call_callback(s, HTTP_SOCKET_DATA, inputptr, inputdatalen);
    PT_YIELD(&s->pt);
  } while(inputdatalen > 0);

  PT_END(&s->pt);
}
Esempio n. 5
0
//===================== Main ======================= //
void main(void) {
    SYSTEMConfig( SYS_FREQ,  SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE);

    ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0;

    PT_setup();
    INTEnableSystemMultiVectoredInt();

    
    // initialize the threads
    PT_INIT(&pt_blink);
    PT_INIT(&pt_capture);
    
    // initialize the display
    tft_init_hw();
    tft_begin();
    tft_fillScreen(ILI9340_BLACK);

    tft_setRotation(0); //240x320 vertical display

    // initialize the comparator
    CMP1Open(CMP_ENABLE | CMP_OUTPUT_ENABLE | CMP1_NEG_INPUT_IVREF);
    
    // initialize the timer2
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_64, 0xffffffff);

    // initialize the input capture, uses timer2
    OpenCapture1( IC_EVERY_RISE_EDGE | IC_FEDGE_RISE | IC_INT_1CAPTURE | IC_TIMER2_SRC | IC_ON);
    ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_3 | IC_INT_SUB_PRIOR_3 );
    INTClearFlag(INT_IC1);

    // initialize the input/output I/O
    mPORTBSetPinsDigitalOut(BIT_3);
    mPORTBClearBits(BIT_3);
    PPSOutput(4, RPB9, C1OUT);		//set up output of comparator for debugging
    PPSInput(3, IC1, RPB13);		//Either Pin 6 or Pin 24 idk
   
    //round-robin scheduler for threads
    while(1) {
	PT_SCHEDULE(protothread_blink(&pt_blink));
	PT_SCHEDULE(protothread_capture(&pt_capture));
    }
    
} //main
Esempio n. 6
0
void
	exo_loop_start()
{
	struct pt driver_pt;

	PT_INIT(&driver_pt);

	while(PT_SCHEDULE(driver_thread(&driver_pt)))
	{
	}
}
Esempio n. 7
0
int main(void)
{

  // === config the uart, DMA, SPI ===========
  PT_setup();

  // == SPI ==
  //enable SPI at 10 MHz clock to meet digital potentiometer specifications
  SpiChnOpen(spiChn, SPI_OPEN_ON | SPI_OPEN_MODE16 | SPI_OPEN_MSTEN | SPI_OPEN_CKE_REV , spiClkDiv);
  
  // === setup system wide interrupts  ====================
  INTEnableSystemMultiVectoredInt();
    
  // === set up i/o port pin ===============================
  //Port B bits, 3,7,8, and 9 are used to select digital output
  //Port B bit 4 is used as chip select for treble digital potentiometer
  //Port B bit 13 is used as a select signal for output effect selection multiplexer
  //Additional functionality would use the TFT to display which output was being
  //selected
  mPORTBSetPinsDigitalOut(BIT_4 | BIT_3|BIT_7 | BIT_8 | BIT_9 |BIT_13);    //Set port as output
 
  //Port A Bits 0,2,and 3 are used to configure digital potentiometers (chip selects). Port A bit 4 is used
  //for multiplexing whether to have input from Digital effector chip, distortion,
  //or pure tonestack sound
  mPORTASetPinsDigitalOut(BIT_0 | BIT_2 | BIT_3 | BIT_4);
  // === now the threads ===================================
  
  // init the threads
  PT_INIT(&pt_cmd);
  PT_INIT(&pt_time);
  
  //==Digipot spi stuff
   // SCK2 is pin 26 
    // SDO1 (MOSI) is in PPS output group 1, could be connected to RB5 which is pin 14
    PPSOutput(2, RPB5, SDO1);
    // control CS for DAC
    //mPORTBSetPinsDigitalOut(BIT_4); //CS
    mPORTBSetBits(BIT_4 | BIT_6);
    //===
    
    mPORTASetBits(BIT_0 | BIT_2 | BIT_3 | BIT_4); //CS pins active high
    mPORTAClearBits(BIT_4);
    mPORTBClearBits(BIT_13);
    mPORTBSetBits(BIT_13);
    
    
  // schedule the threads
  while(1) {
      //cmd used as command center for all effects
    PT_SCHEDULE(protothread_cmd(&pt_cmd));
  }
} // main
Esempio n. 8
0
File: minut.c Progetto: nnayo/egere
void MNT_run(void)
{
	// event sources are :
	//  - take-off detector
	//  - time-out
	//  - door detectors
	//  - frame commands
	//
	//  each generated event is stored in a fifo

	if ( MNT.started ) {
		// check if door has changed
		(void)PT_SCHEDULE(MNT_check_cone(&MNT.pt_chk_cone));

		// check if a time-out has elapsed
		(void)PT_SCHEDULE(MNT_check_time_out(&MNT.pt_chk_time_out));
	}

	// treat each incoming commands
	(void)PT_SCHEDULE(MNT_check_commands(&MNT.pt_chk_cmds));

	if ( MNT.started ) {
		// treat each new event
		mnt_event_t ev;

		// if there is an event
		if ( OK == FIFO_get(&MNT.ev_fifo, &ev) ) {
			// send it to the state machine
			STM_event(&MNT.stm, ev);
		}

		// update state machine
		STM_run(&MNT.stm);
	}

	// send outgoing frame(s) if any
	(void)PT_SCHEDULE(MNT_send_frame(&MNT.pt_out));
}
Esempio n. 9
0
//===================== Main ======================= //
void main(void) {
    SYSTEMConfigPerformance(PBCLK);

    ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0;

    PT_setup();
    refreshRate = 10; //msec
    
    //Temporary Random Ball generator
    head = Ball_create(50, 50, 2, 0,  0, NULL);
    int i = 1;
    for(i = 1; i < 15; i++) {
        signed char troll1 = rand() % 5;
        signed char troll2 = rand() % 5;
        struct Ball *temp = Ball_create(i*10,i*10,troll1,troll2,0,NULL);
        temp->b = head;
        head = temp;
    }
        
    // initialize the threads
    PT_INIT(&pt_calculate);
    PT_INIT(&pt_refresh);
    // initialize the display
    tft_init_hw();
    tft_begin();
    tft_fillScreen(ILI9340_BLACK);
    
    INTEnableSystemMultiVectoredInt();

    tft_setRotation(0); //240x320 vertical display
  
    //round-robin scheduler for threads
    while(1) {
        PT_SCHEDULE(protothread_calculate(&pt_calculate));
        PT_SCHEDULE(protothread_refresh(&pt_refresh));
    }
    
} //main
Esempio n. 10
0
int main(void) {


    SystemCoreClockSet(MSI48M_CLOCKSRC,0,2,0);

    APBPeripheralClockSet(0,0); /* Enable APBx */

    LED_Init(LED_ALL);

    JoyStick_Init();

    PT_INIT(&pt_BlinkGreen);
    PT_INIT(&pt_BlinkRed);
    PT_INIT(&pt_ButtonProc);

    SysTick_Config(SystemCoreClock/1000);   /* 1 ms */

    for (;;) {
        PT_SCHEDULE(Blink_Green(&pt_BlinkGreen));
        PT_SCHEDULE(Blink_Red(&pt_BlinkRed));
        PT_SCHEDULE(ButtonProc(&pt_ButtonProc));
    }
}
int main(void)
{
  // === config the uart, DMA, vref, timer5 ISR =============
  PT_setup();

   // === setup system wide interrupts  ====================
  INTEnableSystemMultiVectoredInt();
    
  // === set up i/o port pin ===============
  mPORTASetBits(BIT_0 | BIT_1 );	//Clear bits to ensure light is off.
  mPORTASetPinsDigitalOut(BIT_0 | BIT_1 );    //Set port as output
  mPORTBSetBits(BIT_0 );	//Clear bits to ensure light is off.
  mPORTBSetPinsDigitalOut(BIT_0 );    //Set port as output

  // === now the threads ====================
  // init  the thread control semaphores
  PT_SEM_INIT(&control_t1, 0); // start blocked
  PT_SEM_INIT(&control_t2, 1); // start unblocked
  PT_SEM_INIT(&send_sem, 1); // start with ready to send

  // init the threads
  PT_INIT(&pt1);
  PT_INIT(&pt2);
  PT_INIT(&pt3);
  PT_INIT(&pt4);
  PT_INIT(&pt5);

  // init the optional rate scheduler
  PT_RATE_INIT();

  // schedule the threads
  while(1) {
    PT_RATE_LOOP(); // not necessary if you use PT_SCHEDULE
    PT_RATE_SCHEDULE(protothread1(&pt1), t1_rate);
    if (run_t4) PT_RATE_SCHEDULE(protothread4(&pt4), t4_rate); //run always
    PT_RATE_SCHEDULE(protothread2(&pt2), t1_rate);
    if (cmd[0] != 'k') PT_RATE_SCHEDULE(protothread3(&pt3),t3_rate);
    PT_SCHEDULE(protothread5(&pt5));

     /*
    // alternate scheme
    PT_SCHEDULE(protothread1(&pt1));
    if (run_t4) PT_SCHEDULE(protothread4(&pt4));
   PT_SCHEDULE(protothread2(&pt2));
    if (run_t4) PT_SCHEDULE(protothread4(&pt4));
    if (cmd[0] != 'k') PT_SCHEDULE(protothread3(&pt3));
     */
  }
} // main
Esempio n. 12
0
// === Main  ======================================================
void main(void) {
 SYSTEMConfigPerformance(PBCLK);
  
  ANSELA = 0; ANSELB = 0; CM1CON = 0; CM2CON = 0;

  // === config threads ==========
  // turns OFF UART support and debugger pin
  PT_setup();

  // === setup system wide interrupts  ========
  INTEnableSystemMultiVectoredInt();

  // init the threads
  PT_INIT(&pt_timer);
  PT_INIT(&pt_color);
  PT_INIT(&pt_anim);
  PT_INIT(&pt_key);

  // init the display
  tft_init_hw();
  tft_begin();
  tft_fillScreen(ILI9340_BLACK);
  //240x320 vertical display
  tft_setRotation(0); // Use tft_setRotation(1) for 320x240

  // seed random color
  srand(1);

  // round-robin scheduler for threads
  while (1){
      PT_SCHEDULE(protothread_timer(&pt_timer));
      PT_SCHEDULE(protothread_color(&pt_color));
      PT_SCHEDULE(protothread_anim(&pt_anim));
      PT_SCHEDULE(protothread_key(&pt_key));
      }
  } // main
Esempio n. 13
0
/*---------------------------------------------------------------------------*/
static int
input_pt(struct http_socket *s,
         const uint8_t *inputptr, int inputdatalen)
{
  int i;
  PT_BEGIN(&s->pt);

  /* Parse the header */
  s->header_received = 0;
  do {
    for(i = 0; i < inputdatalen; i++) {
      if(!PT_SCHEDULE(parse_header_byte(s, inputptr[i]))) {
        s->header_received = 1;
        break;
      }
    }
    inputdatalen -= i;
    inputptr += i;

    if(s->header_received == 0) {
      /* If we have not yet received the full header, we wait for the
         next packet to arrive. */
      PT_YIELD(&s->pt);
    }
  } while(s->header_received == 0);

  s->bodylen = 0;
  do {
    /* Receive the data */
    call_callback(s, HTTP_SOCKET_DATA, inputptr, inputdatalen);

    /* Close the connection if the expected content length has been received */
    if(s->header.content_length >= 0 && s->bodylen < s->header.content_length) {
      s->bodylen += inputdatalen;
      if(s->bodylen >= s->header.content_length) {
        tcp_socket_close(&s->s);
      }
    }

    PT_YIELD(&s->pt);
  } while(inputdatalen > 0);

  PT_END(&s->pt);
}
Esempio n. 14
0
int
main(void)
{
  struct pt driver_pt;

  PT_INIT(&driver_pt);

  while(PT_SCHEDULE(driver_thread(&driver_pt))) {

    /*
     * When running this example on a multitasking system, we must
     * give other processes a chance to run too and therefore we call
     * usleep() resp. Sleep() here. On a dedicated embedded system,
     * we usually do not need to do this.
     */
#ifdef _WIN32
    Sleep(0);
#else
    usleep(10);
#endif
  }
  return 0;
}
Esempio n. 15
0
/*---------------------------------------------------------------------------*/
int main(void)
{   
    uint16_t rval;     

    /* init hardware layer */
    init_hci();
    timer1_init();
    init_serial();    
    sei();

    led1_high();
    led2_high();

    /* init protothreads */
    PT_INIT(&blink_pt);    
    PT_INIT(&nrf24_pt);
    PT_INIT(&www_client_pt);
    PT_INIT(&www_server_pt);
    PT_INIT(&udp_server_pt);
    PT_INIT(&coap_server_pt);    
    PT_INIT(&temperature_pt);
    PT_INIT(&udp_broadcast_pt);

    /* greeting message */
    dbg(PSTR("> Hello World!\r\n"));   

    /* init the ethernet chip */
    enc28j60Init(mymac);        
    enc28j60PhyWrite(PHLCON,0x476);
    
    /* get automatic IP */
    rval=0;
    init_mac(mymac);        
    while(rval==0)
    {
        plen=enc28j60PacketReceive(BUFFER_SIZE, buf);
        rval=packetloop_dhcp_initial_ip_assignment(buf,plen,mymac[5]);
    }
    dhcp_get_my_ip(myip,netmask,gwip); 
    client_ifconfig(myip,netmask);
    
    /* learn the MAC address of the gateway */
    get_mac_with_arp(gwip,0,&arpresolver_result_callback);
    while(get_mac_with_arp_wait())
    {        
        plen=enc28j60PacketReceive(BUFFER_SIZE, buf);
        packetloop_arp_icmp_tcp(buf,plen);
    }
    
    /* set WWW server port */
    www_server_port(MYWWWPORT);        
    
    dbg(PSTR("> System is ready.\r\n"));   

    led1_low();
    led2_low();

    /* main loop */
    while(1)
    {    
        if(enc28j60linkup())
        {            
            /* poll hardware ethernet buffer */
            plen = enc28j60PacketReceive(BUFFER_SIZE,buf);     
            
            /* terminate the buffer */
            buf[BUFFER_SIZE]='\0';

            /* handle DHCP messages if neccessary */
            plen = packetloop_dhcp_renewhandler(buf,plen);

            /* handle and analyse the packet slightly */
            dat_p = packetloop_arp_icmp_tcp(buf,plen);

            if( dat_p == 0)
            {
                udp_client_check_for_dns_answer(buf,plen);
            } 

            new_packet = 0xFF;
            
            PT_SCHEDULE(blink_thread(&blink_pt));      
            PT_SCHEDULE(nrf24_thread(&nrf24_pt));                  
            PT_SCHEDULE(www_server_thread(&www_server_pt));
            PT_SCHEDULE(udp_server_thread(&udp_server_pt));
            PT_SCHEDULE(www_client_thread(&www_client_pt));
            PT_SCHEDULE(coap_server_thread(&coap_server_pt));
            PT_SCHEDULE(temperature_thread(&temperature_pt));
            PT_SCHEDULE(udp_broadcast_thread(&udp_broadcast_pt));
        }
    }    
    return 0;
}
Esempio n. 16
0
void main(void) {
        // === enable system wide interrupts  ========
    INTEnableSystemMultiVectoredInt();

//    // init the threads 
    PT_INIT(&pt_uart);

    PT_setup();
    ANSELA = 0; //make sure analog is cleared
    ANSELB = 0;
   
    OpenI2C2( I2C_EN, BRG_VAL ); 
    I2C2CON |= I2C_7BIT_ADD + I2C_SM_EN;
    I2C2CON |= I2C_RESTART_EN; //restart needed to read from ir temp
    unsigned char cmd = 0; //command line 
    unsigned char data = 0; //output data, digital value to be converted
    //unsigned char addr = 0x1C; 
    //Thermometer sensor: 5A
    
    //===========Configuring the IMU========================//
    unsigned int OPR_CODE = 0x3D;
    SendIMUData(OPR_CODE, 0x0C);        //sets IMU mode
            
    //========================================================//
            
    while(1){
//        temp = RcvIRTemp();
//        cels = temp / 50 - 273; //convert read value to celsius
//        delay_ms(10);
        PT_SCHEDULE(protothread_uart(&pt_uart));
        temp = RcvIMUData(0x20);
        delay_ms(10);

    }


//    // PuTTY
    clrscr();  //clear PuTTY screen
    home();
//    // By default, MPLAB XC32's libraries use UART2 for STDOUT.
//    // This means that formatted output functions such as printf()
//    // will send their output to UART2

//-----------------------------------------------//    
   
   
   
   


    // === configure threads ==========
    // turns OFF UART support and debugger pin, unless defines are set

    // === enable system wide interrupts  ========
    INTEnableSystemMultiVectoredInt();

//    // init the threads 
    PT_INIT(&pt_uart);


//    // === set up input capture 
//  // based on timer3 (need to configure timer 3 seperately)
//  OpenCapture1(IC_EVERY_RISE_EDGE | IC_INT_1CAPTURE | IC_CAP_32BIT | IC_TIMER2_SRC | IC_ON);
//  // turn on the interrupt so that every capture can be recorded
//  ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_3 | IC_INT_SUB_PRIOR_3);
//  INTClearFlag(INT_IC1);
//  // connect PIN 24 to IC1 capture unit
//  PPSInput(3, IC1, RPB13);
//  mPORTBSetPinsDigitalIn(BIT_13); //Set port as input
//
//    // round-robin scheduler for threads
    while (1) {
        PT_SCHEDULE(protothread_uart(&pt_uart));
    }
} // main
Esempio n. 17
0
File: log.c Progetto: nnayo/scalp
// log run method
void LOG_run(void)
{
	// logging job
	(void)PT_SCHEDULE(LOG_log(&LOG.log_pt));
}
Esempio n. 18
0
int main(void)
{

  /* USER CODE BEGIN 1 */


  /* USER CODE END 1 */

  /* MCU Configuration----------------------------------------------------------*/

  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();

  /* Configure the system clock */
  SystemClock_Config();

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_DMA_Init();
  MX_CRC_Init();
  MX_I2C1_Init();
  MX_SPI2_Init();
  MX_TIM2_Init();
  MX_TIM3_Init();
  MX_TIM4_Init();
  MX_USART2_UART_Init();

  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET);

  // reinitialize uart with speed from config
  huart2.Init.BaudRate = USART_DEBUG_SPEED;
  HAL_UART_Init(&huart2);

  DEBUG_PRINTF("Hello, Lepton!\n\r");
  fflush(stdout);

  lepton_init();

  HAL_Delay(1000);

  init_lepton_command_interface();
#ifdef ENABLE_LEPTON_AGC
  enable_lepton_agc();
#endif

#ifdef Y16
  enable_telemetry();
#else
  enable_rgb888(PSUEDOCOLOR_LUT);
#endif

  DEBUG_PRINTF("reading_tmp007_regs...\n\r");

  read_tmp007_regs();

  DEBUG_PRINTF("Initialized...\n\r");

  HAL_Delay(250);

  MX_USB_DEVICE_Init();

  PT_INIT(&lepton_task_pt);
  PT_INIT(&usb_task_pt);
  PT_INIT(&uart_task_pt);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

	  PT_SCHEDULE(lepton_task(&lepton_task_pt));
	  PT_SCHEDULE(usb_task(&usb_task_pt));
	  PT_SCHEDULE(uart_task(&uart_task_pt));
	  PT_SCHEDULE(button_task(&button_task_pt));

  }
  /* USER CODE END 3 */

}
Esempio n. 19
0
void main(void) {
    
    PT_setup();
    ANSELA = 0; //make sure analog is cleared
    ANSELB = 0;
   
    OpenI2C1( I2C_EN, BRG_VAL ); 
    unsigned char cmd = 0; //command line 
    unsigned char data = 0; //output data, digital value to be converted
    //unsigned char addr = 0x1C; 
    //Thermometer sensor: 5A
    
//    SendData(0x75, addr);
    temp = RcvData2(addr);
    
//    while(1);
//    delay_ms(5000);
//        while(1) // run the code over and over again
//    { 
//
//        // start the I2C communication
//        StartI2C1(); // Send the Start Bit (begin of data send) 
//        IdleI2C1(); // Wait to complete 
//
//        // write the address of the chip, defined by pins AD0 and AD1 on the MAX518
//        MasterWriteI2C1 (addr); // address 
//        IdleI2C1(); 
//        
//        
//        while( !I2C1STATbits.ACKSTAT==0 ){}
//        
//        // write the command to tell the MAX518 to change its output on output 0
//        MasterWriteI2C1 (cmd); // command line 
//        IdleI2C1(); 
//        while( !I2C1STATbits.ACKSTAT==0 ){}
//
//        // wite the value to put on the output
//        MasterWriteI2C1(data); // output 
//        IdleI2C1(); 
//        while( !I2C1STATbits.ACKSTAT==0 ){}
//
//        // end the I2C communication
//        StopI2C1(); // end of data send 
//        IdleI2C1(); // Wait to complete 
//
//        // the total write time is ~285us with an I2C clock of 100 kHz
//
//        data++; // increase the data, make a sawtooth wave as an example
//
//        //if(data>255) { // don't have to worry about this, data is 8 bit so it will roll over automatically
//        //    data=0;
//        //}
//
//    } // end while(1)
//    
    
    
    
//------- uncomment to init the uart2 -----------//
//    UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY);
//    UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
//    UARTSetDataRate(UART2, PB_FREQ, BAUDRATE);
//    UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));
//    ConfigIntUART2(UART_RX_INT_EN | UART_TX_INT_EN | UART_ERR_INT_EN | UART_INT_PR0 | UART_INT_SUB_PR0);

     //rxchar = 0 ; // a received character
     //count = 0 ; // count the number of characters

//    // PuTTY
    clrscr();  //clear PuTTY screen
    home();
//    // By default, MPLAB XC32's libraries use UART2 for STDOUT.
//    // This means that formatted output functions such as printf()
//    // will send their output to UART2

//-----------------------------------------------//    
   
   
   
   


    // === configure threads ==========
    // turns OFF UART support and debugger pin, unless defines are set

    // === enable system wide interrupts  ========
    INTEnableSystemMultiVectoredInt();

//    // init the threads 
    PT_INIT(&pt_uart);
//    PT_INIT(&pt_anim);
   
// ---------- uncomment to init the tft display -----------//
//    tft_init_hw();
//    tft_begin();
//    tft_fillScreen(ILI9340_BLACK); //240x320 vertical display
//    tft_setRotation(0); // Use tft_setRotation(1) for 320x240
//---------------------------------------------------------//
    

//    // === set up input capture 
//	// based on timer3 (need to configure timer 3 seperately)
//	OpenCapture1(IC_EVERY_RISE_EDGE | IC_INT_1CAPTURE | IC_CAP_32BIT | IC_TIMER2_SRC | IC_ON);
//	// turn on the interrupt so that every capture can be recorded
//	ConfigIntCapture1(IC_INT_ON | IC_INT_PRIOR_3 | IC_INT_SUB_PRIOR_3);
//	INTClearFlag(INT_IC1);
//	// connect PIN 24 to IC1 capture unit
//	PPSInput(3, IC1, RPB13);
//	mPORTBSetPinsDigitalIn(BIT_13); //Set port as input
//
//    // round-robin scheduler for threads
    while (1) {
        PT_SCHEDULE(protothread_uart(&pt_uart));
        //PT_SCHEDULE(protothread_anim(&pt_anim));
    }
} // main
Esempio n. 20
0
// === Main  ======================================================
void main(void) {
    //SYSTEMConfigPerformance(PBCLK);
    ANSELA = 0; ANSELB = 0; 
    // === config threads ==========
    // turns OFF UART support and debugger pin, unless defines are set
    PT_setup();
    // === setup system wide interrupts  ========
    INTEnableSystemMultiVectoredInt();
    CloseADC10();	// ensure the ADC is off before setting the configuration
    #define PARAM1  ADC_FORMAT_INTG16 | ADC_CLK_AUTO | ADC_AUTO_SAMPLING_OFF //
    // define setup parameters for OpenADC10
    // ADC ref external  | disable offset test | disable scan mode | do 1 sample | use single buf | alternate mode off
    #define PARAM2  ADC_VREF_AVDD_AVSS | ADC_OFFSET_CAL_DISABLE | ADC_SCAN_OFF | ADC_SAMPLES_PER_INT_1 | ADC_ALT_BUF_OFF | ADC_ALT_INPUT_OFF
    // Define setup parameters for OpenADC10
    // use peripherial bus clock | set sample time | set ADC clock divider
    // ADC_CONV_CLK_Tcy2 means divide CLK_PB by 2 (max speed)
    // ADC_SAMPLE_TIME_5 seems to work with a source resistance < 1kohm
    #define PARAM3 ADC_CONV_CLK_PB | ADC_SAMPLE_TIME_5 | ADC_CONV_CLK_Tcy2 //ADC_SAMPLE_TIME_15| ADC_CONV_CLK_Tcy2
    // define setup parameters for OpenADC10
    // set AN11 and  as analog inputs
    #define PARAM4	ENABLE_AN11_ANA // pin 24
    // define setup parameters for OpenADC10
    // do not assign channels to scan
    #define PARAM5	SKIP_SCAN_ALL
    // use ground as neg ref for A | use AN11 for input A     
    // configure to sample AN11 
    SetChanADC10( ADC_CH0_NEG_SAMPLEA_NVREF | ADC_CH0_POS_SAMPLEA_AN11 ); // configure to sample AN4 
    OpenADC10( PARAM1, PARAM2, PARAM3, PARAM4, PARAM5 ); // configure ADC using the parameters defined above
    EnableADC10(); // Enable the ADC      
    OpenTimer2(T2_ON | T2_SOURCE_INT | T2_PS_1_1, 400); 
    mPORTAClearBits(BIT_0 );		//Clear bits to ensure light is off.
    mPORTASetPinsDigitalOut(BIT_0 );    //Set port as output
    int CVRCON_setup;
    // set up the Vref pin and use as a DAC
    // enable module| eanble output | use low range output | use internal reference | desired step
    CVREFOpen( CVREF_ENABLE | CVREF_OUTPUT_ENABLE | CVREF_RANGE_LOW | CVREF_SOURCE_AVDD | CVREF_STEP_0 );
    // And read back setup from CVRCON for speed later
    // 0x8060 is enabled with output enabled, Vdd ref, and 0-0.6(Vdd) range
    CVRCON_setup = CVRCON; //CVRCON = 0x8060
	// Open the desired DMA channel.
	// We enable the AUTO option, we'll keep repeating the same transfer over and over.
	DmaChnOpen(dmaChn, 0, DMA_OPEN_AUTO);
	// set the transfer parameters: source & destination address, source & destination size, number of bytes per event
    // Setting the last parameter to one makes the DMA output one byte/interrut
    //DmaChnSetTxfer(dmaChn, sine_table, (void*) &CVRCON, sizeof(sine_table), 1, 1);
	// set the transfer event control: what event is to start the DMA transfer
    // In this case, timer2 
	DmaChnSetEventControl(dmaChn,  DMA_EV_START_IRQ(_TIMER_2_IRQ));
	// once we configured the DMA channel we can enable it
	// now it's ready and waiting for an event to occur...
	//DmaChnEnable(dmaChn);
  
    int i;
    for(i=0; i <256; i++){
        ball_scored[i] = 0x60|((unsigned char)((float)255/2*(sin(6.2832*(((float)i)/(float)256))+1))) ;
        //ball_lost[i]
       // game_over
    }

        
    // init the threads
    PT_INIT(&pt_timer);
    PT_INIT(&pt_adc);
    PT_INIT(&pt_launch);
    PT_INIT(&pt_anim);
    // init the display
    tft_init_hw();
    tft_begin();
    tft_fillScreen(ILI9340_BLACK);
    tft_setRotation(1); // Use tft_setRotation(1) for 320x240
    while (1){
        PT_SCHEDULE(protothread_timer(&pt_timer));
        PT_SCHEDULE(protothread_adc(&pt_adc));
        PT_SCHEDULE(protothread_launch_balls(&pt_launch));
        PT_SCHEDULE(protothread_anim_balls(&pt_anim));
    }
  } // main
Esempio n. 21
0
// Time Synchro module run method
void TSN_run(void)
{
	// send response if any
	(void)PT_SCHEDULE(TSN_tsn(&TSN.pt));
}
Esempio n. 22
0
File: leds.c Progetto: fd0/rumpus
void led_thread(void)
{
    PT_SCHEDULE(led_main(&pt_led_main));
}