void display_mode(void) { uint8_t mode, last_mode; mode = last_mode = read_mode(); set_mode_lights(mode); input_clear_button_pressed(); while (1) { last_mode = mode; mode = read_mode(); if(mode != last_mode) { set_mode_lights(mode); play_tone(2000,10); game_set_mode(mode); } if (input_button_pressed()) { _delay_ms(100); break; } } set_leds(ALL_LEDS, OFF); }
static int kpn_chip_ready(void) { if (read_mode() & KPN_RDY1) return 1; return 0; }
uint8_t Extsram::read_single_byte(uint16_t addr){ uint8_t data; read_mode(); set_address(addr); ce = low; oe = low; data = *data_v; default_mode(); return data; }
void read_parameters(int *n_threads,char *mode,int *precision, double *x,char *option, int argc, char **argv) { if(argc < 5) error_message(NOT_ENOUGH_PARAMETERS); /* Leitura do primeiro parametro (número de núcleos) */ *n_threads = read_ncores(argv[1]); /* Leitura do segundo parametro (modo)*/ *mode = read_mode(argv[2]); /* leitura do terceiro parametro (precisão) */ *precision = read_precision(argv[3]); /* Leitura do quarto paraemetro (x) */ *x = read_value(argv[4]); /* Leitura do quinto parametro OPCIONAL */ if(argc == 6) *option = read_optional_parameter(argv[5]); }
/*Func: read_from_stat() * This fucnction create stat type struct * Read the information from stat() * Check to see if there is error * Calling functions to read info of the file: * timestamp * user_id, group_id * mode, size, numintro */ void read_from_stat(file *info){ int t=0; struct stat fileinfo; t = fstat(info->desc,&fileinfo); //perror("File Stat"); if(t==-1){ printf(CY"Error: File stat cannot be read. \nProgram is now exiting!\n"NC); exit(EXIT_FAILURE); } read_time(info, fileinfo); read_ids(info, fileinfo); read_mode(info, fileinfo); read_size(info, fileinfo); }
static void pick_startup_mode(void) { // Reading configrutaion etc. from non-volatile memory init_zcl(); uint8_t start_mode = read_mode(); // Actual mode selection if (start_mode != MODE_SLEEP) { cube_start(0); // cube_start() does implicit modification to 'mode'. } mode = start_mode; use_stored_effect(); use_stored_playlist(); }
static void kpn_nand_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) { u8 reg_val = read_mode(); if (ctrl & NAND_CTRL_CHANGE) { reg_val = reg_val & ~(KPN_ALE + KPN_CLE); if (ctrl & NAND_CLE) reg_val = reg_val | KPN_CLE; if (ctrl & NAND_ALE) reg_val = reg_val | KPN_ALE; if (ctrl & NAND_NCE) reg_val = reg_val & ~KPN_CE1N; else reg_val = reg_val | KPN_CE1N; write_mode(reg_val); } if (cmd != NAND_CMD_NONE) write_data(cmd); /* wait until flash is ready */ kpn_wait_rdy(); }
/* ***************************************************************************** * MAIN PROGRAM ***************************************************************************** */ int main (int argc, char *argv[]) { char *progname = argv[0]; char *modeStr = NULL; char *usedModeStr = NULL; char *fileName = NULL; char *modefileName = NULL; char *serialFileName = NULL; FILE *file_speech = NULL; /* File of speech data */ FILE *file_serial = NULL; /* File of coded bits */ FILE *file_modes = NULL; /* File with mode information */ Word16 new_speech[L_FRAME]; /* Pointer to new speech data */ Word16 serial[SERIAL_FRAMESIZE]; /* Output bitstream buffer */ #ifdef MMS_IO UWord8 packed_bits[MAX_PACKED_SIZE]; Word16 packed_size; #endif Word32 frame; Word16 dtx = 0; /* enable encoder DTX */ /* changed eedodr */ Word16 reset_flag; int i; enum Mode mode; enum Mode used_mode; enum TXFrameType tx_type; int useModeFile = 0; Speech_Encode_FrameState *speech_encoder_state = NULL; sid_syncState *sid_state = NULL; proc_head ("Encoder"); fprintf(stderr, "Code compiled with VAD option: %s\n\n", get_vadname()); /*----------------------------------------------------------------------* * Process command line options * *----------------------------------------------------------------------*/ while (argc > 1) { if (strcmp(argv[1], "-dtx") == 0) { dtx = 1; } else if (strncmp(argv[1], "-modefile=", 10) == 0) { useModeFile = 1; modefileName = argv[1]+10; } else break; argc--; argv++; } /*----------------------------------------------------------------------* * Check number of arguments * *----------------------------------------------------------------------*/ if ( (argc != 4 && !useModeFile) || (argc != 3 && useModeFile)) { fprintf (stderr, " Usage:\n\n" " %s [-dtx] amr_mode speech_file bitstream_file\n\n" " or \n\n" " %s [-dtx] -modefile=mode_file speech_file bitstream_file\n\n" " -dtx enables DTX mode\n" " -modefile=mode_file reads AMR modes from text file (one line per frame)\n\n", progname, progname); exit (1); } /*----------------------------------------------------------------------* * Open mode file or convert mode string * *----------------------------------------------------------------------*/ if (useModeFile) { fileName = argv[1]; serialFileName = argv[2]; /* Open mode control file */ if (strcmp(modefileName, "-") == 0) { file_modes = stdin; } else if ((file_modes = fopen (modefileName, "rt")) == NULL) { fprintf (stderr, "Error opening mode control file %s !!\n", modefileName); exit (1); } fprintf (stderr, " Mode control file: %s\n", modefileName); } else { modeStr = argv[1]; fileName = argv[2]; serialFileName = argv[3]; /* check and convert mode string */ if (str2mode(modeStr, &mode) != 0 && mode != MRDTX) { fprintf(stderr, "Invalid amr_mode specified: '%s'\n", modeStr); exit(1); } } /*----------------------------------------------------------------------* * Open speech file and result file (output serial bit stream) * *----------------------------------------------------------------------*/ if (strcmp(fileName, "-") == 0) { file_speech = stdin; } else if ((file_speech = fopen (fileName, "rb")) == NULL) { fprintf (stderr, "Error opening input file %s !!\n", fileName); exit (1); } fprintf (stderr, " Input speech file: %s\n", fileName); if (strcmp(serialFileName, "-") == 0) { file_serial = stdout; } else if ((file_serial = fopen (serialFileName, "wb")) == NULL) { fprintf (stderr,"Error opening output bitstream file %s !!\n",serialFileName); exit (1); } fprintf (stderr, " Output bitstream file: %s\n", serialFileName); /*-----------------------------------------------------------------------* * Initialisation of the coder. * *-----------------------------------------------------------------------*/ if ( Speech_Encode_Frame_init(&speech_encoder_state, dtx, "encoder") || sid_sync_init (&sid_state)) exit(-1); #ifdef MMS_IO /* write magic number to indicate single channel AMR file storage format */ fwrite(AMR_MAGIC_NUMBER, sizeof(UWord8), strlen(AMR_MAGIC_NUMBER), file_serial); #endif /*-----------------------------------------------------------------------* * Process speech frame by frame * *-----------------------------------------------------------------------*/ frame = 0; while (fread (new_speech, sizeof (Word16), L_FRAME, file_speech) == L_FRAME) { /* read new mode string from file if required */ if (useModeFile) { int res; if ((res = read_mode(file_modes, &mode)) == EOF) { fprintf(stderr, "\nend of mode control file reached"); break; } else if (res == 1) exit(-1); } frame++; /* zero flags and parameter bits */ for (i = 0; i < SERIAL_FRAMESIZE; i++) serial[i] = 0; /* check for homing frame */ reset_flag = encoder_homing_frame_test(new_speech); /* encode speech */ Speech_Encode_Frame(speech_encoder_state, mode, new_speech, &serial[1], &used_mode); /* print frame number and mode information */ mode2str(mode, &modeStr); mode2str(used_mode, &usedModeStr); if ( (frame%50) == 0) { fprintf (stderr, "\rframe=%-8d mode=%-5s used_mode=%-5s", frame, modeStr, usedModeStr); } /* include frame type and mode information in serial bitstream */ sid_sync (sid_state, used_mode, &tx_type); #ifndef MMS_IO serial[0] = tx_type; if (tx_type != TX_NO_DATA) { serial[1+MAX_SERIAL_SIZE] = mode; } else { serial[1+MAX_SERIAL_SIZE] = -1; } /* write bitstream to output file */ if (fwrite (serial, sizeof (Word16), SERIAL_FRAMESIZE, file_serial) != SERIAL_FRAMESIZE) { fprintf(stderr, "\nerror writing output file: %s\n", strerror(errno)); exit(-1); } #else packed_size = PackBits(used_mode, mode, tx_type, &serial[1], packed_bits); /* write file storage format bitstream to output file */ if (fwrite (packed_bits, sizeof (UWord8), packed_size, file_serial) != packed_size) { fprintf(stderr, "\nerror writing output file: %s\n", strerror(errno)); exit(-1); } #endif fflush(file_serial); /* perform homing if homing frame was detected at encoder input */ if (reset_flag != 0) { Speech_Encode_Frame_reset(speech_encoder_state); sid_sync_reset(sid_state); } } fprintf (stderr, "\n%d frame(s) processed\n", frame); /*-----------------------------------------------------------------------* * Close down speech coder * *-----------------------------------------------------------------------*/ Speech_Encode_Frame_exit(&speech_encoder_state); sid_sync_exit (&sid_state); return (0); }