Esempio n. 1
0
/* const char arg to be compatible with BSP_output_char decl. */
void
debug_putc_onlcr(const char c)
{
	if ('\n'==c)
		debug_putc('\r');
	debug_putc(c);
}
Esempio n. 2
0
void debug_print_digit(int t)
{
	if (t<10) {
		debug_putc('0'+t);
	} else {
		debug_putc('a'+(t-10));
	}
}
Esempio n. 3
0
static void debug_puts(struct fiq_debugger_state *state, char *s)
{
	unsigned c;
	while ((c = *s++)) {
		if (c == '\n')
			debug_putc(state, '\r');
		debug_putc(state, c);
	}
}
Esempio n. 4
0
static void debug_puts(char *s)
{
	unsigned c;
	while ((c = *s++)) {
		if (c == '\n')
			debug_putc('\r');
		debug_putc(c);
	}
}
Esempio n. 5
0
static void debug_console_write(struct console *co,
				const char *s, unsigned int count)
{
	unsigned long irq_flags;

	
	local_irq_save(irq_flags);
	while (count--) {
		if (*s == '\n')
			debug_putc('\r');
		debug_putc(*s++);
	}
	debug_flush();
	local_irq_restore(irq_flags);
}
static void debug_console_write(struct console *co,
				const char *s, unsigned int count)
{
	unsigned long irq_flags;

	/* disable irq's while TXing outside of FIQ context */
	local_irq_save(irq_flags);
	while (count--) {
		if (*s == '\n')
			debug_putc('\r');
		debug_putc(*s++);
	}
	debug_flush();
	local_irq_restore(irq_flags);
}
Esempio n. 7
0
unsigned char Ax_Send( volatile unsigned char *message_global, int str_length) {
	int i;
	debug_puts("\n message length... \t");
	debug_putdec(str_length);
	debug_puts("\n/////////\n");
	for(i=0;i<str_length;i++){
		FM_buffer[FM_buffer_num][i]=message_global[i];
		debug_puthex(message_global[i]);
		debug_puts(",");
	}
	debug_puts("\n---------\n");
	for(i=0;i<str_length;i++){
		debug_putc(message_global[i]);
	}
	debug_puts("\n/////////\n");
	FM_buffer_length[FM_buffer_num]=str_length;
	FM_buffer_num++;
	if(FM_buffer_num>FM_BUFFER_MAX-1){
		FM_buffer_num=0;
	}
	if(FM_mode==0||FM_mode==3){
		FM_mode=1;	//モード0ならtonさせる
	}
	return 1;
}
Esempio n. 8
0
void debug(uint8_t *data){
    uint8_t c = *data++;
    while(c){
        debug_putc(c);
        c = *data++;
    }
}
Esempio n. 9
0
//put hexadecimal number to debug out.
void debug_put_hex8(uint8_t val){
    uint8_t lo = val&0x0F;
    uint8_t hi = val>>4;
    if (hi<0x0A){
        hi = '0' + hi;
    }else{
        hi = 'A' - 0x0A + hi;
    }

    if (lo<0x0A){
        lo = '0' + lo;
    }else{
        lo = 'A' - 0x0A + lo;
    }
    debug_putc(hi);
    debug_putc(lo);
}
Esempio n. 10
0
void
debug_puts (const char* s)
{
	if (s != NULL) {
		while(*s) {
			debug_putc(*s++);
		}
	}
}
Esempio n. 11
0
// Handle a character from a printf request.
static void
screen_putc(struct putcinfo *action, char c)
{
    if (ScreenAndDebug)
        debug_putc(&debuginfo, c);
    if (c == '\n')
        screenc('\r');
    screenc(c);
}
Esempio n. 12
0
void debug_puts(char *s)
{
	int t;
	char c;
	while (1) {
		c = *s++;
		switch (c) {
		case 0:
			return;
		case '\n':
			debug_putc('\n');
			debug_putc('\r');
			return;
		default:
			debug_putc(c);
			break;
		}
	}
}
Esempio n. 13
0
int debug_putchar(int ch)
{
    /* Do nothing if the debug uart is not initialized.*/
    if (s_debugConsole.type == kDebugConsoleNone)
    {
        return -1;
    }
    debug_putc(ch, NULL);

    return 1;
}
Esempio n. 14
0
// Output a character.
static void
putc(struct putcinfo *action, char c)
{
    if (MODESEGMENT) {
        // Only debugging output supported in segmented mode.
        debug_putc(action, c);
        return;
    }

    void (*func)(struct putcinfo *info, char c) = GET_GLOBAL(action->func);
    func(action, c);
}
Esempio n. 15
0
void
__dprintf(const char *fmt, ...)
{
    if (!MODESEGMENT && CONFIG_THREADS && CONFIG_DEBUG_LEVEL >= DEBUG_thread
        && *fmt != '\\' && *fmt != '/') {
        struct thread_info *cur = getCurThread();
        if (cur != &MainThread) {
            // Show "thread id" for this debug message.
            debug_putc(&debuginfo, '|');
            puthex(&debuginfo, (u32)cur, 8);
            debug_putc(&debuginfo, '|');
            debug_putc(&debuginfo, ' ');
        }
    }

    va_list args;
    va_start(args, fmt);
    bvprintf(&debuginfo, fmt, args);
    va_end(args);
    debug_flush();
}
Esempio n. 16
0
static void telemetry_rx_echo_test(void){
    // just for testing purposes...
    volatile EXTERNAL_MEMORY uint8_t data;

    while(1){
        wdt_reset();
        if (telemetry_pop(&data)){
            // debug_putc(data);
            debug_putc(' ');
            debug_put_hex8(data);
            if (data == 0x5E) debug_put_newline();
        }
    }
}
Esempio n. 17
0
void debug_put_uint(unsigned int value)
{
  int i;
  unsigned char c;

  debug_putc('0');
  debug_putc('x');

  for(i = 0; i < 8; i++) {
    c = (value & 0xf0000000) >> 28;
    
    if(c < 10) {
      debug_putc('0' + c);
    }
    else {
      debug_putc('A' + (c - 10));
    }
    
    value = (value & 0x0fffffff) << 4;
  }

  debug_putc(' ');
}
Esempio n. 18
0
void debug_putc(uint8_t ch){
    //add \r to newlines
    if (ch == '\n') debug_putc('\r');

    //disable interrupts
    hal_debug_int_disable();

    if (hal_debug_int_enabled()){
        //int already active, copy to buffer!
        debug_buffer.data[debug_buffer.write] = ch;
        debug_buffer.write = (debug_buffer.write + 1) & DEBUG_TX_BUFFER_AND_OPERAND;

        //check if free space in buffer:
        if (debug_buffer.write == debug_buffer.read){
            //no more space in buffer! this will loose some data!
            //add LOST data tag (for visual debugging lost data)
            debug_buffer.data[(debug_buffer.write-1) & DEBUG_TX_BUFFER_AND_OPERAND] = '$';

            /*LED_RED_ON();
            LED_GREEN_OFF();
            while(1){
                LED_RED_ON();
                LED_GREEN_ON();
                delay_ms(200);
                LED_RED_OFF();
                LED_GREEN_OFF();
                delay_ms(200);
            }*/
            return;
        }
    }else{
        //no int active. send first byte and reset buffer indices
        debug_buffer.write  = debug_buffer.read;

        hal_debug_start_transmission(ch);
    }

    //re enable interrupts
    hal_debug_int_enable();
}
Esempio n. 19
0
static void debug_fiq(void *data, void *regs)
{
	int c;
	static int last_c;

	while ((c = debug_getc()) != -1) {
		if (!debug_enable) {
			if ((c == 13) || (c == 10)) {
				debug_enable = true;
				debug_count = 0;
				debug_prompt();
			}
		} else if ((c >= ' ') && (c < 127)) {
			if (debug_count < (DEBUG_MAX - 1)) {
				debug_buf[debug_count++] = c;
				debug_putc(c);
			}
		} else if ((c == 8) || (c == 127)) {
			if (debug_count > 0) {
				debug_count--;
				debug_putc(8);
				debug_putc(' ');
				debug_putc(8);
			}
		} else if ((c == 13) || (c == 10)) {
			if (c == '\r' || (c == '\n' && last_c != '\r')) {
				debug_putc('\r');
				debug_putc('\n');
			}
			if (debug_count) {
				debug_buf[debug_count] = 0;
				debug_count = 0;
				debug_exec(debug_buf, regs);
			} else {
				debug_prompt();
			}
		}
		last_c = c;
	}
	debug_flush();
}
Esempio n. 20
0
static uint32_t hal_storage_i2c_read_buffer(uint16_t address, uint8_t *buffer, uint8_t len) {
    if (HAL_STORAGE_I2C_DEBUG) {
        debug("hal_storage: i2c read_buffer(0x");
        debug_put_hex8(address>>8);
        debug_put_hex8(address&0xFF);
        debug(", ..., ");
        debug_put_uint16(len);
        debug(")\n");
        debug_flush();
    }

    timeout_set(EEPROM_I2C_TIMEOUT);
    while (I2C_GetFlagStatus(EEPROM_I2C, I2C_FLAG_BUSY)) {
        if (timeout_timed_out()) {
            debug("hal_i2c: bus busy... timeout!\n");
            return 0;
        }
    }

    // send start
    I2C_GenerateSTART(EEPROM_I2C, ENABLE);

    // set on EV5 and clear it (cleared by reading SR1 then writing to DR)
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_MODE_SELECT)) {
        if (timeout_timed_out()) {
            debug("hal_i2c: master flag error... timeout!\n");
            return 0;
        }
    }

    // send EEPROM address for write
    I2C_Send7bitAddress(EEPROM_I2C, EEPROM_I2C_ADDRESS, I2C_Direction_Transmitter);

    // test on EV6 and clear it
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) {
        if (timeout_timed_out()) {
            debug("hal_i2c: transmitter flag error... timeout!\n");
            return 0;
        }
    }

    // send the EEPROM's internal address to read from: Only one byte address
    I2C_SendData(EEPROM_I2C, address);

    // test on EV8 and clear it
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (!I2C_GetFlagStatus(EEPROM_I2C, I2C_FLAG_BTF) == RESET) {
        if (timeout_timed_out()) {
            debug("hal_i2c: btf flag error... timeout!\n");
            return 0;
        }
    }


    // send START condition a second time
    I2C_GenerateSTART(EEPROM_I2C, ENABLE);

    // set on EV5 and clear it (cleared by reading SR1 then writing to DR)
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_MODE_SELECT)) {
        if (timeout_timed_out()) {
            debug("hal_i2c: master flag error... timeout!\n");
            return 0;
        }
    }

    // send address (READ)
    I2C_Send7bitAddress(EEPROM_I2C, EEPROM_I2C_ADDRESS, I2C_Direction_Receiver);

    // test on EV6 and clear it
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) {
        if (timeout_timed_out()) {
            debug("hal_i2c: receiver flag error... timeout!\n");
            return 0;
        }
    }

    if (HAL_STORAGE_I2C_DEBUG) {
        debug("hal_storage: reading ");
        debug_put_uint8(len);
        debug("bytes: ");
        debug_flush();
    }

    // do not use dma etc, we do not need highspeed. do polling:
    uint16_t i;
    for (i = 0; i < len; i++) {
        // wait on ADDR flag to be set (ADDR is still not cleared at this level)
        timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

        /* Test on EV7 and clear it */
        while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED)) {
            if (timeout_timed_out()) {
                debug("hal_i2c: byte rx error... timeout!\n");
                return 0;
            }
        }

        // read byte received:
        buffer[i] = I2C_ReceiveData(EEPROM_I2C);

        if (HAL_STORAGE_I2C_DEBUG) {
            debug_put_hex8(buffer[i]);
            debug_putc(' ');
            debug_flush();
        }

        if (i == (len-1)) {
            // last byte? -> NACK
            I2C_AcknowledgeConfig(EEPROM_I2C, DISABLE);
        } else {
            // more bytes -> ACK
            I2C_AcknowledgeConfig(EEPROM_I2C, ENABLE);
        }


        // wait for read to finish
        timeout_set(EEPROM_I2C_FLAG_TIMEOUT*100);

        while (!I2C_CheckEvent(EEPROM_I2C, I2C_EVENT_SLAVE_BYTE_RECEIVED)) {
        // while (I2C_GetFlagStatus(EEPROM_I2C, I2C_FLAG_RXNE) == RESET) {
            if (timeout_timed_out()) {
                debug("hal_i2c: read error... timeout!\n");
                return 0;
            }
        }
    }

    // stop transmission
    // clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */
    (void)EEPROM_I2C->SR2;

    // send STOP Condition
    I2C_GenerateSTOP(EEPROM_I2C, ENABLE);

    if (HAL_STORAGE_I2C_DEBUG) {
        debug(". done.\n");
        debug_flush();
    }

    // wait to make sure that STOP control bit has been cleared
    timeout_set(EEPROM_I2C_FLAG_TIMEOUT);

    while (EEPROM_I2C->CR1 & I2C_CR1_STOP) {
        if (timeout_timed_out()) {
            debug("hal_i2c: stop flag error... timeout!\n");
            return 0;
        }
    }

    // re-enable Acknowledgement to be ready for another reception
    I2C_AcknowledgeConfig(EEPROM_I2C, ENABLE);

    if (HAL_STORAGE_I2C_DEBUG) {
        debug("hal_storage: read done\n");
        debug_flush();
    }

    return 1;
}
Esempio n. 21
0
void debug_puts(char *str)
{
  while(*str) {
    debug_putc(*(str++));
  }
}
int debug_putchar(int ch)
{
    debug_putc(ch, NULL);

    return 1;
}
Esempio n. 23
0
__WEAK
void debug_dump_stack (const char *caption, void *sp, void *frame, void *callee)
{
	unsigned char *from, *to, *p;
	unsigned int len;
	char c;
	bool_t flag;

	to = (unsigned char *)frame; 
	from = (unsigned char *)sp;
	if (! uos_valid_memory_address (to) && uos_valid_memory_address (from))
		to = from;
	if (uos_valid_memory_address (to) && ! uos_valid_memory_address (from))
		from = to;

	to -= 16 * sizeof (void*);
	if ((from - to) > (int)(128 * sizeof (void *)))
		from = to + 128 * sizeof (void*);

	from = (unsigned char*) ((size_t) from & ~(sizeof (void *) - 1));
	to = (unsigned char*) ((size_t) to & ~(sizeof (void *) - 1));

	if (to > from) {
		p = to;
		to = from;
		from = p;
	}

	if ( (from - to) < (int)(64 * sizeof (void*)) )
		from = to + 64 * sizeof (void*);

	debug_printf ("%S.stack {%p/%p..%p/%p, %p, %p}\n", caption,
		sp, from, frame, to, callee, __builtin_frame_address (0));

	/* Stack always grows down. */
	for (p = from-1, flag = 0, len = 0; ; ) {
	    p--;
		if (len == 0) {
			if (sizeof (p) == 1)
				debug_printf ("[%8S.%02X]", caption, (size_t) p);
			else if (sizeof (p) == 2)
				debug_printf ("[%8S.%04X]", caption, (size_t) p);
			else if (sizeof (p) == 4)
				debug_printf ("[%8S.%08X]", caption, (size_t) p);
			else if (sizeof (p) == 8)
				debug_printf ("[%8S.%016X]", caption, (size_t) p);
			else
				debug_printf ("[%8S.%0p]", caption, (size_t) p);
		}

		c = ' ';
		if (p == frame)
			c = '=';
		if (p == sp)
			c = '>';

		if (uos_valid_memory_address (p)) {
			if (callee && (flag & 1) == 0 &&
			    ((size_t) p & (sizeof(void*)-1)) == 0 && /* aligned */
			    *(void**)p == callee) {
				c = '*';
				flag |= 1;
			}
			debug_printf ("%c%02X", c, *p);
		} else
			debug_printf ("%c__", c);

		if (p == to)
			flag |= 2;
		if (++len == 16) {
			debug_putc('\n');
			if (flag & 2)
				break;
			len = 0;
		}
	}
}
Esempio n. 24
0
/*
 * Print stack backtrace.
 * Usage:
 *	debug_dump_stack (task_current->name, arch_get_stack_pointer (),
 *		__builtin_frame_address (1),
 *		__builtin_return_address (0));
 */
void debug_dump_stack (const char *caption, void *sp, void *frame, void *callee)
{
	unsigned int *from, *to, *p, len;
	char c;
	bool_t callee_seen;

	from = sp;
	to = frame;
	if (! uos_valid_memory_address (to) && uos_valid_memory_address (from))
		to = from;
	if (uos_valid_memory_address (to) && ! uos_valid_memory_address (from))
		from = to;

	to -= 16;
	if ((from - to) > 128)
		from = to + 128;

	from = (unsigned*) ((size_t) from & ~(sizeof (void*) - 1));
	to = (unsigned*) ((size_t) to & ~(sizeof (void*) - 1));

	if (to > from) {
		p = to;
		to = from;
		from = p;
	}

	if (from - to < 64)
		from = to + 64;

	debug_printf ("%S.stack {%p/%p..%p/%p, %p, %p}\n", caption,
		sp, from, frame, to, callee, __builtin_frame_address (0));

	/* Stack always grows down. */
	p = from;
	callee_seen = 0;
	len = 0;
	for (;;) {
		p--;
		if (len == 0)
			debug_printf ("[%8S.%08x]", caption, (size_t) p);

		c = ' ';
		if (p == frame)
			c = '=';
		if (p == sp)
			c = '>';

		if (uos_valid_memory_address (p)) {
			if (callee && ! callee_seen && *p == (unsigned) callee) {
				c = '*';
				callee_seen = 1;
			}
			debug_printf (" %c%08x", c, *p);
		} else
			debug_printf (" %c________", c);

		if (++len == 4) {
			debug_putc('\n');
			if (p <= to)
				break;
			len = 0;
		}
	}
}
Esempio n. 25
0
File: file.c Progetto: fachat/XD2031
// opens the file, registers an error code in command->error if necessary
// If the open was successful, setup a channel for the given channel number
// (note: explicitely not secondary device number, as IEEE and IEC in parallel
// use overlapping numbers, so they may be shifted or similar to avoid clashes)
//
// The command buffer is used as transmit buffer, so it must not be overwritten
// until the open has been sent.
//
// note that if it returns a value <0 on error, it has to have the error message
// set appropriately.
//
int8_t file_open(uint8_t channel_no, bus_t *bus, errormsg_t *errormsg,
                 void (*callback)(int8_t errnum, uint8_t *rxdata), uint8_t openflag) {

    assert_not_null(bus, "file_open: bus is null");

    cmd_t *command = &(bus->command);
    rtconfig_t *rtconf = &(bus->rtconf);

#ifdef DEBUG_FILE
    debug_printf("OPEN FILE: FOR CHAN: %d WITH NAME: '%s', OPENFLAG=%d\n",
                 channel_no, (char*)&(command->command_buffer), openflag);
#endif

    // note: in a preemtive env, the following would have to be protected
    // to be atomic as we modify static variables

    parse_filename(command, &nameinfo, (openflag & OPENFLAG_LOAD) ? PARSEHINT_LOAD : 0);

#ifdef DEBUG_FILE
    debug_printf("  PARSE -> ACCESS=%c, TYPE=%c\n", nameinfo.access, nameinfo.type);
#endif

    // drive handling needed for error message drive
    if (nameinfo.drive == NAMEINFO_LAST_DRIVE) {
        nameinfo.drive = rtconf->last_used_drive;
    }
    else if (nameinfo.drive == NAMEINFO_UNUSED_DRIVE) {
        // TODO: match CBM behavior
        nameinfo.drive = rtconf->last_used_drive;
    }
    int8_t errdrive = rtconf->errmsg_with_drive ? nameinfo.drive : -1;

    // post-parse

    if (nameinfo.cmd != CMD_NONE && nameinfo.cmd != CMD_DIR && nameinfo.cmd != CMD_OVERWRITE) {
        // command name during open
        // this is in fact ignored by CBM DOS as checked with VICE's true drive emulation
        debug_printf("NO CORRECT CMD: %s\n", command_to_name(nameinfo.cmd));
        nameinfo.cmd = 0;
    }
    if (nameinfo.type != 0 && nameinfo.type != 'S' && nameinfo.type != 'P'
            && nameinfo.type != 'U' && nameinfo.type != 'L') {
        // not set, or set as not sequential and not program
        debug_puts("UNKOWN FILE TYPE: ");
        debug_putc(nameinfo.type);
        debug_putcrlf();
        set_error_tsd(errormsg, CBM_ERROR_FILE_TYPE_MISMATCH, 0, 0, errdrive);
        return -1;
    }
    if (nameinfo.access != 0 && nameinfo.access != 'W' && nameinfo.access != 'R'
            && nameinfo.access != 'A' && nameinfo.access != 'X') {
        debug_puts("UNKNOWN FILE ACCESS TYPE ");
        debug_putc(nameinfo.access);
        debug_putcrlf();
        // not set, or set as not read, write, or append, or r/w ('X')
        set_error_tsd(errormsg, CBM_ERROR_SYNTAX_UNKNOWN, 0, 0, errdrive);
        return -1;
    }
    if (nameinfo.cmd == CMD_DIR && (nameinfo.access != 0 && nameinfo.access != 'R')) {
        // trying to write to a directory
        debug_puts("WRITE TO DIRECTORY!");
        debug_putcrlf();
        set_error_tsd(errormsg, CBM_ERROR_FILE_EXISTS, 0, 0, errdrive);
        return -1;
    }

    uint8_t type = FS_OPEN_RD;

    // file access default
    if (nameinfo.access == 0) {
        if (openflag == OPENFLAG_LOAD) {
            nameinfo.access = 'R';
        } else if (openflag == OPENFLAG_SAVE) {
            nameinfo.access = 'W';
        }
    }

    // file type defaults
    if (nameinfo.type == 0) {
        // do we create a file (access=='W')?
        if (nameinfo.access == 'W') {
            // write (like save)
            if (openflag == OPENFLAG_SAVE) {
                nameinfo.type = 'P';
            } else {
                nameinfo.type = 'S';
            }
        }
        if (nameinfo.access == 'R') {
            if (openflag == OPENFLAG_LOAD) {
                // on load, 'P' is the default
                nameinfo.type = 'P';
            }
        }
    }

    if (nameinfo.access == 'X') {
        // trying to open up a R/W channel
        debug_puts("OPENING UP A R/W CHANNEL!");
        debug_putcrlf();
        type = FS_OPEN_RW;
    }

    if (nameinfo.name[0] == '#') {
        // trying to open up a direct channel
        // Note: needs to be supported for D64 support with U1/U2/...
        // Note: '#' is still blocking on read!
        debug_puts("OPENING UP A DIRECT CHANNEL!");
        debug_putcrlf();

        type = FS_OPEN_DIRECT;
    }

    // if ",W" or secondary address is one, i.e. save
    if (nameinfo.access == 'W') {
        type = FS_OPEN_WR;
    }
    if (nameinfo.access == 'A') {
        type = FS_OPEN_AP;
    }
    if (nameinfo.cmd == CMD_DIR) {
        if (openflag & OPENFLAG_LOAD) {
            type = FS_OPEN_DR;
        } else {
            type = FS_OPEN_RD;
        }
    } else if (nameinfo.cmd == CMD_OVERWRITE) {
        type = FS_OPEN_OW;
    }

#ifdef DEBUG_FILE
    debug_printf("NAME='%s' (%d)\n", nameinfo.name, nameinfo.namelen);
    debug_printf("ACCESS=%c\n", nameinfo.access);
    debug_printf("CMD=%d\n", nameinfo.cmd);
    debug_flush();
#endif

    return file_submit_call(channel_no, type, command->command_buffer, errormsg, rtconf, callback, 0);

}
Esempio n. 26
0
File: file.c Progetto: fachat/XD2031
uint8_t file_submit_call(uint8_t channel_no, uint8_t type, uint8_t *cmd_buffer,
                         errormsg_t *errormsg, rtconfig_t *rtconf,
                         void (*callback)(int8_t errnum, uint8_t *rxdata), uint8_t iscmd) {

    assert_not_null(errormsg, "file_submit_call: errormsg is null");
    assert_not_null(rtconf, "file_submit_call: rtconf is null");

    // check for default drive (here is the place to set the last used one)
    if (nameinfo.drive == NAMEINFO_LAST_DRIVE) {
        nameinfo.drive = rtconf->last_used_drive;
    }
    else if (nameinfo.drive == NAMEINFO_UNUSED_DRIVE) {
        // TODO: match CBM behavior
        nameinfo.drive = rtconf->last_used_drive;
    }
    else if (nameinfo.drive < MAX_DRIVES) {
        // only save real drive numbers as last used default
        rtconf->last_used_drive = nameinfo.drive;
    }

    // if second name does not have a drive, use drive from first,
    // but only if it is defined
    if (nameinfo.file[0].drive == NAMEINFO_UNUSED_DRIVE && nameinfo.drive != NAMEINFO_UNDEF_DRIVE) {
        nameinfo.file[0].drive = nameinfo.drive;
    }

    // here is the place to plug in other file system providers,
    // like SD-Card, or even an outgoing IEC or IEEE, to convert between
    // the two bus systems. This is done depending on the drive number
    // and managed with the ASSIGN call.
    //provider_t *provider = &serial_provider;
    endpoint_t *endpoint = NULL;
    if (type == FS_OPEN_DIRECT) {
        debug_printf("Getting direct endpoint provider for channel %d\n", channel_no);
        endpoint = direct_provider();
    } else {
        endpoint = provider_lookup(nameinfo.drive, (char*) nameinfo.drivename);
    }

    // convert from bus' PETSCII to provider
    // currently only up to the first zero byte is converted, options like file type
    // are still ASCII only
    // in the future the bus may have an own conversion option...
    cconv_converter(CHARSET_PETSCII, endpoint->provider->charset(endpoint->provdata))
    ((char*)nameinfo.name, strlen((char*)nameinfo.name),
     (char*)nameinfo.name, strlen((char*)nameinfo.name));
    for (uint8_t i=0 ; i < nameinfo.num_files ; ++i) {
        if (nameinfo.file[i].name != NULL) {
            cconv_converter(CHARSET_PETSCII, endpoint->provider->charset(endpoint->provdata))
            ((char*)nameinfo.file[i].name, strlen((char*)nameinfo.file[i].name),
             (char*)nameinfo.file[i].name, strlen((char*)nameinfo.file[i].name));
        }
    }

    if (type == FS_MOVE
            && nameinfo.file[0].drive != NAMEINFO_UNUSED_DRIVE 	// then use ep from first drive anyway
            && nameinfo.file[0].drive != nameinfo.drive) {		// no need to check if the same

        // two-name command(s) with possibly different drive numbers
        endpoint_t *endpoint2 = provider_lookup(nameinfo.file[0].drive, (char*) nameinfo.file[0].name);

        if (endpoint2 != endpoint) {
            debug_printf("ILLEGAL DRIVE COMBINATION: %d vs. %d\n", nameinfo.drive+0x30, nameinfo.file[0].drive+0x30);
            set_error_tsd(errormsg, CBM_ERROR_DRIVE_NOT_READY, 0, 0, nameinfo.drive);
            return -1;
        }
    }

    // check the validity of the drive (note that in general provider_lookup
    // returns a default provider - serial-over-USB to the PC, which then
    // may do further checks
    if (endpoint == NULL) {
        debug_puts("ILLEGAL DRIVE: ");
        debug_putc(0x30+nameinfo.drive);
        debug_putcrlf();
        set_error_tsd(errormsg, CBM_ERROR_DRIVE_NOT_READY, 0, 0, nameinfo.drive);
        return -1;
    }
    provider_t *provider = endpoint->provider;

    // find open slot
    //int8_t slot = -1;
    open_t *activeslot = NULL;
    for (uint8_t i = 0; i < MAX_ACTIVE_OPEN; i++) {
        if (active[i].channel_no < 0) {
            //slot = i;
            activeslot = (open_t*) &active[i];
            break;
        }
    }
    //if (slot < 0) {
    if (activeslot == NULL) {
        debug_puts("NO OPEN SLOT FOR OPEN!");
        debug_putcrlf();
        set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive);
        return -1;
    }

    activeslot->endpoint = endpoint;

    uint8_t len = assemble_filename_packet(cmd_buffer, &nameinfo);
#ifdef DEBUG_FILE
    debug_printf("LEN AFTER ASSEMBLE=%d\n", len);
#endif
    packet_init(&activeslot->txbuf, len, cmd_buffer);

    // store pointer to runtime config in packet
    // used by providers running on the device
    activeslot->txbuf.rtc = rtconf;

    packet_set_filled(&activeslot->txbuf, channel_no, type, len);

    if (!iscmd) {
        // only for file opens
        // note: we need the provider for the dir converter,
        // so we can only do it in here.

        // open channel
        uint8_t writetype = WTYPE_READONLY;
        if (type == FS_OPEN_WR || type == FS_OPEN_AP || type == FS_OPEN_OW) {
            writetype = WTYPE_WRITEONLY;
        } else if (type == FS_OPEN_RW) {
            writetype = WTYPE_READWRITE;
        }
        if (nameinfo.options & NAMEOPT_NONBLOCKING) {
            writetype |= WTYPE_NONBLOCKING;
        }

        int8_t (*converter)(void *, packet_t*, uint8_t) =
            (type == FS_OPEN_DR) ? (provider->directory_converter) : NULL;


        // TODO: if provider->channel_* are not NULL, we should probably not allocate a channel
        // but that would break the FILE OPEN detection here.
        channel_t *channel = channel_find(channel_no);
        if (channel != NULL) {
            // clean up
            channel_close(channel_no);
            // Note: it seems possible to open the same channel multiple times
            // on a direct file
            if (type != FS_OPEN_DIRECT) {
                debug_puts("FILE OPEN ERROR");
                debug_putcrlf();
                set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive);
                return -1;
            }
        }
        int8_t e = channel_open(channel_no, writetype, endpoint, converter, nameinfo.drive);
        if (e < 0) {
            debug_puts("E=");
            debug_puthex(e);
            debug_putcrlf();
            set_error_tsd(errormsg, CBM_ERROR_NO_CHANNEL, 0, 0, nameinfo.drive);
            return -1;
        }
    }

    activeslot->callback = callback;

    // no more error here, just the submit.
    // so callers can be sure if this function returns <0, they do not need
    // to close the channel, as it has not been opened
    // If this function returns 0, a callback must be received and handled,
    // and the channel is already opened.

    activeslot->channel_no = channel_no;

    // prepare response buffer
    packet_init(&activeslot->rxbuf, OPEN_RX_DATA_LEN, activeslot->rxdata);

    provider->submit_call(endpoint->provdata, channel_no, &activeslot->txbuf,
                          &activeslot->rxbuf, _file_open_callback);

    return 0;
}
Esempio n. 27
0
File: main.c Progetto: Smitc114/3010
void main(void) {
	BRD_init();	//Initalise NP2
	Hardware_init();
	HAL_Delay(3000);
	struct PanTilt pantiltvars;
	pantilt = &pantiltvars;
	pantilt->write_angles = 0;
	pantilt->read_angles = 0;
	pantilt->set_angle_pan = 0;
	pantilt->set_angle_tilt = 0;
	struct Variables variables;
	vars = &variables;
	vars->count = 0;
	vars->bit_half = 1;
	vars->bit_count = 0;
	vars->encoded_bit_count = -1;
	vars->encoded_bit = 0;
	vars->encoded_char = hamming_byte_encoder('<');
	vars->transmit_frequency = 1000;
	vars->period_multiplyer = ((1.000000/vars->transmit_frequency)*500)*0.998;
	vars->recieve_element = 0;
	vars->recieve_flag = 0;
	Pb_init();
	s4353096_radio_setchan(s4353096_chan);
	s4353096_radio_settxaddress(s4353096_tx_addr);
	s4353096_radio_setrxaddress(s4353096_rx_addr);
  while (1) {
		s4353096_radio_setfsmrx();
		s4353096_radio_fsmprocessing();
		if (vars->recieve_flag == 1) {
			manchester_decode();
			vars->recieve_flag = 0;
		}
		if (mode == S4353096_RADIO) {
		/*Processes the current fsm state*/
		RxChar = debug_getc();
		if (RxChar != '\0') {
			s4353096_keystroke = 1;
			while(s4353096_keystroke == 1){
				if (RxChar == '\r' || s4353096_payload_length == 7) {
					for (int j = s4353096_payload_length; j < 7; j++) {
						s4353096_payload_buffer[j] = '-';
					}
					s4353096_radio_fsmcurrentstate = S4353096_IDLE_STATE;
					s4353096_radio_fsmprocessing();
					s4353096_radio_fsmcurrentstate = S4353096_TX_STATE;
					debug_printf("\n");
					/*Compiles the transmit packet. Transmits packet if in TX state*/
					s4353096_radio_sendpacket(s4353096_radio_getchan(), s4353096_addr_get, s4353096_payload_buffer);
					s4353096_radio_fsmprocessing();
					s4353096_radio_setfsmrx();
					s4353096_radio_fsmprocessing();
					s4353096_payload_length = 0;
					s4353096_keystroke = 0;
				} else if (RxChar != '\0') {
					s4353096_payload_buffer[s4353096_payload_length] = RxChar;
					s4353096_payload_length++;
					debug_putc(RxChar);				//reflect byte using putc - puts character into buffer
					debug_flush();					//Must call flush, to send character		//reflect byte using printf - must delay before calling printf again.
				} else {

				}
				HAL_Delay(125);
				RxChar = debug_getc();
			}
		} else {

		}
		s4353096_radio_fsmprocessing();
		if (s4353096_radio_getrxstatus() == 1) { //Checks if packet has been recieved
				/*Prints recieved packet to console*/
			s4353096_radio_getpacket(s4353096_rx_buffer);
		} else {

		}
	}
		if (pantilt->write_angles == 1) {
			s4353096_pantilt_angle_write(1, pantilt->set_angle_pan);
			s4353096_pantilt_angle_write(0, pantilt->set_angle_tilt);
			pantilt->write_angles = 0;
		}
		if (((HAL_GetTick()/10000) % 100) == 0) {
			debug_printf("\nPan: %d Tlit: %d\n", pantilt->set_angle_pan, pantilt->set_angle_tilt);
		}
		if (pantilt->read_angles == 1) { /*Delay for 1 second or setup to delay for 0.2 seconds and set angle to += or -= 1 each time*/
			if (mode == S4353096_JOYSTICK) {
				y_value = s4353096_joystick_y_read();
				if ((y_value > 2500) && (pantilt->set_angle_pan < 76)) {
					pantilt->set_angle_pan += 1;
				} else if ((y_value < 1550) && (pantilt->set_angle_pan > -76)) {
					pantilt->set_angle_pan -= 1;
				} else { //Joystick is stationary, no input
				}
				x_value = s4353096_joystick_x_read();
				if ((x_value > 2500) && (pantilt->set_angle_tilt < 76)) {
					pantilt->set_angle_tilt += 1;
				} else if ((x_value < 1550) && (pantilt->set_angle_tilt > -76)) {
					pantilt->set_angle_tilt -= 1;
				} else {
				}
			} else if (mode == S4353096_TERMINAL) {
				/* Receive characters using getc */
				RxChar = debug_getc();
				/* Check if character is not Null */
				if (RxChar != '\0') {
					switch (RxChar) {
						case 'w':
							pantilt->set_angle_tilt += 1;
							break;
						case 's':
							pantilt->set_angle_tilt -= 1;
							break;
						case 'a':
							pantilt->set_angle_pan += 1;
							break;
						case 'd':
							pantilt->set_angle_pan -= 1;
							break;
						case 't':
							mode = S4353096_LASER_TRANSMIT;
							break;
						default:
							break;
					}
					debug_flush();
				}
				s4353096_terminal_angle_check();

			}
			pantilt->read_angles = 0;
		}
	}
}
Esempio n. 28
0
/* Handler for external interrupts.
 * On the P2020, the various external interrupt sources are multiplexed onto the one external interrupt vector by a
 * Programmable Interrupt Controller (PIC).
 * For demo purposes, we just handle each interrupt by raising an interrupt event to a distinct task, for each
 * distinct interrupt source we are able to disambiguate by querying the P2020 PIC. */
bool
exti_interrupt(void)
{
    uint32_t inc_vector;

    debug_print("exti_interrupt: ");

    inc_vector = pic_iack_get();

    debug_printhex32(inc_vector);
    debug_print(": ");

    switch (inc_vector) {
    case PIC_IIV_DUART_EXAMPLE_VECTOR:
        /* The incoming character must be read to clear the interrupt condition */
        if (duart1_rx_ready()) {
            debug_print("DUART1: ");
            debug_putc(duart1_rx_get());
            rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_I);
            if (duart2_rx_ready()) {
                debug_print(", DUART2: ");
                debug_putc(duart2_rx_get());
                rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_K);
            }
        } else if (duart2_rx_ready()) {
            debug_print("DUART2: ");
            debug_putc(duart2_rx_get());
            rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_J);
        }
        debug_println("");
        break;
    case PIC_GT_EXAMPLE_VECTOR(0):
        debug_println("PIC timer A0");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_A);
        break;
    case PIC_GT_EXAMPLE_VECTOR(1):
        debug_println("PIC timer A1");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_B);
        break;
    case PIC_GT_EXAMPLE_VECTOR(2):
        debug_println("PIC timer A2");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_C);
        break;
    case PIC_GT_EXAMPLE_VECTOR(3):
        debug_println("PIC timer A3");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_D);
        break;
    case PIC_GT_EXAMPLE_VECTOR(4):
        debug_println("PIC timer B0");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_E);
        break;
    case PIC_GT_EXAMPLE_VECTOR(5):
        debug_println("PIC timer B1");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_F);
        break;
    case PIC_GT_EXAMPLE_VECTOR(6):
        debug_println("PIC timer B2");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_G);
        break;
    case PIC_GT_EXAMPLE_VECTOR(7):
        debug_println("PIC timer B3");
        rtos_interrupt_event_raise(RTOS_INTERRUPT_EVENT_ID_EVT_H);
        break;
    case PIC_SPURIOUS_VECTOR_CODE:
        debug_println("spurious vector!");
        break;
    default:
        debug_println("unknown vector!");
        break;
    }

    pic_eoi_put();

    return true;
}
Esempio n. 29
0
static void debug_puts(const char *s)
{
    int i;
    for(i = 0; i < strlen(s); i++)
        debug_putc(s[i]);
}