dwc_tasklet_t *DWC_TASK_ALLOC(char *name, dwc_tasklet_callback_t cb, void *data) { dwc_tasklet_t *t = DWC_ALLOC(sizeof(*t)); if (t == NULL) { return NULL; } t->cb = cb; t->data = data; return t; }
void *__DWC_DMA_ALLOC(void *dma_ctx, uint32_t size, dwc_dma_t * dma_addr) { void *buf = DWC_ALLOC(size); if (!buf) { return NULL; } *dma_addr = (dwc_dma_t) buf; DWC_MEMSET(buf, 0, size); return buf; }
/* Computes the modular exponentiation (num^exp % mod). num, exp, and mod are * big endian numbers of size len, in bytes. Each len value must be a multiple * of 4. */ int dwc_dh_modpow(void *num, uint32_t num_len, void *exp, uint32_t exp_len, void *mod, uint32_t mod_len, void *out) { /* modpow() takes little endian numbers. AM uses big-endian. This * function swaps bytes of numbers before passing onto modpow. */ int retval = 0; uint32_t *result; uint32_t *bignum_num = DWC_ALLOC(num_len + 4); uint32_t *bignum_exp = DWC_ALLOC(exp_len + 4); uint32_t *bignum_mod = DWC_ALLOC(mod_len + 4); dh_swap_bytes(num, &bignum_num[1], num_len); bignum_num[0] = num_len / 4; dh_swap_bytes(exp, &bignum_exp[1], exp_len); bignum_exp[0] = exp_len / 4; dh_swap_bytes(mod, &bignum_mod[1], mod_len); bignum_mod[0] = mod_len / 4; result = dwc_modpow(bignum_num, bignum_exp, bignum_mod); if (!result) { retval = -1; goto dh_modpow_nomem; } dh_swap_bytes(&result[1], out, result[0] * 4); DWC_FREE(result); dh_modpow_nomem: DWC_FREE(bignum_num); DWC_FREE(bignum_exp); DWC_FREE(bignum_mod); return retval; }
dwc_timer_t *DWC_TIMER_ALLOC(char *name, dwc_timer_callback_t cb, void *data) { dwc_timer_t *t = DWC_ALLOC(sizeof(*t)); /*OS_ERR_TYPE err;*/ if (t == NULL) { DWC_ERROR("Cannot allocate memory for timer"); return NULL; } t->lock = DWC_SPINLOCK_ALLOC(); if (!t->lock) { DWC_ERROR("Cannot allocate memory for lock"); goto no_lock; } t->scheduled = 0; t->cb = cb; t->data = data; /*t->t = timer_create(timer_callback, (void *)t, 0, 0, 0, &err); if (err == E_OS_ERR) { DWC_ERROR("Cannot allocate memory for timer->t"); goto no_timer; }*/ return t; /* no_timer: */ DWC_SPINLOCK_FREE(t->lock); no_lock: DWC_FREE(t); return NULL; }