Beispiel #1
0
static void prvSetupHardware( void )
{
extern unsigned long _vStackTop[], _pvHeapStart[];
unsigned long ulInterruptStackSize;

	/* Initialize GPIO (sets up clock) */
	GPIOInit();
	/* Set LED port pin to output */
	GPIOSetDir(LED_PORT, LED_GREEN_BIT, 1);
	GPIOSetDir(LED_PORT, LED_RED_BIT, 1);
	GPIOSetValue(LED_PORT, LED_GREEN_BIT, 0);
	GPIOSetValue(LED_PORT, LED_RED_BIT, 0);

	PumpsInit();
	FlowrateInit();
	PacketInit(230400);

	/* The size of the stack used by main and interrupts is not defined in
	the linker, but just uses whatever RAM is left.  Calculate the amount of
	RAM available for the main/interrupt/system stack, and check it against
	a reasonable number.  If this assert is hit then it is likely you don't
	have enough stack to start the kernel, or to allow interrupts to nest.
	Note - this is separate to the stacks that are used by tasks.  The stacks
	that are used by tasks are automatically checked if
	configCHECK_FOR_STACK_OVERFLOW is not 0 in FreeRTOSConfig.h - but the stack
	used by interrupts is not.  Reducing the conifgTOTAL_HEAP_SIZE setting will
	increase the stack available to main() and interrupts. */
	ulInterruptStackSize = ( ( unsigned long ) _vStackTop ) - ( ( unsigned long ) _pvHeapStart );
	configASSERT( ulInterruptStackSize > 350UL );

	/* Fill the stack used by main() and interrupts to a known value, so its
	use can be manually checked. */
	memcpy( ( void * ) _pvHeapStart, ucExpectedInterruptStackValues, sizeof( ucExpectedInterruptStackValues ) );
}
Beispiel #2
0
int main(void) {
  init();

  //******
  //TEST 1
  //******
#if _TEST == 1  
  bool toggle = false;
  uint8_t packet_pos = 0;
  char c;
  DDRD |= (1 << PD6);

  init();

  while(true) {
    c = uart0_getchar();
    
    if (c == 'y') {
      toggle = false;
      uart0_putchar('y');
    }
    if (c == 'n') {
      toggle = true;
      uart0_putchar('n');
    }
    if (toggle)
      PORTD |= (1 << PD6);
    else
      PORTD &= ~(1 << PD6);
  }

  //******
  //TEST 2
  //******
#elif _TEST == 2
  char c;
  DDRD |= (1 << PD6)          // set outputs in PORTD
    | (1 << PD5)
    | (1 << PD4);
  TCCR1A = 0x00;              // clear all current timer 1 settings
  TCCR1B = 0x00;
  TCCR1B |= (1 << WGM12);     // turn on CTC mode:
                              // Clear Timer on Compare Match
  TIMSK1 = (1 << TOIE1);      // enable global and timer overflow interrupt
  TCCR1B |= (1 << CS10);

  while(true) {
    c = uart0_getchar();
    if (c != EOF) {
      if (c == 'f')
	servoTurn(0);
      if (c == 'g')
	servoTurn(90);
      if (c == 'h')
	servoTurn(180);
    }
  }

  //******
v  //TEST 3
  //******
#elif _TEST == 3
  Packet host_packet;
  PacketInit(&host_packet);
  int len = 0;
  char c;
  DDRD |= (1 << PD6);

  while(1) {
    c = uart0_getchar();
    if (c != EOF)
      len = PacketProcessChar(&host_packet, c);
    if (len > 0)
      uart0_printstr("got a packet!\r\n");
    }

  //******
  //TEST 4
  //******
#elif _TEST == 4
  uint8_t messageBuf[4];
  uint8_t TWI_slaveAddress = 0x10;
  DDRD |= (1 << PD5) | (1 << PD6);
  TWIInit();
  sei();
  while(1) {
    PORTD ^= (1 << PD5) | (1 << PD6);
    TWIStart();
    
    //TWIStop();
    _delay_ms(500);
  }

#elif _TEST == 5
  Packet host_packet;
  PacketInit(&host_packet);
  int len = 0;
  char c;
  DDRD |= (1 << PD5);

  uint8_t message_buf[] = {0xFE, 0xFE, 0x01, 0x04, 0x02, 0x2B, 0x01, 0xCC};
  int i;
  while(1) {
    c = uart0_getchar();
    if (c != EOF) {
      len = PacketProcessChar(&host_packet, c);
    }
    if (len > 0) {
      PORTD ^= (1 << PD5);
      len = 0;
    }


    //for (i = 0; i < 8; i++)
    //  uart0_putchar(message_buf[i]);
    //uart0_putchar(0xFD);
    //uart0_putchar(0xFF);
    //c = uart0_getchar();
    //if (c != EOF) {
    //  len = PacketProcessChar(&host_packet, c);
      //PORTD ^= (1 << PD5);
    //}
    //if (len > 0)
    //PORTD ^= (1 << PD5);
    //_delay_ms(1000);
  }


  /*
  DDRD |= (1 << PD5);
  char c;
  while(1) {
    c = uart0_getchar();
    if (c != EOF) {
      uart0_putchar(c);
      PORTD ^= (1 << PD5);
      //_delay_ms(500);
    }
    }*/

#endif // _TEST
  return 0;
}