void setup_jtag_gpio() { char tmp = LED_GREEN_OFF; gpio_ioctl_cb_t gpctl; gpctl.ioctl_code = VOS_IOCTL_GPIO_SET_MASK; gpctl.value = ~4; // ALL OUTPUT except TDO vos_dev_ioctl(hGPIO_PORT_A, &gpctl); vos_dev_write(hGPIO_PORT_A, &tmp, 1, NULL); }
void close_jtag_gpio() { char tmp = 0; gpio_ioctl_cb_t gpctl; gpctl.ioctl_code = VOS_IOCTL_GPIO_SET_MASK; gpctl.value = LED_RED_OFF | LED_GREEN_OFF; vos_dev_ioctl(hGPIO_PORT_A, &gpctl); // set all to inputs (hi-z) tmp = LED_RED_OFF; vos_dev_write(hGPIO_PORT_A, &tmp, 1, NULL); }
////////////////////////////////////////////////////////////////////// // // SET LED // ////////////////////////////////////////////////////////////////////// void setLed(unsigned char mask, unsigned char value) { unsigned char leds; vos_dev_read(hGpioA,&leds,1,NULL); if(value) leds |= mask; else leds &= ~mask; vos_dev_write(hGpioA,&leds,1,NULL); }
void SendIntOut(BYTE* BufferPtr, WORD BufferLength) { usbhost_xfer_t xfer; BYTE Status; vos_memset(&xfer, 0, sizeof(usbhost_xfer_t)); xfer.s = &IntTransferComplete; xfer.ep = IntOut; xfer.buf = BufferPtr; xfer.len = BufferLength; // Send packet to X10 controller Status = vos_dev_write(hDevice[Host], (BYTE*)&xfer, sizeof(usbhost_xfer_t), NULL); if (Status != USBHOST_OK) dprint("Send X10 packet Error (%d)\n", &Status); }
// Declare program thread(s) // Blink thread, toggles LED3 on GPIO1 void Blink(void) { BYTE PortData = LED3; StartupDevices(); dprint("Blink has started\n", 0); while (1) { vos_delay_msecs(512); PortData ^= LED3; // Now write pattern to the GPIO port. vos_dev_write(hDevice[LEDs] ,&PortData, 1, NULL); dprint("LED is %s ", (PortData & LED3) ? "Off" : "On"); } }
/* ** number ** ** Print a character in the terminal application. ** ** Parameters: val - Byte to be printed ** Returns: void ** Comments: */ void number(unsigned char val) { // unsigned char nibble; // nibble = (val >> 4) + '0'; // if (nibble > '9') nibble += ('A' - '9' - 1); // vos_dev_write(hUART, &nibble, (uint16) 1, NULL); // nibble = (val & 15) + '0'; // if (nibble > '9') nibble += ('A' - '9' - 1); // vos_dev_write(hUART, &nibble, (uint16) 1, NULL); vos_dev_write(hUART, &val, (uint8) 1, NULL); }
void RunUSBSend() { unsigned char attached; uint8 msg[3]; int param = 1; int i; unsigned short bytes_written; VOS_HANDLE hUSB; // wait for setup to complete vos_wait_semaphore(&setupSem); vos_signal_semaphore(&setupSem); msg[0] = 0; while(1) { int count = fifo_read(&stSPIReadFIFO, usbSendBuffer, 64); for(i=0;i<count;++i) { if(usbSendBuffer[i]&0x80) { msg[0] = usbSendBuffer[i]; param = 1; } else if(param == 1) { msg[1] = usbSendBuffer[i]; param = 2; } else if(param == 2) { msg[2] = usbSendBuffer[i]; param = 1; if(msg[0]) { VOS_ENTER_CRITICAL_SECTION; hUSB = PortA.hUSBHOSTGENERIC; VOS_EXIT_CRITICAL_SECTION; if(hUSB) { vos_dev_write(hUSB, msg, 3, &bytes_written); } } } } } }
void RunSPISend() { unsigned short bytes_written; // wait for setup to complete vos_wait_semaphore(&setupSem); vos_signal_semaphore(&setupSem); while(1) { int count = fifo_read(&stSPIWriteFIFO, spiSendBuffer, 64); vos_dev_write(hSPISlave, spiSendBuffer, (unsigned short)count, &bytes_written); setGpioA(LED_SIGNAL,0); setGpioA(LED_SIGNAL,LED_SIGNAL|LED_ACTIVITY); } }
// USBHOSTBoms write function unsigned char usbhostBoms_write(char *buf, unsigned short num_to_write, unsigned short *num_written, usbhostBoms_context_t *ctx) { unsigned short actual_write = 0; unsigned char status = USBHOSTBOMS_NOT_FOUND; usbhost_xfer_t xfer; vos_semaphore_t s; if (ctx->hc) { vos_memset(&xfer, 0, sizeof(usbhost_xfer_t)); vos_init_semaphore(&s, 0); xfer.buf = buf; xfer.len = num_to_write; xfer.ep = ctx->epBulkOut; xfer.s = &s; xfer.cond_code = USBHOST_CC_NOTACCESSED; xfer.flags = USBHOST_XFER_FLAG_START_BULK_ENDPOINT_LIST; status = vos_dev_write(ctx->hc, (unsigned char *) &xfer, sizeof(usbhost_xfer_t), NULL); if (status == USBHOST_OK) { status = (unsigned char)USBHOSTBOMS_OK; actual_write = xfer.len; } else { status |= (unsigned char)USBHOSTBOMS_USBHOST_ERROR; } } if (num_written) { *num_written = actual_write; } return status; }
////////////////////////////////////////////////////////////////////// // // APPLICATION SETUP THREAD FUNCTION // ////////////////////////////////////////////////////////////////////// void Setup() { common_ioctl_cb_t spis_iocb; usbhostGeneric_ioctl_t generic_iocb; gpio_ioctl_cb_t gpio_iocb; common_ioctl_cb_t uart_iocb; unsigned char uchLeds; // Open up the base level drivers hGpioA = vos_dev_open(VOS_DEV_GPIO_A); PortA.hUSBHOST = vos_dev_open(VOS_DEV_USBHOST_1); //PortB.hUSBHOST = vos_dev_open(VOS_DEV_USBHOST_2); gpio_iocb.ioctl_code = VOS_IOCTL_GPIO_SET_MASK; gpio_iocb.value = 0b00001110; vos_dev_ioctl(hGpioA, &gpio_iocb); uchLeds = 0b00001000; vos_dev_write(hGpioA,&uchLeds,1,NULL); hUART = vos_dev_open(VOS_DEV_UART); /* UART ioctl call to enable DMA and link to DMA driver */ uart_iocb.ioctl_code = VOS_IOCTL_COMMON_ENABLE_DMA; vos_dev_ioctl(hUART, &uart_iocb); // Set up for MIDI uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_BAUD_RATE; uart_iocb.set.uart_baud_rate = 31250; vos_dev_ioctl(hUART, &uart_iocb); uart_iocb.ioctl_code = VOS_IOCTL_UART_SET_FLOW_CONTROL; uart_iocb.set.param = UART_FLOW_NONE; vos_dev_ioctl(hUART, &uart_iocb); // Set up the metronome MetroInit(&metro, VOS_DEV_TIMER0, TIMER_0); // Release other application threads vos_signal_semaphore(&setupSem); }
//////////////////////////////////////////////////////////////////////////////// // SET GPIO A //////////////////////////////////////////////////////////////////////////////// void setGpioA(uint8 mask, uint8 data) { gpioAOutput &= ~mask; gpioAOutput |= data; vos_dev_write(hGpioA,&gpioAOutput,1,NULL); }