/*write 0*/ void serial_write_bit_low(void) { SET_DATA_LOW(); /* ____ */ SET_CLK_LOW(); /* _-_ */ serial_delay(); SET_CLK_HIGH(); serial_delay(); SET_CLK_LOW(); }
/*write 1*/ void serial_write_bit_high(void) { SET_DATA_HIGH(); /* ---- */ SET_CLK_LOW(); /* _-_ */ serial_delay(); SET_CLK_HIGH(); serial_delay(); SET_CLK_LOW(); }
/***************************************************************************** * submit a channel rpc call to the UART * If buffer slot is available, return immediately. * Otherwise wait until slot is available, then return * (while data is transferred in the background) * * Note: submitter must check buf_is_empty() for true or buf_wait_free() * before reuse or freeing the memory! * * callback is called from delay() context when the response has been * received */ void serial_submit_call(void *epdata, int8_t channelno, packet_t *txbuf, packet_t *rxbuf, uint8_t (*callback)(int8_t channelno, int8_t errnum, packet_t *packet)) { if (channelno < 0) { debug_printf("!!!! submit with channelno=%d\n", channelno); } if (txbuf->chan < 0) { debug_printf("!!!! submit with packet->chan=%d\n", txbuf->chan); } // check rx slot // wait / loop until receive buffer is being freed by interrupt routine int8_t channelpos = -1; while (channelpos < 0) { for (uint8_t i = 0; i < NUMBER_OF_SLOTS; i++) { // note: take either a free one or overwrite an existing one // the latter case is only used for rtconfig_pullconfig() // sending a new request if (rx_channels[i].channelno < 0 || rx_channels[i].channelno == channelno) { channelpos = i; break; } } serial_delay(); } rx_channels[channelpos].channelno = channelno; rx_channels[channelpos].rxpacket = rxbuf; rx_channels[channelpos].callback = callback; // send request serial_submit(epdata, txbuf); }
// Used by the master to synchronize timing with the slave. static void sync_recv(void) { serial_input(); // This shouldn't hang if the slave disconnects because the // serial line will float to high if the slave does disconnect. while (!serial_read_pin()); serial_delay(); }
void serial_write_chunk(uint8_t data, uint8_t bit) { uint8_t b, p; for( p = 0, b = 1<<(bit-1); b ; b >>= 1) { if(data & b) { serial_high(); p ^= 1; } else { serial_low(); p ^= 0; } serial_delay(); } /* send parity bit */ if(p & 1) { serial_high(); } else { serial_low(); } serial_delay(); serial_low(); // sync_send() / senc_recv() need raise edge }
inline static void change_reciver2sender(void) { sync_recv(); //0 serial_delay(); //1 serial_low(); //3 serial_output(); //3 serial_delay_half1(); //4 }
// Used by the slave to send a synchronization signal to the master. static void sync_send(void) { serial_output(); serial_low(); serial_delay(); serial_high(); }
static void serial_echo_column_labels(const uint8_t sp) { SERIAL_ECHO_SP(7); for (int8_t i = 0; i < GRID_MAX_POINTS_X; i++) { if (i < 10) SERIAL_CHAR(' '); SERIAL_ECHO(i); SERIAL_ECHO_SP(sp); } serial_delay(10); }
/*read*/ kal_uint16 serial_read_data(void) { kal_uint16 data=0; kal_int16 i; kal_uint32 savedMask; kal_uint32 retry=0; //savedMask = SaveAndSetIRQMask(); SET_CLK_LOW(); SET_CLK_HIGH(); while(GET_BUSY_BIT()) { SET_CLK_LOW(); SET_CLK_HIGH(); retry++; if(retry>1000000)/*give up the read. controller may be broken*/ return 0; }; for(i=11;i>=0;i--) { //SET_CLK_LOW(); //serial_delay(); SET_CLK_HIGH(); serial_delay(); if(GET_DATA_BIT()) data |= (1<<i); SET_CLK_LOW(); serial_delay(); } for(i=0;i<ZERO_FIELD_COUNT;i++) { SET_CLK_LOW(); serial_delay(); SET_CLK_HIGH(); SET_CLK_LOW(); } data&=0x3fff; //RestoreIRQMask(savedMask); return data; }
static void serial_echo_xy(const uint8_t sp, const int16_t x, const int16_t y) { SERIAL_ECHO_SP(sp); SERIAL_CHAR('('); if (x < 100) { SERIAL_CHAR(' '); if (x < 10) SERIAL_CHAR(' '); } SERIAL_ECHO(x); SERIAL_CHAR(','); if (y < 100) { SERIAL_CHAR(' '); if (y < 10) SERIAL_CHAR(' '); } SERIAL_ECHO(y); SERIAL_CHAR(')'); serial_delay(5); }
// Reads a byte from the serial line static uint8_t serial_read_byte(void) { uint8_t byte = 0; serial_input(); for ( uint8_t i = 0; i < 8; ++i) { byte = (byte << 1) | serial_read_pin(); serial_delay(); _delay_us(1); } return byte; }
// Sends a byte with MSB ordering static void serial_write_byte(uint8_t data) { uint8_t b = 8; serial_output(); while( b-- ) { if(data & (1 << b)) { serial_high(); } else { serial_low(); } serial_delay(); } }
void unified_bed_leveling::report_state( #if NUM_SERIAL > 1 const int8_t port/*= -1*/ #endif ) { echo_name( #if NUM_SERIAL > 1 port #endif ); SERIAL_ECHOPGM_P(port, " System v" UBL_VERSION " "); if (!planner.leveling_active) SERIAL_ECHOPGM_P(port, "in"); SERIAL_ECHOLNPGM_P(port, "active."); serial_delay(50); }
void unified_bed_leveling::report_current_mesh( #if NUM_SERIAL > 1 const int8_t port/*= -1*/ #endif ) { if (!leveling_is_valid()) return; SERIAL_ECHO_MSG_P(port, " G29 I99"); for (uint8_t x = 0; x < GRID_MAX_POINTS_X; x++) for (uint8_t y = 0; y < GRID_MAX_POINTS_Y; y++) if (!isnan(z_values[x][y])) { SERIAL_ECHO_START_P(port); SERIAL_ECHOPAIR_P(port, " M421 I", x); SERIAL_ECHOPAIR_P(port, " J", y); SERIAL_ECHOPAIR_F_P(port, " Z", z_values[x][y], 2); SERIAL_EOL_P(port); serial_delay(75); // Prevent Printrun from exploding } }
/***************************************************************************** * submit the contents of a buffer to the UART * If buffer slot is available, return immediately. * Otherwise wait until slot is available, then return * (while data is transferred in the background (=delay() calls)) * * Note: submitter must check buf_is_empty() for true or buf_wait_free() * before reuse or freeing the memory! */ void serial_submit(void *epdata, packet_t *buf) { // wait for slot free while (slots_used >= (NUMBER_OF_SLOTS-1)) { serial_delay(); } // note: slots_used can only decrease until here, as this is the // only place to increase it, so there is no race from the while() // above to setting it here. slots[slots_used] = buf; slots_used++; if (slots_used == 1) { // no packet before, so need to start sending txstate = TX_TYPE; send(); //led_on(); } }
void main_delay() { serial_delay(); }
/***************************************************************************** * wait until everything has been flushed out - for debugging, to make * sure all messages have been sent */ void serial_flush() { while (slots_used > 0) { serial_delay(); } }