Esempio n. 1
0
allocate_buffer P1(int, size)
{
    buffer_t *buf;

#ifndef DISALLOW_BUFFER_TYPE
    if ((size < 0) || (size > max_buffer_size)) {
	error("Illegal buffer size.\n");
    }
    if (size == 0) {
	return null_buffer();
    }
    /* using calloc() so that memory will be zero'd out when allocated */
    buf = (buffer_t *) DCALLOC(sizeof(buffer_t) + size - 1, 1,
				    TAG_BUFFER, "allocate_buffer");
    buf->size = size;
    buf->ref = 1;
    return buf;
#else
    return NULL;
#endif
}
Esempio n. 2
0
/* Main Function */
int main(void){
	
	enum states{
		setup,
		drawing,
		readusart,
	} currentstate = setup;

	unsigned char STRING1[]="YAY THIS";
	unsigned char STRING2[]="WORKS!!!";
	unsigned char STR1CMP[9];
	unsigned char STR2CMP[9];
	unsigned char x, i, j;
	unsigned char send[50];
				
	while(1){
	
		switch(currentstate){
			case setup:
				initialize();
				clearArray();
				PORTB = 0b10000000;
				PORTC |= 0b10000000;
				ht1632_initialize();
				PORTC |= 0b01000000;
				InitializeUART();
				PORTC |= 0b00100000;
				
				sprintf(send, "Initialized...\n");
				PORTC |= 0b00010000;
				SendStringUART(send);
				_delay_ms(200);
				PORTC = 0;
				strcpy(STRING1, "YAY THIS");
				strcpy(STRING2, "WORKS!!!");
				currentstate = drawing;
				break;
			case drawing:
				for(x=1;x<sizeof(STRING1);x++) {
					null_buffer();
					for(i=0;i<8;i++){
						for(j=0;j<8;j++){
							set_buffer(STRING1[x-1]);
							if (~buffer[i][j] & (1<<0)) {
                                ht1632_plot(j+(8*(x-1))-1,i,GREEN);
								PORTC = ~PORTC;
							} else {
								ht1632_plot(j+(8*(x-1))-1,i,BLACK);
								PORTC = ~PORTC;
							}
						}
					}
				}
				for(x=1;x<sizeof(STRING2);x++) {
					null_buffer();
					for(i=0;i<8;i++){
						for(j=0;j<8;j++){
							set_buffer(STRING2[x-1]);
							if (~buffer[i][j] & (1<<0)) {
                                ht1632_plot(j+(8*(x-1))-1,i+8,GREEN);
								PORTC = ~PORTC;
							} else {
								ht1632_plot(j+(8*(x-1))-1,i+8,BLACK);
								PORTC = ~PORTC;
							}
						}
					}
				}
				PORTC = 0;
				currentstate = readusart;
				break;
			case readusart:
				strcpy(STR1CMP, STRING1);
				strcpy(STR2CMP, STRING2);
				NewScreen(STRING1, STRING2);
				
				if((strcmp(STRING1, "RESETRES") == 0)){
					currentstate = setup;
				}else if((strcmp(STRING1, STR1CMP) != 0) | (strcmp(STRING2, STR2CMP) != 0)){
					currentstate = drawing;
				}
				
				break;
		}
	}
}