Deoptimized.

This commit is contained in:
Kai Lauterbach 2011-12-17 22:03:57 +01:00
parent f1f99f4576
commit 44ca75161f
7 changed files with 68 additions and 89 deletions

View file

@ -68,33 +68,49 @@ int main(int argc, char **argv)
#endif
//usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_EEPROM, 0, 0, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_LOAD_EEPROM, 0, 1, buffer, 0, 300);
sleep(1);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_LOAD_EEPROM, 0, 0, buffer, 0, 300);
sleep(1);
//usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_EEPROM_SET_FRAME, 0, 1, buffer, 0, 300);
//sleep(1);
//usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_EEPROM_SET_FRAME, 0, 0, buffer, 0, 300);
//sleep(1);
// int usb_control_msg(usb_dev_handle *dev, int requesttype, int request, int value, int index, char *bytes, int size, int timeout);
// 32 bit in 2 transmission
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x7217, 0, buffer, 0, 300);
//sleep(2);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0743, 1, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0000, 0, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0000, 1, buffer, 0, 300);
sleep(1);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x7347, 0, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0712, 1, buffer, 0, 300);
sleep(1);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x7007, 0, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x0700, 1, buffer, 0, 300);
sleep(1);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0xffff, 0, buffer, 0, 300);
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_FRAME, 0x07ff, 1, buffer, 0, 300);
sleep(1);
// bitwise set/get
//usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_STATUS, 0, 25, buffer, 0, 5000);
sleep(1);
//sleep(1);
int i = 0;
/*int i = 0;
for (i = 0; i < 27; i++)
{
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_LED, 1, i, buffer, 0, 300);
usleep(250000);
usleep(100000);
}
for (i = 26; i >= 0; i--)
{
usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_OUT, CUSTOM_RQ_SET_LED, 0, i, buffer, 0, 300);
usleep(250000);
}
usleep(100000);
}*/
usb_close(handle);
return 0;

View file

@ -1,52 +0,0 @@
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
int main (void)
{
int PORTD = 0xff;
int PORTB = 0xff;
int cube = 0x000001ff;
int cube_level = 0;
char test[100];
int i = 0;
for (i = 0; i < 3; i++)
{
printf("-----------------\ncube_level = %d\n",cube_level);
printf("PORTD = 0x%2x\n", PORTD);
printf("PORTB = 0x%2x\n", PORTB);
PORTD &= 0x87; // 0x87 = 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
printf("& 0b10000111: PORTD = 0x%2x\n", PORTD);
PORTD |= ((1 << cube_level)<< 3); // cube_level setzen (Ebene A=0, B=1, C=2)
printf("Level festlegen: PORTD = 0x%2x\n", PORTD);
int tmp = cube_level * 9;
printf("8 Bits aus cube: PORTD = 0x%2x\n", ((~cube & (0xff << tmp)) >> tmp));
// PORTB = 1..8
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
PORTB = ((~cube & (0xff << tmp)) >> tmp);
printf("Pins1-8: PORTB = 0x%2x\n", PORTB);
// PORTD &= 0b10111111; // bereits oben erledigt
PORTD |= (((~cube & (1 << (tmp+8))) >> (tmp+8)) << 6);
printf("Pin9: PORTD = 0x%2x\n", PORTD);
cube_level++;
if (cube_level > 2) cube_level = 0;
}
}

View file

@ -18,6 +18,11 @@ main()
init();
init_usb();
//cube_t c;
//cube = &c;
frame = 0x07ffffff;
//cube->level = 0x00;
// Hauptschleife
for (;;)
{
@ -62,19 +67,19 @@ ISR (TIMER1_COMPA_vect)
// PORTD = __, 9, C, B, A,D+,D-,__
PORTD &= 0b10000111; // 7tes Bit löschen (Leitung 9) und alle Ebenen deaktivieren
PORTD |= (1 << 6) | ((1 << cube_level) << 3); // cube_level setzen (Ebene A=0, B=1, C=2)
PORTD |= (1 << 6) | ((1 << level) << 3); // level setzen (Ebene A=0, B=1, C=2)
uint32_t tmp = cube_level * 9;
uint8_t tmp = level * 9;
// PORTB = 1..8
// 0 = leuchtet, 1 = leuchtet nicht (invertiert!)
PORTB = ~((cube >> tmp) & 0xff);
PORTB = ~((frame >> tmp) & 0xff);
if ( (((cube >> tmp) >> 8) & 0x01) )
if ( (((frame >> tmp) >> 8) & 0x01) )
PORTD &= ~(1 << 6); // 9. led setzen falls notwendig
cube_level++;
if (cube_level > 2) cube_level = 0;
level++;
if (level > 2) level = 0;
}

View file

@ -14,12 +14,17 @@
// Includes
#include "globals.h"
#include "type.h"
#include <avr/interrupt.h>
#include <avr/io.h>
// Cube-Data
uint32_t cube = 0xffffffff;
uint32_t frame = 0xffffffff;
// Bit Offset in Cube-Data
uint8_t cube_level; // Aktive Ebene
uint8_t level; // Aktive Ebene
//cube_t *cube;
// Prototypen
void init(void);

View file

@ -16,10 +16,11 @@
#ifndef __REQUESTS_H_INCLUDED__
#define __REQUESTS_H_INCLUDED__
#define CUSTOM_RQ_SET_LED 1
#define CUSTOM_RQ_SET_FRAME 2
#define CUSTOM_RQ_SET_EEPROM 3
#define CUSTOM_RQ_GET_EEPROM 4
#define CUSTOM_RQ_LOAD_EEPROM 5
#define CUSTOM_RQ_SET_FRAME 1
#define CUSTOM_RQ_EEPROM_STORE_FRAME 2
#define CUSTOM_RQ_EEPROM_SET_FRAME 3
#define CUSTOM_RQ_LOOP_ANIMATION 4
#define CUSTOM_RQ_START_ANIMATION 5
#define CUSTOM_RQ_STOP_ANIMATION 6
#endif /* __REQUESTS_H_INCLUDED__ */

View file

@ -16,13 +16,13 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
if ( (rq->bmRequestType & USBRQ_TYPE_MASK) == USBRQ_TYPE_VENDOR )
{
if ( rq->bRequest == CUSTOM_RQ_SET_LED )
/*if ( rq->bRequest == CUSTOM_RQ_SET_LED )
{
if ( rq->wValue.bytes[0] == 1 )
cube |= ((uint32_t)1 << rq->wIndex.bytes[0]);
else
cube &= ~((uint32_t)1 << rq->wIndex.bytes[0]);
} else if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
} else*/ if ( rq->bRequest == CUSTOM_RQ_SET_FRAME )
{
/* requires more flash space
@ -31,21 +31,21 @@ usbMsgLen_t usbFunctionSetup(uchar data[8])
( (uint32_t)(rq->wIndex.bytes[0] + (rq->wIndex.bytes[1] << 8)) << 16 );*/
if ( rq->wIndex.bytes[0] == 0 )
{
cube = (cube & (uint32_t)0xffff0000) |
frame = (frame & (uint32_t)0xffff0000) |
( rq->wValue.bytes[0] +
(rq->wValue.bytes[1] << 8) );
} else {
cube = (cube & (uint32_t)0x0000ffff) |
frame = (frame & (uint32_t)0x0000ffff) |
((uint32_t)( rq->wValue.bytes[0] +
(rq->wValue.bytes[1] << 8) ) << 16);
}
/*} else if ( rq->bRequest == CUSTOM_RQ_SET_EEPROM )
} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_STORE_FRAME )
{
eeprom_write_dword(&eep_anim[0], 0x07007007);*/
} else if ( rq->bRequest == CUSTOM_RQ_LOAD_EEPROM )
eeprom_write_dword(&eep_anim[0], 0x07007007);
} else if ( rq->bRequest == CUSTOM_RQ_EEPROM_SET_FRAME )
{
cube = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] );
frame = eeprom_read_dword( &eep_anim[rq->wIndex.bytes[0]] );
}
}

View file

@ -18,6 +18,8 @@
#include "globals.h"
#include "type.h"
/*
This example should run on most AVRs with only little changes. No special
hardware resources except INT0 are used. You may have to change usbconfig.h for
@ -58,7 +60,9 @@ void init_usb(void);
uint32_t eep_anim[32] EEMEM;
// usb buffer
extern uint32_t cube; // Framebuffer
extern uint32_t frame; // Framebuffer
//extern cube_t *cube;
#endif // __usb_h__