static void send_bit(uint8_t bit) { ir_set(!bit); wait_ticks(HALF_BIT_TICKS); ir_set(bit); wait_ticks(HALF_BIT_TICKS); }
void sensor_delay_ms(uint32_t msecs) { if (msecs >= CONVERT_TICKS_TO_MS(1)) { T_SEMAPHORE sem = semaphore_create(0); semaphore_take(sem, (int)msecs + 1); /* details in FIRE-5618 */ semaphore_delete(sem); } else { wait_ticks(msecs * AON_CNT_TICK_PER_MS); } }
/* * We implement the delay by converting the delay (the number of * microseconds to wait) into a number of time base ticks; then we * watch the time base until it has incremented by that amount. */ void udelay(unsigned long usec) { ulong ticks, kv; do { kv = usec > CONFIG_WD_PERIOD ? CONFIG_WD_PERIOD : usec; ticks = usec2ticks (kv); wait_ticks (ticks); usec -= kv; } while(usec); }
void sensor_delay_ms(uint32_t msecs) { if (msecs >= CONVERT_TICKS_TO_MS(1)) { T_SEMAPHORE sem = semaphore_create(0); /* Ensure that we will wait at least 'msecs' millisecond as if semaphore_take is called * right before the timer tick interrupt it will be released immediately */ semaphore_take(sem, (int)msecs + 1); semaphore_delete(sem); } else { wait_ticks(msecs * AON_CNT_TICK_PER_MS); } }
int main(void) { int value, i; unsigned char data[0x4000]; FILE *file; ioperm(PORT_BASE,8,1); out_port(0,0); out_port(0,1); // CS on out_port(0,2); // out_port(0,6); // vpp off out_port(4,3); // VCC on, VCC=5V, Socket=24pin, /OE=0, read wait_ticks (100000); // for (i=0; i<0x40; i++) { for (i=0; i<0x4000; i++) { out_addr(i); wait_ticks(100); value=inb(PORT_BASE+4); data[i]=value; if ((i&0xf)==0) printf("%.4x:",i); printf(" %.2x", value); if ((i&0xf)==0xf) printf("\n"); } out_port(0xf8,2); // led off out_port(0,3); //VCC off out_port(0,6); //VPP off out_port(0,0); file=fopen("dil24.bin","wb"); fwrite(data,1,sizeof(data),file); fclose(file); return 0; }
void writelog( signed char *str, int rc, signed char *msg ) { int i = 0; time_t tt; FILE *fp; if ( *logfile && *msg ) { time( &tt ); while( i++ < 5 ) { /* Try 5 times to open the potentially busy file*/ if ( !( fp = fopen( logfile, "a" ) ) ) { wait_ticks( 10 ); /* 0.5 seconds between attempts */ continue; } fprintf( fp, "%s: %24.24s %s %d %s\n", pname, ctime( &tt ), str, rc, msg ); fclose( fp ); break; } if ( i == 5 ) fprintf( stderr, "Unable to append to logfile '%s'.\n", logfile ); } }
/* * We implement the delay by converting the delay (the number of * microseconds to wait) into a number of time base ticks; then we * watch the time base until it has incremented by that amount. */ void __udelay(unsigned long usec) { ulong ticks = usec2ticks(usec); wait_ticks(ticks); }
void* arrumador(void* arg) { info_t info; int fd_vehicle; int accepted = 0; feedback_t feedback; pthread_detach(pthread_self()); info = *(info_t *) arg; if ( (fd_vehicle = open(info.vehicle_fifo_name, O_WRONLY)) == -1 ) { perror(strcat(info.vehicle_fifo_name, " FIFO opening failed on arrumador")); free(arg); return NULL; } // Validar entrada (Zona critica) pthread_mutex_lock(&arrumador_lock); if (numLugaresOcupados < numLugares) { accepted = 1; numLugaresOcupados++; strcpy(feedback.msg, ACCEPTED_STR); park_log(info, LOG_ACCEPTED_STR); } else { strcpy(feedback.msg, FULL_STR); park_log(info, LOG_FULL_STR); } pthread_mutex_unlock(&arrumador_lock); /*********************************/ write(fd_vehicle, &feedback, sizeof(feedback)); if (accepted) { feedback_t exit_feedback; // Esperar wait_ticks(info.parking_time); // Validar saida (Zona critica) pthread_mutex_lock(&arrumador_lock); numLugaresOcupados--; strcpy(exit_feedback.msg, EXITING_STR); park_log(info, LOG_EXITING_STR); pthread_mutex_unlock(&arrumador_lock); /*********************************/ write(fd_vehicle, &exit_feedback, sizeof(exit_feedback)); } free(arg); close(fd_vehicle); return NULL; }