diff --git a/firmware/source/buffer.c b/firmware/source/buffer.c index 45402c0..faffb70 100644 --- a/firmware/source/buffer.c +++ b/firmware/source/buffer.c @@ -46,20 +46,44 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint16_t *rlen) switch (spacket->opcode) { - //opcodes which don't address a specific buffer object + //some opcodes place buffer number in misc/data + if ( (spacket->opcode > BUFFN_INMISC_MIN) && (spacket->opcode < BUFFN_INMISC_MAX) ) { + switch ( spacket->miscdata ) { + //2 buffers minimum support + case 0: called_buff = &buff0; break; + case 1: called_buff = &buff1; break; +# if ( defined(NUM_BUFFERS_4) || (defined(NUM_BUFFERS_8)) ) + //4-8 buffers + case 2: called_buff = &buff2; break; + case 3: called_buff = &buff3; break; +# endif +# ifdef NUM_BUFFERS_8 + //8 buffers + case 4: called_buff = &buff4; break; + case 5: called_buff = &buff5; break; + case 6: called_buff = &buff6; break; + case 7: called_buff = &buff7; break; +# endif + default: //opcode sent for non-existent buffer + rv[RV_ERR_IDX] = ERR_BUFN_DOES_NOT_EXIST; + } + } + + //now that buffer obtained, decode opcode and make call with called_buff if needed. case BUFF_OPCODE_NRV_MIN ... BUFF_OPCODE_NRV_MAX: - rv[RV_ERR_IDX] = buffer_opcode_no_return( spacket->opcode, NULL, + rv[RV_ERR_IDX] = buffer_opcode_no_return( spacket->opcode, called_buff, spacket->operandMSB, spacket->operandLSB, spacket->miscdata ); *rlen = 1; break; case BUFF_OPCODE_RV_MIN ... BUFF_OPCODE_RV_MAX: - rv[RV_ERR_IDX] = buffer_opcode_return( spacket->opcode, NULL, - spacket->operandMSB, spacket->operandLSB, spacket->miscdata, &rv[1] ); - *rlen = 2; + rv[RV_ERR_IDX] = buffer_opcode_return( spacket->opcode, called_buff, + spacket->operandMSB, spacket->operandLSB, spacket->miscdata, + &rv[RV_DATA0_IDX], rlen ); + // set *rlen in function depending on opcode break; - //opcodes which include designation of which buffer is being called in lower bits + //opcodes which include designation of which buffer is being called in lower bits of opcode case BUFF_OPCODE_BUFN_MIN ... BUFF_OPCODE_BUFN_MAX: //mask out last three bits to detect buffer being called based on opcode number switch ( (spacket->opcode) & 0x07) { @@ -84,7 +108,8 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint16_t *rlen) //now that we have pointer to buffer object call associated function switch ( spacket->opcode ) { case BUFF_OPCODE_BUFN_NRV_MIN ... BUFF_OPCODE_BUFN_NRV_MAX: - rv[RV_ERR_IDX] = buffer_opcode_buffnum_no_return( spacket->opcode, called_buff, + rv[RV_ERR_IDX] = buffer_opcode_buffnum_no_return( + spacket->opcode, called_buff, spacket->operandMSB, spacket->operandLSB, spacket->miscdata ); break; case BUFF_OPCODE_BUFN_RV_MIN ... BUFF_OPCODE_BUFN_RV_MAX: @@ -134,12 +159,28 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint16_t *rlen) * Post:function call complete. * Rtn: SUCCESS if opcode found, ERR_UNKN_BUFF_OPCODE_NRV if opcode not present. */ -uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff, uint8_t oper1, uint8_t oper2, uint8_t oper3 ) +uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata ) { switch (opcode) { case RAW_BUFFER_RESET: raw_buffer_reset(); break; + case SET_MEM_N_PART: + buff->mem_type = operMSB; + buff->part_num = operLSB; + break; + case SET_MULT_N_ADDMULT: + buff->multiple = operMSB; + buff->add_mult = operLSB; + break; + case SET_MAP_N_MAPVAR: + buff->mapper = operMSB; + buff->mapvar = operLSB; + break; + case SET_FUNCTION: + buff->function = operLSB; + break; default: //opcode doesn't exist return ERR_UNKN_BUFF_OPCODE_NRV; @@ -157,11 +198,34 @@ uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff, uint8_t oper1, ui * Post:function call complete. * Rtn: SUCCESS if opcode found, ERR_UNKN_BUFF_OPCODE_NRV if opcode not present. */ -uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff, uint8_t operMSB, uint8_t operLSB, uint8_t miscdata, uint8_t *rvalue ) +uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata, + uint8_t *rvalue, uint16_t *rlength ) { switch (opcode) { case RAW_BANK_STATUS: *rvalue = raw_bank_status[operLSB]; + *rlength += 1; + break; + case GET_PRI_ELEMENTS: + rvalue[0] = buff->size; + rvalue[1] = buff->status; + rvalue[2] = buff->cur_byte; + rvalue[3] = buff->reload; + rvalue[4] = buff->id; + rvalue[5] = buff->page_num; //pretty sure this assigns next line too + rvalue[6] = (buff->page_num>>8);//little endian + *rlength += 7; + break; + case GET_SEC_ELEMENTS: + rvalue[0] = buff->mem_type; + rvalue[1] = buff->part_num; + rvalue[2] = buff->multiple; + rvalue[3] = buff->add_mult; + rvalue[4] = buff->mapper; + rvalue[5] = buff->mapvar; + rvalue[6] = buff->function; + *rlength += 7; break; default: //opcode doesn't exist @@ -182,11 +246,18 @@ uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff, uint8_t operMSB, uin * Post:function call complete. * Rtn: SUCCESS if opcode found, ERR_UNKN_BUFF_OPCODE_BUFN_NRV if opcode not present. */ -uint8_t buffer_opcode_buffnum_no_return( uint8_t opcode, buffer *buff, uint8_t oper1, uint8_t oper2, uint8_t oper3 ) +uint8_t buffer_opcode_buffnum_no_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata ) { switch (opcode) { case ALLOCATE_BUFFER0 ... ALLOCATE_BUFFER7: - return allocate_buffer( buff, oper1, oper2, oper3 ); + return allocate_buffer( buff, operMSB, operLSB, miscdata ); + //uint8_t allocate_buffer( *buff, new_id, base_bank, num_banks ) + break; + case SET_RELOAD_PAGENUM0 ... SET_RELOAD_PAGENUM7: + buff->reload = miscdata; + buff->page_num = (operMSB<<8); + buff->page_num |= operLSB; break; default: //opcode doesn't exist diff --git a/firmware/source/buffer.h b/firmware/source/buffer.h index 465f0d0..b82e04b 100644 --- a/firmware/source/buffer.h +++ b/firmware/source/buffer.h @@ -10,9 +10,16 @@ uint8_t * buffer_usb_call( setup_packet *spacket, uint8_t *rv, uint16_t *rlen); -uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff, uint8_t oper1, uint8_t oper2, uint8_t oper3 ); -uint8_t buffer_opcode_buffnum_no_return( uint8_t opcode, buffer *buff, uint8_t oper1, uint8_t oper2, uint8_t oper3 ); -uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff, uint8_t operMSB, uint8_t operLSB, uint8_t miscdata, uint8_t *rvalue ); +uint8_t buffer_opcode_no_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata ); + +uint8_t buffer_opcode_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata, + uint8_t *rvalue, uint16_t *rlength ); + +uint8_t buffer_opcode_buffnum_no_return( uint8_t opcode, buffer *buff, + uint8_t operMSB, uint8_t operLSB, uint8_t miscdata ); + void raw_buffer_reset( ); uint8_t allocate_buffer( buffer *buff, uint8_t new_id, uint8_t base_bank, uint8_t num_banks ); diff --git a/firmware/source/logic.h b/firmware/source/logic.h index 0eddc1c..3232778 100644 --- a/firmware/source/logic.h +++ b/firmware/source/logic.h @@ -1,7 +1,7 @@ #ifndef _logic_h #define _logic_h -#define NULL 0x00 +#define NILL 0x00 #define LO 0x00 #define HI 0xFF diff --git a/host/source/test.c b/host/source/test.c index 1d0831e..0ec9cd6 100644 --- a/host/source/test.c +++ b/host/source/test.c @@ -9,9 +9,9 @@ int test_function( USBtransfer *transfer ) dictionary_call( transfer, BUFFER, RAW_BUFFER_RESET, 0, 0, USB_IN, NULL, 0); dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0, USB_IN, NULL, 0); debug("allocate buff0 256B"); //id:basebank num32B banks - dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER0, 0x1000, 4, USB_IN, NULL, 0); + dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER0, 0x1000, 8, USB_IN, NULL, 0); debug("allocate buff1 256B"); //id:basebank num32B banks - dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER1, 0x2004, 4, USB_IN, NULL, 0); + dictionary_call( transfer, BUFFER, ALLOCATE_BUFFER1, 0x2008, 8, USB_IN, NULL, 0); debug("status"); //id:basebank num32B banks dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 0, 0, USB_IN, NULL, 0); dictionary_call( transfer, BUFFER, RAW_BANK_STATUS, 4, 0, USB_IN, NULL, 0); @@ -65,9 +65,9 @@ int test_function( USBtransfer *transfer ) clock_t tstart, tstop; tstart = clock(); - //for ( i = (1024 * 2); i>0; i--) { - for ( i = (1033 * 2); i>0; i--) { - dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_IN, load_out, 254); + for ( i = (1024 * 2); i>0; i--) { + //for ( i = (1033 * 2); i>0; i--) { + dictionary_call( transfer, BUFFER, BUFF_PAYLOAD0, 0, 0, USB_OUT, load_out, 254); } tstop = clock(); float timediff = ( (float)(tstop-tstart) / CLOCKS_PER_SEC); diff --git a/shared/shared_dict_buffer.h b/shared/shared_dict_buffer.h index 7a0e5d2..937d0be 100644 --- a/shared/shared_dict_buffer.h +++ b/shared/shared_dict_buffer.h @@ -40,8 +40,8 @@ //current max is 8, but only really limited by opcode definitions to address all buffers //makes #ifdef code simpler to only allow buffer numbers that are power of 2 //#define NUM_BUFFERS_2 2 -//#define NUM_BUFFERS_4 4 -#define NUM_BUFFERS_8 8 +#define NUM_BUFFERS_4 4 +//#define NUM_BUFFERS_8 8 //defined here so identical to host and firmware //status values @@ -68,6 +68,9 @@ #define BUFF_OPCODE_NRV_MIN 0x00 #define BUFF_OPCODE_NRV_MAX 0x3F // +#define BUFFN_INMISC_MIN 0x30 //overlaps above +#define BUFFN_INMISC_MAX 0x4F //overlaps below +// #define BUFF_OPCODE_RV_MIN 0x40 #define BUFF_OPCODE_RV_MAX 0x7F //============================================================================================= @@ -75,12 +78,72 @@ //blindly clear all allocation of raw buffer space //reset all buffers to unallocated +//no operands no return value #define RAW_BUFFER_RESET 0x00 + + +//SET BUFFER ELEMENTS + +//memory type and part number +//miscdata: buffer number +//operMSB: memory type +//operLSB: part number +#define SET_MEM_N_PART 0x30 + +//set multiple and add multiple +//miscdata: buffer number +//operMSB: multiple +//operLSB: add multiple +#define SET_MULT_N_ADDMULT 0x31 + +//set mapper and mapper variant +//miscdata: buffer number +//operMSB: mapper +//operLSB: mapper variant +#define SET_MAP_N_MAPVAR 0x32 + +//set function +//miscdata: buffer number +//operMSB: (might be needed if this is a ponter..?) or might need more than one function def.. +//operLSB: function +#define SET_FUNCTION 0x33 + + + + +//return buffer elements +//misc/data: buffer number +//rv0: success/error code +//rv1: size +//rv2: status +//rv3: cur_byte +//rv4: reload +//rv5: id +//rv76: page_num +#define GET_PRI_ELEMENTS 0x40 + +//return buffer elements +//misc/data: buffer number +//rv0: success/error code +//rv1: mem_type +//rv2: part_num +//rv3: multiple +//rv4: add_multiple +//rv5: mapper +//rv6: mapvar +//rv7: function +#define GET_SEC_ELEMENTS 0x41 + + + //send bank number and read back it's status //0xFF-UNALLOC //gets assigned buffer ID number when allocated -#define RAW_BANK_STATUS 0x40 +//operandMSB/miscdata: unused +//operandLSB: raw bank number to retrieve status of +//return value status of that raw bank (set to bank id if allocated) +#define RAW_BANK_STATUS 0x50 //============================================================================================= // OPCODES with up to 24bit operand and no return value besides SUCCESS/ERROR_CODE @@ -107,6 +170,10 @@ //base address 0-255 (in 32byte chunks) //returns SUCCESS if able to allocate //returns error code if unable to allocate +//operMSB: id to give to new buffer +// (upper id bits used to set any address bits not covered by page and buff size if needed) +//operLSB: base bank number +//misc/data: size (number of banks to allocate to buffer) #define ALLOCATE_BUFFER0 0x80 #define ALLOCATE_BUFFER1 0x81 #define ALLOCATE_BUFFER2 0x82 @@ -117,8 +184,24 @@ #define ALLOCATE_BUFFER7 0x87 +//SET BUFFER ELEMENTS + +//set reload and page_num +//misc/data reload +//operMSB:LSB page_num (16 bit) +#define SET_RELOAD_PAGENUM0 0x90 +#define SET_RELOAD_PAGENUM1 0x91 +#define SET_RELOAD_PAGENUM2 0x92 +#define SET_RELOAD_PAGENUM3 0x93 +#define SET_RELOAD_PAGENUM4 0x94 +#define SET_RELOAD_PAGENUM5 0x95 +#define SET_RELOAD_PAGENUM6 0x96 +#define SET_RELOAD_PAGENUM7 0x97 + + //designate what buffer to fill with opcode //endpoint direction determines if read/write +//no operands no return value aside from payload for transfer IN #define BUFF_PAYLOAD0 0xF0 #define BUFF_PAYLOAD1 0xF1 #define BUFF_PAYLOAD2 0xF2