int notmain ( void ) { unsigned int ra; //PUT8(PADIR_L,GET8(PADIR_L)|0x01); PUT8(PASEL0_L,GET8(PASEL0_L)& ~0x01); PUT8(PASEL1_L,GET8(PASEL1_L)& ~0x01); PUT32(SYST_CSR,4); PUT32(SYST_RVR,1200000-1); PUT32(SYST_CVR,1200000-1); PUT32(SYST_CSR,5); ra=GET8(PAOUT_L); while(1) { ra^=1; PUT8(PAOUT_L,ra); delay(); ra^=1; PUT8(PAOUT_L,ra); delay(); } return(0); }
void EP0_RX_routine() { if((GET8(USB0_CORE + CSR0)&0b1) == 0) // if !RxPktRdy, { return; } uint32_t size = GET8(USB0_CORE+COUNT0)&0x7F; if(size == 0) { return; } if((to_receive - ptr_received) > 64) { USB_ReadFrom(&(EP_get_buffer[0][ptr_received]),size,0); PUT8(USB0_CORE+CSR0,(1<<6)); ptr_received += size; } else { USB_ReadFrom(&(EP_get_buffer[0][ptr_received]),size,0); PUT8(USB0_CORE+CSR0,(1<<6)|(1<<3)); ptr_received = 0; to_receive = 0; USB_state_EP0 = IDLE; } }
void UART_putC(UART_t uart, char c) { unsigned int uart_base = UART_ARRAY_BASE[uart]; while((GET8(uart_base+0x14)&0x20)!=0x20); //wait until txfifo is empty PUT8(uart_base +0,c); while((GET8(uart_base+0x14)&0x20)!=0x20); //wait until txfifo is empty }
static void lpc2292_serial_putc(const char c) { if (c == '\n') { while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */ PUT8(U0THR, '\r'); } while((GET8(U0LSR) & (1<<5)) == 0); /* Wait for empty U0THR */ PUT8(U0THR, c); }
//------------------------------------------------------------------------ static void uart_init ( void ) { PUT8(PASEL1_L,GET8(PASEL1_L)&0xF3); PUT8(PASEL0_L,GET8(PASEL0_L)|0x0C); PUT16(UCA0CTLW0,0x0081); //PUT16(UCA0BRW,104); //12000000/115200 = 104 PUT16(UCA0BRW,26); //3000000/115200 = 26 PUT16(UCA0MCTLW,0x0000); PUT16(UCA0IE,0); PUT16(UCA0CTLW0,0x0081); PUT16(UCA0CTLW0,0x0080); }
void acpi_db_display_namestring ( NATIVE_CHAR *name) { u32 seg_count; u8 do_dot = FALSE; if (!name) { acpi_os_printf ("<NULL NAME PTR>"); return; } if (acpi_ps_is_prefix_char (GET8 (name))) { /* append prefix character */ acpi_os_printf ("%1c", GET8 (name)); name++; } switch (GET8 (name)) { case AML_DUAL_NAME_PREFIX: seg_count = 2; name++; break; case AML_MULTI_NAME_PREFIX_OP: seg_count = (u32) GET8 (name + 1); name += 2; break; default: seg_count = 1; break; } while (seg_count--) { /* append Name segment */ if (do_dot) { /* append dot */ acpi_os_printf ("."); } acpi_os_printf ("%4.4s", name); do_dot = TRUE; name += 4; } }
static isc_result_t value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) { unsigned int msgtype; isc_uint32_t len; isccc_sexpr_t *value; isccc_region_t active; isc_result_t result; if (REGION_SIZE(*source) < 1 + 4) return (ISC_R_UNEXPECTEDEND); GET8(msgtype, source->rstart); GET32(len, source->rstart); if (REGION_SIZE(*source) < len) return (ISC_R_UNEXPECTEDEND); active.rstart = source->rstart; active.rend = active.rstart + len; source->rstart = active.rend; if (msgtype == ISCCC_CCMSGTYPE_BINARYDATA) { value = isccc_sexpr_frombinary(&active); if (value != NULL) { *valuep = value; result = ISC_R_SUCCESS; } else result = ISC_R_NOMEMORY; } else if (msgtype == ISCCC_CCMSGTYPE_TABLE) result = table_fromwire(&active, NULL, valuep); else if (msgtype == ISCCC_CCMSGTYPE_LIST) result = list_fromwire(&active, valuep); else result = ISCCC_R_SYNTAX; return (result); }
static isc_result_t table_fromwire(isccc_region_t *source, isccc_region_t *secret, isc_uint32_t algorithm, isccc_sexpr_t **alistp) { char key[256]; isc_uint32_t len; isc_result_t result; isccc_sexpr_t *alist, *value; isc_boolean_t first_tag; unsigned char *checksum_rstart; REQUIRE(alistp != NULL && *alistp == NULL); checksum_rstart = NULL; first_tag = ISC_TRUE; alist = isccc_alist_create(); if (alist == NULL) return (ISC_R_NOMEMORY); while (!REGION_EMPTY(*source)) { GET8(len, source->rstart); if (REGION_SIZE(*source) < len) { result = ISC_R_UNEXPECTEDEND; goto bad; } GET_MEM(key, len, source->rstart); key[len] = '\0'; /* Ensure NUL termination. */ value = NULL; result = value_fromwire(source, &value); if (result != ISC_R_SUCCESS) goto bad; if (isccc_alist_define(alist, key, value) == NULL) { result = ISC_R_NOMEMORY; goto bad; } if (first_tag && secret != NULL && strcmp(key, "_auth") == 0) checksum_rstart = source->rstart; first_tag = ISC_FALSE; } if (secret != NULL) { if (checksum_rstart != NULL) result = verify(alist, checksum_rstart, (unsigned int) (source->rend - checksum_rstart), algorithm, secret); else result = ISCCC_R_BADAUTH; } else result = ISC_R_SUCCESS; bad: if (result == ISC_R_SUCCESS) *alistp = alist; else isccc_sexpr_free(&alist); return (result); }
BYTE CharacterInfoTable::GetUnicodeCategory(WCHAR wch) { // Access the 8:4:4 table. The compiler should be smart enough to remove the redundant locals in the following code. // These locals are added so that we can debug this easily from the debug build. BYTE index1 = m_pLevel1ByteIndex[GET8(wch)]; WORD offset = m_pLevel2WordOffset[index1].offset[GETHI4(wch)]; BYTE result = m_pByteData[offset+GETLO4(wch)]; return (result); }
int USB_ReadFrom(uint8_t *dst, uint32_t size, uint8_t endpoint) { USB_DBG("RD 0x%X\n",size); for(int i = 0; i < size; i++) { dst[i] = GET8(USB0_CORE+FIFOx+(endpoint<<2)); } return size; }
void notmain ( void ) { unsigned int ra,rb,rc,rd,re,rf; unsigned int lastcount,nowcount; unsigned int nticks; unsigned int oneled; //init GPIO ra=GET8(FIO1DIR2); ra|=0xB4; PUT8(FIO1DIR2,ra); ra=FIO1SET2; rb=FIO1CLR2; rc=0x80; rd=0x20; re=0x10; rf=0x04; PUT8(rb,rc); PUT8(rb,rd); PUT8(rb,re); PUT8(rb,rf); oneled=0; twoled=0; //4MHz, 12000000 counts is 3 seconds PUT32(STCTRL,0x00000004); PUT32(STRELOAD,12000000-1); PUT32(STCTRL,0x00000007); //interrupt enabled //4Mhz/4 = 1Mhz 500000 is half a second nticks=500000; PUT32(T0CR,1); //enable timer lastcount=GET32(T0TC); while(1) { nowcount=GET32(T0TC); nowcount-=lastcount; //upcounter if(nowcount>=nticks) { if(oneled&1) { PUT8(ra,rc); } else { PUT8(rb,rc); } oneled++; lastcount+=nticks; } } while(1) continue; }
UINT16 AcpiPsPeekOpcode ( ACPI_PARSE_STATE *ParserState) { UINT8 *Aml; UINT16 Opcode; Aml = ParserState->Aml; Opcode = (UINT16) GET8 (Aml); Aml++; /* * Original code special cased LNOTEQUAL, LLESSEQUAL, LGREATEREQUAL. * These opcodes are no longer recognized. Instead, they are broken into * two opcodes. * * * if (Opcode == AML_EXTOP * || (Opcode == AML_LNOT * && (GET8 (Aml) == AML_LEQUAL * || GET8 (Aml) == AML_LGREATER * || GET8 (Aml) == AML_LLESS))) * * extended Opcode, !=, <=, or >= */ if (Opcode == AML_EXTOP) { /* Extended opcode */ Opcode = (UINT16) ((Opcode << 8) | GET8 (Aml)); Aml++; } /* don't convert bare name to a namepath */ return (Opcode); }
UINT32 AcpiPsGetNextPackageLength ( ACPI_PARSE_STATE *ParserState) { UINT32 EncodedLength; UINT32 Length = 0; FUNCTION_TRACE ("PsGetNextPackageLength"); EncodedLength = (UINT32) GET8 (ParserState->Aml); ParserState->Aml++; switch (EncodedLength >> 6) /* bits 6-7 contain encoding scheme */ { case 0: /* 1-byte encoding (bits 0-5) */ Length = (EncodedLength & 0x3F); break; case 1: /* 2-byte encoding (next byte + bits 0-3) */ Length = ((GET8 (ParserState->Aml) << 04) | (EncodedLength & 0x0F)); ParserState->Aml++; break; case 2: /* 3-byte encoding (next 2 bytes + bits 0-3) */ Length = ((GET8 (ParserState->Aml + 1) << 12) | (GET8 (ParserState->Aml) << 04) | (EncodedLength & 0x0F)); ParserState->Aml += 2; break; case 3: /* 4-byte encoding (next 3 bytes + bits 0-3) */ Length = ((GET8 (ParserState->Aml + 2) << 20) | (GET8 (ParserState->Aml + 1) << 12) | (GET8 (ParserState->Aml) << 04) | (EncodedLength & 0x0F)); ParserState->Aml += 3; break; } return_VALUE (Length); }
void notmain ( void ) { unsigned int ra,rb,rc,rd,re,rf; unsigned int lastcount,nowcount; pll_init(); //init GPIO ra=GET8(FIO1DIR2); ra|=0xB4; PUT8(FIO1DIR2,ra); ra=FIO1SET2; rb=FIO1CLR2; rc=0x80; rd=0x20; re=0x10; rf=0x04; PUT8(rb,rc); PUT8(rb,rd); PUT8(rb,re); PUT8(rb,rf); PUT32(T0PR,(120-1)); PUT32(T0CR,1); //enable timer lastcount=GET32(T0TC); while(1) { PUT8(ra,rc); while(1) { nowcount=GET32(T0TC); nowcount-=lastcount; //upcounter if(nowcount>=25000000) break; } lastcount+=25000000; PUT8(rb,rc); while(1) { nowcount=GET32(T0TC); nowcount-=lastcount; //upcounter if(nowcount>=25000000) break; } lastcount+=25000000; } }
u32 acpi_ps_get_next_package_length ( ACPI_PARSE_STATE *parser_state) { u32 encoded_length; u32 length = 0; encoded_length = (u32) GET8 (parser_state->aml); parser_state->aml++; switch (encoded_length >> 6) /* bits 6-7 contain encoding scheme */ { case 0: /* 1-byte encoding (bits 0-5) */ length = (encoded_length & 0x3F); break; case 1: /* 2-byte encoding (next byte + bits 0-3) */ length = ((GET8 (parser_state->aml) << 04) | (encoded_length & 0x0F)); parser_state->aml++; break; case 2: /* 3-byte encoding (next 2 bytes + bits 0-3) */ length = ((GET8 (parser_state->aml + 1) << 12) | (GET8 (parser_state->aml) << 04) | (encoded_length & 0x0F)); parser_state->aml += 2; break; case 3: /* 4-byte encoding (next 3 bytes + bits 0-3) */ length = ((GET8 (parser_state->aml + 2) << 20) | (GET8 (parser_state->aml + 1) << 12) | (GET8 (parser_state->aml) << 04) | (encoded_length & 0x0F)); parser_state->aml += 3; break; } return (length); }
/* * audio1575_count() * * Description: * This is called by the framework to get the engine's frame counter * * Arguments: * void *arg The DMA engine to query * * Returns: * frame count for current engine */ static uint64_t audio1575_count(void *arg) { audio1575_port_t *port = arg; audio1575_state_t *statep = port->statep; uint64_t val; uint8_t civ; unsigned n; int civoff; int lvioff; int picoff; mutex_enter(&statep->lock); if (port->num == M1575_REC) { civoff = M1575_PCMICIV_REG; lvioff = M1575_PCMILVIV_REG; picoff = M1575_PCMIPICB_REG; } else { civoff = M1575_PCMOCIV_REG; lvioff = M1575_PCMOLVIV_REG; picoff = M1575_PCMOPICB_REG; } /* * Read the position counters. We also take this opportunity * to update the last valid index to the one just previous to * the one we're working on (so we'll fully loop.) */ n = GET16(picoff); civ = GET8(civoff); PUT8(lvioff, (civ - 1) % M1575_BD_NUMS); n = port->samp_size - (n * sizeof (int16_t)); if (n < port->offset) { val = (port->samp_size - port->offset) + n; } else { val = n - port->offset; } port->offset = n; port->count += (val / (port->nchan * sizeof (int16_t))); val = port->count; mutex_exit(&statep->lock); return (val); }
int Insert844Map( P844_ARRAY pArr, PCT_MAP pMap, WORD WChar, WORD Value1, WORD Value2, WORD Value3, int *cbBuf2, int *cbBuf3) { register int Index; // index into array P844_ARRAY pTbl2; // pointer to second array PCT_MAP_VALUE pTbl3; // pointer to third array // // Use the "8" index to get to the second table. // Allocate it if necessary. // Index = GET8(WChar); if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL) { // // Allocate second table - 16 pointers + 1 word. // The additional 1 word will be used when writing this table // to avoid duplicates of the same table. // if ((pTbl2 = (P844_ARRAY)malloc( (TABLE_SIZE_4 + 1) * sizeof(P844_ARRAY) )) == NULL) { printf("Error: Can't allocate second 8:4:4 buffer.\n"); return (1); } memset(pTbl2, 0, (TABLE_SIZE_4 + 1) * sizeof(P844_ARRAY)); pArr[Index] = pTbl2; // // Keep track of how many "second buffer" allocations were made. // (*cbBuf2)++; } // // Use the "high 4" index to get to the third table. // Allocate it if necessary. // Index = GETHI4(WChar); if ((pTbl3 = pTbl2[Index]) == NULL) { // // Allocate third table - 16 + 2 bytes. // The 2 extra bytes will be used when writing the table. // if ((pTbl3 = (PCT_MAP_VALUE)malloc( (TABLE_SIZE_4 + 2) * (sizeof(CT_MAP_VALUE)) )) == NULL) { printf("Error: Can't allocate third 8:4:4 buffer.\n"); return (1); } // // The last field of the third table is used when writing to the // data file to ensure that each table is written only ONCE // (with muliple pointers to it). This field takes 1 WORD // (2 bytes) and is initialized to 0. // memset(pTbl3, 0, (TABLE_SIZE_4 + 2) * (sizeof(CT_MAP_VALUE))); pTbl2[Index] = pTbl3; // // Keep track of how many "third buffer" allocations were made. // (*cbBuf3)++; } // // Use the "low 4" value to index into the third table. // Save the values at this spot. // Index = GETLO4(WChar); // // Map 3 WORD CType trio to 1 BYTE value. // pTbl3[Index] = MapTrioToByte( pMap, Value1, Value2, Value3 ); // // Make sure the number of entries in the mapping table is // not greater than MAX_CT_MAP_TBL_SIZE. // if (pMap->Length >= MAX_CT_MAP_TBL_SIZE) { printf("Error: CTYPE Mapping Table Too Large.\n"); return (1); } // // Return success. // return (0); }
int Insert844( P844_ARRAY pArr, WORD WChar, DWORD Value, int *cbBuf2, int *cbBuf3, int Size) { register int Index; // index into array P844_ARRAY pTbl2; // pointer to second array P844_ARRAY pTbl3; // pointer to third array // // Use the "8" index to get to the second table. // Allocate it if necessary. // Index = GET8(WChar); if ((pTbl2 = (P844_ARRAY)(pArr[Index])) == NULL) { // // Allocate second table - 16 pointers. // if ((pTbl2 = (P844_ARRAY)malloc( TABLE_SIZE_4 * sizeof(P844_ARRAY) )) == NULL) { printf("Error: Can't allocate second 8:4:4 buffer.\n"); return (1); } memset(pTbl2, 0, TABLE_SIZE_4 * sizeof(P844_ARRAY)); pArr[Index] = pTbl2; // // Keep track of how many "second buffer" allocations were made. // (*cbBuf2)++; } // // Use the "high 4" index to get to the third table. // Allocate it if necessary. // Index = GETHI4(WChar); if ((pTbl3 = pTbl2[Index]) == NULL) { // // Allocate third table - 16 words. // if ((pTbl3 = (P844_ARRAY)malloc(TABLE_SIZE_4 * Size)) == NULL) { printf("Error: Can't allocate third 8:4:4 buffer.\n"); return (1); } memset(pTbl3, 0, TABLE_SIZE_4 * Size); pTbl2[Index] = pTbl3; // // Keep track of how many "third buffer" allocations were made. // (*cbBuf3)++; } // // Use the "low 4" value to index into the third table. // Save the value at this spot. // Index = GETLO4(WChar); if (Size == sizeof(WORD)) { ((WORD *)pTbl3)[Index] = (WORD)Value; } else if (Size == sizeof(DWORD)) { ((DWORD *)pTbl3)[Index] = (DWORD)Value; } else { printf("Code Error: Bad 'Size' parameter for Insert844 Table.\n"); return (1); } // // Return success. // return (0); }
void playdata(u_char *buf, u_int tot, char *name) { long long delta_nsec = 0; u_int delta_ticks; int format, ntrks, divfmt, ticks, t, besttrk = 0; u_int len, mlen; u_char *p, *end, byte, meta; struct track *tracks; u_long bestcur, now; struct track *tp; end = buf + tot; if (verbose) printf("Playing %s (%d bytes) ... \n", name, tot); if (memcmp(buf, MARK_HEADER, MARK_LEN) != 0) { warnx("Not a MIDI file, missing header"); return; } if (GET32(buf + MARK_LEN) != HEADER_LEN) { warnx("Not a MIDI file, bad header"); return; } format = GET16(buf + MARK_LEN + SIZE_LEN); ntrks = GET16(buf + MARK_LEN + SIZE_LEN + 2); divfmt = GET8(buf + MARK_LEN + SIZE_LEN + 4); ticks = GET8(buf + MARK_LEN + SIZE_LEN + 5); p = buf + MARK_LEN + SIZE_LEN + HEADER_LEN; if ((divfmt & 0x80) == 0) ticks |= divfmt << 8; else errx(1, "Absolute time codes not implemented yet"); if (verbose > 1) printf("format=%d ntrks=%d divfmt=%x ticks=%d\n", format, ntrks, divfmt, ticks); if (format != 0 && format != 1) { warnx("Cannnot play MIDI file of type %d", format); return; } if (ntrks == 0) return; tracks = calloc(ntrks, sizeof(struct track)); if (tracks == NULL) err(1, "malloc() tracks failed"); for (t = 0; t < ntrks; ) { if (p >= end - MARK_LEN - SIZE_LEN) { warnx("Cannot find track %d", t); goto ret; } len = GET32(p + MARK_LEN); if (len > end - (p + MARK_LEN + SIZE_LEN)) { warnx("Crazy track length"); goto ret; } if (memcmp(p, MARK_TRACK, MARK_LEN) == 0) { tracks[t].start = p + MARK_LEN + SIZE_LEN; tracks[t].end = tracks[t].start + len; tracks[t].curtime = getvar(&tracks[t]); t++; } p += MARK_LEN + SIZE_LEN + len; } /* * Play MIDI events by selecting the track with the lowest * curtime. Execute the event, update the curtime and repeat. */ now = 0; delta_nsec = 0; if (clock_gettime(CLOCK_MONOTONIC, &ts_last) < 0) err(1, "clock_gettime"); for (;;) { /* Locate lowest curtime */ bestcur = ULONG_MAX; for (t = 0; t < ntrks; t++) { if (tracks[t].curtime < bestcur) { bestcur = tracks[t].curtime; besttrk = t; } } if (bestcur == ULONG_MAX) break; if (verbose > 1) { printf("DELAY %4ld TRACK %2d ", bestcur-now, besttrk); fflush(stdout); } while (now < bestcur) { pause(); if (clock_gettime(CLOCK_MONOTONIC, &ts) < 0) err(1, "clock_gettime"); delta_nsec += 1000000000L * (ts.tv_sec - ts_last.tv_sec); delta_nsec += ts.tv_nsec - ts_last.tv_nsec; ts_last = ts; if (delta_nsec <= 0) continue; delta_ticks = delta_nsec * ticks / (1000LL * tempo); delta_nsec -= 1000LL * delta_ticks * tempo / ticks; now += delta_ticks; } tp = &tracks[besttrk]; byte = *tp->start++; if (byte == MIDI_META) { meta = *tp->start++; mlen = getvar(tp); if (verbose > 1) printf("META %02x (%d)\n", meta, mlen); dometa(meta, tp->start, mlen); tp->start += mlen; } else { if (MIDI_IS_STATUS(byte)) tp->status = byte; else tp->start--; if (MIDI_IS_COMMON(tp->status)) { mlen = MIDI_LENGTH(tp->status); send_event(tp->status, tp->start, mlen); } else if (tp->status == MIDI_SYSEX_START) { mlen = getvar(tp); send_event(MIDI_SYSEX_START, tp->start, mlen); } else if (tp->status == MIDI_SYSEX_STOP) { mlen = getvar(tp); /* Sorry, can't do this yet */; } else { if (verbose) printf("MIDI event 0x%02x ignored\n", tp->status); } tp->start += mlen; } if (tp->start >= tp->end) tp->curtime = ULONG_MAX; else tp->curtime += getvar(tp); } ret: free(tracks); }
/* Test if there is a byte to read */ static int lpc2292_serial_tstc(void) { return (GET8(U0LSR) & 1); }
static int lpc2292_serial_getc(void) { while((GET8(U0LSR) & 1) == 0); return GET8(U0RBR); }
ACPI_PARSE_OBJECT * AcpiPsGetNextField ( ACPI_PARSE_STATE *ParserState) { UINT32 AmlOffset = ParserState->Aml - ParserState->AmlStart; ACPI_PARSE_OBJECT *Field; UINT16 Opcode; UINT32 Name; FUNCTION_TRACE ("PsGetNextField"); /* determine field type */ switch (GET8 (ParserState->Aml)) { default: Opcode = AML_INT_NAMEDFIELD_OP; break; case 0x00: Opcode = AML_INT_RESERVEDFIELD_OP; ParserState->Aml++; break; case 0x01: Opcode = AML_INT_ACCESSFIELD_OP; ParserState->Aml++; break; } /* Allocate a new field op */ Field = AcpiPsAllocOp (Opcode); if (Field) { Field->AmlOffset = AmlOffset; /* Decode the field type */ switch (Opcode) { case AML_INT_NAMEDFIELD_OP: /* Get the 4-character name */ MOVE_UNALIGNED32_TO_32 (&Name, ParserState->Aml); AcpiPsSetName (Field, Name); ParserState->Aml += 4; /* Get the length which is encoded as a package length */ Field->Value.Size = AcpiPsGetNextPackageLength (ParserState); break; case AML_INT_RESERVEDFIELD_OP: /* Get the length which is encoded as a package length */ Field->Value.Size = AcpiPsGetNextPackageLength (ParserState); break; case AML_INT_ACCESSFIELD_OP: /* Get AccessType and AccessAtrib and merge into the field Op */ Field->Value.Integer = ((GET8 (ParserState->Aml) << 8) | GET8 (ParserState->Aml)); ParserState->Aml += 2; break; } } return_PTR (Field); }
/* Test if there is a byte to read */ int serial_tstc (void) { return (GET8(U0LSR) & 1); }
void AcpiPsGetNextSimpleArg ( ACPI_PARSE_STATE *ParserState, UINT32 ArgType, ACPI_PARSE_OBJECT *Arg) { FUNCTION_TRACE_U32 ("PsGetNextSimpleArg", ArgType); switch (ArgType) { case ARGP_BYTEDATA: AcpiPsInitOp (Arg, AML_BYTE_OP); Arg->Value.Integer = (UINT32) GET8 (ParserState->Aml); ParserState->Aml++; break; case ARGP_WORDDATA: AcpiPsInitOp (Arg, AML_WORD_OP); /* Get 2 bytes from the AML stream */ MOVE_UNALIGNED16_TO_32 (&Arg->Value.Integer, ParserState->Aml); ParserState->Aml += 2; break; case ARGP_DWORDDATA: AcpiPsInitOp (Arg, AML_DWORD_OP); /* Get 4 bytes from the AML stream */ MOVE_UNALIGNED32_TO_32 (&Arg->Value.Integer, ParserState->Aml); ParserState->Aml += 4; break; case ARGP_QWORDDATA: AcpiPsInitOp (Arg, AML_QWORD_OP); /* Get 8 bytes from the AML stream */ MOVE_UNALIGNED64_TO_64 (&Arg->Value.Integer, ParserState->Aml); ParserState->Aml += 8; break; case ARGP_CHARLIST: AcpiPsInitOp (Arg, AML_STRING_OP); Arg->Value.String = (char*) ParserState->Aml; while (GET8 (ParserState->Aml) != '\0') { ParserState->Aml++; } ParserState->Aml++; break; case ARGP_NAME: case ARGP_NAMESTRING: AcpiPsInitOp (Arg, AML_INT_NAMEPATH_OP); Arg->Value.Name = AcpiPsGetNextNamestring (ParserState); break; } return_VOID; }
char UART_getC(UART_t uart) { unsigned int uart_base = UART_ARRAY_BASE[uart]; while((GET8(uart_base+0x14)&0x1)==0); //wait for a character to be in the rx fifo return GET8(uart_base+0x0); }
void UART_initUART(UART_t uart, unsigned int baudrate, STOP_BIT_t stopBit, PARITY_BIT_t parity, FLOW_t flowControl) { if(UART_checkValidUart(uart)) { unsigned int uart_base = UART_ARRAY_BASE[uart]; switch(uart) { case UART0: // tx=1.11 rx=1.10 cts=1.8 rts=1.9 GPIO_initPort(GPIO1); CM_setCtrlModule(CM_conf_uart0_txd,0); // do nothing on UART0_tx CM_setCtrlModule(CM_conf_uart0_rxd,(1<<4)|(1<<5)); // set pullup/pulldown & receiver enabled on UART0_rx PAD_setMode(CM_conf_uart0_txd,MODE_0); // set p1.11 as UART0_tx PAD_setMode(CM_conf_uart0_rxd,MODE_0); // set p1.10 as UART0_rx unsigned int temp = CKM_getCLKModuleRegister(CKM_WKUP,CKM_WKUP_CLKSTCTRL); temp &= ~(0b11); temp |= 0b10; // software-forced wake-up transition on the "always on clock domain", TRM Table 8-92 CKM_setCLKModuleRegister(CKM_WKUP,CKM_WKUP_CLKSTCTRL,temp); temp = CKM_getCLKModuleRegister(CKM_PER,CKM_PER_L4HS_CLKSTCTRL); temp &= ~(0b11); temp |= 0b10; // software-forced wake up transition on the L4 high speed domain CKM_setCLKModuleRegister(CKM_PER,CKM_PER_L4HS_CLKSTCTRL,temp); temp = CKM_getCLKModuleRegister(CKM_WKUP,CKM_WKUP_UART0_CLKCTRL); temp &= ~(0b11); temp |= 0b10; // Module is explicitly enabled, TRM Table 8-137 CKM_setCLKModuleRegister(CKM_WKUP,CKM_WKUP_UART0_CLKCTRL,temp); while((CKM_getCLKModuleRegister(CKM_WKUP, CKM_WKUP_UART0_CLKCTRL) & (0b11<<16)) != 0); // wait until clock transition is complete // TODO: verifiy it next block is needed for uart0 // warning, why would the UART1 registers need modification when configuring UART0? temp = CKM_getCLKModuleRegister(CKM_PER,CKM_PER_UART1_CLKCTRL); temp &= ~(0b11); temp |= 0b10; // Module is explicitly enabled, TRM Table 8-137 CKM_setCLKModuleRegister(CKM_PER,CKM_PER_UART1_CLKCTRL,temp); temp = GET32(uart_base+0x54); // SYSC temp |= 0x2; // uart module reset PUT32(uart_base+0x54,temp); while((GET32(uart_base+0x58)&1)==0); // wait for reset to be complete temp = GET8(uart_base+0x54); temp |= (0x1<<3); // no idle PUT8(uart_base+0x54,temp); while(((GET32(uart_base+0x14)&0x40)!=0x40)); // wait for txfifo to be empty float div = 48000000.0/(16.0*(float)baudrate); unsigned int intdiv = (unsigned int) div; PUT8(uart_base+0x04,0); PUT8(uart_base+0x20,0x7); // Disable modeselect (default) TRM table 19-50 PUT8(uart_base+0x0C,~(0x7C)); // divisor latch enable, access DLL DHL, set uart as 8bit PUT8(uart_base+0x00,0); // DLL = 0 PUT8(uart_base+0x04,0); // DHL = 0 PUT8(uart_base+0x0C,0x3); // set uart as 8bit PUT8(uart_base+0x10,0x3); // force /rts & /drt to active (low) (?!) PUT8(uart_base+0x08,0x7); // clear rx&tx FIFOs, and enables them (each 64 bytes deep) PUT8(uart_base+0x0C,~(0x7C)); // divisor latch enable, access DLL DHL, set uart as 8bit PUT8(uart_base+0x00,intdiv&0xFF); // DLL = 0 PUT8(uart_base+0x04,(intdiv>>8)&0x3F); // DHL = 0 // PUT8(uart_base+0x00,26); // DLL/DHL value for 115200 PUT8(uart_base+0x0C,0x3); // set uart as 8 bit PUT8(uart_base+0x20,0); // uart 16x oversampling break; // TODO: implement UART1-5 case UART1: break; case UART2: break; case UART3: break; case UART4: break; case UART5: break; } } }
void USBINT0_IRQHandler() { uint8_t intrusb = GET8(USB0_CORE+INTRUSB); uint16_t intrtx = GET16(USB0_CORE+INTRTX); uint16_t intrrx = GET16(USB0_CORE+INTRRX); NVIC_ClearPending(USBINT0_IRQn); if(intrusb & 0b10) // resume interrupt { // resume routine USB_DBG("resume\n"); } if(intrusb & 0b1000000) // session req interrupt { // session req routine USB_DBG("session req\n"); } if(intrusb & 0b10000000) // Vbus error interrupt { // Vbus error routine USB_DBG("vbus\n"); } if(intrusb & 0b1) // suspend interrupt { // suspend routine USB_DBG("suspend\n"); } if(intrusb & 0b10000) // connect interrupt { // connect routine USB_DBG("connect\n"); } if(intrusb & 0b100000) // disconnect interrupt { // disconnect routine USB_DBG("disconnect\n"); } if(intrusb & 0b100)// reset/babble interrupt { if(0) // host mode? { // babble routine USB_DBG("babble\n"); } else { // reset routine USB_DBG("reset\n"); } } if(intrusb & 0b1000) // SOF interrupt { // SOF routine USB_DBG("sof\n"); } if(intrtx & 0b1) // endpoint 0 interrupt { // endpoint 0 routine //USB_DBG("EP0\n"); USB0_ENDP0Handler(); } if(intrtx & 0xFFFE) // Tx endpoint interrupt { // Tx endpoint routine USB_DBG("TX\n"); } if(intrrx & 0xFFFE) // Rx endpoint interrupt { // Rx endpoint routine USB_DBG("RX\n"); } }
static isc_result_t verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length, isc_uint32_t algorithm, isccc_region_t *secret) { union { isc_hmacmd5_t hmd5; isc_hmacsha1_t hsha; isc_hmacsha224_t h224; isc_hmacsha256_t h256; isc_hmacsha384_t h384; isc_hmacsha512_t h512; } ctx; isccc_region_t source; isccc_region_t target; isc_result_t result; isccc_sexpr_t *_auth, *hmac; unsigned char digest[ISC_SHA512_DIGESTLENGTH]; unsigned char digestb64[HSHA_LENGTH * 4]; /* * Extract digest. */ _auth = isccc_alist_lookup(alist, "_auth"); if (!isccc_alist_alistp(_auth)) return (ISC_R_FAILURE); if (algorithm == ISCCC_ALG_HMACMD5) hmac = isccc_alist_lookup(_auth, "hmd5"); else hmac = isccc_alist_lookup(_auth, "hsha"); if (!isccc_sexpr_binaryp(hmac)) return (ISC_R_FAILURE); /* * Compute digest. */ source.rstart = digest; target.rstart = digestb64; switch (algorithm) { case ISCCC_ALG_HMACMD5: isc_hmacmd5_init(&ctx.hmd5, secret->rstart, REGION_SIZE(*secret)); isc_hmacmd5_update(&ctx.hmd5, data, length); isc_hmacmd5_sign(&ctx.hmd5, digest); source.rend = digest + ISC_MD5_DIGESTLENGTH; break; case ISCCC_ALG_HMACSHA1: isc_hmacsha1_init(&ctx.hsha, secret->rstart, REGION_SIZE(*secret)); isc_hmacsha1_update(&ctx.hsha, data, length); isc_hmacsha1_sign(&ctx.hsha, digest, ISC_SHA1_DIGESTLENGTH); source.rend = digest + ISC_SHA1_DIGESTLENGTH; break; case ISCCC_ALG_HMACSHA224: isc_hmacsha224_init(&ctx.h224, secret->rstart, REGION_SIZE(*secret)); isc_hmacsha224_update(&ctx.h224, data, length); isc_hmacsha224_sign(&ctx.h224, digest, ISC_SHA224_DIGESTLENGTH); source.rend = digest + ISC_SHA224_DIGESTLENGTH; break; case ISCCC_ALG_HMACSHA256: isc_hmacsha256_init(&ctx.h256, secret->rstart, REGION_SIZE(*secret)); isc_hmacsha256_update(&ctx.h256, data, length); isc_hmacsha256_sign(&ctx.h256, digest, ISC_SHA256_DIGESTLENGTH); source.rend = digest + ISC_SHA256_DIGESTLENGTH; break; case ISCCC_ALG_HMACSHA384: isc_hmacsha384_init(&ctx.h384, secret->rstart, REGION_SIZE(*secret)); isc_hmacsha384_update(&ctx.h384, data, length); isc_hmacsha384_sign(&ctx.h384, digest, ISC_SHA384_DIGESTLENGTH); source.rend = digest + ISC_SHA384_DIGESTLENGTH; break; case ISCCC_ALG_HMACSHA512: isc_hmacsha512_init(&ctx.h512, secret->rstart, REGION_SIZE(*secret)); isc_hmacsha512_update(&ctx.h512, data, length); isc_hmacsha512_sign(&ctx.h512, digest, ISC_SHA512_DIGESTLENGTH); source.rend = digest + ISC_SHA512_DIGESTLENGTH; break; default: return (ISC_R_FAILURE); } target.rstart = digestb64; target.rend = digestb64 + sizeof(digestb64); memset(digestb64, 0, sizeof(digestb64)); result = isccc_base64_encode(&source, 64, "", &target); if (result != ISC_R_SUCCESS) return (result); /* * Verify. */ if (algorithm == ISCCC_ALG_HMACMD5) { unsigned char *value; value = (unsigned char *) isccc_sexpr_tostring(hmac); if (!isc_safe_memequal(value, digestb64, HMD5_LENGTH)) return (ISCCC_R_BADAUTH); } else { unsigned char *value; isc_uint32_t valalg; value = (unsigned char *) isccc_sexpr_tostring(hmac); GET8(valalg, value); if ((valalg != algorithm) || !isc_safe_memequal(value, digestb64, HSHA_LENGTH)) return (ISCCC_R_BADAUTH); } return (ISC_R_SUCCESS); }
int serial_getc (void) { while((GET8(U0LSR) & 1) == 0); return GET8(U0RBR); }
NATIVE_CHAR * AcpiPsGetNextNamestring ( ACPI_PARSE_STATE *ParserState) { UINT8 *Start = ParserState->Aml; UINT8 *End = ParserState->Aml; UINT32 Length; FUNCTION_TRACE ("PsGetNextNamestring"); /* Handle multiple prefix characters */ while (AcpiPsIsPrefixChar (GET8 (End))) { /* include prefix '\\' or '^' */ End++; } /* Decode the path */ switch (GET8 (End)) { case 0: /* NullName */ if (End == Start) { Start = NULL; } End++; break; case AML_DUAL_NAME_PREFIX: /* two name segments */ End += 9; break; case AML_MULTI_NAME_PREFIX_OP: /* multiple name segments */ Length = (UINT32) GET8 (End + 1) * 4; End += 2 + Length; break; default: /* single name segment */ /* assert (AcpiPsIsLead (GET8 (End))); */ End += 4; break; } ParserState->Aml = (UINT8*) End; return_PTR ((NATIVE_CHAR *) Start); }