I2CModule * initI2C(void) { I2CModule * i2c = malloc(sizeof (i2c_p)); g_i2c_receiveBuffer = initFIFO(I2C_REC_BUFFER_SIZE); g_i2c_transmitBuffer = initFIFO(I2C_TRN_BUFFER_SIZE); i2c->receiveBuffer = g_i2c_receiveBuffer; i2c->transmitBuffer = g_i2c_transmitBuffer; g_receiveBufferFull = FALSE; g_transmitBufferFull = FALSE; I2C2CONSET = 0x8040; I2C2ADD = SLAVE_ADDRESS; I2C2MSK = 0; IPC9SET = 0xC0000; IFS1CLR = 0x02000000; IEC1SET = 0x02000000; return i2c; }
int main (int argc, char **argv) { #ifdef CLEAR strcpy(table_path, dirname(argv[0])); strcat(table_path, "/"); strcat(table_path, argv[2]); shm_unlink(table_path); #else // verifies if the number of arguments is correct if (argc != 4) { printf("usage: %s <player's name> <table's name> <nr. players>\n", argv[0]); return -1; } if (verifyCmdArgs(argv) == -1) { return -1; } // installs an exit handler if (atexit(exitHandler) == -1) { perror("atexit()"); exit(-1); } blockSignals(); initFIFO(argv[1]); initSharedMem(argv); waitForPlayers(); pthread_t tid; if (is_dealer) { initDefaultDeck(); printCardsList(cards, NULL); shuffleDeck(); randomiseFirstPlayer(); if ((errno = pthread_create(&tid, NULL, dealCards, NULL)) != 0) { perror("pthread_create()"); exit(-1); } } receiveCards(); reorderCardsList(hand); if (is_dealer) { pthread_join(tid, NULL); } //call thread responsible for showing info about the game and manage the game pthread_t tidG; if ((errno = pthread_create(&tidG, NULL, playGame, NULL)) != 0) { perror("pthread_create()"); exit(-1); } pthread_join(tidG, NULL); #endif return 0; }