/** * Outputs link status on serial console */ static void link_status(struct netif *arg){/*{{{*/ #if LWIP_IPV6 TimerHandle_t poll_timer; #endif uart_printf("IP address of interface %c%c set to %hd.%hd.%hd.%hd\n", arg->name[0], arg->name[1], ip4_addr1_16(&arg->ip_addr), ip4_addr2_16(&arg->ip_addr), ip4_addr3_16(&arg->ip_addr), ip4_addr4_16(&arg->ip_addr)); uart_printf("Netmask of interface %c%c set to %hd.%hd.%hd.%hd\n", arg->name[0], arg->name[1], ip4_addr1_16(&arg->netmask), ip4_addr2_16(&arg->netmask), ip4_addr3_16(&arg->netmask), ip4_addr4_16(&arg->netmask)); uart_printf("Gateway of interface %c%c set to %hd.%hd.%hd.%hd\n", arg->name[0], arg->name[1], ip4_addr1_16(&arg->gw), ip4_addr2_16(&arg->gw), ip4_addr3_16(&arg->gw), ip4_addr4_16(&arg->gw)); uart_printf("Hostname of interface %c%c set to %s\n", arg->name[0], arg->name[1], arg->hostname); #if LWIP_IPV6 poll_timer = xTimerCreate ( "poll_ipv6_addr", 1000 / portTICK_PERIOD_MS, pdTRUE, arg, poll_ip6_addr); xTimerStart(poll_timer, 0); #endif }/*}}}*/
/** * Print DIMM configuration */ void spd_print_dimm_presence(void) { unsigned char i, reading; /* walk through all dimms */ for (i = 0; i < SDRAM_MAX_DIMMS; i++) { uart_printf("DDR3 DIMM %d: ", i + 1); /* if payload power is not active - read out SPD EEPROM's */ if (!signal_read(&sig_payload_power)) { /* try to read DIMM SPD register */ if (spd_read_register(i, SDRAM_SPD_REVISION, &reading) == E_OK) { /* get memory size */ spd_get_memory_values(i); } } /* if memory size value not zero */ if (ddr_modules[i].populated != 0) { uart_printf("%d MB ", ddr_modules[i].value); uart_printf(" Type: %d\n", ddr_modules[i].voltage); } else { uart_printf("not populated\n"); } } }
int uart_close(uart_socket_t *u) { if(!u){ uart_printf("uart_close(): u is NULL!\r\n"); return -1; } /* Close uart socket */ if(lwip_close(u->fd) == -1){ uart_printf("%s(): close uart failed!", __func__); } /* Delete uart_action task */ u->fd = -1; RtlUpSema(&u->action_sema); RtlMsleepOS(20); /* Free uart related semaphore */ RtlFreeSema(&u->action_sema); RtlFreeSema(&u->tx_sema); RtlFreeSema(&u->dma_tx_sema); /* Free serial */ serial_free(&u->sobj); RtlMfree((u8 *)u, sizeof(uart_socket_t)); return 0; }
/** * send a message to the ShMM * */ void bmc_make_request(unsigned char netfn, unsigned char cmd, unsigned char *data, unsigned char datalen) { ipmbMSG_t *request; if (!(request = msg_malloc())) { uart_printf("ERR: %s: Not enough memory for request msg.\n", __func__); return; } request->rsSA = 0x20; request->rqSA = global_data.bmc_ipmb_addr; request->rsLUN = event_receiver_lun; request->rqSeq = get_seq_counter(); request->rqLUN = 0; request->orig_channel = MSG_CHANNEL_BMC; request->dest_channel = MSG_CHANNEL_IPMB0; request->cmd = cmd; request->netFN = netfn; request->data_len = datalen; memcpy(request->data, data, datalen); if (xQueueSend(msg_hub_rx_queue, &request, QUEUE_BLOCK_10) != pdPASS) { uart_printf("ERR: %s: msg_hub_rx_queue full\n", __func__); mon_queues |= MON_QUEUE_MSG_HUB_RX; msg_free(request); } }
/** @brief Function handle qdec events. */ static void qdec_event_handler(nrf_drv_qdec_event_t event) { if (event.type == NRF_QDEC_EVENT_REPORTRDY) { m_accdblread = event.data.report.accdbl; m_accread = event.data.report.acc; if (m_accdblread==0) { m_value += m_accread; } if (m_value<0) { m_value = 0; } else if (m_value>100) { m_value=100; } if (m_value != m_last_value) { uart_printf("report dbl=%u acc=%d",m_accdblread,m_accread); if (m_accread>0) { uart_printf("\x1B[1;32m"); // GREEN } else { uart_printf("\x1B[1;31m"); // RED } uart_printf(" val=%d\n\r",m_value); m_last_value = m_value; uart_printf("\x1B[0m"); // DEFAULT color } } }
void PVDTset() { RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); PWR_PVDLevelConfig(PWR_PVDLevel_2V8); //PWR_PVDLevelConfig(PWR_PVDLevel_2V6); PWR_PVDCmd(ENABLE); while(1) { if(PWR_GetFlagStatus(PWR_FLAG_PVDO)) { uart_printf("VDD<2.8V=PWR->CSR\r\n"); break; } } uart_printf("PWR->CSR=0x%x\r\n",PWR->CSR); while(1) { if(PWR_GetFlagStatus(PWR_FLAG_PVDO)==0) { uart_printf("VDD>2.8V=PWR->CSR\r\n"); break; } } }
static void cli_command_set(char *args) { char *token; cli_strip_spaces(&args); token = args; if(cli_strip_word(&args)) { uart_printf("1 Incorrect format, set prompt [\"text\"]\n"); return; } if(strcmp(token, "prompt") == 0) { ++args; cli_strip_spaces(&args); token = args; if(cli_strip_quotes(&args)) { uart_printf("2 Incorrect format, set prompt [\"text\"]\n"); return; } ++token; cli_set_prompt(token); } else { uart_printf("3 Incorrect format, set prompt [\"text\"]\n"); return; } }
// Print stat to UART void stat_dump(void) { unsigned i, ts = rtc_current(); uart_printf("%u %u" UART_EOL, g_stat_group, ts); for (i = 0; i < MAX_GR_ROLES; ++i) { struct stat_buffer const* b = &g_stat_buff[i]; struct stat_entry const* s = &b->e[b->ei]; uart_printf("%u %u %u %u %u ", s->epoch, s->reports_total, s->reports_received, s->first_report_ts, s->last_report_ts ); struct report_packet const* r = &s->last_report; uart_printf("%u %u %u %u %u %u" UART_EOL, r->sn, r->ts, r->bt_pressed, r->bt_pressed_ts, r->bt_released_ts, r->vcc_mv ); } uart_tx_flush(); }
//Magic. void uart_list_devs(void){ const char* directory = "/dev/"; DIR* dir = opendir(directory); if (dir){ struct dirent* de = 0; while ((de = readdir(dir)) != 0){ if (strcmp(de->d_name, ".") == 0 || strcmp(de->d_name, "..") == 0) continue; int pid = -1; int res = sscanf(de->d_name, "%d", &pid); char* instr = strstr(de->d_name, "tty"); if (instr){ uart_printf(CLR_CANCEL,0,"Reading dir: %s \n",de->d_name); char filename[256] = {0}; sprintf(filename, "%s/%s", directory, de->d_name); int fd = open (filename, O_RDWR | O_NONBLOCK); if (fd != -1){ int serinfo; if (ioctl (fd, TIOCMGET, &serinfo) != -1){ uart_printf(CLR_CANCEL,0,"Must be a serial device.\n"); } close(fd); } } } closedir(dir); } }
// transmit to the host new dcd/dsr, it's value based on button. void cdc_serial_state_task(void) { cdc_serial_state_t newState; static cdc_serial_state_t lastState; memset(&newState, 0x00, sizeof(newState)); newState.bRxCarrier = BUTTON_PRESSED(); newState.bTxCarrier = newState.bRxCarrier; if (memcmp(&newState, &lastState, sizeof(newState)) != 0) { uart_printf("\r\nNew button state being sent: "); //change in state, send it. if (usb_cdc_serial_state(newState)) { //state was sent ok, save it in memory so we don't resend it. memcpy(&lastState, &newState, sizeof(lastState)); uart_printf("OK"); } else { uart_printf("FAIL"); } uart_printf("\r\n"); } }
void ftl_trim(UINT32 const lba, UINT32 const num_sectors) { ASSERT(num_sectors > 0); uart_printf("Num sectors: %u", num_sectors); uart_printf("SATA_WBUF_PTR: %u", GETREG(SATA_WBUF_PTR)); uart_printf("g_ftl_write_buf_id: %u", g_ftl_write_buf_id); UINT32 next_write_buf_id = (g_ftl_write_buf_id + num_sectors) % NUM_WR_BUFFERS; for (UINT32 i=0;i<num_sectors;i++) { for (UINT32 j=0;j<512/8;j=j+2) { UINT32 address = read_dram_32(WR_BUF_PTR(g_ftl_write_buf_id)+j*sizeof(UINT32)); UINT32 reg2 = read_dram_32(WR_BUF_PTR(g_ftl_write_buf_id)+(j+1)*sizeof(UINT32)); UINT32 count = reg2 & 0xFFFF0000; // Count stored in the first four words. // If count is zero. We continue, but also, if address is 48bit. // We shouldn't get these unless it is an error. if (count == 0 || (reg2 & 0x0000FFFF) > 0) // continue; // uart_print_hex(address); // uart_print_hex(count); } g_ftl_write_buf_id = (g_ftl_write_buf_id + 1) % NUM_WR_BUFFERS; } SETREG(BM_STACK_WRSET, next_write_buf_id); // change bm_read_limit SETREG(BM_STACK_RESET, 0x02); // change bm_read_limi }
//Interface between fifo and uart_write void uart_write_start(uart_s* uart){ if (!(uart->txfifo)){ uart_printf(CLR_CANCEL,0,"Uart has no txfifo.\n"); return; } //Use a buffer to flatten the fifo. uint8_t* buff = (uint8_t*)malloc(uart->txfifo->size); //Empty the fifo int i = 0; while(fifo_get(uart->txfifo,&buff[i])){ i++; }; uart_printf(CLR_CANCEL,0,"uart_write_start (len %i): \n",i ); #if(UARTDEBUG) printf("Written:\n"); printf_hex_block(buff,i,1); printf("\n"); #endif //Write em out: uart_write(uart,buff,i); //free buffer. free(buff); }
static void cli_command_switch(char *args) { char *token; int value; cli_strip_spaces(&args); token = args; if(cli_strip_decimal_number(&args)) { uart_printf("1 Incorrect format, switch [n] [\"text\"]\n"); return; } value = atoi(token); if(value < 0 || value >= MACRO_MAX) { uart_printf("2 Incorrect format, switch [n] [\"text\"]\n"); return; } ++args; cli_strip_spaces(&args); token = args; if(cli_strip_quotes(&args)) { uart_printf("3 Incorrect format, switch [n] [\"text\"]\n"); return; } macro_set(value, ++token); }
void uart_socket_example(void *param) { char tx_data[] = {0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06}; uart_set_str uartset; struct timeval tv; fd_set readfds; int read_len = 0, count = 0; int ret = 0; char rxbuf[512]; int uart_fd; uart_socket_t *uart_socket = NULL; uartset.BaudRate = 9600; uartset.number = 8; uartset.StopBits = 0; uartset.FlowControl = 0; uartset.parity = 0; strcpy(uartset.UartName, "uart0"); uart_socket = uart_open(&uartset); if(uart_socket == NULL){ uart_printf("Init uart socket failed!\n"); goto Exit; } uart_fd = uart_socket->fd; uart_printf("\nOpen uart socket: %d\n", uart_fd); while(1) { FD_ZERO(&readfds); FD_SET(uart_fd, &readfds); tv.tv_sec = 0; tv.tv_usec = 20000; if(count++ == 50){ uart_write(uart_socket, tx_data, sizeof(tx_data)); //uart_print_data("TX:", tx_data, sizeof(tx_data)); count = 0; } ret = select(uart_fd + 1, &readfds, NULL, NULL, &tv); //uart_printf("[%d] select ret = %x count=%d\n", xTaskGetTickCount(), ret, count); if(ret > 0) { if(FD_ISSET(uart_fd, &readfds)) { read_len = uart_read(uart_socket, rxbuf, sizeof(rxbuf)); if(read_len > 0) { uart_print_data("RX:", rxbuf, read_len); if(rtl_strncmp(rxbuf, "close", 5) == 0) break; } } //else for other sockets } } uart_printf("Exit uart socket example!\n"); uart_close(uart_socket); Exit: vTaskDelete(NULL); }
static void get_transmitter_uptime(void) { if (!g_report_packets) { uart_printf(UART_EOL); } else { uart_printf("%u" UART_EOL, last_report_age() + g_last_report.sn * MEASURING_PERIOD); } uart_tx_flush(); }
//打印舵机角度 void steering_show(void) { int i; int data[22]; steering_get(data); uart_printf("\r\n"); for(i=0 ; i<22 ; i++) uart_printf("%d:%d\r\n", i+1, data[i]); }
uart_socket_t* uart_open(uart_set_str *puartpara) { PinName uart_tx = PA_7;//PA_4; //PA_7 PinName uart_rx = PA_6;//PA_0; //PA_6 uart_socket_t *u; u = (uart_socket_t *)RtlZmalloc(sizeof(uart_socket_t)); if(!u){ uart_printf("%s(): Alloc memory for uart_socket failed!\n", __func__); return NULL; } /*initial uart */ serial_init(&u->sobj, uart_tx,uart_rx); serial_baud(&u->sobj,puartpara->BaudRate); serial_format(&u->sobj, puartpara->number, (SerialParity)puartpara->parity, puartpara->StopBits); /*uart irq handle*/ serial_irq_handler(&u->sobj, uart_irq, (int)u); serial_irq_set(&u->sobj, RxIrq, 1); serial_irq_set(&u->sobj, TxIrq, 1); #if UART_SOCKET_USE_DMA_TX serial_send_comp_handler(&u->sobj, (void*)uart_send_stream_done, (uint32_t)u); #endif /*alloc a socket*/ u->fd = lwip_allocsocketsd(); if(u->fd == -1){ uart_printf("Failed to alloc uart socket!\n"); goto Exit2; } /*init uart related semaphore*/ RtlInitSema(&u->action_sema, 0); RtlInitSema(&u->tx_sema, 1); RtlInitSema(&u->dma_tx_sema, 1); /*create uart_thread to handle send&recv data*/ { #define UART_ACTION_STACKSIZE 512 #define UART_ACTION_PRIORITY 1 if(xTaskCreate(uart_action_handler, ((const char*)"uart_action"), UART_ACTION_STACKSIZE, u, UART_ACTION_PRIORITY, NULL) != pdPASS){ uart_printf("%s xTaskCreate(uart_action) failed", __FUNCTION__); goto Exit1; } } return u; Exit1: /* Free uart related semaphore */ RtlFreeSema(&u->action_sema); RtlFreeSema(&u->tx_sema); RtlFreeSema(&u->dma_tx_sema); Exit2: RtlMfree((u8*)u, sizeof(uart_socket_t)); return NULL; }
void dual_print_reg_dump(unsigned int dual_id, unsigned int *ptr_isp_reg) { if (ptr_isp_reg) { uart_printf("%s %s %s\r\n", DUAL_REG_DUMP_HEADER, DUAL_DUMP_START, DUAL_DUMP_VERSION); uart_printf("%s DEBUG.DUAL_LOG_ID = 0x%08X\r\n", DUAL_REG_DUMP_HEADER, dual_id); DUMP_ISP_REG_MAP(DUAL_CPP_CODE_PRINTF_REG, uart_printf, ptr_isp_reg,); uart_printf("%s %s\r\n", DUAL_REG_DUMP_HEADER, DUAL_DUMP_END); } }
void cli_loop(void) { char buffer[CLI_BUFFER_SIZE]; char c; int buffer_pos; uart_printf("%s", cli_prompt); buffer_pos = 0; while(1) { //wait until a character is available while((c = uart_getchar()) == 0) { ; } //new line means end of the command if(c == '\n') { //only process a command if something was entered if(buffer_pos) { buffer[buffer_pos] = '\0'; cli_process_command(buffer); } buffer_pos = 0; memset(buffer, 0, CLI_BUFFER_SIZE); uart_printf("%s", cli_prompt); } //there is more to come... else if(isgraph(c) || isspace(c)) { buffer[buffer_pos++] = c; } // else if(c == ASCII_DEL) { if(buffer_pos) { buffer_pos--; buffer[buffer_pos] = '\0'; } } //ignore for now else { continue; } //is the command too long? if(buffer_pos >= CLI_BUFFER_SIZE) { uart_printf("\n--Error--, command is too long. Command ignored.\n"); buffer_pos = 0; memset(buffer, 0, CLI_BUFFER_SIZE); uart_printf("%s", cli_prompt); } } }
static void App_TaskStart (void *p_arg) { OS_ERR os_err; (void)p_arg; /* See Note #1. */ BSP_Init(); /* Start BSP and tick initialization. */ BSP_Tick_Init(); /* Start Tick Initialization. */ BSP_UART_Init(BSP_UART_DEFAULT, /* Start UART Initialization */ BSP_BUSCLK, 9600); BSP_LCD_Init(); /* Initialize the seven-segment display panel. */ #if OS_CFG_STAT_TASK_EN > 0u OSStatTaskCPUUsageInit(&os_err); /* Compute CPU capacity with no task running */ #endif #ifdef CPU_CFG_INT_DIS_MEAS_EN CPU_IntDisMeasMaxCurReset(); #endif APP_TRACE_INFO(("Creating Application Events...\n\r")); App_ObjCreate(); /* Create Applicaton kernel objects. */ APP_TRACE_INFO(("Creating Application Tasks...\n\r")); App_TaskCreate(); /* Create Application tasks. */ while (DEF_TRUE) { /* Task body, always written as an infinite loop. */ OSTimeDlyHMSM(0, 0, 2, 0, OS_OPT_TIME_HMSM_STRICT, &os_err); // BSP_UART_Send_String(BSP_UART_1, // "Hello\n"); uart_printf("Hello world\n"); OSTimeDly(10, OS_OPT_TIME_HMSM_STRICT, &os_err); uart_printf("os_err = %d\n", os_err); // while (BSP_SW_Read (BSP_SW_1) != DEF_ON) { // OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); // } // BSP_LED_Toggle(BSP_LED_RED); // // BSP_UART_Send_String(BSP_UART_1, // "Hello\n"); // // while (BSP_SW_Read (BSP_SW_1) == DEF_OFF) { // OSTimeDly(1, OS_OPT_TIME_HMSM_STRICT, &os_err); // } } }
void irtm_print_ekey_info(void) { /* print table header */ uart_printf("+=======================================================================+\n"); uart_printf("|Ch |Type\t|Extension\t|Ports\t\t|Group\t|Asym M\t|Status |\n"); uart_printf("+=======================================================================+\n"); uart_printf("SOON AVAIABLE\n"); /* print table bottom */ uart_printf("+=======================================================================+"); }
// get log vbn from log block mapping table UINT32 get_log_vbn (UINT32 const bank, UINT32 const logLbn) { uart_printf("get_log_vbn(bank=%d, log_lbn=%d)", bank, log_lbn); uart_printf("\treading BMT: log_lbn=%d=>vbn=%d", log_lbn, Read_log_bmt(bank, log_lbn)); #if OPTION_DEBUG_LOG if (logLbn < LOG_BLK_PER_BANK) return Read_log_bmt(bank, logLbn); return INVALID; #else return Read_log_bmt(bank, logLbn); #endif }
// fill entire dataspace static void fillup_dataspace(void) { UINT32 lba = 0; UINT32 const num_sectors = SECTORS_PER_PAGE * NUM_BANKS; uart_printf("start fill entire data space"); while (lba < (NUM_LSECTORS - num_sectors)) { ftl_write(lba, num_sectors); lba += num_sectors; } uart_printf("complete!"); }
/** @brief Function initialization and configuration of QDEC driver instance. */ static void qdec_config(void) { uint32_t err_code; nrf_drv_qdec_config_t qdec_config = NRF_DRV_QDEC_DEFAULT_CONFIG; // Initialize hardware err_code = nrf_drv_qdec_init(&qdec_config, qdec_event_handler); APP_ERROR_CHECK(err_code); printf("QDEC testing started\n"); uart_printf("nrf_drv_qdec_init\n\r"); nrf_drv_qdec_enable(); // Event and corresponding interrupt are enabled. uart_printf("nrf_drv_qdec_enable \n\r"); }
static void cli_command_echo(char *args) { char *token; cli_strip_spaces(&args); token = args; if(cli_strip_quotes(&args)) { uart_printf("Incorrect format, echo [\"text\"]\n"); return; } uart_printf("%s\n", ++token); }
static void format(void) { UINT32 bank, vblock, vcount_val; ASSERT(NUM_MISC_META_SECT > 0); ASSERT(NUM_VCOUNT_SECT > 0); uart_printf("Total FTL DRAM metadata size: %d KB", DRAM_BYTES_OTHER / 1024); uart_printf("VBLKS_PER_BANK: %d", VBLKS_PER_BANK); uart_printf("LBLKS_PER_BANK: %d", NUM_LPAGES / PAGES_PER_BLK / NUM_BANKS); uart_printf("META_BLKS_PER_BANK: %d", META_BLKS_PER_BANK); //---------------------------------------- // initialize DRAM metadata //---------------------------------------- mem_set_dram(PAGE_MAP_ADDR, NULL, PAGE_MAP_BYTES); mem_set_dram(VCOUNT_ADDR, NULL, VCOUNT_BYTES); //---------------------------------------- // erase all blocks except vblock #0 //---------------------------------------- for (vblock = MISCBLK_VBN; vblock < VBLKS_PER_BANK; vblock++) { for (bank = 0; bank < NUM_BANKS; bank++) { vcount_val = VC_MAX; if (is_bad_block(bank, vblock) == FALSE) { nand_block_erase(bank, vblock); vcount_val = 0; } write_dram_16(VCOUNT_ADDR + ((bank * VBLKS_PER_BANK) + vblock) * sizeof(UINT16), vcount_val); } } //---------------------------------------- // initialize SRAM metadata //---------------------------------------- init_metadata_sram(); // flush metadata to NAND logging_pmap_table(); logging_misc_metadata(); write_format_mark(); led(1); uart_print("format complete"); }
int main(void) { int status; memset(RX_BUF,0,4); led_init(); nRF24L01_init(); motor_init(); //电机初始化 QuadCopter_init(&QuadCopter); uart_init(115200); status = nRF_Check(); /*检测NRF模块与MCU的连接*/ if(status == SUCCESS) /*判断连接状态*/ uart_printf("\r\n NRF与MCU连接成功!\r\n"); else uart_printf("\r\n NRF与MCU连接失败,请重新检查接线。\r\n"); nRF_RX_Mode(); LED_OFF; while(1) { nRF_RX_Mode(); nRF_Rx_Dat(RX_BUF); status=RX_BUF[2]; switch(status) { case Q_ON: LED_ON; QuadCopter.Status=Q_ON; QuadCopter.BaseSpeed=300; motor_speed(QuadCopter.BaseSpeed,QuadCopter.BaseSpeed,QuadCopter.BaseSpeed,QuadCopter.BaseSpeed ) ; break; case Q_UP: QuadCopter_up(&QuadCopter); break; case Q_DOWN: QuadCopter_down(&QuadCopter); break; case Q_OFF: LED_OFF; QuadCopter.Status=Q_OFF; motor_speed(0,0,0,0 ) ; break; default: break; } } }
//Reads data into uart's fifo. int uart_read_start(uart_s* uart, int timeout){ if (!uart->rxfifo){ uart_printf(CLR_CANCEL,0,"Uart has no rxfifo\n"); return -1; } uart_printf(CLR_CANCEL,2,"uart_read_start\n"); if (!uart->opened){ uart_open(uart); } //Wiggle /* int status = TIOCM_CTS; ioctl (uart->fd, TIOCMBIS, &status); ioctl (uart->fd, TIOCMBIC, &status); */ //Use a buffer to flatten the fifo. uint8_t* buff = (uint8_t*)malloc(uart->rxfifo->size); int n = uart_read(uart,buff,512,timeout); //Some debug data: uart_printf(CLR_CANCEL,1,"Received %i characters\n",n); #if(UARTDEBUG) if (n){ printf_hex_block(buff,n,1); } #endif if (n == -1){ free(buff); return -1; } //Store in fifo. int i =0; int r=n; while(r--){ fifo_putc(uart->rxfifo,buff[i]); i++; } uart_printf(CLR_CANCEL,1,"Done\n"); free(buff); return n; }
void __attribute__((interrupt("IRQ")))dm9000_isr(void) { unsigned char int_status,Rx_ready; unsigned short Rx_status,Rx_len; int i; if(EINT0PEND & (1 << 7)){ //dm9000 int_status = ior(0xfe); if(int_status & 1){ //rx Rx_ready = ior(0xf0); Rx_ready = ior(0xf0); if(Rx_ready == 1){ DM9000_INDEX = 0xf2; Rx_status = DM9000_DATA16; Rx_len = DM9000_DATA16; for(i = 0;i < (Rx_len + 1) / 2;i++){ ((unsigned short*)Net_Rxbuf)[i] = DM9000_DATA16; } /// uart_puts(Net_Rxbuf + 42); } iow(0xfe,1); } if(int_status & 2){//tx if(ior(0x01) & (4 | 8)){ uart_printf("dm9000 send complete\n"); } iow(0xfe,2); } EINT0PEND = (1 << 7); } VIC0ADDRESS = 0; VIC1ADDRESS = 0; }
// TODO: double check datasheet, could be faster (smaller delays) void humidity_sensor_read(Humidity_Sensor h, char *read_data, uint16_t max_bytes) { if (h.write) {} // stop complaining i2c_start(AM2315_TWI_ADDRESS_WRITE); // Sensor doesn't respond to start signal _delay_ms(2); // TODO: wait could be shorter? i2c_stop(); // should be woke now if(i2c_start(AM2315_TWI_ADDRESS_WRITE)) {// tell it to generate the temp and hum uart_puts_P(PSTR("Couldn't communicate with humidity sensor\r\n")); return; } i2c_write(READREGCODE); i2c_write(BEGINREG); i2c_write(NUMREGTOREAD); i2c_stop(); _delay_ms(10); // TODO: wait could be shorter? uint8_t ret[NUMBYTESTOSTORE]; i2c_start(AM2315_TWI_ADDRESS_READ); // now read the data for (int i = 0; i < NUMBYTESTOSTORE - 1; i++) ret[i] = i2c_read(1); ret[NUMBYTESTOSTORE - 1] = i2c_read(0); // this reads and sends a CRC signal i2c_stop(); if (ret[0] != READREGCODE || ret[1] != NUMREGTOREAD) { uart_puts_P(PSTR("Error reading humidity sensor\r\n")); return; } // note that both these values are 10 times what they should be but // representing with floating point is a terrible idea so we manipulate the // print statement instead uint16_t hum = ((ret[2] << 8) | ret[3]); uint16_t temp = ((ret[4] << 8) | ret[5]); // NOTE that leading bit is sign uart_printf("Humidity is %d.%d %%RH and Temperature is %s%d.%d C\r\n", hum / 10, hum % 10, // hum / 10 first, then last digit goes after '.' ret[4] & 0x80 ? "-" : "", // handle the sign (if leading is set, then neg) (temp & 0x7f) / 10, temp % 10); // same as humidity except don't count b15 snprintf(read_data, max_bytes, "%d.%d %%RH\r\n", hum / 10, hum % 10); }