void Buzzer_Beep(BuzzFreq_t freq, uint8_t volume, int32_t ticks) { if (ticks > 0 || freq == BUZZ_NONE) { requested_buzz_freq = freq; requested_buzz_volume = volume; requested_buzz_length = ticks; Sched_SetState(BUZZER_WORK, 2, 0); } }
int main(void) { char buf[22]; int len; PLLCFG = (1<<5) | (4<<0); //PLL MSEL=0x4 (+1), PSEL=0x1 (/2) so 11.0592*5 = 55.296MHz, Fcco = (2x55.296)*2 = 221MHz which is within 156 to 320MHz PLLCON = 0x01; PLLFEED = 0xaa; PLLFEED = 0x55; // Feed complete while(!(PLLSTAT & (1<<10))); // Wait for PLL to lock PLLCON = 0x03; PLLFEED = 0xaa; PLLFEED = 0x55; // Feed complete VPBDIV = 0x01; // APB runs at the same frequency as the CPU (55.296MHz) MAMTIM = 0x03; // 3 cycles flash access recommended >40MHz MAMCR = 0x02; // Fully enable memory accelerator Sched_Init(); IO_Init(); Set_Heater(0); Set_Fan(0); Serial_Init(); I2C_Init(); EEPROM_Init(); NV_Init(); if( NV_GetConfig(REFLOW_BEEP_DONE_LEN) == 255 ) { NV_SetConfig(REFLOW_BEEP_DONE_LEN, 10); // Default 1 second beep length } printf("\nInitializing improved reflow oven..."); LCD_Init(); LCD_BMPDisplay(logobmp,0,0); // Setup watchdog WDTC = PCLKFREQ / 3; // Some margin (PCLKFREQ/4 would be exactly the period the WD is fed by sleep_work) WDMOD = 0x03; // Enable WDFEED = 0xaa; WDFEED = 0x55; uint8_t resetreason = RSIR; RSIR = 0x0f; // Clear it out printf("\nReset reason(s): %s%s%s%s", (resetreason&(1<<0))?"[POR]":"", (resetreason&(1<<1))?"[EXTR]":"", (resetreason&(1<<2))?"[WDTR]":"", (resetreason&(1<<3))?"[BODR]":""); // Request part number command[0] = IAP_READ_PART; iap_entry(command, result); const char* partstrptr = NULL; for(int i=0; i<NUM_PARTS; i++) { if(result[1] == partmap[i].id) { partstrptr = partmap[i].name; break; } } // Read part revision partrev=*(uint8_t*)PART_REV_ADDR; if(partrev==0 || partrev > 0x1a) { partrev = '-'; } else { partrev += 'A' - 1; } len = snprintf(buf,sizeof(buf),"%s rev %c",partstrptr,partrev); LCD_disp_str((uint8_t*)buf, len, 0, 64-6, FONT6X6); printf("\nRunning on an %s", buf); LCD_FB_Update(); Keypad_Init(); Buzzer_Init(); ADC_Init(); RTC_Init(); OneWire_Init(); Reflow_Init(); Sched_SetWorkfunc( MAIN_WORK, Main_Work ); Sched_SetState( MAIN_WORK, 1, TICKS_SECS( 2 ) ); // Enable in 2 seconds Buzzer_Beep( BUZZ_1KHZ, 255, TICKS_MS(100) ); while(1) { int32_t sleeptime; sleeptime=Sched_Do( 0 ); // No fast-forward support //printf("\n%d ticks 'til next activity"),sleeptime); } return 0; }
uint32_t OneWire_Init(void) { printf("\n%s called", __FUNCTION__); Sched_SetWorkfunc(ONEWIRE_WORK, OneWire_Work); printf("\nScanning 1-wire bus..."); tempidx = -1; // Assume we don't find a temperature sensor for (int i = 0; i < sizeof(tcidmapping); i++) { tcidmapping[i] = -1; // Assume we don't find any thermocouple interfaces } uint32_t save = VIC_DisableIRQ(); int rslt = OWFirst(); VIC_RestoreIRQ( save ); numowdevices = 0; while (rslt && numowdevices < MAX_OW_DEVICES) { memcpy(owdeviceids[numowdevices], ROM_NO, sizeof(ROM_NO)); numowdevices++; save = VIC_DisableIRQ(); rslt = OWNext(); VIC_RestoreIRQ( save ); } if (numowdevices) { for (int iter = 0; iter < numowdevices; iter++) { printf("\n Found "); for (int idloop = 7; idloop >= 0; idloop--) { printf("%02x", owdeviceids[iter][idloop]); } uint8_t family = owdeviceids[iter][0]; if (family == OW_FAMILY_TEMP1 || family == OW_FAMILY_TEMP2 || family == OW_FAMILY_TEMP3) { const char* sensorname = "UNKNOWN"; if (family == OW_FAMILY_TEMP1) { sensorname = "DS1822"; } else if (family == OW_FAMILY_TEMP2) { sensorname = "DS18B20"; } else if (family == OW_FAMILY_TEMP3) { sensorname = "DS18S20"; } save = VIC_DisableIRQ(); selectdevbyidx(iter); xferbyte(OW_WRITE_SCRATCHPAD); xferbyte(0x00); xferbyte(0x00); xferbyte(0x1f); // Reduce resolution to 0.5C to keep conversion time reasonable VIC_RestoreIRQ(save); tempidx = iter; // Keep track of where we saw the last/only temperature sensor printf(" [%s Temperature sensor]", sensorname); } else if (family == OW_FAMILY_TC) { save = VIC_DisableIRQ(); selectdevbyidx(iter); xferbyte(OW_READ_SCRATCHPAD); xferbyte(0xff); xferbyte(0xff); xferbyte(0xff); xferbyte(0xff); uint8_t tcid = xferbyte(0xff) & 0x0f; VIC_RestoreIRQ( save ); tcidmapping[tcid] = iter; // Keep track of the ID mapping printf(" [Thermocouple interface, ID %x]",tcid); } } } else { printf(" No devices found!"); } if (numowdevices) { Sched_SetState(ONEWIRE_WORK, 2, 0); // Enable OneWire task if there's at least one device } return numowdevices; }