void ExtEeprom_ReadBlock(uns8 *array, const uns8 adress, const uns8 length) { if (adress <= EEPROM_MEMORY_END_ADRESS) { if (g_ExtEepromDetected) { I2C_ReadBlock(EEPROM_ADRESS, array, adress, length); } } else { Trace_String("invalid ext eeprom adress"); } }
void ExtEeprom_Write(const uns8 adress, const uns8 data) { if (adress <= EEPROM_MEMORY_END_ADRESS) { if (g_ExtEepromDetected) { I2C_Write(EEPROM_ADRESS, adress, data); } } else { Trace_String("invalid ext eeprom adress"); } }
uns8 ExtEeprom_Read(const uns8 adress) { if (adress <= EEPROM_MEMORY_END_ADRESS) { if (g_ExtEepromDetected) { return I2C_Read(EEPROM_ADRESS, adress); } } else { Trace_String("invalid ext eeprom adress"); } return 0; }
void Rtc_Init(void) { I2C_Init(); if (I2C_DetectSlave(RTC_MCP79410)) { Trace_String(" 79410 detected "); g_RtcAdress = RTC_MCP79410; } else if (I2C_DetectSlave(RTC_8564JE)) { Trace_String(" 8564JE detected"); g_RtcAdress = RTC_8564JE; } else { Trace_String(" NO RTC detected"); g_RtcAdress = 0x00; } if (g_RtcAdress == RTC_MCP79410) { uns8 temp; //set ST bit in RTC 0x00 //set EXTOSC bit in RTC 0x00 temp = I2C_Read(g_RtcAdress, 0x00); I2C_Write(g_RtcAdress, 0x00, temp | 0b10001000); //set enable Battery bit in RTC 0x03 temp = I2C_Read(g_RtcAdress, 0x03); I2C_Write(g_RtcAdress, 0x03, temp | 0b00001000); //print statusregister Trace_String(" RTC 03:"); Trace_Hex(I2C_Read(g_RtcAdress, 0x03)); } else if (g_RtcAdress == RTC_8564JE) { I2C_Write(g_RtcAdress,0x00,0x00); //Make sure that the TEST-Bits in the RTC-Device are set to zero I2C_Write(g_RtcAdress,0x01,0x00); //Disable Interrupts in the RTC-Device } }
void Rtc_Ctl(enum RTC_request req,struct rtc_time *pRtcTime) { uns8 temp; switch(req) { case RTC_RD_TIME: { if (g_RtcAdress == RTC_MCP79410) { temp = BcdToBin( I2C_Read(g_RtcAdress, 0x00) & 0b01111111); pRtcTime->tm_sec = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x01) & 0b01111111); pRtcTime->tm_min = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x02) & 0b00111111); pRtcTime->tm_hour = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x04) & 0b00111111); pRtcTime->tm_mday = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x03) & 0b00000111); pRtcTime->tm_wday = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x05) & 0b00011111); temp -= 1; pRtcTime->tm_mon = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x06) & 0b11111111); pRtcTime->tm_year = temp; } else if (g_RtcAdress == RTC_8564JE) { temp = BcdToBin( I2C_Read(g_RtcAdress, 0x02) & 0b01111111); pRtcTime->tm_sec = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x03) & 0b01111111); pRtcTime->tm_min = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x04) & 0b00111111); pRtcTime->tm_hour = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x05) & 0b00111111); pRtcTime->tm_mday = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x06) & 0b00000111); pRtcTime->tm_wday = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x07) & 0b00011111); temp -= 1; pRtcTime->tm_mon = temp; temp = BcdToBin( I2C_Read(g_RtcAdress, 0x08) & 0b11111111); pRtcTime->tm_year = temp; } else { Trace_String("NO RTC"); } } break; case RTC_SET_TIME: { if (g_RtcAdress == RTC_MCP79410) { //clear ST Bit I2C_Write(g_RtcAdress, 0x00, 0x00); temp = BinToBcd(pRtcTime->tm_min); I2C_Write(g_RtcAdress,0x01,(temp)); temp = BinToBcd(pRtcTime->tm_hour); I2C_Write(g_RtcAdress,0x02,(temp)); temp = BinToBcd(pRtcTime->tm_mday); I2C_Write(g_RtcAdress,0x04,(temp)); temp = BinToBcd(pRtcTime->tm_wday); I2C_Write(g_RtcAdress,0x03,(temp | 0b00001000)); temp = BinToBcd((pRtcTime->tm_mon + 1)); I2C_Write(g_RtcAdress,0x05,(temp)); temp = BinToBcd(pRtcTime->tm_year); I2C_Write(g_RtcAdress,0x06,(temp)); //set sec and ST bit temp = BinToBcd(pRtcTime->tm_sec); I2C_Write(g_RtcAdress,0x00,(temp | 0b10000000)); } else if (g_RtcAdress == RTC_8564JE) { temp = BinToBcd(pRtcTime->tm_sec); I2C_Write(g_RtcAdress,0x02,(temp)); temp = BinToBcd(pRtcTime->tm_min); I2C_Write(g_RtcAdress,0x03,(temp)); temp = BinToBcd(pRtcTime->tm_hour); I2C_Write(g_RtcAdress,0x04,(temp)); temp = BinToBcd(pRtcTime->tm_mday); I2C_Write(g_RtcAdress,0x05,(temp)); temp = BinToBcd(pRtcTime->tm_wday); I2C_Write(g_RtcAdress,0x06,(temp)); temp = BinToBcd((pRtcTime->tm_mon + 1)); I2C_Write(g_RtcAdress,0x07,(temp)); temp = BinToBcd(pRtcTime->tm_year); I2C_Write(g_RtcAdress,0x08,(temp)); } else { Trace_String("NO RTC"); } } break; } }
void CommandIO_GetCommands() { if(RingBuf_HasError(&g_RingBuf)) { Trace_String(ERROR_RECEIVEBUFFER_FULL);//RingbufferFull // *** if a RingBufError occure, I have to throw away the current command, // *** because the last byte was not saved. Commandstring is inconsistent RingBuf_Init(&g_RingBuf); CommandIO_Error(); return; } while(!RingBuf_IsEmpty(&g_RingBuf)) { // *** get new_byte from ringbuffer uns8 new_byte = RingBuf_Get(&g_RingBuf); switch(g_CmdBuf.state) { case CS_WaitForSTX: { if(new_byte == STX) { CheckForFwIdentMessage(); DeleteBuffer(); g_CmdBuf.state = CS_SaveChar; } break; } case CS_UnMaskChar: { WriteByte(new_byte); g_CmdBuf.state = CS_SaveChar; break; } case CS_SaveChar: { if(new_byte == DLE) { g_CmdBuf.state = CS_UnMaskChar; break; } if(new_byte == STX) { CheckForFwIdentMessage(); DeleteBuffer(); break; } if(new_byte == ETX) { /* Setup statemachine for new state */ g_Odd_STX_Received = FALSE; g_CmdBuf.state = CS_WaitForSTX; /* Set default answer value */ ErrorCode mRetValue = BAD_PACKET; /* CRC Check */ if((0 == g_CmdBuf.CrcL) && (0 == g_CmdBuf.CrcH)) { // [0] contains cmd_frame->cmd. Reply this cmd as response to client #ifndef __CC8E__ mRetValue = ScriptCtrl_Add((struct led_cmd *)&g_CmdBuf.buffer[0]); #else mRetValue = ScriptCtrl_Add(&g_CmdBuf.buffer[0]); #endif if(mRetValue == NO_RESPONSE) { /* do not send a response if client does not want an echo */ break; } } else { mRetValue = CRC_CHECK_FAILED; } /* send response */ CommandIO_CreateResponse(&g_ResponseBuf, g_CmdBuf.buffer[0], mRetValue); CommandIO_SendResponse(&g_ResponseBuf); break; } WriteByte(new_byte); break; } } } }
void main(void) { #else int g_start_gl = 1; int main(int argc, const char** argv) { if ((argc > 1) && (argv[1][0] == 'h')) g_start_gl = 0; #endif /* softReset() on x86 will jump here! */ softResetJumpDestination(); InitAll(); while(1) { Timer_StartStopwatch(eMAIN); #ifndef __CC8E__ // give opengl thread a chance to run usleep(10); #endif /* #ifndef __CC8E__ */ do_and_measure(Platform_CheckInputs); do_and_measure(Error_Throw); do_and_measure(CommandIO_GetCommands); if(g_UpdateLedStrip > 0) { do_and_measure(Ledstrip_UpdateLed); Timer1Enable(); g_UpdateLedStrip = 0; } Timer_StopStopwatch(eMAIN); do_and_measure(ScriptCtrl_Run); if(g_UpdateLed > 0) { do_and_measure(Ledstrip_DoFade); Timer5InterruptLock(); g_UpdateLed = 0; Timer5InterruptUnlock(); } } } //*********************** UNTERPROGRAMME ********************************************** void InitAll() { clearRAM(); Trace_Init(); Platform_OsciInit(); Platform_IOInit(); RingBuf_Init(&g_RingBuf); UART_Init(); Timer_Init(); Ledstrip_Init(); CommandIO_Init(); Rtc_Init(); ScriptCtrl_Init(); ExtEeprom_Init(); #ifndef __CC8E__ init_x86(g_start_gl); #endif /* #ifndef CC8E */ Platform_AllowInterrupts(); /* Startup Wait-Time 2s * to protect Wifly-Modul from errors*/ gScriptBuf.waitValue = 20; CommandIO_CreateResponse(&g_ResponseBuf, FW_STARTED, OK); CommandIO_SendResponse(&g_ResponseBuf); Trace_String(" Init Done "); Platform_DisableBootloaderAutostart(); }
*/ static REBCNT Parse_Next_String(REBPARSE *parse, REBCNT index, REBVAL *item, REBCNT depth) /* ** Match the next item in the string ruleset. ** ** If it matches, return the index just past it. ** Otherwise return NOT_FOUND. ** ***********************************************************************/ { // !!! THIS CODE NEEDS CLEANUP AND REWRITE BASED ON OTHER CHANGES REBSER *series = parse->series; REBSER *ser; REBCNT flags = parse->flags | AM_FIND_MATCH | AM_FIND_TAIL; int rewrite_needed; if (Trace_Level) { Trace_Value(7, item); Trace_String(8, STR_SKIP(series, index), series->tail - index); } if (IS_NONE(item)) return index; if (index >= series->tail) return NOT_FOUND; switch (VAL_TYPE(item)) { // Do we match a single character? case REB_CHAR: if (HAS_CASE(parse)) index = (VAL_CHAR(item) == GET_ANY_CHAR(series, index)) ? index+1 : NOT_FOUND; else index = (UP_CASE(VAL_CHAR(item)) == UP_CASE(GET_ANY_CHAR(series, index))) ? index+1 : NOT_FOUND; break; case REB_EMAIL: case REB_STRING: case REB_BINARY: index = Find_Str_Str(series, 0, index, SERIES_TAIL(series), 1, VAL_SERIES(item), VAL_INDEX(item), VAL_LEN(item), flags); break; // Do we match to a char set? case REB_BITSET: flags = Check_Bit(VAL_SERIES(item), GET_ANY_CHAR(series, index), !HAS_CASE(parse)); index = flags ? index + 1 : NOT_FOUND; break; /* case REB_DATATYPE: // Currently: integer! if (VAL_DATATYPE(item) == REB_INTEGER) { REBCNT begin = index; while (IS_LEX_NUMBER(*str)) str++, index++; if (begin == index) index = NOT_FOUND; } break; */ case REB_TAG: case REB_FILE: // case REB_ISSUE: // !! Can be optimized (w/o COPY) ser = Copy_Form_Value(item, 0); index = Find_Str_Str(series, 0, index, SERIES_TAIL(series), 1, ser, 0, ser->tail, flags); break; case REB_NONE: break; // Parse a sub-rule block: case REB_BLOCK: index = Parse_Rules_Loop(parse, index, VAL_BLK_DATA(item), depth); break; // Do an expression: case REB_PAREN: item = Do_Block_Value_Throw(item); // might GC // old: if (IS_ERROR(item)) Throw_Error(VAL_ERR_OBJECT(item)); index = MIN(index, series->tail); // may affect tail break; default: Trap1(RE_PARSE_RULE, item); } return index; }