Exemplo n.º 1
0
static void notify8(io_queue_t *qp)
{
  (void)qp;
  fifo_load(&SD8);
}
Exemplo n.º 2
0
/** main function
 */
int main(void) {
    init_output();
    init_pwm();

#if SERIAL_UART
    init_uart();
#endif

#if RC5_DECODER
    init_rc5();
#endif

#if I2C
    init_i2c();
#endif

    global_pwm.channels[0].brightness = 50;
    global_pwm.channels[0].target_brightness = 50;

#if STATIC_SCRIPTS
    init_script_threads();

    #if RS485_CTRL == 0
    /* start the example scripts */
    script_threads[0].handler.execute = &memory_handler_flash;
    script_threads[0].handler.position = (uint16_t) &colorchange_red;
    script_threads[0].flags.disabled = 0;

    //script_threads[1].handler.execute = &memory_handler_flash;
    //script_threads[1].handler.position = (uint16_t) &testscript_flash2;
    //script_threads[1].flags.disabled = 0;
    //
    //script_threads[2].handler.execute = &memory_handler_eeprom;
    //script_threads[2].handler.position = (uint16_t) &testscript_eeprom;
    //script_threads[2].flags.disabled = 0;

    //script_threads[0].handler.execute = &memory_handler_flash;
    //script_threads[0].handler.position = (uint16_t) &blinken;
    //script_threads[0].flags.disabled = 0;
    #endif

#endif

#if I2C_MASTER
    i2c_global.send_messages[0].command.size = 4;
    i2c_global.send_messages[0].command.code = COMMAND_SET_COLOR;
    i2c_global.send_messages[0].command.set_color_parameters.colors[0] = 0x10;
    i2c_global.send_messages[0].command.set_color_parameters.colors[1] = 0x10;
    i2c_global.send_messages[0].command.set_color_parameters.colors[2] = 0x10;

    i2c_global.send_messages_count = 1;
#endif

#if RS485_CTRL
    /* init command bus */
    UCSR0A = _BV(MPCM0); /* enable multi-processor communication mode */
    UCSR0C = _BV(UCSZ00) | _BV(UCSZ01); /* 9 bit frame size */

    #define UART_UBRR 8 /* 115200 baud at 16mhz */
    UBRR0H = HIGH(UART_UBRR);
    UBRR0L = LOW(UART_UBRR);

    UCSR0B = _BV(RXEN0) | _BV(TXEN0) | _BV(UCSZ02); /* enable receiver and transmitter */
#endif

    /* enable interrupts globally */
    sei();

    while (1) {
        /* after the last pwm timeslot, rebuild the timeslot table */
        if (global.flags.last_pulse) {
            global.flags.last_pulse = 0;

            update_pwm_timeslots();
        }

        /* at the beginning of each pwm cycle, call the fading engine and
         * execute all script threads */
        if (global.flags.new_cycle) {
            global.flags.new_cycle = 0;

            update_brightness();
#if STATIC_SCRIPTS
            execute_script_threads();
#endif

            continue;
        }


#if SERIAL_UART
        /* check if we received something via uart */
        if (fifo_fill(&global_uart.rx_fifo) > 0) {
            check_serial_input(fifo_load(&global_uart.rx_fifo));
            continue;
        }
#endif


#if RC5_DECODER
        /* check if we received something via ir */
        if (global_rc5.new_data) {
            static uint8_t toggle_bit = 2;

            /* if key has been pressed again */
            if (global_rc5.received_command.toggle_bit != toggle_bit) {

                /* if code is 0x01 (key '1' on a default remote) */
                if (global_rc5.received_command.code == 0x01) {

                    /* install script into thread 1 */
                    script_threads[1].handler.execute = &memory_handler_flash;
                    script_threads[1].handler.position = (uint16_t) &green_flash;
                    script_threads[1].flags.disabled = 0;
                    script_threads[1].handler_stack_offset = 0;

                }

                /* store new toggle bit state */
                toggle_bit = global_rc5.received_command.toggle_bit;

            }

            /* reset the new_data flag, so that new commands can be received */
            global_rc5.new_data = 0;

            continue;
        }
#endif

#if RS485_CTRL
        if (UCSR0A & _BV(RXC0)) {

            uint8_t address = UCSR0B & _BV(RXB80); /* read nineth bit, zero if data, one if address */
            uint8_t data = UDR0;
            static uint8_t buffer[8];
            static uint8_t fill = 0;

            if (UCSR0A & _BV(MPCM0) || address) { /* if MPCM mode is still active, or ninth bit set, this is an address packet */

                /* check if we are ment */
                if (data == 0 || data == RS485_ADDRESS) {

                    /* remove MPCM flag and reset buffer fill counter */
                    UCSR0A &= ~_BV(MPCM0);
                    fill = 0;

                    continue;

                } else {/* turn on MPCM */

                    UCSR0A |= _BV(MPCM0);
                    continue;

                }
            }

            /* else this is a data packet, put data into buffer */
            buffer[fill++] = data;

            if (buffer[0] == 0x01) {  /* soft reset */

                jump_to_bootloader();

            } else if (buffer[0] == 0x02 && fill == 4) { /* set color */

                for (uint8_t pos = 0; pos < 3; pos++) {
                    global_pwm.channels[pos].target_brightness = buffer[pos + 1];
                    global_pwm.channels[pos].brightness = buffer[pos + 1];
                }

                UCSR0A |= _BV(MPCM0); /* return to MPCM mode */

            } else if (buffer[0] == 0x03 && fill == 6) { /* fade to color */

                for (uint8_t pos = 0; pos < 3; pos++) {
                    global_pwm.channels[pos].speed_h = buffer[1];
                    global_pwm.channels[pos].speed_l = buffer[2];
                    global_pwm.channels[pos].target_brightness = buffer[pos + 3];
                }

                UCSR0A |= _BV(MPCM0); /* return to MPCM mode */
            }

        }
#endif

#if I2C_MASTER
        i2c_master_check_queue();
#endif
    }
}
Exemplo n.º 3
0
int main (int argc, char** argv)
{
  bound_t* limit; /* limites globais */
  cdf_t* dict;   /* o dicionario com simbolos */
  FILE* msg; /* o arquivo com a mensagem codificada */
  FILE* dmsg; /* o arquivo com a mensagem decodificada */
  fifo_t* coded; /* a mensagem codificada */
  unsigned long buff; /* caracter decodificado */
  clock_t start, end; /* cronometro */
  double cpu_time_used;
  unsigned long lsize; /* um contador */

#ifdef DEBUGGING
  mtrace();
#endif

  if (argc != 3) {
    fprintf(stderr, "uso: %s <dicionario> <arquivo-codificada>\n", argv[0]);
    exit(1);
  }

  /* carrega dicionario */
  dict = cdf_load(argv[1]);

  /* inicializa limites */
  limit = init_bound(); /* ajusta limites para 0 e 1 */
  cdf_min_ulimit(dict,limit); /* ajusta limite */

  /* inicializa fifo com a mensagem a ser decodificada */
  coded = init_fifo();
  if ( (msg = fopen(argv[2],"r")) == NULL ) {
    perror("[test_encode] *ERROR* ");
    exit(1);
  }
  fifo_load(coded, msg);
  fclose(msg);
#ifdef DEBUGGING
  fprintf(stderr, "[test_decode] fifo inicializada.\n");
#endif

  /* decodifica mensagem */
  if ( (dmsg = fopen("decoded.mesg","w")) == NULL ) {
    perror("[test_encode] *ERROR* ");
    exit(1);
  }

  lsize = 0;
  start = clock();
  for (;;) /* forever */ {
    arith_decode(dict, coded, limit, &buff);
    if ( buff == cdf_terminator(dict) ) break;
    ++lsize;
    fprintf(dmsg, "%lu\n", buff);
  }
  end = clock();
  cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
  fclose(dmsg);
    
  fprintf(stderr, "[test_decode] mensagem decodificada,");
  fprintf(stderr, " %lu simbolos\n", lsize);
  fprintf(stderr, "[test_cdf] Tempo total = %e s\n",cpu_time_used);
  fprintf(stderr, "[test_cdf] Por simbolo ~= %e s\n",cpu_time_used/lsize);

  /* libera memoria alocada */
  free_bound(limit);
  free_cdf(dict);
  free_fifo(coded);

  return 0;
}