Example #1
0
/* Initialize stella */
void
stella_init (void)
{
	int_table = &timetable_1;
	cal_table = &timetable_2;
	int_table->head = 0;
	cal_table->head = 0;
	int_table->portmask = 0;
	cal_table->portmask = 0;
	
	stella_sync = NOTHING_NEW;

	/* set stella port pins to output and save the negated port mask */
	stella_portmask_neg = (uint8_t)~(((1 << STELLA_PINS) - 1) << STELLA_OFFSET);
	STELLA_DDR = ((1 << STELLA_PINS) - 1) << STELLA_OFFSET;
	//DDRC = 255;
	//debug_printf("stella ok_ %i \n", ((1 << STELLA_PINS) - 1) << STELLA_OFFSET);

	/* we need at least 64 ticks for the compare interrupt,
	* therefore choose a prescaler of at least 64. */
	
	#ifdef STELLA_HIGHFREQ
	/* Normal PWM Mode, 64 Prescaler */
	_TCCR2_PRESCALE = _BV(CS22);
	debug_printf("Stella freq: %u Hz\n", F_CPU/64/(256*2));
	#else
	/* Normal PWM Mode, 128 Prescaler */
	_TCCR2_PRESCALE |= _BV(CS20) | _BV(CS22);
	debug_printf("Stella freq: %u Hz\n", F_CPU/128/(256*2));
	#endif

	/* Interrupt on overflow and CompareMatch */
	_TIMSK_TIMER2 |= _BV(TOIE2) | _BV(_OUTPUT_COMPARE_IE2);

	/* initialise the fade counter. Fading works like this:
	* -> decrement fade_counter
	* -> on zero, fade if neccessary
	* -> reset counter to fade_step
	*/
	stella_fade_counter = stella_fade_step;

	#if STELLA_START == stella_start_eeprom
	stella_loadFromEEROMFading();
	#endif
	#if STELLA_START == stella_start_all
	memset(stella_fade, 1, sizeof(stella_fade));
	#endif

	stella_sort();
	
}
Example #2
0
void
stella_init(void)
{
  int_table = &timetable_1;
  cal_table = &timetable_2;
  cal_table->head = 0;

  stella_sync = NOTHING_NEW;

  /* set stella port pins to output and save the port mask */
  stella_portmask[0] = ((1 << STELLA_PINS_PORT1) - 1) << STELLA_OFFSET_PORT1;
  STELLA_DDR_PORT1 |= stella_portmask[0];
  cal_table->port[0].port = &STELLA_PORT1;
  cal_table->port[0].mask = 0;
#ifdef STELLA_PINS_PORT2
  stella_portmask[1] = ((1 << STELLA_PINS_PORT2) - 1) << STELLA_OFFSET_PORT2;
  STELLA_DDR_PORT2 |= stella_portmask[1];
  cal_table->port[0].port = &STELLA_PORT2;
  cal_table->port[1].mask = 0;
#endif

  /* initialise the fade counter. Fading works like this:
   * -> decrement fade_counter
   * -> on zero, fade if neccessary
   * -> reset counter to fade_step
   */
  stella_fade_counter = stella_fade_step;

#if !defined(TEENSY_SUPPORT) && STELLA_START == stella_start_eeprom
  stella_loadFromEEROMFading();
#endif
#if STELLA_START == stella_start_all
  memset(stella_fade, 255, sizeof(stella_fade));
#endif
#if STELLA_START == stella_start_zero
  memset(stella_fade, 0, sizeof(stella_fade));
#endif

  stella_sort();

  /* we need at least 64 ticks for the compare interrupt,
   * therefore choose a prescaler of at least 64. */
#if STELLA_FREQ == stella_vslow
  STELLA_TC_PRESCALER_1024;
  debug_printf("Stella freq: %u Hz\n", F_CPU / 1024 / (256 * 2));
#elif STELLA_FREQ == stella_slow
  STELLA_TC_PRESCALER_256;
  debug_printf("Stella freq: %u Hz\n", F_CPU / 256 / (256 * 2));
#elif STELLA_FREQ == stella_normal
  STELLA_TC_PRESCALER_128;
  debug_printf("Stella freq: %u Hz\n", F_CPU / 128 / (256 * 2));
#elif STELLA_FREQ == stella_fast
  STELLA_TC_PRESCALER_64;
  debug_printf("Stella freq: %u Hz\n", F_CPU / 64 / (256 * 2));
#endif

  STELLA_TC_INT_OVERFLOW_ON;
  STELLA_TC_INT_COMPARE_ON;

#ifdef DMX_STORAGE_SUPPORT
  /* Setup DMX-Storage Connection */
  stella_dmx_conn_id = dmx_storage_connect(STELLA_UNIVERSE);
#endif
}