void SingleSendBuffer::insert_fragment(SequenceNumber sequence, SequenceNumber fragment, TransportSendStrategy::QueueType* queue, ACE_Message_Block* chain) { check_capacity(); // Insert into buffers_ so that the overall capacity is maintained // The entry in buffers_ with two null pointers indicates that the // actual data is stored in fragments_[sequence]. buffers_[sequence] = std::make_pair(static_cast<QueueType*>(0), static_cast<ACE_Message_Block*>(0)); BufferType& buffer = fragments_[sequence][fragment]; insert_buffer(buffer, queue, chain); if (Transport_debug_level > 5) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) SingleSendBuffer::insert_fragment() - ") ACE_TEXT("saved PDU: %q,%q as buffer(0x%@,0x%@)\n"), sequence.getValue(), fragment.getValue(), buffer.first, buffer.second )); } }
void add_buffer_to_sym(char *buffer,InputItem *sym) { if (gInInsertMode) insert_buffer(buffer, sym); else overwrite_buffer(buffer, sym); }
void *insert_full_table( BUFFER *complete_font, OTF_TABLE_RECORD *head_entry, BUFFER *insert_me ) { buffer_alloc( complete_font, 4 - ( complete_font->position % 4 ) ); /* Pad to a multiple of 4 */ void *table = &complete_font->data[complete_font->position]; head_entry->offset = complete_font->position; head_entry->length = insert_me->position; insert_buffer( complete_font, insert_me ); free_buffer( insert_me ); return table; }
/* The offsets are where the blocks would have been if the top dict hadn't held their offsets - that is, if this function returned a 0-byte buffer. */ BUFFER *make_topdict_offsets( PRIVATE_DICT_OFFSETS *offsets ) { /* First, decide how many bytes this will take. */ BUFFER *private_len_enc = encode_charstring_number( offsets->private_len ); int guessed_len = 8 + private_len_enc->position; /* Absolute minimum */ int calculated_len = guessed_len; do { guessed_len = calculated_len; calculated_len = 4 + private_len_enc->position; /* Operators */ calculated_len += get_encoded_charstring_len( offsets->charstrings_pos + guessed_len ); calculated_len += get_encoded_charstring_len( offsets->private_pos + guessed_len ); calculated_len += get_encoded_charstring_len( offsets->encoding_pos + guessed_len ); calculated_len += get_encoded_charstring_len( offsets->charset_pos + guessed_len ); } while ( guessed_len != calculated_len ); BUFFER *res = makebuffer( calculated_len ); BUFFER *charstring_enc = encode_charstring_number( offsets->charstrings_pos + calculated_len ); BUFFER *private_enc = encode_charstring_number( offsets->private_pos + calculated_len ); BUFFER *encoding_enc = encode_charstring_number( offsets->encoding_pos + calculated_len ); BUFFER *charset_enc = encode_charstring_number( offsets->charset_pos + calculated_len ); insert_buffer( res, charstring_enc ); put_int8( res, 17 ); insert_buffer( res, private_len_enc ); insert_buffer( res, private_enc ); put_int8( res, 18 ); insert_buffer( res, encoding_enc ); put_int8( res, 16 ); insert_buffer( res, charset_enc ); put_int8( res, 15 ); free_buffer( charstring_enc ); free_buffer( private_enc ); free_buffer( private_len_enc ); free_buffer( encoding_enc) ; free_buffer( charset_enc ); return res; }
BUFFER *set_table_name( struct names *font_names ) { uint32_t records_in_total = 16; /* Eight name records in two formats. */ BUFFER *name_buf = makebuffer( sizeof( OTF_TABLE_NAME ) ); BUFFER *rec_buf = makebuffer( sizeof( NAME_RECORD ) * records_in_total ); BUFFER *stringbuf = makebuffer( BUFSIZE ); BUFFER *return_buf = makebuffer( BUFSIZE ); OTF_TABLE_NAME *t_nametable = buffer_alloc( name_buf, sizeof( OTF_TABLE_NAME ) ); t_nametable->format = 0; t_nametable->count = htons( records_in_total ); t_nametable->stringOffset = htons( sizeof( OTF_TABLE_NAME ) + ( sizeof( NAME_RECORD ) * records_in_total ) ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->copyrightNotice, 1, 0, 0, 0 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->fontFamilyName, 1, 0, 0, 1 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->fontFamilyStyle, 1, 0, 0, 2 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->uniqueFontName, 1, 0, 0, 3 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->fullFontName, 1, 0, 0, 4 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->versionString, 1, 0, 0, 5 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->postscriptName, 1, 0, 0, 6 ); put_namerecord( rec_buf, stringbuf, ( char* ) font_names->foundryVendorID, 1, 0, 0, 8 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->copyrightNotice, 3, 1, 1033, 0 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->fontFamilyName, 3, 1, 1033, 1 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->fontFamilyStyle, 3, 1, 1033, 2 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->uniqueFontName, 3, 1, 1033, 3 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->fullFontName, 3, 1, 1033, 4 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->versionString, 3, 1, 1033, 5 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->postscriptName, 3, 1, 1033, 6 ); put_namerecord_w( rec_buf, stringbuf, ( char* ) font_names->foundryVendorID , 3, 1, 1033, 8 ); insert_buffer( return_buf, name_buf ); free_buffer( name_buf ); insert_buffer( return_buf, rec_buf ); free_buffer( rec_buf ); insert_buffer( return_buf, stringbuf ); free_buffer( stringbuf ); return return_buf; }
int yank_from_kill_buffer( void ) { int count = arg; int i; if( input_mode == 1 ) gui_input_mode_before_insert(); if( cur_exec != 0 && cur_exec->p_nargs > 0 ) count = count * numeric_arg( 1 ); for( i=1; i<=count ; ++i ) insert_buffer( kill_buffer_str ); return 0; }
void SingleSendBuffer::insert(SequenceNumber sequence, TransportSendStrategy::QueueType* queue, ACE_Message_Block* chain) { check_capacity(); BufferType& buffer = this->buffers_[sequence]; insert_buffer(buffer, queue, chain); if (Transport_debug_level > 5) { ACE_DEBUG((LM_DEBUG, ACE_TEXT("(%P|%t) SingleSendBuffer::insert() - ") ACE_TEXT("saved PDU: %q as buffer(0x%@,0x%@)\n"), sequence.getValue(), buffer.first, buffer.second )); } }
extern int insert_buffer_critical_path(lofig_list* lofig, int optim_level) { ptype_list* ptype; losig_list* losig; ptype_list* long_path; long count=0; long index=0; int change=1; /*search new index*/ for (losig = lofig->LOSIG; losig; losig = losig->NEXT) { if (index < losig->INDEX) index = losig->INDEX; } if (index!=0) index++; /*relaxation algorithm*/ while (change) { change=0; /*too dangerous to put some buffer on clock!!!*/ long_path=critical_path_without_clock(lofig); long_path=sort_capa(long_path); /* on all signals of the critical path, improve capa*/ for (ptype=long_path; ptype; ptype=ptype->NEXT) { losig=(losig_list*) ptype->DATA; if (insert_buffer(losig, lofig, optim_level, index)) { count++; index++; change=1; break; } } freeptype(long_path); } return count; }
struct cff_result *set_table_cff( struct names* font_names ) { struct cff_result *result = ( struct cff_result* ) malloc( sizeof( struct cff_result ) ); BUFFER *cff_buffer = makebuffer( BUFSIZE ); CFF_HEADER *cff_header = buffer_alloc( cff_buffer, sizeof( CFF_HEADER ) ); cff_header->majorVersion = 1; cff_header->minorVersion = 0; cff_header->headerSize = 4; cff_header->offsetSize = 1; CFF_INDEX_SINGLE_ENTRY *cff_index_name = buffer_alloc( cff_buffer, sizeof( CFF_INDEX_SINGLE_ENTRY ) ); cff_index_name->count = htons( 1 ); cff_index_name->offsetSize = 1; cff_index_name->offset = 1; cff_index_name->length = strlen( font_names->postscriptName ) + 1; copy_string_to_buffer( cff_buffer, font_names->postscriptName ); CFF_INDEX_SINGLE_ENTRY *cff_index_dict = buffer_alloc( cff_buffer, sizeof( CFF_INDEX_SINGLE_ENTRY ) ); cff_index_dict->count = htons( 1 ); cff_index_dict->offsetSize = 1; cff_index_dict->offset = 1; /* There are 390 standard strings. * String IDs above 390 refer to string N-390 in the index. * (That is: 391 is the first, etc.) */ uint8_t magic1[] = { 0xf8, 0x1b, /* 391 : String 0 */ 0x00, /* 0 : Operator "version"*/ 0xf8, 0x1c, /* 392 : String 1 */ 0x02, /* 2 : Operator "FullName" */ 0xf8, 0x1d, /* 393 : String 2 */ 0x03, /* 3 : Operator "FamilyName" */ 0xf8,0x19, /* 389 : "Roman" */ 0x04, /* 4 : Operator "Weight" */ 0x1c, 0x6f, 0x00, /* 28416 */ 0x0d, /* 13 : Operator "UniqueID" */ 0xfb, 0x3c, /* -168 */ 0xfb, 0x6e, /* -218 */ 0xfa, 0x7c, /* 1000 */ 0xfa, 0x16, /* 898 */ 0x05, /* 5 : Operator "FontBBox" */ }; /* Private dict, as specified in the Compact Font Format. * Constant, since it only describes aspects of the glyphs. */ uint8_t magic2[] = { 0x7d, /* -14 */ 0x99, /* 14 */ 0xf9, 0x2a, /* 662 */ 0x99, /* 14 */ 0xfb, 0x76, /* -226 */ 0x95, /* 10 */ 0xf7, 0x73, /* 223 */ 0x8b, /* 0 */ 0x06, /* BlueValues */ 0xf7, 0x9a, /* 262 */ 0x93, /* 8 */ 0xfc, 0x7c, /* -488 */ 0x8c, /* 1 */ 0x07, /* OtherBlues */ 0x7d, /* -14 */ 0x99, /* 14 */ 0xf8, 0x56, /* 450 */ 0x95, /* 10 */ 0xf7, 0x5e, /* 202 */ 0x99, /* 14 */ 0x08, /* FamilyBlues */ 0xfb, 0x6e, /* -218 */ 0x8c, /* 1 */ 0xf8, 0x73, /* 479 */ 0x93, /* 8 */ 0xf7, 0x10, /* 124 */ 0x8b, /* 0 */ 0x09, /* FamilyOtherBlues */ 0xa7, /* 28 */ 0x0a, /* StdHW */ 0xdf, /* 84 */ 0x0b, /* StdVW */ 0xf7, 0x1f, /* 139 */ 0x14 /* defaultWidthX */ }; uint8_t *magic_here = buffer_alloc( cff_buffer, sizeof( magic1 ) ); memcpy( magic_here, magic1, sizeof( magic1 ) ); PRIVATE_DICT_OFFSETS pd_offsets; pd_offsets.charstrings_pos = cff_buffer->position + sizeof( CFF_INDEX_STRING ) + strlen( "001.007" ) + strlen( font_names->fullFontName ) + strlen( font_names->fontFamilyName ) + sizeof( CFF_INDEX_EMPTY ); pd_offsets.private_pos = pd_offsets.charstrings_pos + sizeof( CFF_INDEX_CHARS ) + 4; pd_offsets.encoding_pos = pd_offsets.private_pos + sizeof( magic2 ); pd_offsets.charset_pos = pd_offsets.encoding_pos + 5; pd_offsets.private_len = sizeof( magic2 ); BUFFER *topdict_offsets = make_topdict_offsets( &pd_offsets ); insert_buffer( cff_buffer, topdict_offsets ); cff_index_dict->length = sizeof( magic1 ) + topdict_offsets->position + 1; free_buffer( topdict_offsets ); CFF_INDEX_STRING *cff_index_string = buffer_alloc( cff_buffer, sizeof( CFF_INDEX_STRING ) ); cff_index_string->count = htons( 3 ); cff_index_string->offsetSize = 1; cff_index_string->offset1 = 1; cff_index_string->offset2 = strlen( "001.007" ) + cff_index_string->offset1; cff_index_string->offset3 = strlen( font_names->fullFontName ) + cff_index_string->offset2; cff_index_string->length = cff_index_string->offset3 + strlen( font_names->fontFamilyName ); copy_string_to_buffer( cff_buffer, "001.007" ); /* SID for "space" and "ampersand" replace 7 with 0 for ".notdef", maybe? */ copy_string_to_buffer( cff_buffer, font_names->fullFontName ); copy_string_to_buffer( cff_buffer, font_names->fontFamilyName ); CFF_INDEX_EMPTY *cff_index_gsubrs = buffer_alloc( cff_buffer, sizeof( CFF_INDEX_EMPTY ) ); cff_index_gsubrs->count = htons( 0 ); CFF_INDEX_CHARS *cff_index_chars = buffer_alloc( cff_buffer, sizeof( CFF_INDEX_CHARS ) ); cff_index_chars->count = htons( 4 ); cff_index_chars->offsetSize = 1; cff_index_chars->offset1 = 1; cff_index_chars->offset2 = 2; cff_index_chars->offset3 = 3; cff_index_chars->offset4 = 4; cff_index_chars->length = 5; /* Fill in two end characters in the buffer * Recommended as in http://www.microsoft.com/typography/otspec/recom.htm (First Four Glyphs in Fonts) * .notdef, .null, CR, and space */ uint16_t *endchars = buffer_alloc( cff_buffer, 2 ); uint16_t *endchars2 = buffer_alloc( cff_buffer, 2 ); *endchars = 0x0e0e; *endchars2 = 0x0e0e; /* Private dict here */ uint8_t *magic2_here = buffer_alloc( cff_buffer, sizeof( magic2 ) ); memcpy( magic2_here, magic2, sizeof( magic2 ) ); /* encoding */ buffer_alloc( cff_buffer, 1 ); /* Format = 0 */ uint8_t *encodingCount = buffer_alloc( cff_buffer, 1 ); *encodingCount = 3; uint8_t *encoding = buffer_alloc( cff_buffer, 3 ); encoding[0] = 0; /* null */ encoding[1] = '\n'; /* CR */ encoding[2] = ' '; /* space */ /* character set */ buffer_alloc( cff_buffer, 0 ); /* format = 0 */ uint16_t *charset_target = buffer_alloc( cff_buffer, 4 * sizeof( uint16_t ) ); uint16_t charset[4] = { 0, 0, 0, 0 }; memcpy( charset_target, charset, 4 * sizeof( uint16_t ) ); result->cffData = cff_buffer; result->indexChars = cff_index_chars; return result; }
/** * Control ISR */ static interrupt void isr_controller(void) { static float temp[4]; static uint16_t i; SET_DEBUG_GPIO1; temp[0] = 0.0; temp[1] = 0.0; temp[2] = 0.0; temp[3] = 0.0; /// Get HRADC samples for(i = 0; i < decimation_factor; i++) { temp[0] += (float) *(HRADCs_Info.HRADC_boards[0].SamplesBuffer++); temp[1] += (float) *(HRADCs_Info.HRADC_boards[1].SamplesBuffer++); temp[2] += (float) *(HRADCs_Info.HRADC_boards[2].SamplesBuffer++); temp[3] += (float) *(HRADCs_Info.HRADC_boards[3].SamplesBuffer++); } //CLEAR_DEBUG_GPIO1; HRADCs_Info.HRADC_boards[0].SamplesBuffer = buffers_HRADC[0]; HRADCs_Info.HRADC_boards[1].SamplesBuffer = buffers_HRADC[1]; HRADCs_Info.HRADC_boards[2].SamplesBuffer = buffers_HRADC[2]; HRADCs_Info.HRADC_boards[3].SamplesBuffer = buffers_HRADC[3]; temp[0] *= HRADCs_Info.HRADC_boards[0].gain * decimation_coeff; temp[0] += HRADCs_Info.HRADC_boards[0].offset; temp[1] *= HRADCs_Info.HRADC_boards[1].gain * decimation_coeff; temp[1] += HRADCs_Info.HRADC_boards[1].offset; temp[2] *= HRADCs_Info.HRADC_boards[2].gain * decimation_coeff; temp[2] += HRADCs_Info.HRADC_boards[2].offset; temp[3] *= HRADCs_Info.HRADC_boards[3].gain * decimation_coeff; temp[3] += HRADCs_Info.HRADC_boards[3].offset; V_CAPBANK_MOD_A = temp[0]; IOUT_RECT_MOD_A = temp[1]; V_CAPBANK_MOD_B = temp[2]; IOUT_RECT_MOD_B = temp[3]; /******** Timeslicer for controllers *********/ RUN_TIMESLICER(TIMESLICER_CONTROLLER) /*********************************************/ /// Run notch filters for capacitor bank voltage feedback run_dsp_iir_2p2z(NOTCH_FILT_2HZ_V_CAPBANK_MOD_A); run_dsp_iir_2p2z(NOTCH_FILT_4HZ_V_CAPBANK_MOD_A); run_dsp_iir_2p2z(NOTCH_FILT_2HZ_V_CAPBANK_MOD_B); run_dsp_iir_2p2z(NOTCH_FILT_4HZ_V_CAPBANK_MOD_B); /// Check whether power supply is ON if(g_ipc_ctom.ps_module[0].ps_status.bit.state > Interlock) { /// Calculate reference according to operation mode switch(g_ipc_ctom.ps_module[0].ps_status.bit.state) { case SlowRef: case SlowRefSync: { run_dsp_srlim(SRLIM_V_CAPBANK_REFERENCE, USE_MODULE); break; } case Cycle: { /*run_dsp_srlim(SRLIM_SIGGEN_AMP, USE_MODULE); run_dsp_srlim(SRLIM_SIGGEN_OFFSET, USE_MODULE); SIGGEN.p_run_siggen(&SIGGEN); break;*/ } case RmpWfm: { break; } case MigWfm: { break; } default: { break; } } /// Open-loop if(g_ipc_ctom.ps_module[0].ps_status.bit.openloop) { SATURATE(V_CAPBANK_REFERENCE, MAX_REF_OL, MIN_REF_OL); DUTY_CYCLE_MOD_A = 0.01 * V_CAPBANK_REFERENCE; SATURATE(DUTY_CYCLE_MOD_A, PWM_MAX_DUTY_OL, PWM_MIN_DUTY_OL); DUTY_CYCLE_MOD_B = DUTY_CYCLE_MOD_A; } /// Closed-loop else { /// Run capacitor bank voltage control law SATURATE(g_ipc_ctom.ps_module[0].ps_reference, MAX_REF, MIN_REF); run_dsp_error(ERROR_V_CAPBANK_MOD_A); run_dsp_pi(PI_CONTROLLER_V_CAPBANK_MOD_A); run_dsp_error(ERROR_V_CAPBANK_MOD_B); run_dsp_pi(PI_CONTROLLER_V_CAPBANK_MOD_B); /// Run rectifier output current control law run_dsp_error(ERROR_IOUT_RECT_MOD_A); run_dsp_iir_2p2z(RESSONANT_2HZ_CONTROLLER_IOUT_RECT_MOD_A); run_dsp_iir_2p2z(RESSONANT_4HZ_CONTROLLER_IOUT_RECT_MOD_A); run_dsp_pi(PI_CONTROLLER_IOUT_RECT_MOD_A); SATURATE(DUTY_CYCLE_MOD_A, PWM_MAX_DUTY, PWM_MIN_DUTY); run_dsp_error(ERROR_IOUT_RECT_MOD_B); run_dsp_iir_2p2z(RESSONANT_2HZ_CONTROLLER_IOUT_RECT_MOD_B); run_dsp_iir_2p2z(RESSONANT_4HZ_CONTROLLER_IOUT_RECT_MOD_B); run_dsp_pi(PI_CONTROLLER_IOUT_RECT_MOD_B); SATURATE(DUTY_CYCLE_MOD_B, PWM_MAX_DUTY, PWM_MIN_DUTY); } set_pwm_duty_chA(PWM_MODULATOR_MOD_A, DUTY_CYCLE_MOD_A); set_pwm_duty_chA(PWM_MODULATOR_MOD_B, DUTY_CYCLE_MOD_B); } /*********************************************/ END_TIMESLICER(TIMESLICER_CONTROLLER) /*********************************************/ /******** Timeslicer for samples buffer ******/ RUN_TIMESLICER(TIMESLICER_BUFFER) /*********************************************/ insert_buffer(BUF_SAMPLES, IOUT_RECT_MOD_A); insert_buffer(BUF_SAMPLES, DUTY_CYCLE_MOD_A); insert_buffer(BUF_SAMPLES, IOUT_RECT_MOD_B); insert_buffer(BUF_SAMPLES, DUTY_CYCLE_MOD_B); /*********************************************/ END_TIMESLICER(TIMESLICER_BUFFER) /*********************************************/ CLEAR_DEBUG_GPIO1; PWM_MODULATOR_MOD_A->ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all |= M_INT3; }
interrupt void isr_controller(void) { static float temp[4]; static uint16_t i; SET_DEBUG_GPIO1; temp[0] = 0.0; temp[1] = 0.0; temp[2] = 0.0; temp[3] = 0.0; /// Get HRADC samples for(i = 0; i < decimation_factor; i++) { temp[0] += (float) *(HRADCs_Info.HRADC_boards[0].SamplesBuffer++); temp[1] += (float) *(HRADCs_Info.HRADC_boards[1].SamplesBuffer++); temp[2] += (float) *(HRADCs_Info.HRADC_boards[2].SamplesBuffer++); temp[3] += (float) *(HRADCs_Info.HRADC_boards[3].SamplesBuffer++); } //CLEAR_DEBUG_GPIO1; HRADCs_Info.HRADC_boards[0].SamplesBuffer = buffers_HRADC[0]; HRADCs_Info.HRADC_boards[1].SamplesBuffer = buffers_HRADC[1]; HRADCs_Info.HRADC_boards[2].SamplesBuffer = buffers_HRADC[2]; HRADCs_Info.HRADC_boards[3].SamplesBuffer = buffers_HRADC[3]; temp[0] *= HRADCs_Info.HRADC_boards[0].gain * decimation_coeff; temp[0] += HRADCs_Info.HRADC_boards[0].offset; temp[1] *= HRADCs_Info.HRADC_boards[1].gain * decimation_coeff; temp[1] += HRADCs_Info.HRADC_boards[1].offset; temp[2] *= HRADCs_Info.HRADC_boards[2].gain * decimation_coeff; temp[2] += HRADCs_Info.HRADC_boards[2].offset; temp[3] *= HRADCs_Info.HRADC_boards[3].gain * decimation_coeff; temp[3] += HRADCs_Info.HRADC_boards[3].offset; I_LOAD_1 = temp[0]; I_LOAD_2 = temp[1]; I_LOAD_MEAN = 0.5*(I_LOAD_1 + I_LOAD_2); I_LOAD_DIFF = I_LOAD_1 - I_LOAD_2; g_controller_ctom.net_signals[10].f = temp[2]; g_controller_ctom.net_signals[11].f = temp[3]; /// Check whether power supply is ON if(g_ipc_ctom.ps_module[0].ps_status.bit.state > Interlock) { /// Calculate reference according to operation mode switch(g_ipc_ctom.ps_module[0].ps_status.bit.state) { case SlowRef: case SlowRefSync: { run_dsp_srlim(SRLIM_I_LOAD_REFERENCE, USE_MODULE); break; } case Cycle: { run_dsp_srlim(SRLIM_SIGGEN_AMP, USE_MODULE); run_dsp_srlim(SRLIM_SIGGEN_OFFSET, USE_MODULE); SIGGEN.p_run_siggen(&SIGGEN); break; } case RmpWfm: { switch(WFMREF.sync_mode) { case OneShot: { /*********************************************/ RUN_TIMESLICER(TIMESLICER_WFMREF) if( WFMREF.wfmref_data.p_buf_idx <= WFMREF.wfmref_data.p_buf_end) { I_LOAD_REFERENCE = *(WFMREF.wfmref_data.p_buf_idx++) * (WFMREF.gain) + WFMREF.offset; } END_TIMESLICER(TIMESLICER_WFMREF) /*********************************************/ break; } case SampleBySample: case SampleBySample_OneCycle: { if(WFMREF.wfmref_data.p_buf_idx <= WFMREF.wfmref_data.p_buf_end) { I_LOAD_REFERENCE = *(WFMREF.wfmref_data.p_buf_idx) * (WFMREF.gain) + WFMREF.offset; } break; } } break; } case MigWfm: { break; } default: { break; } } /// Open-loop if(g_ipc_ctom.ps_module[0].ps_status.bit.openloop) { SATURATE(I_LOAD_REFERENCE, MAX_REF_OL, MIN_REF_OL); DUTY_CYCLE_MOD_1 = 0.01 * I_LOAD_REFERENCE; SATURATE(DUTY_CYCLE_MOD_1, PWM_MAX_DUTY_OL, PWM_MIN_DUTY_OL); } /// Closed-loop else { SATURATE(I_LOAD_REFERENCE, MAX_REF, MIN_REF); run_dsp_error(ERROR_I_LOAD); run_dsp_pi(PI_CONTROLLER_I_LOAD); //run_dsp_iir_2p2z(IIR_2P2Z_CONTROLLER_I_LOAD); SATURATE(DUTY_CYCLE_MOD_1, PWM_MAX_DUTY, PWM_MIN_DUTY); } DUTY_CYCLE_MOD_2 = DUTY_CYCLE_MOD_1; DUTY_CYCLE_MOD_3 = DUTY_CYCLE_MOD_1; DUTY_CYCLE_MOD_4 = DUTY_CYCLE_MOD_1; /** * TODO: for 8 modules, create new function to set duty on channel B, * used by modules 5, 6, 7 and 8. */ set_pwm_duty_hbridge(PWM_MODULATOR_Q1_MOD_1_5, DUTY_CYCLE_MOD_1); set_pwm_duty_hbridge(PWM_MODULATOR_Q1_MOD_2_6, DUTY_CYCLE_MOD_2); set_pwm_duty_hbridge(PWM_MODULATOR_Q1_MOD_3_7, DUTY_CYCLE_MOD_3); set_pwm_duty_hbridge(PWM_MODULATOR_Q1_MOD_4_8, DUTY_CYCLE_MOD_4); } /*********************************************/ RUN_TIMESLICER(TIMESLICER_BUFFER) /*********************************************/ insert_buffer(BUF_SAMPLES, I_LOAD_1); //insert_buffer(BUF_SAMPLES, I_LOAD_2); //insert_buffer(BUF_SAMPLES, g_controller_ctom.net_signals[10].f); /*********************************************/ END_TIMESLICER(TIMESLICER_BUFFER) /*********************************************/ CLEAR_DEBUG_GPIO1; PWM_MODULATOR_Q1_MOD_1_5->ETCLR.bit.INT = 1; PWM_MODULATOR_Q2_MOD_1_5->ETCLR.bit.INT = 1; PieCtrlRegs.PIEACK.all |= M_INT3; }