diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2011-03-02 08:49:38 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2011-03-02 08:49:38 +0000 |
commit | 12375d1d3aa41f7d277a9af584c7b810b636ec95 (patch) | |
tree | fc9ce8029a6910a8dac71b3bf60c71155a01eea4 /firmware/target/arm/as3525 | |
parent | 05e180a1308a095d51d51d0e047fcd44425ea88f (diff) |
Merge functionality of wakeups and semaphores-- fewer APIs and object types. semaphore_wait takes a timeout now so codecs and plugins have to be made incompatible. Don't make semaphores for targets not using them.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29492 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/target/arm/as3525')
-rw-r--r-- | firmware/target/arm/as3525/ascodec-as3525.c | 27 | ||||
-rw-r--r-- | firmware/target/arm/as3525/ascodec-target.h | 2 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525.c | 12 | ||||
-rw-r--r-- | firmware/target/arm/as3525/sd-as3525v2.c | 16 | ||||
-rw-r--r-- | firmware/target/arm/as3525/usb-drv-as3525.c | 24 | ||||
-rw-r--r-- | firmware/target/arm/as3525/usb-drv-as3525.h | 2 | ||||
-rw-r--r-- | firmware/target/arm/as3525/usb-drv-as3525v2.c | 22 |
7 files changed, 55 insertions, 50 deletions
diff --git a/firmware/target/arm/as3525/ascodec-as3525.c b/firmware/target/arm/as3525/ascodec-as3525.c index 822d48e241..39658c0637 100644 --- a/firmware/target/arm/as3525/ascodec-as3525.c +++ b/firmware/target/arm/as3525/ascodec-as3525.c @@ -107,7 +107,7 @@ struct ascodec_request { unsigned char status; unsigned char cnt; unsigned char data[ASCODEC_REQ_MAXLEN]; - struct wakeup wkup; + struct semaphore complete; ascodec_cb_fn *callback; struct ascodec_request *next; }; @@ -121,7 +121,7 @@ static unsigned char *req_data_ptr = NULL; static struct ascodec_request *req_head = NULL; static struct ascodec_request *req_tail = NULL; -static struct wakeup adc_wkup; +static struct semaphore adc_done_sem; static struct ascodec_request as_audio_req; #ifdef DEBUG @@ -168,7 +168,7 @@ static void ascodec_finish_req(struct ascodec_request *req) if (req->callback) { req->callback(req->data, req_data_ptr - req->data); } - wakeup_signal(&req->wkup); + semaphore_release(&req->complete); req_head = req->next; req->next = NULL; @@ -263,7 +263,7 @@ void ascodec_init(void) int prescaler; mutex_init(&as_mtx); - wakeup_init(&adc_wkup); + semaphore_init(&adc_done_sem, 1, 0); /* enable clock */ bitset32(&CGU_PERI, CGU_I2C_AUDIO_MASTER_CLOCK_ENABLE); @@ -312,7 +312,7 @@ void ascodec_init(void) static void ascodec_req_init(struct ascodec_request *req, int type, unsigned int index, unsigned int cnt) { - wakeup_init(&req->wkup); + semaphore_init(&req->complete, 1, 0); req->next = NULL; req->callback = NULL; req->type = type; @@ -337,19 +337,10 @@ static void ascodec_submit(struct ascodec_request *req) restore_irq(oldlevel); } -static int irq_disabled(void) -{ - unsigned long cpsr; - - asm volatile ("mrs %0, cpsr" : "=r"(cpsr)); - - return (cpsr & IRQ_STATUS) == IRQ_DISABLED; -} - static void ascodec_wait(struct ascodec_request *req) { - if (!irq_disabled()) { - wakeup_wait(&req->wkup, TIMEOUT_BLOCK); + if (irq_enabled()) { + semaphore_wait(&req->complete, TIMEOUT_BLOCK); return; } @@ -477,7 +468,7 @@ static void ascodec_read_cb(unsigned const char *data, unsigned int len) } if (data[2] & IRQ_ADC) { /* adc finished */ IFDEBUG(int_adc++); - wakeup_signal(&adc_wkup); + semaphore_release(&adc_done_sem); } VIC_INT_ENABLE = INTERRUPT_AUDIO; } @@ -492,7 +483,7 @@ void INT_AUDIO(void) void ascodec_wait_adc_finished(void) { - wakeup_wait(&adc_wkup, TIMEOUT_BLOCK); + semaphore_wait(&adc_done_sem, TIMEOUT_BLOCK); } #ifdef CONFIG_CHARGING diff --git a/firmware/target/arm/as3525/ascodec-target.h b/firmware/target/arm/as3525/ascodec-target.h index 7c47bd7e9c..85c3d1c103 100644 --- a/firmware/target/arm/as3525/ascodec-target.h +++ b/firmware/target/arm/as3525/ascodec-target.h @@ -28,7 +28,7 @@ #ifndef SIMULATOR #include "as3514.h" -#include "kernel.h" /* for struct wakeup */ +#include "kernel.h" /* for struct semaphore */ #include "clock-target.h" /* for AS3525_I2C_PRESCALER */ #include "system-arm.h" diff --git a/firmware/target/arm/as3525/sd-as3525.c b/firmware/target/arm/as3525/sd-as3525.c index 5a6e0df39a..a2d20c36fa 100644 --- a/firmware/target/arm/as3525/sd-as3525.c +++ b/firmware/target/arm/as3525/sd-as3525.c @@ -136,7 +136,7 @@ static bool hs_card = false; #define EXT_SD_BITS (1<<2) #endif -static struct wakeup transfer_completion_signal; +static struct semaphore transfer_completion_signal; static volatile unsigned int transfer_error[NUM_VOLUMES]; #define PL180_MAX_TRANSFER_ERRORS 10 @@ -191,7 +191,7 @@ void INT_NAND(void) transfer_error[INTERNAL_AS3525] = status & MCI_DATA_ERROR; - wakeup_signal(&transfer_completion_signal); + semaphore_release(&transfer_completion_signal); MCI_CLEAR(INTERNAL_AS3525) = status; } @@ -202,7 +202,7 @@ void INT_MCI0(void) transfer_error[SD_SLOT_AS3525] = status & MCI_DATA_ERROR; - wakeup_signal(&transfer_completion_signal); + semaphore_release(&transfer_completion_signal); MCI_CLEAR(SD_SLOT_AS3525) = status; } #endif @@ -568,7 +568,7 @@ int sd_init(void) bitset32(&CCU_IO, 1<<2); #endif - wakeup_init(&transfer_completion_signal); + semaphore_init(&transfer_completion_signal, 1, 0); init_pl180_controller(INTERNAL_AS3525); ret = sd_init_card(INTERNAL_AS3525); @@ -678,7 +678,7 @@ static int sd_select_bank(signed char bank) (9<<4) /* 2^9 = 512 */ ; /* Wakeup signal from NAND/MCIO isr on MCI_DATA_ERROR | MCI_DATA_END */ - wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK); + semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK); /* Wait for FIFO to empty, card may still be in PRG state */ while(MCI_STATUS(INTERNAL_AS3525) & MCI_TX_ACTIVE ); @@ -837,7 +837,7 @@ static int sd_transfer_sectors(IF_MD2(int drive,) unsigned long start, (9<<4) /* 2^9 = 512 */ ; /* Wakeup signal from NAND/MCIO isr on MCI_DATA_ERROR | MCI_DATA_END */ - wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK); + semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK); /* Wait for FIFO to empty, card may still be in PRG state for writes */ while(MCI_STATUS(drive) & MCI_TX_ACTIVE); diff --git a/firmware/target/arm/as3525/sd-as3525v2.c b/firmware/target/arm/as3525/sd-as3525v2.c index 70d7c8fda1..b863337cbc 100644 --- a/firmware/target/arm/as3525/sd-as3525v2.c +++ b/firmware/target/arm/as3525/sd-as3525v2.c @@ -342,8 +342,8 @@ static struct event_queue sd_queue; bool sd_enabled = false; #endif -static struct wakeup transfer_completion_signal; -static struct wakeup command_completion_signal; +static struct semaphore transfer_completion_signal; +static struct semaphore command_completion_signal; static volatile bool retry; static volatile int cmd_error; @@ -365,12 +365,12 @@ void INT_NAND(void) retry = true; if( status & (MCI_INT_DTO|MCI_DATA_ERROR)) - wakeup_signal(&transfer_completion_signal); + semaphore_release(&transfer_completion_signal); cmd_error = status & MCI_CMD_ERROR; if(status & MCI_INT_CD) - wakeup_signal(&command_completion_signal); + semaphore_release(&command_completion_signal); MCI_CTRL |= INT_ENABLE; } @@ -442,7 +442,7 @@ static bool send_cmd(const int drive, const int cmd, const int arg, const int fl _buttonlight_off(); } #endif - wakeup_wait(&command_completion_signal, TIMEOUT_BLOCK); + semaphore_wait(&command_completion_signal, TIMEOUT_BLOCK); /* Handle command responses & errors */ if(flags & MCI_RESP) @@ -769,8 +769,8 @@ int sd_init(void) | (AS3525_SDSLOT_DIV << 2) | 1; /* clock source = PLLA */ - wakeup_init(&transfer_completion_signal); - wakeup_init(&command_completion_signal); + semaphore_init(&transfer_completion_signal, 1, 0); + semaphore_init(&command_completion_signal, 1, 0); #if defined(SANSA_FUZEV2) || defined(SANSA_CLIPPLUS) if (amsv2_variant == 1) @@ -932,7 +932,7 @@ sd_transfer_retry_with_reinit: goto sd_transfer_error; } - wakeup_wait(&transfer_completion_signal, TIMEOUT_BLOCK); + semaphore_wait(&transfer_completion_signal, TIMEOUT_BLOCK); last_disk_activity = current_tick; diff --git a/firmware/target/arm/as3525/usb-drv-as3525.c b/firmware/target/arm/as3525/usb-drv-as3525.c index 2e5330ec1b..69c50cda93 100644 --- a/firmware/target/arm/as3525/usb-drv-as3525.c +++ b/firmware/target/arm/as3525/usb-drv-as3525.c @@ -40,6 +40,7 @@ static struct usb_endpoint endpoints[USB_NUM_EPS][2]; static int got_set_configuration = 0; static int usb_enum_timeout = -1; +static bool initialized = false; /* * dma/setup descriptors and buffers should avoid sharing @@ -180,19 +181,19 @@ static void reset_endpoints(int init) if (endpoints[i][0].state & EP_STATE_BUSY) { if (endpoints[i][0].state & EP_STATE_ASYNC) { endpoints[i][0].rc = -1; - wakeup_signal(&endpoints[i][0].complete); + semaphore_release(&endpoints[i][0].complete); } else { usb_core_transfer_complete(i, USB_DIR_IN, -1, 0); } } endpoints[i][0].state = 0; - wakeup_init(&endpoints[i][0].complete); + semaphore_wait(&endpoints[i][0].complete, TIMEOUT_NOBLOCK); if (i != 2) { /* Skip the OUT EP0 alias */ if (endpoints[i][1].state & EP_STATE_BUSY) usb_core_transfer_complete(i, USB_DIR_OUT, -1, 0); endpoints[i][1].state = 0; - wakeup_init(&endpoints[i][1].complete); + semaphore_wait(&endpoints[i][1].complete, TIMEOUT_NOBLOCK); USB_OEP_SUP_PTR(i) = 0; } } @@ -225,6 +226,18 @@ void usb_drv_init(void) { logf("usb_drv_init() !!!!\n"); + if (!initialized) + { + int i; + for (i = 0; i < USB_NUM_EPS; i++) + { + semaphore_init(&endpoints[i][0].complete, 1, 0); + semaphore_init(&endpoints[i][1].complete, 1, 0); + } + + initialized = true; + } + usb_enable_pll(); /* we have external power, so boost cpu */ @@ -322,6 +335,7 @@ void usb_drv_exit(void) ascodec_write(AS3515_USB_UTIL, ascodec_read(AS3515_USB_UTIL) & ~(1<<4)); usb_disable_pll(); cpu_boost(0); + initialized = false; logf("usb_drv_exit() !!!!\n"); } @@ -529,7 +543,7 @@ int usb_drv_send(int ep, void *ptr, int len) } ep_send(ep, ptr, len); - if (wakeup_wait(&endpoints[ep][0].complete, HZ) == OBJ_WAIT_TIMEDOUT) + if (semaphore_wait(&endpoints[ep][0].complete, HZ) == OBJ_WAIT_TIMEDOUT) logf("send timed out!\n"); return endpoints[ep][0].rc; @@ -570,7 +584,7 @@ static void handle_in_ep(int ep) endpoints[ep][0].state &= ~EP_STATE_ASYNC; usb_core_transfer_complete(ep, USB_DIR_IN, 0, endpoints[ep][0].len); } else { - wakeup_signal(&endpoints[ep][0].complete); + semaphore_release(&endpoints[ep][0].complete); } ep_sts &= ~USB_EP_STAT_TDC; } diff --git a/firmware/target/arm/as3525/usb-drv-as3525.h b/firmware/target/arm/as3525/usb-drv-as3525.h index 960b023039..0f8b3c0668 100644 --- a/firmware/target/arm/as3525/usb-drv-as3525.h +++ b/firmware/target/arm/as3525/usb-drv-as3525.h @@ -310,7 +310,7 @@ struct usb_endpoint unsigned int len; volatile unsigned int state; int rc; - struct wakeup complete; + struct semaphore complete; struct usb_dev_dma_desc *uc_desc; }; diff --git a/firmware/target/arm/as3525/usb-drv-as3525v2.c b/firmware/target/arm/as3525/usb-drv-as3525v2.c index 78dc2a603f..24548f30c5 100644 --- a/firmware/target/arm/as3525/usb-drv-as3525v2.c +++ b/firmware/target/arm/as3525/usb-drv-as3525v2.c @@ -61,7 +61,7 @@ static const uint8_t out_ep_list[NUM_OUT_EP + 1] = {0, OUT_EP_LIST}; struct usb_endpoint { unsigned int len; /* length of the data buffer */ - struct wakeup complete; /* wait object */ + struct semaphore complete; /* wait object */ int8_t status; /* completion status (0 for success) */ bool active; /* true is endpoint has been requested (true for EP0) */ bool wait; /* true if usb thread is blocked on completion */ @@ -281,7 +281,7 @@ static void reset_endpoints(void) if(endpoints[ep][DIR_IN].wait) { endpoints[ep][DIR_IN].wait = false; - wakeup_signal(&endpoints[ep][DIR_IN].complete); + semaphore_release(&endpoints[ep][DIR_IN].complete); } if(DIEPCTL(ep) & DEPCTL_epena) DIEPCTL(ep) = DEPCTL_snak; @@ -297,7 +297,7 @@ static void reset_endpoints(void) if(endpoints[ep][DIR_OUT].wait) { endpoints[ep][DIR_OUT].wait = false; - wakeup_signal(&endpoints[ep][DIR_OUT].complete); + semaphore_release(&endpoints[ep][DIR_OUT].complete); } if(DOEPCTL(ep) & DEPCTL_epena) DOEPCTL(ep) = DEPCTL_snak; @@ -329,7 +329,7 @@ static void cancel_all_transfers(bool cancel_ep0) if(endpoints[ep][DIR_IN].wait) { endpoints[ep][DIR_IN].wait = false; - wakeup_signal(&endpoints[ep][DIR_IN].complete); + semaphore_release(&endpoints[ep][DIR_IN].complete); } DIEPCTL(ep) = (DIEPCTL(ep) & ~DEPCTL_usbactep) | DEPCTL_snak; } @@ -340,7 +340,7 @@ static void cancel_all_transfers(bool cancel_ep0) if(endpoints[ep][DIR_OUT].wait) { endpoints[ep][DIR_OUT].wait = false; - wakeup_signal(&endpoints[ep][DIR_OUT].complete); + semaphore_release(&endpoints[ep][DIR_OUT].complete); } DOEPCTL(ep) = (DOEPCTL(ep) & ~DEPCTL_usbactep) | DEPCTL_snak; } @@ -457,9 +457,9 @@ void usb_drv_init(void) /* Core init */ core_init(); FOR_EACH_IN_EP_AND_EP0(i, ep) - wakeup_init(&endpoints[ep][DIR_IN].complete); + semaphore_init(&endpoints[ep][DIR_IN].complete, 1, 0); FOR_EACH_OUT_EP_AND_EP0(i, ep) - wakeup_init(&endpoints[ep][DIR_OUT].complete); + semaphore_init(&endpoints[ep][DIR_OUT].complete, 1, 0); /* Enable global interrupts */ enable_global_interrupts(); } @@ -498,7 +498,7 @@ static void handle_ep_in_int(int ep) if(endpoint->wait) { endpoint->wait = false; - wakeup_signal(&endpoint->complete); + semaphore_release(&endpoint->complete); } } } @@ -515,7 +515,7 @@ static void handle_ep_in_int(int ep) if(endpoint->wait) { endpoint->wait = false; - wakeup_signal(&endpoint->complete); + semaphore_release(&endpoint->complete); } } } @@ -549,7 +549,7 @@ static void handle_ep_out_int(int ep) if(endpoint->wait) { endpoint->wait = false; - wakeup_signal(&endpoint->complete); + semaphore_release(&endpoint->complete); } } } @@ -798,7 +798,7 @@ static int usb_drv_transfer(int ep, void *ptr, int len, bool dir_in, bool blocki if(blocking) { - wakeup_wait(&endpoint->complete, TIMEOUT_BLOCK); + semaphore_wait(&endpoint->complete, TIMEOUT_BLOCK); return endpoint->status; } |