static guint count_parity (GtkRBTree *tree, GtkRBNode *node) { guint res; if (node == tree->nil) return 0; res = count_parity (tree, node->left) + count_parity (tree, node->right) + (guint)1 + (node->children ? count_parity (node->children, node->children->root) : 0); res = res % (guint)2; if (res != node->parity) g_print ("parity incorrect for node\n"); if (get_parity (node) != 1) g_error ("Node has incorrect parity %u", get_parity (node)); return res; }
//TODO: implement sanity checks. hal_uart_port hal_uart_open(hal_uart_port port, hal_uart_baudrate baudrate, hal_uart_parity parity, hal_uart_stop_bits stop_bits, hal_uart_on_data_received_callback data_received){ on_data_received[port] = data_received; assert(port >= HAL_UART_PORT_1 && port <= HAL_UART_NUMBER_OF_PORTS ); /* Configure uart */ UART_MODULE uart = logic_uart2phy_uart(port); SetRxTxPins(uart); UARTConfigure(uart, UART_ENABLE_PINS_TX_RX_ONLY); UARTSetFifoMode(uart, UART_INTERRUPT_ON_TX_DONE | UART_INTERRUPT_ON_RX_NOT_EMPTY); UARTSetLineControl(uart, UART_DATA_SIZE_8_BITS | get_parity(parity) | get_stop_bits(stop_bits)); UARTSetDataRate(uart, PIC32_PERIPHERALBUS_FREQ, get_baudrate(baudrate)); UARTEnable(uart, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_TX | UART_RX)); INTClearFlag(INT_SOURCE_UART_RX(uart)); INTEnable(INT_SOURCE_UART_RX(uart),INT_ENABLED); return port; }