// Allocates a pmem_OSBuffer instance of 'size' and 'tag'. // Returns 0 on failure. pmem_OSBuffer *pmem_alloc(uint32_t size, OSMallocTag_t tag) { pmem_OSBuffer *buffer = (pmem_OSBuffer *)OSMalloc(sizeof(pmem_OSBuffer), tag); if (!buffer) { goto error; } bzero(buffer, sizeof(pmem_OSBuffer)); buffer->size = size; buffer->tag = tag; buffer->buffer = (char *)OSMalloc(size, tag); if (!buffer->buffer) { goto error; } bzero(buffer->buffer, buffer->size); return buffer; error: if (buffer) { OSFree(buffer, sizeof(pmem_OSBuffer), tag); } return 0; }
__private_extern__ ANPacketInfo * ANControlListEntryGetPacket(OSMallocTag tag, ANControlListEntry * entry) { if (entry->bufferLength < 8) return NULL; uint32_t length = ((uint32_t *)entry->packetBuffer)[1]; if (length > entry->bufferLength) return NULL; // allocate the packet and copy the buffer into it ANPacketInfo * info = (ANPacketInfo *)OSMalloc(length, tag); if (!info) return NULL; memcpy(info, entry->packetBuffer, length); // move the remaining data back in the buffer if (length == entry->bufferLength) { // we used up the entire buffer OSFree(entry->packetBuffer, entry->bufferLength, tag); entry->packetBuffer = NULL; entry->bufferLength = 0; } else { uint32_t newLength = entry->bufferLength - length; char * newBuffer = (char *)OSMalloc(newLength, tag); if (newBuffer) { memcpy(newBuffer, &entry->packetBuffer[length], newLength); OSFree(entry->packetBuffer, entry->bufferLength, tag); entry->packetBuffer = newBuffer; entry->bufferLength = newLength; } else { OSFree(entry->packetBuffer, entry->bufferLength, tag); entry->packetBuffer = 0; entry->bufferLength = 0; } } return info; }
int main(void) { ButtonDescriptorDef *buttonDescriptor; TaskParametersDef *taskParameters; void *event; WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer /* Set the system clock characteristics */ OSInitializeSystemClocks(); // Initialize output I/O ports P1OUT = 0x00; // Initially start at low P1DIR = 0x03; // Set to output P4OUT |= 0x3; P4REN |= 0x3; P4IES |= 0x3; P4IFG &= ~0x3; P4IE |= 0x3; #if defined(ZOTTAOS_VERSION_HARD) event = OSCreateEventDescriptor(); // Register button P4.0 interrupt buttonDescriptor = (ButtonDescriptorDef *)OSMalloc(sizeof(ButtonDescriptorDef)); buttonDescriptor->ButtonInterruptHandler = ButtonISR; buttonDescriptor->event = event; OSSetISRDescriptor(OS_IO_PORT4_0,buttonDescriptor); // Create the first event-driven task taskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); taskParameters->Delay = 1000; // Impulse width to visualize the task execution taskParameters->Flag_Pin = BIT0; taskParameters->Button_Pin = BIT0; taskParameters->event = event; // Needed to reschedule itself OSCreateSynchronousTask(ButtonTask,10000,event,taskParameters); // Register button P4.1 interrupt event = OSCreateEventDescriptor(); buttonDescriptor = (ButtonDescriptorDef *)OSMalloc(sizeof(ButtonDescriptorDef)); buttonDescriptor->ButtonInterruptHandler = ButtonISR; buttonDescriptor->event = event; OSSetISRDescriptor(OS_IO_PORT4_1,buttonDescriptor); // Create the second event-driven task that taskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); taskParameters->Delay = 2000; taskParameters->Flag_Pin = BIT1; taskParameters->Button_Pin = BIT1; taskParameters->event = event; OSCreateSynchronousTask(ButtonTask,20000,event,taskParameters); #elif defined(ZOTTAOS_VERSION_SOFT) #error Untested #else #error Wrong kernel version #endif /* Start the OS so that it starts scheduling the user tasks */ return OSStartMultitasking(NULL,NULL); } /* end of main */
void* rpal_memory_alloc ( uint32_t size ) { void* ptr = NULL; unsigned char* realPtr = NULL; if( 0 == g_mem_tag ) { g_mem_tag = OSMalloc_Tagalloc( "hcp_hbs_acq", 0 ); } size += sizeof( uint32_t ); realPtr = OSMalloc( size, g_mem_tag ); if( NULL != realPtr ) { *(uint32_t*)realPtr = size; ptr = realPtr + sizeof( uint32_t ); } return ptr; }
__private_extern__ ANControlList * ANControlListCreate(OSMallocTag tag) { ANControlList * list = (ANControlList *)OSMalloc(sizeof(ANControlList), tag); if (!list) return NULL; bzero(list, sizeof(ANControlList)); list->tag = tag; return list; }
// Resize 'meta' to have at least 'min_room' of bytes at the end. This will // deallocate the old meta struct, so 'metaret' will change to point to the new // buffer. // // Arguments: // metaret: The meta struct to resize. Will change to point to new struct. // min_room: The new struct will have at least this much room, but probably // more. // // Returns: // KERN_SUCCESS or KERN_FAILURE. On KERN_FAILURE the old struct MAY still be // valid; if so, the pointer will not be updated. static kern_return_t pmem_metaresize(pmem_meta_t **metaret, uint32_t min_room) { pmem_meta_t *meta = *metaret; uint32_t min_size = meta->size + min_room; if (min_size < meta->size || meta->size > UINT32_MAX / 2) { pmem_error("32 bit int overflow detected - meta struct is too big."); return KERN_FAILURE; } if (min_size < meta->size * 2) { min_size = meta->size * 2; } pmem_meta_t *newmeta = (pmem_meta_t *)OSMalloc(min_size, pmem_alloc_tag); if (!newmeta) { return KERN_FAILURE; } pmem_debug(("Meta struct %p of size %u has been resized and is now %p " "of size %u"), meta, meta->size, newmeta, min_size); memcpy(newmeta, meta, meta->size); pmem_metafree(meta); newmeta->size = min_size; *metaret = newmeta; return KERN_SUCCESS; }
/*********************************************************************************************************** *Function Name: GPS_BinInfo() *Attributes: *client IN Client identifier *num IN Number of bininfo[] array. Set the number of output bins obtained by gpsGetSysInfo(). *bininfo OUT Output Bin Information Structure *bininfo_num OUT Returns the number of bins set to bininfo[] array. *notify IN Enable/disable receiving an event whenever there is a change in the information. *Description: This function obtains output bin information. ************************************************************************************************************/ int GPS_BinInfo() { long binInfo; int nTrayIndex; #ifdef PMS_OIL_MERGE_DISABLE_MEM gpsBinInfo = (gps_bininfo_t*) OSMalloc(sysinfo.num_bin * sizeof(gps_bininfo_t), PMS_MemoryPoolPMS); g_pstOutputInfo = (PMS_TyOutputInfo*) OSMalloc(sysinfo.num_bin * sizeof(PMS_TyOutputInfo), PMS_MemoryPoolPMS); #else gpsBinInfo = (gps_bininfo_t*) mmalloc(sysinfo.num_bin * sizeof(gps_bininfo_t)); g_pstOutputInfo = (PMS_TyOutputInfo*) mmalloc(sysinfo.num_bin * sizeof(PMS_TyOutputInfo)); #endif if( -1 == gpsGetBinInfo(gps_client, sysinfo.num_bin, gpsBinInfo, &binInfo, GPS_NOTIFY_CHANGE_OFF) ) return -1; /* To do - Map SDK str from GPS Specification DB - 01.pdf : page no 40 */ /* gpsGetTrayInfo - page no 200 */ for(nTrayIndex = 0; nTrayIndex < binInfo; nTrayIndex++) { /*g_pstOutputInfo[nTrayIndex].eOutputTray = gpsBinInfo[nTrayIndex].id; */ switch (gpsBinInfo[nTrayIndex].id) { case 1: case 2: case 3: g_pstOutputInfo[nTrayIndex].eOutputTray = gpsBinInfo[nTrayIndex].id; break; default: g_pstOutputInfo[nTrayIndex].eOutputTray = PMS_OUTPUT_TRAY_AUTO; break; /* yet to map PMS_OUTPUT_TRAY_UPPER, PMS_OUTPUT_TRAY_LOWER, PMS_OUTPUT_TRAY_EXTRA */ } g_pstOutputInfo[nTrayIndex].nPriority = nTrayIndex; /*assumption yet to conform. */ } g_nOutputTrays = sysinfo.num_bin; #ifdef PMS_OIL_MERGE_DISABLE_MEM OSFree( gpsBinInfo, PMS_MemoryPoolPMS ); #else mfree( gpsBinInfo ); #endif gpsBinInfo = NULL; return 0; }
// Driver entry point. Initializes globals and registers driver node in /dev. kern_return_t pmem_start(kmod_info_t * ki, void *d) { int error = 0; pmem_log("Loading /dev/%s driver", pmem_pmem_devname); // Memory allocations are tagged to prevent leaks pmem_tag = OSMalloc_Tagalloc(pmem_tagname, OSMT_DEFAULT); // Allocate one page for zero padding of illegal read requests pmem_zero_page = static_cast<uint8_t *>(OSMalloc(PAGE_SIZE, pmem_tag)); if (pmem_zero_page == NULL) { pmem_error("Failed to allocate memory for page buffer"); return pmem_cleanup(KERN_FAILURE); } bzero(pmem_zero_page, PAGE_SIZE); // Access the boot arguments through the platform export, // and parse the systems physical memory configuration. boot_args * ba = reinterpret_cast<boot_args *>(PE_state.bootArgs); pmem_physmem_size = ba->PhysicalMemorySize; pmem_mmap = reinterpret_cast<EfiMemoryRange *>(ba->MemoryMap + pmem_kernel_voffset); pmem_mmap_desc_size = ba->MemoryMapDescriptorSize; pmem_mmap_size = ba->MemoryMapSize; pmem_log("Size of physical memory:%lld", pmem_physmem_size); pmem_log("Size of physical pages:%d (PAGE_SHIFT=%d, PAGE_MASK=%#016x)", PAGE_SIZE, PAGE_SHIFT, PAGE_MASK); pmem_log("Phys. Memory map at:%#016llx (size:%lld desc_size:%d)", pmem_mmap, pmem_mmap_size, pmem_mmap_desc_size); pmem_log("Number of segments in memory map: %d", pmem_mmap_size / pmem_mmap_desc_size); // Install switch table pmem_devmajor = cdevsw_add(-1, &pmem_cdevsw); if (pmem_devmajor == -1) { pmem_error("Failed to create character device"); return pmem_cleanup(KERN_FAILURE); } // Create physical memory device file pmem_log("Adding node /dev/%s", pmem_pmem_devname); pmem_devpmemnode = devfs_make_node(makedev(pmem_devmajor, pmem_dev_pmem_minor), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0660, pmem_pmem_devname); if (pmem_devpmemnode == NULL) { pmem_error("Failed to create /dev/%s node", pmem_pmem_devname); return pmem_cleanup(KERN_FAILURE); } pmem_log("obtaining kernel dtb pointer"); __asm__ __volatile__("movq %%cr3, %0" :"=r"(pmem_dtb)); // Only bits 51-12 (inclusive) in cr3 are part of the dtb pointer pmem_dtb &= ~PAGE_MASK; pmem_log("kernel dtb: %#016llx", pmem_dtb); pmem_log("initializing pte_mmap module"); pmem_log("pmem driver loaded, physical memory available in /dev/%s", pmem_pmem_devname); return error; }
__private_extern__ ANControlListEntry * ANControlListEntryCreate(OSMallocTag tag, uint32_t unit, kern_ctl_ref ctlref) { ANControlListEntry * entry = (ANControlListEntry *)OSMalloc(sizeof(ANControlListEntry), tag); if (!entry) return NULL; bzero(entry, sizeof(ANControlListEntry)); entry->unit = unit; entry->ctlref = ctlref; entry->connected = TRUE; return entry; }
/*! \brief Create a semaphore * * UNIX/Linux * * Semaphore is casted to \c void* for platform portability. * * \param[in] initialValue Initial semaphore value. * \return Pointer to semaphore created (casted to \c void*). */ void * PMS_CreateSemaphore(int initialValue) { #ifdef MACOSX mac_sema_desc_t *sem; /* Mac OS X returns a failure for sem_init, so we have to use sem_open instead. sem_open requires a name, so we will invent one. */ char name[SEM_NAME_LEN]; sem_t *ossem; if ( (sem = OSMalloc(sizeof(mac_sema_desc_t), PMS_MemoryPoolPMS)) == NULL ) return NULL; do { sprintf(name, "pms-%d-%d", getpid(), ++semno) ; if ( (ossem = sem_open(name, O_CREAT | O_EXCL, 0777, initialValue)) == (sem_t *)SEM_FAILED ) semno += 100; /* try to avoid other semaphores from the same crash */ } while (ossem == (sem_t *)SEM_FAILED && errno == EEXIST); if (ossem == (sem_t *)SEM_FAILED) { OSFree(sem, PMS_MemoryPoolPMS); return NULL; } sem->sem = ossem; sem->semno = semno; sem_count++; #else #ifdef PMS_OIL_MERGE_DISABLE_MEM sem_t *sem; sem = (sem_t *) OSMalloc(sizeof(sem_t), PMS_MemoryPoolPMS); if (sem == NULL) return NULL; #else sem_t sem[16]; #endif if (sem_init(sem, 0, initialValue)) { #ifdef PMS_OIL_MERGE_DISABLE_MEM OSFree(sem, PMS_MemoryPoolPMS); #endif return NULL; } #endif return (void*)sem; }
/*! \brief Start a new thread. * * UNIX/Linux * * \param start_address Funtion pointer to the threads entry point. * \param stack_size Size of stack to use, in bytes. * \param arglist Pointer to argument list. * \return Pointer to thread (casted to void * for platform portability) * */ void *PMS_BeginThread(void( *start_address )( void * ), unsigned int stack_size, void *arglist ) { pthread_attr_t attr; unsigned int result; #ifdef PMS_OIL_MERGE_DISABLE_MEM PMS_TyThreadFunction *ptThreadInfo = OSMalloc(sizeof(PMS_TyThreadFunction), PMS_MemoryPoolPMS); #else PMS_TyThreadFunction *ptThreadInfo = mmalloc(sizeof(PMS_TyThreadFunction)); #endif if(!ptThreadInfo) { return (NULL); } ptThreadInfo->bCondBroadcasted = 0; if ( pthread_mutex_init(&ptThreadInfo->mutexThread, NULL) != 0 ) { goto thread_info_destroy; } if ( pthread_cond_init(&ptThreadInfo->condThread, NULL) != 0 ) { goto thread_mutex_destroy; } if (pthread_attr_init(&attr)) { goto thread_cond_destroy; } ptThreadInfo->start_routine = start_address; ptThreadInfo->arg = arglist; result = pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE) || pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) || pthread_create(&ptThreadInfo->tid, &attr, PMSThreadWrapper, (void*)ptThreadInfo); (void)pthread_attr_destroy(&attr) ; if (result != 0) { PMS_SHOW_ERROR("Failed to create thread: \n"); goto thread_cond_destroy; } return (void*)ptThreadInfo; thread_cond_destroy: (void)pthread_cond_destroy(&ptThreadInfo->condThread) ; thread_mutex_destroy: (void)pthread_mutex_destroy(&ptThreadInfo->mutexThread) ; thread_info_destroy: #ifdef PMS_OIL_MERGE_DISABLE_MEM OSFree(ptThreadInfo, PMS_MemoryPoolPMS); #else mfree(ptThreadInfo); #endif return (NULL); }
static errno_t ppfilter_attach(void **cookie, socket_t so) { pp_filter_cookie_t cp = OSMalloc(sizeof(*cp), pp_malloc_tag); if (cp) { cp->pid = proc_selfpid(); cp->action = COOKIE_NO_ACTION; } *cookie = (void*)cp; return (0); }
/* Prepend length */ static void* ipsec_alloc(size_t size) { size_t *mem = OSMalloc(size + sizeof(size_t), ipsec_malloc_tag); if (mem) { *mem = size + sizeof(size_t); mem++; } return (void*)mem; }
/* Prepend length */ void* utun_alloc(size_t size) { size_t *mem = OSMalloc(size + sizeof(size_t), utun_malloc_tag); if (mem) { *mem = size + sizeof(size_t); mem++; } return (void*)mem; }
// Make a new meta struct. static pmem_meta_t *pmem_metaalloc() { uint32_t required_size = (uint32_t)sizeof(pmem_meta_t); pmem_meta_t *meta = (pmem_meta_t *)OSMalloc(required_size, pmem_alloc_tag); if (!meta) { return nullptr; } bzero(meta, required_size); meta->pmem_api_version = PMEM_API_VERSION; meta->records_offset = __offsetof(pmem_meta_t, records); meta->size = required_size; return meta; }
/** * \brief Fill Tray Information. * * This routine simulates sensing of page attributes from available media sources. \n */ int EngineGetTrayInfo(void) { int nTrayIndex; /* query engine and fill in information about available attributes * NOTE - maximum of 10 trays */ g_pstTrayInfo = (PMS_TyTrayInfo *) OSMalloc( NUMFIXEDMEDIASOURCES * sizeof(PMS_TyTrayInfo), PMS_MemoryPoolPMS ); nTrayIndex = 0; if( g_pstTrayInfo != NULL ) { g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_MANUALFEED; g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A4; g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_DONT_KNOW; g_pstTrayInfo[nTrayIndex].eMediaColor = PMS_COLOR_DONT_KNOW; g_pstTrayInfo[nTrayIndex].uMediaWeight = 0; g_pstTrayInfo[nTrayIndex].nPriority = 1; g_pstTrayInfo[nTrayIndex].bTrayEmptyFlag = FALSE; g_pstTrayInfo[nTrayIndex].nNoOfSheets = 200; nTrayIndex++; g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_TRAY1; g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A4_R; g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_DONT_KNOW; g_pstTrayInfo[nTrayIndex].eMediaColor = PMS_COLOR_DONT_KNOW; g_pstTrayInfo[nTrayIndex].uMediaWeight = 0; g_pstTrayInfo[nTrayIndex].nPriority = 2; g_pstTrayInfo[nTrayIndex].bTrayEmptyFlag = FALSE; g_pstTrayInfo[nTrayIndex].nNoOfSheets = 200; nTrayIndex++; g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_TRAY2; g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LETTER; g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_DONT_KNOW; g_pstTrayInfo[nTrayIndex].eMediaColor = PMS_COLOR_DONT_KNOW; g_pstTrayInfo[nTrayIndex].uMediaWeight = 0; g_pstTrayInfo[nTrayIndex].nPriority = 3; g_pstTrayInfo[nTrayIndex].bTrayEmptyFlag = FALSE; g_pstTrayInfo[nTrayIndex].nNoOfSheets = 200; nTrayIndex++; return nTrayIndex; } return 0; }
__private_extern__ errno_t ANControlListEntryAppend(OSMallocTag tag, ANControlListEntry * entry, mbuf_t packet) { uint32_t packSize = (uint32_t)mbuf_len(packet); if (packSize == 0) return 0; uint32_t newSize = packSize + entry->bufferLength; char * buffer = (char *)OSMalloc(newSize, tag); if (!buffer) return ENOMEM; if (entry->packetBuffer) { // copy old data to the buffer memcpy(buffer, entry->packetBuffer, entry->bufferLength); OSFree(entry->packetBuffer, entry->bufferLength, tag); } mbuf_copydata(packet, 0, packSize, &buffer[entry->bufferLength]); entry->packetBuffer = buffer; entry->bufferLength = newSize; return 0; }
// Resizes 'buffer' to 'size', preserving old content. // Size must be larger than current buffer->size. // Works by allocating a larger buffer and using memcpy. After this call, // old buffer->buffer will be invalid memory. // On error, returns 0 and deallocates everything, so buffer will be invalid. kern_return_t pmem_resize(pmem_OSBuffer *buffer, uint32_t size) { char *newbuf = 0; if (!buffer) { goto error; } if (size < buffer->size) { // We're already bigger. That's fine - nothing to do. return KERN_SUCCESS; } newbuf = (char *)OSMalloc(size, buffer->tag); if (!newbuf) { goto error; } bzero(newbuf, size); memcpy(newbuf, buffer->buffer, buffer->size); OSFree(buffer->buffer, buffer->size, buffer->tag); buffer->buffer = newbuf; buffer->size = size; return KERN_SUCCESS; error: if (newbuf) { OSFree(newbuf, size, buffer->tag); } if (buffer) { if (buffer->buffer) { OSFree(buffer->buffer, buffer->size, buffer->tag); } OSFree(buffer, sizeof(pmem_OSBuffer), buffer->tag); } return KERN_FAILURE; }
// Driver entry point. Initializes globals and registers driver node in /dev. kern_return_t chipsec_start(kmod_info_t * ki, void *d) { int error = 0; pmem_log("Loading /dev/%s driver", chipsec_devname); // Memory allocations are tagged to prevent leaks pmem_tag = OSMalloc_Tagalloc(pmem_tagname, OSMT_DEFAULT); // Allocate one page for zero padding of illegal read requests pmem_zero_page = static_cast<uint8_t *>(OSMalloc(PAGE_SIZE, pmem_tag)); if (pmem_zero_page == NULL) { pmem_error("Failed to allocate memory for page buffer"); return pmem_cleanup(KERN_FAILURE); } bzero(pmem_zero_page, PAGE_SIZE); // Install the character device chipsec_dev_major = cdevsw_add(-1, &pmem_cdevsw); if (chipsec_dev_major == -1) { pmem_error("Failed to create character device"); return pmem_cleanup(KERN_FAILURE); } // Create physical memory device file pmem_log("Adding node /dev/%s", chipsec_devname); pmem_devpmemnode = devfs_make_node(makedev(chipsec_dev_major, chipsec_dev_minor), DEVFS_CHAR, UID_ROOT, GID_WHEEL, 0660, chipsec_devname); if (pmem_devpmemnode == NULL) { pmem_error("Failed to create /dev/%s node", chipsec_devname); return pmem_cleanup(KERN_FAILURE); } pmem_log("pmem driver loaded, physical memory available in /dev/%s", chipsec_devname); return error; }
/** * \brief Add an input module node to the linked list of input modules. * */ int Add_Input_Module( int (*pfnInitDataStream)(void), int (*pfnOpenDataStream)(void), int (*pfnCloseDataStream)(void), int (*pfnPeekDataStream)(unsigned char * buffer, int nBytesToRead), int (*pfnConsumeDataStream)(int nBytesToConsume), int (*pfnWriteDataStream)(unsigned char * pBuffer, int nBytesToWrite, int * pnBytesWritten) ) { struct input_modules *pModuleNode; PMS_ASSERT(pfnOpenDataStream, ("Add_Input_Module: pfnOpenDataStream must be defined for all modules\n")); #ifdef PMS_OIL_MERGE_DISABLE_MEM pModuleNode = OSMalloc(sizeof(struct input_modules), PMS_MemoryPoolPMS); #else pModuleNode = mmalloc(sizeof(struct input_modules)); #endif if(!pModuleNode) { return FALSE; } pModuleNode->pNext = NULL; pModuleNode->tInput.pfnInitDataStream = pfnInitDataStream; pModuleNode->tInput.pfnOpenDataStream = pfnOpenDataStream; pModuleNode->tInput.pfnCloseDataStream = pfnCloseDataStream; pModuleNode->tInput.pfnPeekDataStream = pfnPeekDataStream; pModuleNode->tInput.pfnConsumeDataStream = pfnConsumeDataStream; pModuleNode->tInput.pfnWriteDataStream = pfnWriteDataStream; if(l_ptModulesTail == NULL) { l_ptModules = pModuleNode; l_ptModulesTail = pModuleNode; } else { l_ptModulesTail->pNext = pModuleNode; l_ptModulesTail = pModuleNode; } return TRUE; }
/** * \brief Fill Output Tray Information. * * This routine simulates sensing of page attributes from available media destinations. \n */ int EngineGetOutputInfo(void) { int nTrayIndex; /* query engine and fill in information about available attributes * NOTE - maximum of 10 trays */ g_pstOutputInfo = (PMS_TyOutputInfo *) OSMalloc( NUMFIXEDMEDIADESTS * sizeof(PMS_TyOutputInfo), PMS_MemoryPoolPMS ); nTrayIndex = 0; if( g_pstOutputInfo != NULL ) { g_pstOutputInfo[nTrayIndex].eOutputTray = PMS_OUTPUT_TRAY_UPPER; g_pstOutputInfo[nTrayIndex].nPriority = 1; nTrayIndex++; g_pstOutputInfo[nTrayIndex].eOutputTray = PMS_OUTPUT_TRAY_LOWER; g_pstOutputInfo[nTrayIndex].nPriority = 2; nTrayIndex++; return nTrayIndex; } return 0; }
//called for new socket // ->find rule, and attach entry (so know to allow/deny for later actions) // if no rule is found, that's ok (new proc), request user input in connect_out or sf_data_out, etc static kern_return_t attach(void **cookie, socket_t so) { //result kern_return_t result = kIOReturnError; //unset *cookie = NULL; //dbg msg IOLog("LULU: in %s\n", __FUNCTION__); //set cookie *cookie = (void*)OSMalloc(sizeof(struct cookieStruct), allocTag); if(NULL == *cookie) { //no memory result = ENOMEM; //bail goto bail; } //set rule action // not found, block, allow, etc ((struct cookieStruct*)(*cookie))->ruleAction = queryRule(proc_selfpid()); //dbg msg IOLog("LULU: rule action for %d: %d\n", proc_selfpid(), ((struct cookieStruct*)(*cookie))->ruleAction); //happy result = kIOReturnSuccess; bail: return result; }
/* * Finds the procfsnode_t for a node with a given id and referencing a given structure node * on a given instance of the file system. If the node does not already exist, it is created, * entered into the node has table and a vnode is created and attached to it. If the node already * exists, it is returned along with its vnode. In both cases, the vnode has an additional iocount, * which the caller must remove at some point by calling vnode_put(). * * Creation of a vnode cannot be performed by this function because the information required * to initialize it is known only to the caller. The caller must supply a pointer to a function * that will create the vnode when required, along with an opaque context pointer that is passed * to the creation function, along with a pointer to the corresponding procfsnode_t. The creation * function must either create the vnode and link it to the procfsnode_t or return an error. * * The allocation of the procfsnode_t that is done here is reversed in the procfs_reclaim() function, * which is called when the node's associated vnode is being reclaimed. */ int procfsnode_find(procfs_mount_t *pmp, procfsnode_id_t node_id, procfs_structure_node_t *snode, procfsnode_t **pnpp, vnode_t *vnpp, create_vnode_func create_vnode_func, void *create_vnode_params) { int error = 0; boolean_t locked = TRUE; procfsnode_t *target_procfsnode = NULL; // This is the node that we will return. procfsnode_t *new_procfsnode = NULL; // Newly allocated node. Will be freed if not used. vnode_t target_vnode = NULL; // Start by assuming we will not get a vnode. int32_t mount_id = pmp->pmnt_id; // File system id. // Lock the hash table. We'll keep this locked until we are done, // unless we need to allocate memory. In that case, we'll drop the // lock, but we'll have to revisit all of our assumptions when we // reacquire it, because another thread may have created the node // we are looking for. lck_mtx_lock(procfsnode_hash_mutex); boolean_t done = FALSE; while (!done) { assert(locked); error = 0; // Select the correct hash bucket and walk along it, looking for an existing // node with the correct attributes. int nodehash = HASH_FOR_MOUNT_AND_ID(mount_id, node_id); procfs_hash_head *hash_bucket = PROCFS_NODE_HASH_TO_BUCKET_HEADER(nodehash); LIST_FOREACH(target_procfsnode, hash_bucket, node_hash) { if (target_procfsnode->node_mnt_id == mount_id && target_procfsnode->node_id.nodeid_pid == node_id.nodeid_pid &&target_procfsnode->node_id.nodeid_objectid == node_id.nodeid_objectid && target_procfsnode->node_id.nodeid_base_id == node_id.nodeid_base_id) { // Matched. break; } } // We got a match if target_procfsnode is not NULL. if (target_procfsnode == NULL) { // We did not find a match, so either allocate a new node or use the // one we created last time around this loop. if (new_procfsnode == NULL) { // We need to allocate a new node. Before doing that, unlock // the node hash, because the memory allocation may block. lck_mtx_unlock(procfsnode_hash_mutex); locked = FALSE; new_procfsnode = (procfsnode_t *)OSMalloc(sizeof(procfsnode_t), procfs_osmalloc_tag); if (new_procfsnode == NULL) { // Allocation failure - bail. Nothing to clean up and // we don't hold the lock. error = ENOMEM; break; } // We got a new procfsnode. Relock the node hash, then go around the // loop again. This is necessary because someone else may have created // the same node after we dropped the lock. If that's the case, we'll // find that node next time around and we'll use it. The one we just // allocated will remain in target_procfsnode and will be freed before we return. lck_mtx_lock(procfsnode_hash_mutex); locked = TRUE; continue; } else { // If we get here, we know that we need to use the node that we // allocated last time around the loop, so promote it to target_procfsnode assert(locked); assert(new_procfsnode != NULL); target_procfsnode = new_procfsnode; // Initialize the new node. memset(target_procfsnode, 0, sizeof(procfsnode_t)); target_procfsnode->node_mnt_id = mount_id; target_procfsnode->node_id = node_id; target_procfsnode->node_structure_node = snode; // Add the node to the node hash. We already know which bucket // it belongs to. LIST_INSERT_HEAD(hash_bucket, target_procfsnode, node_hash); } } // At this point, we have a procfsnode_t, which either already existed // or was just created. We also have the lock for the node hash table. assert(target_procfsnode != NULL); assert(locked); // Check whether another thread is already in the process of creating a // vnode for this procfsnode_t. If it is, wait until it's done and go // around the loop again. if (target_procfsnode->node_attaching_vnode) { // Indicate that a wakeup is needed when the attaching thread // is done. target_procfsnode->node_thread_waiting_attach = TRUE; // Sleeping will drop and relock the mutex. msleep(target_procfsnode, procfsnode_hash_mutex, PINOD, "procfsnode_find", NULL); // Since anything can have changed while we were away, go around // the loop again. continue; } target_vnode = target_procfsnode->node_vnode; if (target_vnode != NULL) { // We already have a vnode. We need to check if it has been reassigned. // To do that, unlock and check the vnode id. uint32_t vid = vnode_vid(target_vnode); lck_mtx_unlock(procfsnode_hash_mutex); locked = FALSE; error = vnode_getwithvid(target_vnode, vid); if (error != 0) { // Vnode changed identity, so we need to redo everything. Relock // because we are expected to hold the lock at the top of the loop. // Getting here means that the vnode was reclaimed and the procfsnode // was removed from the hash and freed, so we will be restarting from scratch. lck_mtx_lock(procfsnode_hash_mutex); target_procfsnode = NULL; new_procfsnode = NULL; locked = TRUE; continue; } // The vnode was still present and has not changed id. All we need to do // is terminate the loop. We don't hold the lock, "locked" is FALSE and // we don't need to relock (and indeed doing so would introduce yet more // race conditions). vnode_getwithvid() added an iocount reference for us, // which the caller is expected to eventually release with vnode_put(). assert(error == 0); break; } // At this point, we have procfsnode_t in the node hash, but we don't have a // vnode. To create the vnode, we have to release the node hash lock and invoke // the caller's create_vnode_func callback. Before doing that, we need to set // node_attaching_vnode to force any other threads that come in here to wait for // this thread to create the vnode (or fail). target_procfsnode->node_attaching_vnode = TRUE; lck_mtx_unlock(procfsnode_hash_mutex); locked = FALSE; error = (*create_vnode_func)(create_vnode_params, target_procfsnode, &target_vnode); assert(error != 0 || target_vnode != NULL); // Relock the hash table and clear node_attaching_vnode now that we are // safely back from the caller's callback. lck_mtx_lock(procfsnode_hash_mutex); locked = TRUE; target_procfsnode->node_attaching_vnode = FALSE; // If there are threads waiting for the vnode attach to complete, // wake them up. if (target_procfsnode->node_thread_waiting_attach) { target_procfsnode->node_thread_waiting_attach = FALSE; wakeup(target_procfsnode); } // Now check whether we succeeded. if (error != 0) { // Failed to create the vnode -- this is fatal. // Remove the procfsnode_t from the hash table and // release it. procfsnode_free_node(target_procfsnode); new_procfsnode = NULL; // To avoid double free. break; } // We got the new vnode and it's already linked to the procfsnode_t. // Link the procfsnode_t to it. Also add a file system reference to // the vnode itself. target_procfsnode->node_vnode = target_vnode; vnode_addfsref(target_vnode); break; } // Unlock the hash table, if it is still locked. if (locked) { lck_mtx_unlock(procfsnode_hash_mutex); } // Free the node we allocated, if we didn't use it. We do this // *after* releasing the hash lock just in case it might block. if (new_procfsnode != NULL && new_procfsnode != target_procfsnode) { OSFree(new_procfsnode, sizeof(procfsnode_t), procfs_osmalloc_tag); } // Set the return value, or NULL if we failed. *pnpp = error == 0 ? target_procfsnode : NULL; *vnpp = error == 0 ? target_vnode : NULL; return error; }
int main(void) { TaskParametersDef *TaskParameters; /* Stop timer during debugger connection */ #if ZOTTAOS_TIMER == OS_IO_TIM17 DBGMCU_Config(DBGMCU_TIM17_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM16 DBGMCU_Config(DBGMCU_TIM16_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM15 DBGMCU_Config(DBGMCU_TIM15_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM14 DBGMCU_Config(DBGMCU_TIM14_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM13 DBGMCU_Config(DBGMCU_TIM13_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM12 DBGMCU_Config(DBGMCU_TIM12_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM11 DBGMCU_Config(DBGMCU_TIM11_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM10 DBGMCU_Config(DBGMCU_TIM10_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM9 DBGMCU_Config(DBGMCU_TIM9_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM8 DBGMCU_Config(DBGMCU_TIM8_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM5 DBGMCU_Config(DBGMCU_TIM5_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM4 DBGMCU_Config(DBGMCU_TIM4_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM3 DBGMCU_Config(DBGMCU_TIM3_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM2 DBGMCU_Config(DBGMCU_TIM2_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM1 DBGMCU_Config(DBGMCU_TIM1_STOP,ENABLE); #endif /* Keep debugger connection during sleep mode */ DBGMCU_Config(DBGMCU_SLEEP,ENABLE); /* Initialize Hardware */ SystemInit(); InitializeFlags(FLAG1_PIN | FLAG2_PIN | FLAG3_PIN); /* Create the 3 tasks. Notice that each particular task receives a private set of para- ** meters that it inherits from the main program and that it is the only task that can ** later access. */ #if defined(ZOTTAOS_VERSION_HARD) TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG1_PIN; TaskParameters->Delay = 150; OSCreateTask(FixedDelayTask,0,700,699,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG2_PIN; TaskParameters->Delay = 150; OSCreateTask(FixedDelayTask,0,700,700,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG3_PIN; TaskParameters->Delay = 7000; OSCreateTask(VariableDelayTask,0,2100,2100,TaskParameters); #elif defined(ZOTTAOS_VERSION_SOFT) TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG1_PIN; TaskParameters->Delay = 600; OSCreateTask(FixedDelayTask,200,0,700,250,1,3,0,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG2_PIN; TaskParameters->Delay = 600; OSCreateTask(FixedDelayTask,200,0,700,700,1,3,0,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG3_PIN; TaskParameters->Delay = 7000; OSCreateTask(VariableDelayTask,1600,0,2100,2100,1,1,0,TaskParameters); #endif /* Start the OS so that it starts scheduling the user tasks */ return OSStartMultitasking(); } /* end of main */
/*********************************************************************************************************** *Function Name: GPS_TrayInfo() *Attributes: *client IN Client identifier *num IN Number of the trayinfo[] arrays. Set the number of trays indicated in the information obtained * by gpsGetSysInfo() function. *trayinfo OUT Input Tray Information Structure *trayinfo_num OUT Returns the number of trays set to trayinfo[] array. *notify IN Set to receive / not receive event whenever there is a change in the information. *Description: This function obtains input tray information. ************************************************************************************************************/ int GPS_TrayInfo() { long trayNum; int nTrayIndex; #define YET_TO_FIND_0 200 #define YET_TO_FIND_1 201 #define YET_TO_FIND_2 202 #define YET_TO_FIND_3 203 #define YET_TO_FIND_4 204 #define YET_TO_FIND_5 205 #define YET_TO_FIND_6 206 #define YET_TO_FIND_7 207 #ifdef PMS_OIL_MERGE_DISABLE_MEM gpsTrayInfo = (gps_trayinfo_t*) OSMalloc(sysinfo.num_tray * sizeof(gps_trayinfo_t), PMS_MemoryPoolPMS); g_pstTrayInfo = (PMS_TyTrayInfo*) OSMalloc(sysinfo.num_tray * sizeof(PMS_TyTrayInfo), PMS_MemoryPoolPMS); #else gpsTrayInfo = (gps_trayinfo_t*) mmalloc(sysinfo.num_tray * sizeof(gps_trayinfo_t)); g_pstTrayInfo = (PMS_TyTrayInfo*) mmalloc(sysinfo.num_tray * sizeof(PMS_TyTrayInfo)); #endif if( -1 == gpsGetTrayInfo(gps_client, sysinfo.num_tray, gpsTrayInfo, &trayNum, GPS_NOTIFY_CHANGE_OFF) ) return -1; /* To do - Map SDK str from GPS Specification DB - 01.pdf : page no 37 */ /* gpsGetTrayInfo - page no 197 */ for(nTrayIndex = 0; nTrayIndex < trayNum; nTrayIndex++) { switch(gpsTrayInfo[nTrayIndex].id) { case 0: g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_MANUALFEED; break; case 1: g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_TRAY1; break; case 2: g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_TRAY2; break; case 3: g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_TRAY3; break; default: g_pstTrayInfo[nTrayIndex].eMediaSource = PMS_TRAY_AUTO; break; //Yet to map PMS_TRAY_BYPASS, PMS_TRAY_ENVELOPE } //Guess!!!!!! the paper size. /* GPS_CODE_NO_PAPER = 0, GPS_CODE_A0, GPS_CODE_A1, GPS_CODE_A2, GPS_CODE_A3, GPS_CODE_A4, GPS_CODE_A5, GPS_CODE_A6, GPS_CODE_A7, GPS_CODE_B0, GPS_CODE_B1, GPS_CODE_B2, GPS_CODE_B3, GPS_CODE_B4, GPS_CODE_B5, GPS_CODE_B6, GPS_CODE_B7, GPS_CODE_WMAIL, GPS_CODE_MAIL, GPS_CODE_LINE1, GPS_CODE_LINE2, GPS_CODE_LIB6, GPS_CODE_LIB8, GPS_CODE_210x170, GPS_CODE_210x182, GPS_CODE_267x388, GPS_CODE_FREEmm = 31, GPS_CODE_11x17, GPS_CODE_11x14, GPS_CODE_10x15, GPS_CODE_10x14, GPS_CODE_8Hx14, GPS_CODE_8Hx13, GPS_CODE_8Hx11, GPS_CODE_8Qx14, GPS_CODE_8Qx13, GPS_CODE_8x13, GPS_CODE_8x10H, GPS_CODE_8x10, GPS_CODE_5Hx8H, GPS_CODE_7Qx10H, GPS_CODE_12x18 = 47, GPS_CODE_12x14H, GPS_CODE_11x15, GPS_CODE_9Hx11, GPS_CODE_8Hx12, GPS_CODE_13x19, GPS_CODE_8KAI = 66, GPS_CODE_16KAI, GPS_CODE_NO_10 = 80, GPS_CODE_NO_7, GPS_CODE_C5 = 83, GPS_CODE_C6, GPS_CODE_DL, GPS_CODE_NO_SIZE = 128, GPS_CODE_A0T, GPS_CODE_A1T, GPS_CODE_A2T, GPS_CODE_A3T, GPS_CODE_A4T, GPS_CODE_A5T, GPS_CODE_A6T, GPS_CODE_A7T, GPS_CODE_B0T, GPS_CODE_B1T, GPS_CODE_B2T, GPS_CODE_B3T, GPS_CODE_B4T, GPS_CODE_B5T, GPS_CODE_B6T, GPS_CODE_B7T, GPS_CODE_WMAILT, GPS_CODE_MAILT, GPS_CODE_LINE1T, GPS_CODE_LINE2T, GPS_CODE_LIB6T, GPS_CODE_LIB8T, GPS_CODE_210x170T, GPS_CODE_210x182T, GPS_CODE_267x388T, GPS_CODE_FREEmmT = 159, GPS_CODE_11x17T, GPS_CODE_11x14T, GPS_CODE_10x15T, GPS_CODE_10x14T, GPS_CODE_8Hx14T, GPS_CODE_8Hx13T, GPS_CODE_8Hx11T, GPS_CODE_8Qx14T, GPS_CODE_8Qx13T, GPS_CODE_8x13T, GPS_CODE_8x10HT, GPS_CODE_8x10T, GPS_CODE_5Hx8HT, GPS_CODE_7Qx10HT, GPS_CODE_12x18T = 175, GPS_CODE_12x14HT, GPS_CODE_11x15T, GPS_CODE_9Hx11T, GPS_CODE_8Hx12T, GPS_CODE_13x19T, GPS_CODE_8KAIT = 194, GPS_CODE_16KAIT, GPS_CODE_NO_10T = 208, GPS_CODE_NO_7T, GPS_CODE_C5T = 211, GPS_CODE_C6T, GPS_CODE_DL_T */ switch(gpsTrayInfo[nTrayIndex].p_size) { case GPS_CODE_8Hx11: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LETTER; break; case GPS_CODE_A4: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A4; break; case GPS_CODE_8Hx14: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LEGAL; break; case GPS_CODE_7Qx10H: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_EXE; break; case GPS_CODE_A3: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A3; break; case GPS_CODE_11x17: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_TABLOID; break; case GPS_CODE_A5: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A5; break; case GPS_CODE_A6: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A6; break; case GPS_CODE_C5: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_C5_ENV; break; case GPS_CODE_DL: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_DL_ENV; break; case YET_TO_FIND_0: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LEDGER; break; case YET_TO_FIND_2: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_OFUKU; break; case GPS_CODE_10x14: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_JISB4; break; case YET_TO_FIND_3: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_JISB5; break; case GPS_CODE_8Hx11T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LETTER_R; break; case GPS_CODE_A4T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A4_R; break; case GPS_CODE_8Hx14T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LEGAL_R; break; case GPS_CODE_7Qx10HT: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_EXE_R; break; case GPS_CODE_A3T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A3_R; break; case GPS_CODE_11x17T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_TABLOID_R; break; case GPS_CODE_A5T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A5_R; break; case GPS_CODE_A6T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_A6_R; break; case GPS_CODE_C5T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_C5_ENV_R; break; case GPS_CODE_DL_T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_DL_ENV_R; break; case YET_TO_FIND_4: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_LEDGER_R; break; case YET_TO_FIND_5: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_OFUKU_R; break; case GPS_CODE_10x14T: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_JISB4_R; break; case YET_TO_FIND_6: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_JISB5_R; break; case YET_TO_FIND_7: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_CUSTOM; break; default: g_pstTrayInfo[nTrayIndex].ePaperSize = PMS_SIZE_DONT_KNOW; break; } switch(gpsTrayInfo[nTrayIndex].p_kind) { case DI_PAPER_NORMAL: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_PLAIN; break; case DI_PAPER_BOND: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_BOND; break; case DI_PAPER_SPECIAL: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_SPECIAL; break; case DI_PAPER_GLOSSY: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_GLOSSY; break; case DI_PAPER_OHP: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_TRANSPARENCY; break; case DI_PAPER_RECYCLE: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_RECYCLED; break; case DI_PAPER_MIDDLETHICK: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_THICK; break; case DI_PAPER_ENVELOPE: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_ENVELOPE; break; case DI_PAPER_POSTCARD: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_POSTCARD; break; case DI_PAPER_THIN: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_THIN; break; case DI_PAPER_LABEL: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_LABEL; break; case DI_PAPER_PREPRINT: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_PREPRINTED; break; case DI_PAPER_LETTER_HEAD: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_LETTERHEAD; break; default: g_pstTrayInfo[nTrayIndex].eMediaType = PMS_TYPE_DONT_KNOW; break; } g_pstTrayInfo[nTrayIndex].eMediaColor = PMS_COLOR_DONT_KNOW; /* yet to map */ g_pstTrayInfo[nTrayIndex].uMediaWeight = 0; /* yet to map */ g_pstTrayInfo[nTrayIndex].nPriority = nTrayIndex; /* assumption yet to conform. */ g_pstTrayInfo[nTrayIndex].bTrayEmptyFlag = (GPS_TRAY_PAPEREND == gpsTrayInfo[nTrayIndex].status); g_pstTrayInfo[nTrayIndex].nNoOfSheets = gpsTrayInfo[nTrayIndex].remain; } g_nInputTrays = sysinfo.num_tray; #ifdef PMS_OIL_MERGE_DISABLE_MEM OSFree( gpsTrayInfo, PMS_MemoryPoolPMS ); #else mfree( gpsTrayInfo ); #endif gpsTrayInfo = NULL; return 0; }
/** * \brief Open the next file. * * Opens the file contaning next job data.\n */ int File_OpenDataStream(void) { /* PMS_SHOW("File_OpenDataStream()\n"); */ if(!GetNextFilename(szJobFilename)) return -1; /* -1 means don't try opening this module again */ if ( (l_fileCurrent = fopen((char *)szJobFilename, "rb") ) == NULL ) { PMS_SHOW_ERROR(" ***ASSERT*** File_OpenDataStream: Failed to open file %s \n", szJobFilename); return 0; /* 0 means you may try this module again to try the next job */ } if(g_tSystemInfo.nStoreJobBeforeRip) { int nRead; int nChunk = 16 * 1024; PMS_SHOW("Storing job before passing to rip...\n"); l_pStoreBuffer = OSMalloc(g_tSystemInfo.cbReceiveBuffer,PMS_MemoryPoolMisc); if(!l_pStoreBuffer) { PMS_SHOW_ERROR(" ***ASSERT*** File_OpenDataStream: Failed to allocate buffer for storing job\n"); fclose(l_fileCurrent); l_fileCurrent = NULL; return 0; /* 0 means you may try this module again to try the next job */ } fseek(l_fileCurrent,0,SEEK_END); l_nStoreBufferUsed = ftell(l_fileCurrent); fseek(l_fileCurrent,0,SEEK_SET); if(l_nStoreBufferUsed > g_tSystemInfo.cbReceiveBuffer) { PMS_SHOW_ERROR(" ***ASSERT*** File_OpenDataStream: Failed to store job. Job size is larger than the memory buffer.\n"); fclose(l_fileCurrent); l_fileCurrent = NULL; OSFree(l_pStoreBuffer, PMS_MemoryPoolMisc); l_pStoreBuffer = NULL; return 0; /* 0 means you may try this module again to try the next job */ } l_nStoreBufferUsed = 0; l_nStoreBufferPos = 0; do { if((l_nStoreBufferUsed + nChunk) < g_tSystemInfo.cbReceiveBuffer) { nRead = (int)fread(l_pStoreBuffer + l_nStoreBufferUsed, 1, nChunk, l_fileCurrent); } else if(l_nStoreBufferUsed < g_tSystemInfo.cbReceiveBuffer) { nRead = (int)fread(l_pStoreBuffer + l_nStoreBufferUsed, 1, g_tSystemInfo.cbReceiveBuffer - l_nStoreBufferUsed, l_fileCurrent); } else { nRead = 0; } l_nStoreBufferUsed += nRead; } while (nRead>0); fclose(l_fileCurrent); l_fileCurrent = NULL; PMS_SHOW("Stored %d bytes.\n", l_nStoreBufferUsed); } return 1; /* 1 means we have a job ready to rip */ }
int main(void) { TaskParametersDef *TaskParameters; WDTCTL = WDTPW + WDTHOLD; // Disable watchdog timer // Initialize output I/O ports P1OUT = 0x00; // Initially start at low P1DIR = 0x07; // Set to output /* Set the system clock characteristics */ OSInitializeSystemClocks(); /* Create the 3 tasks. Notice that each particular task receives a private set of para- ** meters that it inherits from the main program and that it is the only task that can ** later access. */ #if defined(ZOTTAOS_VERSION_HARD) /* Calculation of the total load: ** 1250 / 5000 -> 25% ** 2500 / 10000 -> 25% ** 12000 / 30000 -> 40% ** Total: 90% */ TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x1; TaskParameters->Delay = 600; // wcet 1250 OSCreateTask(FixedDelayTask,0,5000,5000,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x2; TaskParameters->Delay = 1200; // wcet 2500 OSCreateTask(FixedDelayTask,0,10000,10000,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x4; TaskParameters->Delay = 7000; // wcet 12000 OSCreateTask(VariableDelayTask,0,30000,30000,TaskParameters); #elif defined(ZOTTAOS_VERSION_SOFT) /* Calculation of the total load: ** Without ZottaOS-Soft capabilities: ** 1250 / 5000 -> 25% ** 2500 / 10000 -> 25% ** 24000 / 30000 -> 80% ** Total: 130% (Task set is NOT schedulable) ** With ZottaOS-Soft capabilities: ** 1250 / 5000 / 3 -> 8% ** 2500 / 10000 / 3 -> 8% ** 24000 / 30000 / 1 -> 80% ** Total: 96% (Task set is schedulable) */ TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x1; TaskParameters->Delay = 600; // wcet 1250 OSCreateTask(FixedDelayTask,1250,0,5000,5000,1,3,2,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x2; TaskParameters->Delay = 1200; // wcet 2500 OSCreateTask(FixedDelayTask,2500,0,10000,10000,1,3,0,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIO_Pin = 0x4; TaskParameters->Delay = 13500; // wcet 2400 OSCreateTask(VariableDelayTask,2400,0,30000,30000,1,1,0,TaskParameters); #else #error Wrong kernel version #endif /* Start the OS so that it starts scheduling the user tasks */ return OSStartMultitasking(NULL,NULL); } /* end of main */
int main(void) { TaskParametersDef *TaskParameters; // Enable debug module clock RCC_APB2PeriphClockCmd(RCC_APB2Periph_DBGMCU, ENABLE); /* Stop timer during debugger connection */ #if ZOTTAOS_TIMER == OS_IO_TIM17 DBGMCU_APB2PeriphConfig(DBGMCU_TIM17_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM16 DBGMCU_APB2PeriphConfig(DBGMCU_TIM16_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM15 DBGMCU_APB2PeriphConfig(DBGMCU_TIM15_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM14 DBGMCU_APB1PeriphConfig(DBGMCU_TIM14_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM3 DBGMCU_APB1PeriphConfig(DBGMCU_TIM3_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM2 DBGMCU_APB1PeriphConfig(DBGMCU_TIM2_STOP,ENABLE); #elif ZOTTAOS_TIMER == OS_IO_TIM1 DBGMCU_APB2PeriphConfig(DBGMCU_TIM1_STOP,ENABLE); #endif /* Initialize Hardware */ SystemInit(); InitializeFlags(FLAG1_PIN | FLAG2_PIN | FLAG3_PIN); /* Create the 3 tasks. Notice that each particular task receives a private set of para- ** meters that it inherits from the main program and that it is the only task that can ** later access. */ #if defined(ZOTTAOS_VERSION_HARD) /* Calculation of the total load: ** 1250 / 5000 -> 25% ** 2500 / 10000 -> 25% ** 12000 / 30000 -> 40% ** Total: 90% */ TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG1_PIN; TaskParameters->Delay = 350; OSCreateTask(FixedDelayTask,0,500,500,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG2_PIN; TaskParameters->Delay = 700; OSCreateTask(FixedDelayTask,0,1000,1000,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG3_PIN; TaskParameters->Delay = 3000; OSCreateTask(VariableDelayTask,0,3000,3000,TaskParameters); #elif defined(ZOTTAOS_VERSION_SOFT) /* Calculation of the total load: ** Without ZottaOS-Soft capabilities: ** 1250 / 5000 -> 25% ** 2500 / 10000 -> 25% ** 24000 / 30000 -> 80% ** Total: 130% (Task set is NOT schedulable) ** With ZottaOS-Soft capabilities: ** 1250 / 5000 / 3 -> 8% ** 2500 / 10000 / 3 -> 8% ** 24000 / 30000 / 1 -> 80% ** Total: 96% (Task set is schedulable) */ TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG1_PIN; TaskParameters->Delay = 300; OSCreateTask(FixedDelayTask,125,0,500,500,1,2,0,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG2_PIN; TaskParameters->Delay = 600; OSCreateTask(FixedDelayTask,250,0,1000,1000,1,3,0,TaskParameters); TaskParameters = (TaskParametersDef *)OSMalloc(sizeof(TaskParametersDef)); TaskParameters->GPIOx = FLAG_PORT; TaskParameters->GPIO_Pin = FLAG3_PIN; TaskParameters->Delay = 5000; OSCreateTask(VariableDelayTask,2400,0,3000,3000,1,1,0,TaskParameters); #endif /* Start the OS so that it starts scheduling the user tasks */ return OSStartMultitasking(NULL,NULL); } /* end of main */